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

@rico-core/parser

v0.0.4

Published

WebAssembly bindings for Rico - A high-performance Apache Thrift IDL parser

Readme

@rico-core/parser

WebAssembly bindings for Rico - A high-performance Apache Thrift IDL parser and writer library.

Installation

npm install @rico-core/parser

Usage

import Rico, { Document, Struct } from '@rico-core/parser';

async function main() {
  // Initialize Rico (required before any operations)
  await Rico.initialize();

  const input = `
    namespace rs demo

    struct User {
      1: string name
      2: i32 age
    }
  `;

  try {
    // Parse Thrift IDL to AST with full type information
    const ast: Document = await Rico.parse(input, false);

    // Type-safe access to AST properties
    ast.members.forEach(member => {
      if (member.kind === 'StructDefinition') {
        const struct = member as Struct;
        console.log('Found struct:', struct.name.value);
        struct.members.forEach(field => {
          console.log(
            ` - ${field.name.value}: ${field.fieldType.value} (ID: ${field.fieldID?.value})`
          );
        });
      }
    });

    // Write AST back to Thrift IDL
    const output = Rico.write(ast);
    console.log('Generated Thrift IDL:', output);
  } catch (error) {
    console.error('Error:', error);
  }
}

main().catch(console.error);

API

Rico.initialize(): Promise<void>

Initializes the WebAssembly module. Must be called before using any other methods.

Rico.parse(input: string): Promise<Document>

Parses a Thrift IDL string and returns the AST (Abstract Syntax Tree) with full type information.

Rico.write(ast: Document): string

Converts an AST back to Thrift IDL format.

Type System

Rico provides a comprehensive type system that exactly matches the Rust AST definitions. All types are automatically generated from the Rust source code to ensure perfect alignment.

Core Types

  • Document: The root AST node
  • DocumentMember: Union type of all possible top-level definitions
  • BaseNode: Common properties for all AST nodes
  • NodeType: Enum of all possible node types

Definition Types

  • Namespace: Namespace declarations
  • Include: Include statements
  • Const: Constant definitions
  • Typedef: Type aliases
  • Enum: Enum definitions
  • Struct: Struct definitions
  • Union: Union definitions
  • Exception: Exception definitions
  • Service: Service definitions

Field Types

  • Field: Field definitions in structs/unions/exceptions
  • FieldType: Union type of all possible field types
    • CommonType: Basic types (string, i32, etc.)
    • FieldSetType: Sets
    • FieldListType: Lists
    • MapType: Map types with key and value types

Value Types

  • FieldValue: Union type of all possible values
    • ConstValue: Basic constant values
    • ConstList: List literals
    • ConstMap: Map literals

Location Information

All nodes include source location information:

interface LOC {
  start: Span;
  end: Span;
}

interface Span {
  line: number;
  column: number;
  index: number;
}

Type Safety Example

import { Document, Struct, Field, FieldType } from '@rico-core/parser';

function processStruct(struct: Struct) {
  // All fields are properly typed
  struct.members.forEach((field: Field) => {
    // Type-safe field access
    const fieldName = field.name.value;
    const fieldType = field.fieldType;
    const isRequired = field.requiredType === 'required';

    // Type-safe pattern matching on field types
    if (fieldType.kind === 'CollectionType') {
      console.log(
        `${fieldName} is a collection of ${fieldType.valueType.value}`
      );
    } else if (fieldType.kind === 'MapType') {
      console.log(
        `${fieldName} is a map from ${fieldType.keyType.value} to ${fieldType.valueType.value}`
      );
    }
  });
}

Development

  1. Build the WebAssembly module:
npm run build
  1. Run tests:
npm test

License

MIT