npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@beland/schemas

v1.1.1

Published

Decentraland data structure interfaces and validators for TypeScript-based projects.

Downloads

3

Readme

common-schemas

Decentraland data structure interfaces and validators for TypeScript-based projects.

Install it with:

npm i @mtv/schemas

Design Guidelines

  • Prevent type problems across projects
  • Fail as early as possible, aim for compile-time
  • Preserve user optionality through runtime helpers
  • Prefer no-cost implementations and allow no-dependency import
  • Code is written once, read hundreds of times

Implementation decisions:

  • The main entrypoint should only export types
  • Every type is also a namespace
  • Type names are PascalCase
  • Validators and schemas are camelCase

Collaborator's Guide

Generating types, validators and schemas

This library export types that also act as values. This is achieved through TypeScript's namespaces. This means that every type imported from this library can also be used as a JS object. These types will include two properties named schema and validate. namespaces in typescript can be considered "cost imports".

Example Type Definition

// Declare type
export type MyType = {
  value: number;
};

// Declare namespace for the type
export namespace MyType {
  export const schema: Schema<MyType> = {
    type: "object",
    properties: {
      value: { type: number },
    },
    additionalProperties: false,
    required: ["value"],
  };

  export const validate = generateValidator<MyType>(schema);
}

MyType can now be both used as type const a: MyType or as an object MyType.validate(a).

Beware that validate has type ValidateFunction<T> which ajv creates automatically. When writing new validations always try to implement it as an ajv validation, even if custom code is needed. See here.

Particularly, beware of using the library like this, because reports by the validator.validate function are lost and never returned to the caller.

const validator = generateValidator<MyType>(schema);
export const validate = (mt: MyType) =>
  validator.validate(mt) && otherValidations(mt);

Code ownership

Please add types and schemas of your domain into the src/<team> folder, also add your team to the CODEOWNERS repository to make sure nobody accidentally changes it without your team noticing it.

Informing changes

Please notify about changes to the schemas to relevant teams by adding the whole team (i.e. @mtv/dapps) as reviewers of the pull requests.

It is recommended to subscribe to this repository (using the Watch function) if you use any internal part of the Decentraland ecosystem.

Making changes

To make sure the relevant persons and groups are aware of changes in these types, there's an api-extraction process executed with https://api-extractor.com that creates a report file for review between commits. It gets included as part of PRs for easier read.

To generate the file before submitting a PR, run npm run refresh-api. This is executed by the CI by runnig npm run check-api. It also verifies that the generated file matches the exported types.

Versioning and Publishing

Versions are handled manually using Github releases and semver.

Main branch is automatically published to the @next dist tag to test integrations before final releases happen.