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

@bare-ts/tools

v0.16.0

Published

Compiler for Binary Application Record Encoding (BARE) schemas

Downloads

144

Readme

NPM package bundle size - minified and gzipped Coverage

Binary Application Record Encoding (BARE) is a schema-based binary format that favors compactness and composability. @bare-ts/tools provides a compiler to generate Typescript and JavaScript codes from a BARE schema.

Warning: BARE specification is currently an IEF draft. The specification is now pretty stable. However, it may still evolve before its final release.

Getting started

@bare-ts/tools NPM version @bare-ts/lib NPM version

First, install @bare-ts/tools and @bare-ts/lib:

npm install --save-dev @bare-ts/tools
npm install @bare-ts/lib
  • @bare-ts/tools enables to generate decoders and encoders from a schema

  • @bare-ts/lib provides basic decoders and encoders

Alternatively, you can download a bundled and executable version of @bare-ts/tools named bare in the section Assets of every release on GitHub.

Then, write a schema:

type Gender enum {
    FEMALE
    FLUID
    MALE
}

type Person struct {
    name: str
    email: str
    gender: optional<Gender>
}

type Organization struct {
    name: str
    email: str
}

type Contact union { Person | Organization }

type Contacts list<Contact>

Compile your schema into code:

bare compile schema.bare --out=code.ts

Once the code is generated, encode and decode messages:

import { Gender, decodeContacts, encodeContacts } from "./code.js"
import { strict } from "node:assert"

const contacts = [
    {
        tag: "Person",
        val: {
            name: "Seldon",
            email: "[email protected]",
            gender: Gender.Male,
        },
    },
]

const payload = encodeContacts(contacts)
const contacts2 = decodeContacts(payload)

strict.deepEqual(contacts, contacts2)

Why BARE?

Compact messages: in contrast to BSON, CBOR, and MessagePack, BARE messages do not embed schema information.

Bijective encoding when possible: most of BARE values have a single binary representation. This makes easier the support of use-cases such as message deduplication.

Focus on modern platforms: messages are octet-aligned and use little-endian representation.

Simple: in contrast to Protocol Buffer and Flat Buffer, BARE doesn't constrain its binary format to support schema evolution. Protocol Buffer embeds metadata in every message and makes optional every field. BARE recommends using a tagged union as message type to support backward compatibility.

Why bare-ts?

Pragmatic error reporting: bare-ts distinguishes recoverable errors from API misuses. Decoders may emit recoverable errors (BareError) and provide enough information to understand why the message is malformed. An API misuse emits an AssertionError. bare-ts assumes the use of TypeScript. This assumption reduces the number of API misuses to check.

Optimized bundle size: bare-ts adopts functional and procedural programming styles. This enables to take advantage of modern dead-code elimination techniques, such as tree-shaking. Using bundlers such as ESbuild, Rollup, or Webpack, your bundle contains only the functions which are actually used. Moreover, bare-ts uses assertions to express preconditions. You can use dedicated tools such as unassert to remove them.

Generation of efficient code bare-ts takes care to generate code that modern JavaScript engines may optimize.