Poindexter/examples/wasm-browser-ts
Claude 4609b7b2bf
feat: Expose networking analytics for KD-Tree NAT routing
Add comprehensive networking analytics to support peer selection based
on performance and trust metrics for KD-Tree based NAT routing:

- Add kdtree_analytics.go with TreeAnalytics, PeerAnalytics,
  DistributionStats, NATRoutingMetrics, TrustMetrics, and
  QualityWeights structures
- Track query/insert/delete operations with timing statistics
- Track per-peer selection frequency and average distances
- Add PeerQualityScore() for composite peer ranking
- Add ComputeTrustScore() for reputation-based selection
- Add distribution statistics (min, max, mean, median, percentiles)
- Add feature normalization helpers for multi-dimensional peer data

WASM/TypeScript integration:
- Expose all analytics via WASM bindings
- Update TypeScript definitions with full type coverage
- Update loader.js with new API methods
- Update TypeScript demo to showcase analytics features

Includes comprehensive test coverage for all analytics functionality.
2025-12-25 12:18:18 +00:00
..
scripts Add KDTree normalization helpers and TypeScript demo with Vite 2025-11-04 02:15:04 +00:00
src feat: Expose networking analytics for KD-Tree NAT routing 2025-12-25 12:18:18 +00:00
index.html Add KDTree normalization helpers and TypeScript demo with Vite 2025-11-04 02:15:04 +00:00
package.json Add KDTree normalization helpers and TypeScript demo with Vite 2025-11-04 02:15:04 +00:00
README.md Add KDTree normalization helpers and TypeScript demo with Vite 2025-11-04 02:15:04 +00:00
tsconfig.json Add KDTree normalization helpers and TypeScript demo with Vite 2025-11-04 02:15:04 +00:00
vite.config.ts Add KDTree normalization helpers and TypeScript demo with Vite 2025-11-04 02:15:04 +00:00

WASM Browser Example (TypeScript + Vite)

This is a minimal TypeScript example that runs Poindexters WebAssembly build in the browser. It bundles a tiny page with Vite and demonstrates creating a KDTree and running Nearest, KNearest, and Radius queries.

Prerequisites

  • Go toolchain installed
  • Node.js 18+ (tested with Node 20)

Quick start

  1. Build the WASM artifacts at the repo root:
make wasm-build

This creates dist/poindexter.wasm and dist/wasm_exec.js.

  1. From this example directory, install deps and start the dev server (the script copies the required files into public/ before starting Vite):
npm install
npm run dev
  1. Open the URL printed by Vite (usually http://127.0.0.1:5173/). Open the browser console to see outputs.

What the dev script does

  • Copies ../../dist/poindexter.wasm and ../../dist/wasm_exec.js into public/
  • Copies ../../npm/poindexter-wasm/loader.js into public/
  • Starts Vite with public/ as the static root for those assets

The TypeScript code imports the loader from /loader.js and initializes with:

const px = await init({
  wasmURL: '/poindexter.wasm',
  wasmExecURL: '/wasm_exec.js',
});

Notes

  • This example is local-only and not built in CI to keep jobs light.
  • You can adapt the same structure inside your own web projects; alternatively, install the published npm package when available and serve dist/ as static assets.