Skip to content

Commit

Permalink
fix: rename types
Browse files Browse the repository at this point in the history
  • Loading branch information
ALPAC-4 committed Mar 11, 2024
1 parent d909a44 commit d9e7a48
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
19 changes: 13 additions & 6 deletions package/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import * as fs from "fs";
import * as json5 from "json5";

const schemata: Record<string, string> = {
assetlist: "Assetlist",
assetlist: "AssetList",
chain: "Chain",
ibc_data: "IBCData",
};

const schemaTitle: Record<string, string> = {
assetlist: "AssetLists",
chain: "CosmosChain",
ibc_data: "IBCData",
};

async function main() {
fs.mkdirSync("./src/types");
fs.mkdirSync("./src/zods");
Expand All @@ -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",
});
Expand Down
2 changes: 1 addition & 1 deletion package/src/types/Assetlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
2 changes: 1 addition & 1 deletion package/src/types/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./Assetlist"
export * from "./AssetList"
export * from "./Chain"
export * from "./IBCData"
2 changes: 1 addition & 1 deletion package/src/zods/Assetlist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";

export const AssetlistSchema = z
export const AssetListSchema = z
.object({
$schema: z
.string()
Expand Down
2 changes: 1 addition & 1 deletion package/src/zods/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./IBCData"
export * from "./Assetlist"
export * from "./AssetList"
export * from "./Chain"

0 comments on commit d9e7a48

Please sign in to comment.