0.1.4 • Published 3 years ago

@upshot-tech/upshot-schemas v0.1.4

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
3 years ago

Upshot Schemas

Usage

Generate

Given a schema version and some nonformatted json it generates a valid, minified, alphabetized json

const metadata = {
  name: "Sample Group",
  description: "This is a sample description",
  network: "1",
  profileImage: "https://siasky.net/NABKOpMMF89Wla4YDGn7ds-d5T5llttzfSF6rKG9MqeTcQ",
  coverImage: "https://siasky.net/XAA2MUrOudjva38vC7GcZsrEaSpeZ_d6xFa1OzWbiXsbiw",
  prompt: {
    comparison: "Prompt for comparison questions",
    multichoice: "Prompt for multichoice questions"
  },
  options: {
    params: {
      SIZE_OF_COMMITTEE: 3,
      MIN_CONFIDENCE: 0.5
    },
    rewards: {
      TICKET_ADDRESS: "0x597B280EcA614558D0F7FEbb357455772DC762De"
    }
  },
  allowedAssets: [
    {
      name: "CryptoKitties",
      address: "0xf5b0a3efb8e8e4c201e2a935f110eaaf3ffecb8d"
    }
  ],
  strategies: [
    {
      name: "erc-20-balance-of",
      params: {
        address: "0xBA27D43A21e529CD961E11d207D27C8E22Fe453b",
        symbol: "UP1"
      }
    }
  ],
  admins: [
    "0x31f75b7bdb183664B4d17e97eaeFCbe09C58742b",
    "0xE4c2DC318F4215dD496D5B078689ab79047605fA"
  ],
  filters: {
    minScore: 1,
    onlyAdmins: true
  },
  version: 'group-20210215'
}

const generator = new Generator(metadata.version)
const minified = generator.generate(metadata)

Validate

const metadata = {
  name: "Sample Group",
  description: "This is a sample description",
  network: "1",
  profileImage: "https://siasky.net/NABKOpMMF89Wla4YDGn7ds-d5T5llttzfSF6rKG9MqeTcQ",
  coverImage: "https://siasky.net/XAA2MUrOudjva38vC7GcZsrEaSpeZ_d6xFa1OzWbiXsbiw",
  prompt: {
    comparison: "Prompt for comparison questions",
    multichoice: "Prompt for multichoice questions"
  },
  options: {
    params: {
      SIZE_OF_COMMITTEE: 3,
      MIN_CONFIDENCE: 0.5
    },
    rewards: {
      TICKET_ADDRESS: "0x597B280EcA614558D0F7FEbb357455772DC762De"
    }
  },
  allowedAssets: [
    {
      name: "CryptoKitties",
      address: "0xf5b0a3efb8e8e4c201e2a935f110eaaf3ffecb8d"
    }
  ],
  strategies: [
    {
      name: "erc-20-balance-of",
      params: {
        address: "0xBA27D43A21e529CD961E11d207D27C8E22Fe453b",
        symbol: "UP1"
      }
    }
  ],
  admins: [
    "0x31f75b7bdb183664B4d17e97eaeFCbe09C58742b",
    "0xE4c2DC318F4215dD496D5B078689ab79047605fA"
  ],
  filters: {
    minScore: 1,
    onlyAdmins: true
  },
  version: 'group-20210215'
}

const validator = new Validator(metadata.version)
const validated = validator.validate(metadata)

Parse

const json = `
{
  name: "Sample Group",
  description: "This is a sample description",
  network: "1",
  profileImage: "https://siasky.net/NABKOpMMF89Wla4YDGn7ds-d5T5llttzfSF6rKG9MqeTcQ",
  coverImage: "https://siasky.net/XAA2MUrOudjva38vC7GcZsrEaSpeZ_d6xFa1OzWbiXsbiw",
  prompt: {
    comparison: "Prompt for comparison questions",
    multichoice: "Prompt for multichoice questions"
  },
  options: {
    params: {
      SIZE_OF_COMMITTEE: 3,
      MIN_CONFIDENCE: 0.5
    },
    rewards: {
      TICKET_ADDRESS: "0x597B280EcA614558D0F7FEbb357455772DC762De"
    }
  },
  allowedAssets: [
    {
      name: "CryptoKitties",
      address: "0xf5b0a3efb8e8e4c201e2a935f110eaaf3ffecb8d"
    }
  ],
  strategies: [
    {
      name: "erc-20-balance-of",
      params: {
        address: "0xBA27D43A21e529CD961E11d207D27C8E22Fe453b",
        symbol: "UP1"
      }
    }
  ],
  admins: [
    "0x31f75b7bdb183664B4d17e97eaeFCbe09C58742b",
    "0xE4c2DC318F4215dD496D5B078689ab79047605fA"
  ],
  filters: {
    minScore: 1,
    onlyAdmins: true
  },
  version: 'group-20210215'
}
`

const parser = new Parser('group-20210215')
const parsed =  parser.parse(json)

Tests

yarn test

Define a New Schema

To define a new schema version, locate the directory of your project's name in schemas/. If a directory does not already exist create one. Within the project directory create a new file with the desired calendar version as the file name example: schema/group/20210215.json

  • Define the schema according to JSON Schema specification.
  • Write some tests in the schema.tests.ts file.
  • run yarn codegen to generate type specifically for your new schema
  • Add your version to the supportedVersions and supportedVersionsTypeMapping in versions.ts
  • Add your version type to the exported types in types.ts

Further Reading

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago