@everyprotocol/every-cli 0.1.5 → 0.1.7
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/cmds/pick.js +130 -0
- package/dist/commander-patch.js +3 -4
- package/dist/logger.js +1 -1
- package/dist/program.js +3 -1
- package/package.json +3 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import jp from "jsonpath";
|
|
4
|
+
import * as _ from "lodash-es";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { loadMergedConfig } from "../config.js";
|
|
7
|
+
const DEFAULT_DIR = "./register";
|
|
8
|
+
const DEFAULT_UNIVERSE = "anvil";
|
|
9
|
+
const STATIC_RULES = {
|
|
10
|
+
// config
|
|
11
|
+
"universe.id": { file: "config://universe.json", root: "$", field: "id" },
|
|
12
|
+
"universe.sreg": { file: "config://universe.json", root: "$", field: "contracts.SetRegistry" },
|
|
13
|
+
"universe.oreg": { file: "config://universe.json", root: "$", field: "contracts.OmniRegistry" },
|
|
14
|
+
"universe.kreg": { file: "config://universe.json", root: "$", field: "contracts.KindRegistry" },
|
|
15
|
+
"universe.ereg": { file: "config://universe.json", root: "$", field: "contracts.ElementRegistry" },
|
|
16
|
+
"universe.minter": { file: "config://universe.json", root: "$", field: "contracts.ObjectMinter" },
|
|
17
|
+
"universe.rpc": { file: "config://universe.json", root: "$", field: "rpc" },
|
|
18
|
+
"universe.observer": { file: "config://universe.json", root: "$", field: "observer" },
|
|
19
|
+
// contract
|
|
20
|
+
"deploy.addr": { file: "deploy.json", root: "$", field: "deployedTo" },
|
|
21
|
+
"contract.addr": { file: "contract.json", root: "$", field: "deployedTo" },
|
|
22
|
+
// kind
|
|
23
|
+
"kind.id": { file: "kind.json", root: "$.events[?(@.name=='KindRegistered')].data", field: "id" },
|
|
24
|
+
"kind.rev": { file: "kind.json", root: "$.events[?(@.name=='KindRegistered')].data.desc", field: "rev" },
|
|
25
|
+
"kind.krev": { file: "kind.json", root: "$.events[?(@.name=='KindRegistered')].data.desc", field: "kindRev" },
|
|
26
|
+
"kind.srev": { file: "kind.json", root: "$.events[?(@.name=='KindRegistered')].data.desc", field: "setRev" },
|
|
27
|
+
// set
|
|
28
|
+
"set.id": { file: "set.json", root: "$.events[?(@.name=='SetRegistered')].data", field: "id" },
|
|
29
|
+
"set.rev": { file: "set.json", root: "$.events[?(@.name=='SetRegistered')].data.desc", field: "rev" },
|
|
30
|
+
"set.krev": { file: "set.json", root: "$.events[?(@.name=='SetRegistered')].data.desc", field: "kindRev" },
|
|
31
|
+
"set.srev": { file: "set.json", root: "$.events[?(@.name=='SetRegistered')].data.desc", field: "setRev" },
|
|
32
|
+
// matter: first entry’s MatterRegistered by default
|
|
33
|
+
"matter.hash": { file: "matter.json", root: "$[0].events[?(@.event=='MatterRegistered')].data", field: "1" },
|
|
34
|
+
"matter.who": { file: "matter.json", root: "$[0].events[?(@.event=='MatterRegistered')].data", field: "0" },
|
|
35
|
+
};
|
|
36
|
+
function dynamicRule(key) {
|
|
37
|
+
const esc = (s) => s.replace(/'/g, "\\'");
|
|
38
|
+
// hash=<path> → hashes.json: find by .path and return .hash
|
|
39
|
+
{
|
|
40
|
+
const m = key.match(/^hash=(.+)$/);
|
|
41
|
+
if (m) {
|
|
42
|
+
const filePath = esc(m[1]);
|
|
43
|
+
return {
|
|
44
|
+
file: "hashes.json",
|
|
45
|
+
root: `$[?(@.path=='${filePath}')]`,
|
|
46
|
+
field: "hash",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// matter.hash=<path> → matter.json: find entry by .file, then MatterRegistered.data[1]
|
|
51
|
+
{
|
|
52
|
+
const m = key.match(/^matter\.hash=(.+)$/);
|
|
53
|
+
if (m) {
|
|
54
|
+
const filePath = esc(m[1]);
|
|
55
|
+
return {
|
|
56
|
+
file: "matter.json",
|
|
57
|
+
root: `$[?(@.file=='${filePath}')].events[?(@.event=='MatterRegistered')].data`,
|
|
58
|
+
field: "1",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// matter.who=<path> → matter.json: find entry by .file, then MatterRegistered.data[0]
|
|
63
|
+
{
|
|
64
|
+
const m = key.match(/^matter\.who=(.+)$/);
|
|
65
|
+
if (m) {
|
|
66
|
+
const filePath = esc(m[1]);
|
|
67
|
+
return {
|
|
68
|
+
file: "matter.json",
|
|
69
|
+
root: `$[?(@.file=='${filePath}')].events[?(@.event=='MatterRegistered')].data`,
|
|
70
|
+
field: "0",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
function resolveRule(key) {
|
|
77
|
+
let rule = dynamicRule(key);
|
|
78
|
+
if (rule)
|
|
79
|
+
return rule;
|
|
80
|
+
rule = STATIC_RULES[key];
|
|
81
|
+
if (!rule)
|
|
82
|
+
throw new Error(`Unknown key: ${key}`);
|
|
83
|
+
return rule;
|
|
84
|
+
}
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
function pickOnce(getData, key) {
|
|
87
|
+
const rule = resolveRule(key);
|
|
88
|
+
const data = getData(rule.file);
|
|
89
|
+
const roots = jp.query(data, rule.root);
|
|
90
|
+
if (roots.length === 0) {
|
|
91
|
+
throw new Error(`Root not found for key "${key}": ${rule.root} in ${rule.file}`);
|
|
92
|
+
}
|
|
93
|
+
// Pick the first matched root
|
|
94
|
+
const obj = roots[0];
|
|
95
|
+
const value = rule.field ? _.get(obj, rule.field) : obj;
|
|
96
|
+
if (value === undefined) {
|
|
97
|
+
throw new Error(`Field not found for key "${key}": ${rule.field} in ${rule.file}`);
|
|
98
|
+
}
|
|
99
|
+
return String(value);
|
|
100
|
+
}
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
+
function loadJson(fullPath) {
|
|
103
|
+
const raw = fs.readFileSync(fullPath, "utf8");
|
|
104
|
+
return JSON.parse(raw);
|
|
105
|
+
}
|
|
106
|
+
export const pickCmd = new Command("pick")
|
|
107
|
+
.description("Pick values from outputs")
|
|
108
|
+
.argument("<keys...>", "Keys to resolve")
|
|
109
|
+
.option("--from <dir>", "Output directory", DEFAULT_DIR)
|
|
110
|
+
.option("-u, --universe <name>", "Universe name", DEFAULT_UNIVERSE)
|
|
111
|
+
.action(function (keys) {
|
|
112
|
+
const { from, universe } = this.opts();
|
|
113
|
+
const loadJsonCache = _.memoize((rel) => {
|
|
114
|
+
if (rel == "config://universe.json") {
|
|
115
|
+
return loadUniverseConfig(universe);
|
|
116
|
+
}
|
|
117
|
+
const full = path.join(from, rel);
|
|
118
|
+
return loadJson(full);
|
|
119
|
+
});
|
|
120
|
+
const outputs = keys.map((key) => pickOnce(loadJsonCache, key));
|
|
121
|
+
console.log(outputs.join(" "));
|
|
122
|
+
});
|
|
123
|
+
function loadUniverseConfig(universe) {
|
|
124
|
+
const config = loadMergedConfig();
|
|
125
|
+
const uniConf = config.universes?.[universe];
|
|
126
|
+
if (!uniConf) {
|
|
127
|
+
throw new Error(`config for universe ${universe} not found`);
|
|
128
|
+
}
|
|
129
|
+
return uniConf;
|
|
130
|
+
}
|
package/dist/commander-patch.js
CHANGED
|
@@ -7,11 +7,10 @@ export const privateKey = new Option("-k, --private-key <key>", "Private key to
|
|
|
7
7
|
export const foundry = new Option("-f, --foundry", "Use foundry keystores (~/.foundry/keystores)");
|
|
8
8
|
export const universe = new Option("-u, --universe <universe>", "Universe name").default("anvil");
|
|
9
9
|
export const network = new Option("-n, --network <network>", "Network name").default("dev");
|
|
10
|
-
export const json = new Option("-j, --json [file]", "Output result as JSON to stdout or file
|
|
10
|
+
export const json = new Option("-j, --json [file]", "Output result as JSON to stdout or file");
|
|
11
11
|
export const quiet = new Option("-q, --quiet", "Suppress info messages");
|
|
12
|
-
export const noQuiet = new Option("--no-quiet", "Force info messages even when --json is set");
|
|
13
12
|
export const keystoreOptions = [account, password, passwordFile, foundry];
|
|
14
|
-
export const outputOptions = [json, quiet
|
|
13
|
+
export const outputOptions = [json, quiet];
|
|
15
14
|
export const writeOptions = [universe, account, password, passwordFile, foundry];
|
|
16
15
|
Command.prototype.addCommands = function (commands) {
|
|
17
16
|
commands.forEach((cmd) => this.addCommand(cmd));
|
|
@@ -29,7 +28,7 @@ Command.prototype.addKeystoreOptions = function () {
|
|
|
29
28
|
return this.addOptions([account, password, passwordFile, foundry]);
|
|
30
29
|
};
|
|
31
30
|
Command.prototype.addOutputOptions = function () {
|
|
32
|
-
return this.addOptions([json, quiet
|
|
31
|
+
return this.addOptions([json, quiet]);
|
|
33
32
|
};
|
|
34
33
|
Command.prototype.addWriteOptions = function () {
|
|
35
34
|
return this.addKeystoreOptions().addOption(universe);
|
package/dist/logger.js
CHANGED
package/dist/program.js
CHANGED
|
@@ -12,6 +12,7 @@ import { setCmd } from "./cmds/set.js";
|
|
|
12
12
|
import { objectCmd } from "./cmds/object.js";
|
|
13
13
|
import { minterCmd } from "./cmds/minter.js";
|
|
14
14
|
import { universeCmd } from "./cmds/universe.js";
|
|
15
|
+
import { pickCmd } from "./cmds/pick.js";
|
|
15
16
|
export const program = new Command("every")
|
|
16
17
|
.description("CLI for interacting with Every Protocol")
|
|
17
18
|
.version(version())
|
|
@@ -27,4 +28,5 @@ export const program = new Command("every")
|
|
|
27
28
|
.addCommand(minterCmd)
|
|
28
29
|
.addCommand(balanceCmd)
|
|
29
30
|
.addCommand(walletCmd)
|
|
30
|
-
.addCommand(configCmd)
|
|
31
|
+
.addCommand(configCmd)
|
|
32
|
+
.addCommand(pickCmd, { hidden: true });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@everyprotocol/every-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/",
|
|
7
7
|
"abis/",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"@eslint/js": "^9.26.0",
|
|
17
17
|
"@types/bun": "latest",
|
|
18
18
|
"@types/columnify": "^1.5.4",
|
|
19
|
+
"@types/jsonpath": "^0.2.4",
|
|
19
20
|
"@types/lodash-es": "^4.17.12",
|
|
20
21
|
"@types/prompt-sync": "^4.2.3",
|
|
21
22
|
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
"ethers": "^6.14.0",
|
|
40
41
|
"json11": "^2.0.2",
|
|
41
42
|
"json5": "^2.2.3",
|
|
43
|
+
"jsonpath": "^1.1.1",
|
|
42
44
|
"lodash-es": "^4.17.21",
|
|
43
45
|
"prompt-sync": "^4.2.0",
|
|
44
46
|
"viem": "^2.29.1"
|