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

capnp-js-plugin

v0.2.11

Published

Capnproto implementation for Javascript

Downloads

20

Readme

capnp-js-plugin Build Status

Generate Javascript serialization classes for Capnproto.

Installation and preferred use

  • Install by npm: npm install capnp-js-plugin.
  • This plugin checks out and then builds the Capnproto compiler.
    • The build takes about 5 minutes on my system, so I use a global install: npm install -g capnp-js-plugin.
    • For each project that uses a Capnproto schema, I include the plugin as a devDependency: npm install --save-dev capnp-js-plugin.
    • I avoid including the plugin as a dependency, because this would result in absurdly long build times for non-dev users.
    • Under this arrangement, I must distribute generated-code instead of creating it client-side--I feel that the build time-savings warrants the source-of-truth confusion.

Usage

  • The compiler is invoked with capnp compile -ojs someSchema.capnp to generate a someSchema.capnp.d directory that contains the schema's AMD files.
  • Run capnp help compile for additional options.
  • To obtain Node modules, I convert the generated AMD modules with a fork of Nodefy called Nfy. See this nfy script for an example. I suspect that AMDefine provides an alternate solution, but I won't chase any upstream bugs related to the use of AMDefine.

Serialization Classes

This plugin generates serialization classes similar to those of the c++ reference implementation. Given a schema someSchema.capnp, capnp compile -ojs someSchema.capnp will generate someSchema.capnp.d/readers.js, someSchema.capnp.d/builders.js, and some internal files:

Readers (someSchema.capnp.d/readers.js)

Javascript implementation of readers for members of someSchema.capnp. See Readers from the reference implementation's documentation.

Builders (someSchema.capnp.d/builders.js)

Javascript implementation of builders for members of someSchema.capnp. See Builders from the reference implementation's documentation.

Internal Files

The following files exist under someSchema.capnp.d/, but should not be imported by user code. These files facilitate circular reference resolution by creating types and accumulating them, without calling any prototype methods.

  • someSchema.capnp.d/rTypes.js: Reader types defined in someSchema.capnp.
  • someSchema.capnp.d/rScope.js: Merge all Reader types imported by someSchema.capnp with those created within someSchema.capnp.
  • someSchema.capnp.d/bTypes.js: Analogous to rTypes.js.
  • someSchema.capnp.d/bScope.js: Analogous to rScope.js.

Absolute Imports

The Javascript plugin maps absolute imports to absolute AMD paths. Consider the messaging example from the rtc-github repository:

So why the /rtc-github-protocol prefix? Why not using import "/user.capnp".User;, capnp compile -ojs -I ./node_modules/rtc-github-protocol/ capnp/*.capnp, and then provide a user.capnp.d path to the AMD loader? Nfy doesn't remap absolute names. If I need to use capnp/server.capnp in a Node module, then every absolute path's root will need a corresponding entry under node_modules/. This is no big deal if you're using npm link for these modules, but if you want to distribute under npm's official public registry (and don't want dependencies that point at git repositories), then publishing user.capnp.d seems wrong. The schemas under /rtc-github-protocol are used by an RTC signaling server that will probably appear on npm's official public registry someday, hence the /rtc-github-protocol prefix.

Production Builds

You should minify the generated code for production builds. The generated code contains console.warn calls for development purposes--use something like uglifyjs -c drop_console to eliminate them.