Code Monkey home page Code Monkey logo

media-metadata-schemas's Introduction

Media Metadata Schemas

Overview

The SIP-009 requires media that is minted on its smart contracts contain a URI pointing to its metadata.

The SIP-009 maintains zero opinion about the structure of that metadata. It is explicitly not enforceable at the blockchain level.

However, the SIP-016 defines a json schema and more properties to standardize the metadata.

This repository contains tools to for the SIP-016 JSON Schema, and will generate Types, Parsers, Generators, and Validators.stac

Usage

Generate

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

const metadata = {
  version: 'stacks-20220422',
  name: randomName,
  description: randomDescription,
  image: imageUrl
}
const generator = new Generator(metadata.sip)
const minified = generator.generate(metadata)

Validate

const metadata = {
  version: 'stacks-20220422',
  name: randomName,
  description: randomDescription,
  image: imageUrl
}

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

Parse

const json = `
  {
    "version": "stacks-20220422",
    "name": "randomName",
    "description": "randomDescription",
    "image": "image"
  }
`

const parser = new Parser('stacks-20220422')
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: schemas/stacks/20220422.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

Submit a PR!

Someone on our team will review and merge.

Further Reading

media-metadata-schemas's People

Contributors

sporkspatula avatar iainnash avatar daenamkim avatar friedger avatar robinsloan avatar tbtstl avatar jzstern avatar tomj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.