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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mikrojs/schema

v0.22.0

Published

Schema DSL for Mikro.js: declare a shape once, infer its type, validate against it, and publish it for a registry to render a form from

Readme

@mikrojs/schema

The schema DSL behind Mikro.js: declare a shape once, infer its TypeScript type, validate values against it, and serialize it as plain JSON for something else to read. Zero dependencies, no Node APIs, so it runs on Node, Bun, Deno, Cloudflare Workers and in a browser.

Apps on a device import mikro/schema instead, which is this same DSL backed by a native module plus a Result-returning parse(). This package is the host half: the CLI evaluating mikro.config.ts, a registry validating what an operator saves, and anything else that needs to read a published schema.

import {number, object, string, validate} from '@mikrojs/schema'

const Config = object({
  mqttUrl: string({title: 'Broker URL', format: 'url'}),
  interval: number({title: 'Publish interval', unit: 's', default: 60, min: 1, max: 3600}),
})

validate(Config, {mqttUrl: 'mqtt://box.local', interval: 60}, '') // => null
validate(Config, {mqttUrl: 'mqtt://box.local', interval: 0}, '')
// => {ok: false, error: {name: 'ValidationFailed', message: 'below the minimum of 1', path: '.interval'}}

validate() returns null when the value is good, and covers shape plus every numeric and length bound. format is not checked here; see @mikrojs/schema/config.

Annotations

Nodes carry annotations, and they divide in two. Display annotations (title, description, mask) describe how a value should be presented and never change what validates, so a consumer may ignore any it does not recognise. Constraints (min, max, integer, minLength, maxLength, minItems, maxItems, format, unit) do change what validates, and a consumer must not ignore one it does not recognise: ignoring a constraint means accepting a value the author ruled out.

unit is a closed enum following SenML with ASCII keys. It is a display hint and constrains nothing. Never convert a stored value through a unit's scale — see the note beside UNITS.

@mikrojs/schema/config

The host-side machinery for Mikro.js OTA config, which is what a registry needs:

  • validateConfig(schema, value) — validate() plus format, returning {ok, value} or {ok: false, error}
  • parseConfigSchema(value) — validate a schema that arrived as JSON, rejecting malformed annotations and unknown format or unit values
  • deriveOverlay / parseEffective / materializeDefaults — the sparse-overlay model, where a registry stores only deviations from the author's defaults and serves the complete document
  • diffConfigSchemas(previous, next) — what changed between two releases, and whether it needs an operator's attention
  • UNITS, FORMATS — the unit table and the format names

format lives here rather than in the main entry for two reasons: the expressions are a denial-of-service surface a device should not carry, and a device has no regular-expression engine to carry them with.

The wire format is the contract. It is specified in the OTA Registry Spec under "The config schema", and that document, not this package's version number, is what a third-party registry should build against.

Documentation

mikrojs.dev/api/schema