# parse-cosmwasm-schema

> Parser for JSON schemas generated from CosmWasm, useful for creating automated contract tooling.

Latest version **0.2.0** (published 2021-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-cosmwasm-schema
pnpm add parse-cosmwasm-schema
yarn add parse-cosmwasm-schema
bun add parse-cosmwasm-schema
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-08-31 |
| First published | 2021-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 3 |
| Unpacked size | 252.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | William Chen |
| Maintainers | williamterra |

## Links

- npm: https://www.npmjs.com/package/parse-cosmwasm-schema
- npm.io page: https://npm.io/package/parse-cosmwasm-schema

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.172
- [@apidevtools/json-schema-ref-parser](https://npm.io/package/@apidevtools/json-schema-ref-parser.md) ^9.0.9

## Recent versions

- 0.2.0 (latest) — 2021-08-31
- 0.1.5 — 2021-08-29
- 0.1.4 — 2021-08-29
- 0.1.3 — 2021-08-29
- 0.1.2 — 2021-08-29
- 0.1.1 — 2021-08-29

## README

# `parse-cosmwasm-schema` <!-- omit in toc -->

Parser for JSON schemas generated from CosmWasm, useful for creating automated contract tooling.

## Table of Contents

- [Table of Contents](#table-of-contents)
- [Quickstart](#quickstart)
- [Introduction](#introduction)
- [Output Structure](#output-structure)
  - [Simple Nodes](#simple-nodes)
    - [None](#none)
    - [Boolean](#boolean)
    - [String](#string)
    - [Integer](#integer)
  - [Composite Nodes](#composite-nodes)
    - [Enum](#enum)
    - [Struct](#struct)
    - [Optional](#optional)
    - [Array](#array)
    - [Vec](#vec)
    - [Tuple](#tuple)
- [List of Tools](#list-of-tools)
  - [By Terraform Labs](#by-terraform-labs)
  - [Community](#community)

## Quickstart

Add to your `package.json` by using Yarn or NPM.

```sh
$ yarn add parse-cosmwasm-schema
```

Then, in your program:

```ts
import parseSchema from "parse-cosmwasm-schema";

// any schema generated by CosmWasm
const schema = {
  ...
};

parseSchema(schema).then(parseTree => {
  // the resultant parse tree is JSON
  console.log(JSON.stringify(parseTree, null, 2));
})
```

## Introduction

Smart contracts on Terra (powered by [CosmWasm](https://cosmwasm.com)) use JSON messages to define interactions. Each smart contract defines its interface through a **JSON schema** which specifies the structure and expected format of the messages that it can respond to. By reading the JSON schema, we are able to extract information which can be used to automatically generate tools that would otherwise require tedious manual labor.

`parse-cosmwasm-schema` provides an algorithm that reads in a CosmWasm-generated JSON schema and produces a JSON-based parse tree of the original Rust data. Because it is written in TypeScript, it also provides a set of types that are helpful for walking the parse tree, for writing your own custom solutions.

## Output Structure

The output is a parse tree represented as a JSON object, which can be one of several `NodeType` definitions.

All nodes follow the format:

```jsonc
{
  "type": "<node-type>",
  "value": {
    "title": "<node-title>", // or undefined
    "description": "<node-description>", // or undefined
    "ref": "<ref-name>" // if derived from a resolved reference, will be a string.
    ... // additional properties depending on node type
  }
}
```

### Simple Nodes

#### None

- type: `none`

#### Boolean

- type: `boolean`

#### String

- type: `string`

#### Integer

- type: `integer`
- properties:
  - size: type of integer (e.g. u32, u64, etc.)

### Composite Nodes

The following node types can include other node types.

#### Enum

- type: `enum`
- properties:
  - variants: a list of possible other node types

#### Struct

- type: `struct`
- properties:
  - members: an object where keys are member names and values are nodes

#### Optional

- type: `optional`
- properties:
  - body: a node type

#### Array

- type: `array`
- properties:
  - contents: node type of array's elements
  - size: number size of array

#### Vec

- type: `vec`
- properties:
  - contents: node type of vector's elements

#### Tuple

- type: `tuple`
- properties:
  - contents: an array of node types

## List of Tools

`parse-cosmwasm-schema` is used to power a number of useful contract tools.

### By Terraform Labs

| Name                | Description                                              |
| ------------------- | -------------------------------------------------------- |
| `gen-contract-docs` | Generates documentation for smart contract messages      |
| `gen-contract-sdk`  | Generates Python and JavaScript SDKs for smart contracts |
| `gen-contract-cli`  | Generates a command-line interface for smart contract    |
| `gen-contract-ui`   | Web-based UI tool for interacting with smart contracts   |

### Community

Made something cool but not on here? Make a pull request to add it to the list.

<table>
    <tr>
        <th>Name</th>
        <th>Description</th>
    </tr>
    <tr>
        <td colspan="2">
            <i>Currently no community tools -- be the first one!</i>
        </td>
    </tr>
</table>

---
_Source: https://npm.io/package/parse-cosmwasm-schema · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
