-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforc-index.ts
83 lines (66 loc) · 2.55 KB
/
forc-index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import * as path from "jsr:@std/path";
import { parse as parseToml } from "jsr:@std/toml";
import { Command } from "npm:commander@^12.1.0";
import process from "node:process";
import chalk from "npm:chalk@^5.3.0";
interface ForcConfig {
project: {
metadata?: {
indexing?: {
schema_path?: string;
};
};
};
}
interface AbiLoggedType {
logId: string;
concreteTypeId: string;
}
interface AbiSchema {
loggedTypes?: AbiLoggedType[];
}
const program = new Command();
program
.version("1.0.0")
.description("Forc.toml metadata parser that validates and reads ABI schema")
.requiredOption("-p, --path <value>", "Path to the Forc.toml file")
.parse(process.argv);
const options = program.opts();
try {
// Read and validate Forc.toml
console.log(chalk.blue.bold('\n📖 Reading Forc.toml configuration...'));
const content = Deno.readFileSync(options.path);
const contentString = new TextDecoder().decode(content);
const forcConfig = parseToml(contentString) as unknown as ForcConfig;
// Validate the required structure exists
if (!forcConfig.project?.metadata?.indexing?.schema_path) {
throw new Error(chalk.red('Missing required project.metadata.indexing.schema_path in Forc.toml'));
}
// Get the ABI schema path and read it
const schemaPath = forcConfig.project.metadata!.indexing!.schema_path;
const projectPath = path.dirname(options.path);
const abiPath = path.join(projectPath, schemaPath);
console.log(chalk.green('✓ Forc.toml validated successfully'));
console.log(chalk.blue.bold('\n📑 Reading ABI schema...'));
console.log(chalk.dim(`Path: ${abiPath}`));
const abiContent = Deno.readFileSync(abiPath);
const abiSchema = JSON.parse(new TextDecoder().decode(abiContent)) as AbiSchema;
if (!abiSchema.loggedTypes || abiSchema.loggedTypes.length === 0) {
console.log(chalk.yellow('⚠️ No logged types found in ABI'));
process.exit(1);
}
console.log(chalk.green('✓ ABI schema loaded successfully'));
console.log(chalk.magenta.bold('\n📋 Logged Types:'));
abiSchema.loggedTypes!.forEach((loggedType, index) => {
console.log(chalk.cyan(`\n[Entry ${index + 1}]`));
console.log(chalk.yellow(` 🔍 Log ID: ${chalk.white(loggedType.logId)}`));
console.log(chalk.yellow(` 🔑 Concrete Type ID: ${chalk.white(loggedType.concreteTypeId)}`));
});
console.log('\n'); // Add extra newline for cleaner output
} catch (error) {
if (error instanceof Error) {
console.error(chalk.red.bold('❌ Error: ') + chalk.red(error.message));
process.exit(1);
}
throw error;
}