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

@layers/core-wasm

v2.1.0

Published

Layers SDK Rust core compiled to WASM with JS glue

Readme

@layers/core-wasm

Rust analytics core compiled to WebAssembly with TypeScript wrappers. This is an internal package -- consumers should use @layers/client, @layers/node, or @layers/react-native.

Architecture

                  +---------------------------+
                  |   Platform SDKs           |
                  |  (client / node / RN)     |
                  +------------+--------------+
                               |
                  +------------v--------------+
                  |   @layers/core-wasm       |
                  |   JS wrapper (LayersCore) |
                  +------------+--------------+
                               |
                  +------------v--------------+
                  |   Rust / WASM binary      |
                  |   (event queue, consent,  |
                  |    rate limiting, session) |
                  +---------------------------+

The Rust/WASM core is the single source of truth for event acceptance, building, and queuing. When WASM is loaded, track()/screen() delegate entirely to Rust. The JS layer handles HTTP networking, persistence backends, retry with circuit breaker, periodic flush timers, and event hydration from persistence.

When WASM is not available (e.g. environments where WASM cannot load), a pure-JS fallback builds events and manages its own queue with identical behavior.

Entry Points

| Entry | Condition | WASM loading | | ----------------------------- | ---------------- | ----------------------------------------------------------- | | @layers/core-wasm (default) | Node.js | Sync via fs.readFileSync -- no async init needed | | @layers/core-wasm/browser | Browser bundlers | Async via initWasm() -- call before creating LayersCore |

Browser bundlers (webpack, vite, esbuild) automatically resolve the "browser" export condition, which avoids importing node:fs.

API Reference

LayersCore.init(init: LayersCoreInit): LayersCore

Create and initialize a new core instance.

import { FetchHttpClient, LayersCore, createDefaultPersistence } from '@layers/core-wasm';

const core = LayersCore.init({
  config: {
    apiKey: 'your-api-key',
    appId: 'your-app-id',
    environment: 'production',
    enableDebug: false,
    flushThreshold: 20, // events before auto-flush (default: 20)
    maxQueueSize: 10_000, // max queue depth (default: 10,000)
    maxBatchSize: 1_000, // max events per HTTP batch (default: 1,000)
    flushIntervalMs: 30_000 // periodic flush timer (default: 30s)
  },
  httpClient: new FetchHttpClient(),
  persistence: createDefaultPersistence('your-app-id')
});

core.track(eventName, properties?, userId?, anonymousId?)

Record a custom analytics event. Delegates to the WASM core when available.

core.screen(screenName, properties?, userId?, anonymousId?)

Record a screen view event.

core.identify(userId)

Associate subsequent events with a user ID.

core.setUserProperties(properties)

Set user-level properties that persist across sessions.

core.setConsent(consent)

Update consent state. Pass { analytics: true/false, advertising: true/false }.

core.flush()

Synchronous flush -- drains the queue to persistence.

core.flushAsync()

Async flush -- sends events over HTTP with retry and circuit breaker.

core.shutdown()

Persist remaining events and stop the flush timer.

core.setDeviceContext(context)

Set device-level fields (platform, OS version, locale, etc.).

core.getSessionId()

Get the current session ID. Sessions auto-rotate after 30 minutes of inactivity.

core.startNewSession()

Force-start a new session.

core.queueDepth()

Return the number of queued events.

Persistence Backends

| Backend | Use case | | --------------------------------- | ------------------------------------------------------------------ | | LocalStoragePersistence | Browser environments (window.localStorage) | | MemoryPersistence | SSR, tests, Node.js | | NullPersistence | No persistence -- events only live in memory | | createDefaultPersistence(appId) | Auto-detects: localStorage if available, otherwise NullPersistence |

Custom backends implement the PersistenceBackend interface:

interface PersistenceBackend {
  write(key: string, data: Uint8Array): void;
  read(key: string): Uint8Array | null;
  delete(key: string): void;
  listKeys(prefix: string): string[];
}

HTTP Client

The included FetchHttpClient uses the Fetch API with configurable timeout (default 30s). Custom HTTP clients implement the HttpClient interface:

interface HttpClient {
  post(url: string, headers: [string, string][], body: Uint8Array): Promise<HttpResponse>;
  get(url: string, headers: [string, string][]): Promise<HttpResponse>;
}

Error Handling

All errors are typed as LayersError with a code field:

import { LayersError } from '@layers/core-wasm';

try {
  core.track('event');
} catch (e) {
  if (e instanceof LayersError) {
    console.error(e.code, e.message); // e.g. 'INVALID_ARGUMENT', 'eventName must not be empty'
  }
}

Error codes: INVALID_CONFIG, INVALID_ARGUMENT, SHUT_DOWN, QUEUE_FULL, HTTP, CIRCUIT_OPEN, NETWORK, SERIALIZATION, RATE_LIMITED, CONSENT_NOT_GRANTED, PERSISTENCE, REMOTE_CONFIG, EVENT_DENIED, INTERNAL.

License

MIT