@json-eval-rs/webcore
v0.0.41
Published
JSON Eval RS core JavaScript wrapper (internal package - not published)
Downloads
1,107
Maintainers
Readme
@json-eval-rs/webcore
High-level JavaScript API for JSON Eval RS WASM bindings.
Installation
# Install bridge + your target WASM package
yarn install @json-eval-rs/webcore @json-eval-rs/bundler
# Or for direct browser use
yarn install @json-eval-rs/webcore @json-eval-rs/vanilla
# Or for Node.js
yarn install @json-eval-rs/webcore @json-eval-rs/nodeUsage
With Bundler (Webpack, Vite, Next.js, etc.)
import { JSONEval } from '@json-eval-rs/webcore';
import * as wasmModule from '@json-eval-rs/bundler';
const evaluator = new JSONEval({
schema: {
type: 'object',
properties: {
name: {
type: 'string',
rules: {
required: { value: true, message: 'Name is required' },
minLength: { value: 3, message: 'Min 3 characters' }
}
}
}
},
wasmModule // Pass the WASM module explicitly
});
// Validate data
const result = await evaluator.validate({
data: { name: 'Jo' }
});
if (result.has_error) {
console.log('Errors:', result.errors);
}
// Don't forget to free resources
evaluator.free();Dynamic Import (for Next.js client components)
'use client';
useEffect(() => {
Promise.all([
import('@json-eval-rs/webcore'),
import('@json-eval-rs/bundler')
]).then(([{ JSONEval }, wasmModule]) => {
const evaluator = new JSONEval({ schema, wasmModule });
// Use evaluator...
});
}, []);API
new JSONEval(options)
Create a new evaluator instance.
Options:
schema(required) - JSON schema objectcontext(optional) - Context data objectdata(optional) - Initial data objectwasmModule(optional) - Pre-loaded WASM module
await evaluator.validate({ data, context? })
Validate data against schema rules.
Returns: { has_error: boolean, errors: ValidationError[] }
await evaluator.evaluate({ data, context? })
Evaluate schema with data.
Returns: Evaluated schema object
await evaluator.evaluateDependents({ changedPaths, data, context?, nested? })
Re-evaluate fields that depend on changed paths.
Options:
changedPaths- Array of field paths that changeddata- Current datacontext(optional) - Context datanested(optional, default: true) - Follow dependency chains
Returns: Updated evaluated schema
evaluator.free()
Free WASM resources. Call this when done.
Why Use the Core?
The core package provides:
- Clean API - Options objects instead of positional JSON strings
- Type Safety - Full TypeScript support
- Auto-detection - Automatically loads the right WASM target
- Flexibility - Works with bundler/web/node targets
Direct WASM Usage
If you prefer minimal overhead, you can use WASM packages directly:
import { JSONEvalWasm } from '@json-eval-rs/bundler';
const instance = new JSONEvalWasm(
JSON.stringify(schema),
JSON.stringify(context),
JSON.stringify(data)
);
const result = await instance.validate(JSON.stringify(data));
instance.free();License
MIT
