diff --git a/package/package.json b/package/package.json index cb4cb2f..04a202b 100644 --- a/package/package.json +++ b/package/package.json @@ -1,6 +1,6 @@ { "name": "@initia/initia-registry-types", - "version": "0.0.2", + "version": "0.0.3", "description": "The package provides TypeScript type definitions and Zod integration for initia-registry.", "types": "./dist/types/index.d.ts", "exports": { diff --git a/package/src/generate.ts b/package/src/generate.ts index 564ac63..5a4becc 100644 --- a/package/src/generate.ts +++ b/package/src/generate.ts @@ -4,11 +4,17 @@ import * as fs from "fs"; import * as json5 from "json5"; const schemata: Record = { - assetlist: "Assetlist", + assetlist: "AssetList", chain: "Chain", ibc_data: "IBCData", }; +const schemaTitle: Record = { + assetlist: "AssetLists", + chain: "CosmosChain", + ibc_data: "IBCData", +}; + async function main() { fs.mkdirSync("./src/types"); fs.mkdirSync("./src/zods"); @@ -26,20 +32,21 @@ async function generateTypeAndZod(key: string) { fs.writeFileSync("./src/zods/index.ts", ""); } - const assetlistSchema = json5.parse( + const schema = json5.parse( fs.readFileSync(`../${key}.schema.json`).toString() ); - compile(assetlistSchema, schemata[key]).then((ts) => - fs.writeFileSync(`./src/types/${schemata[key]}.ts`, ts) - ); + compile(schema, schemata[key]).then((ts) => { + ts = ts.replace(schemaTitle[key], schemata[key]); + fs.writeFileSync(`./src/types/${schemata[key]}.ts`, ts); + }); fs.appendFileSync( "./src/types/index.ts", `export * from "./${schemata[key]}"\n` ); - const zod = await jsonSchemaToZodDereffed(assetlistSchema, { + const zod = await jsonSchemaToZodDereffed(schema, { module: "esm", name: schemata[key] + "Schema", }); diff --git a/package/src/types/Assetlist.ts b/package/src/types/Assetlist.ts index 8009f3c..2e41e6d 100644 --- a/package/src/types/Assetlist.ts +++ b/package/src/types/Assetlist.ts @@ -8,7 +8,7 @@ /** * Asset lists are a similar mechanism to allow frontends and other UIs to fetch metadata associated with Cosmos SDK denoms, especially for assets sent over IBC. */ -export interface AssetLists { +export interface AssetList { $schema?: string; chain_name: string; assets: Asset[]; diff --git a/package/src/types/Chain.ts b/package/src/types/Chain.ts index b06acee..fd9d88d 100644 --- a/package/src/types/Chain.ts +++ b/package/src/types/Chain.ts @@ -11,7 +11,7 @@ export type Amount = string; /** * Cosmos Chain.json is a metadata file that contains information about a cosmos sdk based chain. */ -export interface CosmosChain { +export interface Chain { $schema?: string; chain_name: string; chain_id: string; diff --git a/package/src/types/index.ts b/package/src/types/index.ts index f8f847b..cefe32f 100644 --- a/package/src/types/index.ts +++ b/package/src/types/index.ts @@ -1,3 +1,3 @@ -export * from "./Assetlist" +export * from "./AssetList" export * from "./Chain" export * from "./IBCData" diff --git a/package/src/zods/Assetlist.ts b/package/src/zods/Assetlist.ts index cc7810f..5ec41eb 100644 --- a/package/src/zods/Assetlist.ts +++ b/package/src/zods/Assetlist.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -export const AssetlistSchema = z +export const AssetListSchema = z .object({ $schema: z .string() diff --git a/package/src/zods/index.ts b/package/src/zods/index.ts index c5975fc..24398f6 100644 --- a/package/src/zods/index.ts +++ b/package/src/zods/index.ts @@ -1,3 +1,3 @@ export * from "./IBCData" -export * from "./Assetlist" +export * from "./AssetList" export * from "./Chain"