Skip to content

Offline-first Cosmos chain registry JavaScript/TypeScript client generator 🪭

License

Notifications You must be signed in to change notification settings

graz-sh/wadesta

Repository files navigation

wadesta

npm/v npm/dt stars

Offline-first Cosmos chain registry JavaScript/TypeScript client generator 🪭

How it works

Unlike other clients which fetches data remotely, wadesta fetches the registry's latest repository state once to generate the client locally using tiged.

By knowing what chains exist beforehand, wadesta can generate strongly typed client which knows what chains are available.

Installing

npm install wadesta     # install locally
npm -g install wadesta  # install globally
npx wadesta             # run without installing

Generate usage

Generate via CLI

# generate with default output to ./generated/chains/
wadesta generate

# generate using interactive mode
wadesta generate -i

# generate help command
wadesta generate --help

#   -r, --registry <source>    Chain registry source
#   -s, --registry-src <path>  Local chain registry path (if registry is `local`)
#   -o, --out-dir <path>       Generated client output directory
#   -m, --merged               Merge variables (e.g. only `chainIds` instead of `mainnetChainIds`, `testnetChainIds`, and `chainIds`)
#   -c, --clean                Clean output directory
#   -i, --interactive          Interactive mode
#   -h, --help                 Display this message

Generate programatically

import { generate } from "wadesta";

// default arguments
generate({
  registry: "github:cosmos/chain-registry",
  outDir: "./generated/chains/",
});

// use local registry instead of cloning remotely
generate({
  registry: "local",
  registrySrc: "./path/to/registry/",
});

// unify variables instead of separate per network types
// e.g. false -> import { chainIds, mainnetChainIds, testnetChainIds } from "./generated/chains";
//      true  -> import { chainIds } from "./generated/chains";
generate({
  merged: true,
});

API usage

chainData

These exports aggregate all chain data into Proxy objects, which includes chain registry data, chain info, and assetlist. Objects are fully typed with chain id and chain paths.

chains and chainInfos

Same as chainData but aggregates chain registry data and chain info respectively. Objects are fully typed with chain id and chain paths.

chainIds and chainNames

These exports aggregate chain ids and chain names as array objects. Specific network types are also available as mainnetChainIds, mainnetChainNames, testnetChainIds, and testnetChainNames.

getChainData

This export is a function that returns an object with chain registry data as given parameters. e.g. given ["a", "b", "c"] will return { a, b, c }. Objects are fully typed same as chainData.

getChainDataArray

Same as getChainData but returns an array chain registry data as given parameters. e.g. given ["a", "b", "c"] will return [a, b, c]. Objects are fully typed same as chainData.

Generator API usage

import { generate, type GenerateArgs } from "wadesta";
interface GenerateArgs {
  clean?: boolean;
  registry?: (string & {}) | "local";
  registrySrc?: string;
  outDir?: string;
  merged?: boolean;
}

declare const generate: (args?: GenerateArgs) => Promise<void>;

Roadmap

  • Generate chain registry client
  • Generate IBC paths
  • Filter generated chains
  • Select module type (CommonJS, ESM)
  • Select output extensions (.js, .cjs, .mjs, .ts)

Maintainers

License

MIT License, Copyright (c) 2023 Graz

About

Offline-first Cosmos chain registry JavaScript/TypeScript client generator 🪭

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published