3.0.7 • Published 2 years ago

@rainprotocol/meta v3.0.7

Weekly downloads
-
License
CAL-1.0
Repository
github
Last release
2 years ago

Rain Protocol Meta

Utility library for Rain Protocol's metadata. Also provides the schemas generated from typescript types for Rain Protocol's metadata such as op meta and contract meta. (uses ts-json-schema-generator)

Usage

Install the package with following:

npm install @rainprotocol/meta

or

yarn add @rainprotocol/meta

Schemas can used in vscode to automatically validate a json file when you specify it in vscode workspace setting:

  • Create a folder .vscode in your workspace and make a new file settings.json. (skip this if these are already present)
  • Add the following to the settings.json:
{
  "json.schemas": [
    {
      "fileMatch": ["*.op.meta.json"],
      "url": "./node_modules/@rainprotocol/meta/schemas/op.meta.schema.json"
    },
    {
      "fileMatch": ["*.contract.meta.json"],
      "url": "./node_modules/@rainprotocol/meta/schemas/contract.meta.schema.json"
    }
  ]
}

you can specify what files will be validated automatically by providing a glob pattern for fileMatch. See the ./example folder content for some examples.

Schemas can also be imported and used programmatically:

import { OpMetaSchema, ContractMetaSchema } from "@rainprotocol/meta";

For getting an op meta from subgraph:

// importing
import { getOpMetaFromSg } from "@rainprotocol/meta";

// get opmeta
const opmeta = await getOpMetaFromSg(deployerAddress, networkOrChainIdOrSgUrl)

To validate a meta against generated schemas:

// importing
import { validateMeta, metaFromBytes, OpMetaSchema } from "@rainprotocol/meta";

// convert "opmeta" from previous guide which is is bytes from (hex string) to op meta as object
const opmetaObj = metaFromBytes(opmeta);

// to validate the opmeta object against the OpMetaSchema
validateMeta(opmetaObj, OpMetaSchema);

// alternatively "metaFromBytes()" can perform the validation internally if the schema is provided as second arg
const opmetaObj = metaFromBytes(opmeta, OpMetaSchema);

Developers Guide

Clone the repo and then install all the dependencies:

npm install

There is prepare hook that will compile and generate the schemas after installing the deps. Versions of the generated schemas (schema $id field) are specified at the beginning of their types file with the following form:

// specify the version of the meta in the following line
// version 0.0.0

Modify the digits for specifying the version for the generated schema.

To generate the schemas:

npm run gen-schema

To run the tests:

npm test
2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.5

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago