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

@cparra/apex-reflection

v4.0.0

Published

Provides tools for reflecting Apex code, the language used in Salesforce development.

Readme

Apex Reflection

Provides basic reflection for the Apex programming language.

Installation

npm i @cparra/apex-reflection

Usage

This library exposes a single function that handles parsing the body of an Apex top level type (class, interface, or enum) and returns the result.

import { reflect } from "@cparra/apex-reflection";

const classBody = "public with sharing class ExampleClass {}";
const response = reflect(classBody);

If you wish to parse an Apex type that comes from a file, you can read the file contents and use that as the source to reflect

import * as fs from 'fs';
import {reflect} from '@cparra/apex-reflection';

const path = './MyClass.cls';
const rawFile = fs.readFileSync(path);
const response = reflect(rawFile.toString());

The reflect function returns a ReflectionResult which contains either the results of the parsed Type (which will either be a ClassMirror, an InterfaceMirror, or an EnumMirror) or a ParsingError if the passed in body was not parsed successfully, with a message indicating where the error occurred.

Contributing

Even though this library is exposed as a Node.js library, the project's source code is written in Dart. The source can be found in the lib/src directory of the repository.

This package ships the Dart code compiled to a WebAssembly module (dist/node.wasm) together with its JS loader (dist/node.mjs), loaded lazily by the thin TypeScript wrapper in index.mts. Node.js 22 or newer is required (the module uses WasmGC). To rebuild the module after changing the Dart source, run from the repository root:

dart compile wasm lib/src/node/node.dart -o js/node.wasm

npm run build compiles the TypeScript wrapper and copies the wasm module and its loader into dist/.

Tests

Both the Dart source code and the packaged WebAssembly module must be tested.

The Dart tests live in the repository's test directory. The Dart source code must have unit tests testing each individual Dart file as well as end-to-end tests that verify the overall parsing functionality.

The JS tests live in __tests__. These are end-to-end tests that run against the built package (dist/), so they also guard against publishing a stale WebAssembly artifact. Run them with npm test.

JSON serialization

The reflection operation outputs a JSON representation of the Apex type, which is then deserialized on the JS side to return typed objects.

Serialization is handled through the json_serializable package, which helps automatically create the round-trip code for serialization and de-serialization.

When changing any of the model classes with serialization support, to re-build the serialization code run

dart run build_runner build

Parsing

Parsing is implemented with handwritten petitparser grammars. The Apex grammar parses only the declaration structure needed for reflection (bodies are skipped as balanced blocks), and the Apexdoc grammar is composed into it, so doc comments are parsed in the same single pass. See the repository README for details.

Typescript

This library provides its own TS type definition.