@json-eval-rs/bundler 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -0
- package/index.d.ts +124 -0
- package/index.js +45 -0
- package/package.json +36 -0
- package/pkg/json_eval_rs.d.ts +501 -0
- package/pkg/json_eval_rs.js +5 -0
- package/pkg/json_eval_rs_bg.js +2281 -0
- package/pkg/json_eval_rs_bg.wasm +0 -0
- package/pkg/json_eval_rs_bg.wasm.d.ts +83 -0
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @json-eval-rs/bundler
|
|
2
|
+
|
|
3
|
+
JSON Eval RS for modern bundlers (Webpack, Vite, Rollup, Next.js, etc.) with ergonomic API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn install @json-eval-rs/bundler
|
|
9
|
+
# or
|
|
10
|
+
yarn add @json-eval-rs/bundler
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { JSONEval } from '@json-eval-rs/bundler';
|
|
17
|
+
|
|
18
|
+
const evaluator = new JSONEval({
|
|
19
|
+
schema: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
name: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
rules: {
|
|
25
|
+
required: { value: true, message: 'Name is required' },
|
|
26
|
+
minLength: { value: 3, message: 'Min 3 characters' }
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
email: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
rules: {
|
|
32
|
+
required: { value: true, message: 'Email is required' },
|
|
33
|
+
email: { value: true, message: 'Invalid email' }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Initialize (loads WASM)
|
|
41
|
+
await evaluator.init();
|
|
42
|
+
|
|
43
|
+
// Validate data
|
|
44
|
+
const result = await evaluator.validate({
|
|
45
|
+
data: { name: 'Jo', email: 'invalid' }
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (result.has_error) {
|
|
49
|
+
console.log('Validation errors:', result.errors);
|
|
50
|
+
// [{ path: 'name', rule_type: 'minLength', message: 'Min 3 characters' }, ...]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Evaluate schema with data
|
|
54
|
+
const evaluated = await evaluator.evaluate({
|
|
55
|
+
data: { name: 'John', email: 'john@example.com' }
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Get schema values
|
|
59
|
+
const values = await evaluator.getSchemaValue();
|
|
60
|
+
|
|
61
|
+
// Clean up when done
|
|
62
|
+
evaluator.free();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
### `new JSONEval(options)`
|
|
68
|
+
|
|
69
|
+
Create a new evaluator instance.
|
|
70
|
+
|
|
71
|
+
**Options:**
|
|
72
|
+
- `schema` (required) - JSON schema object
|
|
73
|
+
- `context` (optional) - Context data object
|
|
74
|
+
- `data` (optional) - Initial data object
|
|
75
|
+
|
|
76
|
+
### `await evaluator.init()`
|
|
77
|
+
|
|
78
|
+
Initialize the WASM module. Must be called before other methods.
|
|
79
|
+
|
|
80
|
+
### `await evaluator.validate({ data, context? })`
|
|
81
|
+
|
|
82
|
+
Validate data against schema rules.
|
|
83
|
+
|
|
84
|
+
Returns: `{ has_error: boolean, errors: ValidationError[] }`
|
|
85
|
+
|
|
86
|
+
### `await evaluator.evaluate({ data, context? })`
|
|
87
|
+
|
|
88
|
+
Evaluate schema with data and return evaluated schema.
|
|
89
|
+
|
|
90
|
+
### `await evaluator.evaluateDependents({ changedPaths, data, context?, nested? })`
|
|
91
|
+
|
|
92
|
+
Re-evaluate fields that depend on changed paths.
|
|
93
|
+
|
|
94
|
+
### `await evaluator.getEvaluatedSchema({ skipLayout? })`
|
|
95
|
+
|
|
96
|
+
Get the evaluated schema with optional layout resolution.
|
|
97
|
+
|
|
98
|
+
### `await evaluator.getSchemaValue()`
|
|
99
|
+
|
|
100
|
+
Get all schema values (evaluations ending with `.value`).
|
|
101
|
+
|
|
102
|
+
### `await evaluator.reloadSchema({ schema, context?, data? })`
|
|
103
|
+
|
|
104
|
+
Reload schema with new data.
|
|
105
|
+
|
|
106
|
+
### `await evaluator.cacheStats()`
|
|
107
|
+
|
|
108
|
+
Get cache statistics: `{ hits, misses, entries }`.
|
|
109
|
+
|
|
110
|
+
### `await evaluator.clearCache()`
|
|
111
|
+
|
|
112
|
+
Clear the evaluation cache.
|
|
113
|
+
|
|
114
|
+
### `await evaluator.cacheLen()`
|
|
115
|
+
|
|
116
|
+
Get number of cached entries.
|
|
117
|
+
|
|
118
|
+
### `evaluator.free()`
|
|
119
|
+
|
|
120
|
+
Free WASM resources. Always call when done.
|
|
121
|
+
|
|
122
|
+
### `version()`
|
|
123
|
+
|
|
124
|
+
Get library version string.
|
|
125
|
+
|
|
126
|
+
## Example: Next.js
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
'use client';
|
|
130
|
+
|
|
131
|
+
import { JSONEval } from '@json-eval-rs/bundler';
|
|
132
|
+
import { useEffect, useState } from 'react';
|
|
133
|
+
|
|
134
|
+
export default function MyForm() {
|
|
135
|
+
const [evaluator, setEvaluator] = useState(null);
|
|
136
|
+
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
// Dynamically import (client-side only)
|
|
139
|
+
import('@json-eval-rs/bundler').then(({ JSONEval }) => {
|
|
140
|
+
const instance = new JSONEval({ schema });
|
|
141
|
+
setEvaluator(instance);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return () => {
|
|
145
|
+
if (evaluator) evaluator.free();
|
|
146
|
+
};
|
|
147
|
+
}, []);
|
|
148
|
+
|
|
149
|
+
// ... use evaluator
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @json-eval-rs/bundler - TypeScript definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ValidationError {
|
|
6
|
+
path: string;
|
|
7
|
+
rule_type: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ValidationResult {
|
|
12
|
+
has_error: boolean;
|
|
13
|
+
errors: ValidationError[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface JSONEvalOptions {
|
|
17
|
+
schema: any;
|
|
18
|
+
context?: any;
|
|
19
|
+
data?: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ValidateOptions {
|
|
23
|
+
data: any;
|
|
24
|
+
context?: any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface EvaluateOptions {
|
|
28
|
+
data: any;
|
|
29
|
+
context?: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface EvaluateDependentsOptions {
|
|
33
|
+
changedPaths: string[];
|
|
34
|
+
data: any;
|
|
35
|
+
context?: any;
|
|
36
|
+
nested?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface GetEvaluatedSchemaOptions {
|
|
40
|
+
skipLayout?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ReloadSchemaOptions {
|
|
44
|
+
schema: any;
|
|
45
|
+
context?: any;
|
|
46
|
+
data?: any;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface CacheStats {
|
|
50
|
+
hits: number;
|
|
51
|
+
misses: number;
|
|
52
|
+
entries: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface EvaluateSubformOptions {
|
|
56
|
+
subformPath: string;
|
|
57
|
+
data: any;
|
|
58
|
+
context?: any;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface ValidateSubformOptions {
|
|
62
|
+
subformPath: string;
|
|
63
|
+
data: any;
|
|
64
|
+
context?: any;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface EvaluateDependentsSubformOptions {
|
|
68
|
+
subformPath: string;
|
|
69
|
+
changedPath: string;
|
|
70
|
+
data?: any;
|
|
71
|
+
context?: any;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface ResolveLayoutSubformOptions {
|
|
75
|
+
subformPath: string;
|
|
76
|
+
evaluate?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface GetEvaluatedSchemaSubformOptions {
|
|
80
|
+
subformPath: string;
|
|
81
|
+
resolveLayout?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface GetSchemaValueSubformOptions {
|
|
85
|
+
subformPath: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface GetEvaluatedSchemaByPathSubformOptions {
|
|
89
|
+
subformPath: string;
|
|
90
|
+
schemaPath: string;
|
|
91
|
+
skipLayout?: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class JSONEval {
|
|
95
|
+
constructor(options: JSONEvalOptions);
|
|
96
|
+
init(): Promise<void>;
|
|
97
|
+
validate(options: ValidateOptions): Promise<ValidationResult>;
|
|
98
|
+
evaluate(options: EvaluateOptions): Promise<any>;
|
|
99
|
+
evaluateDependents(options: EvaluateDependentsOptions): Promise<any>;
|
|
100
|
+
getEvaluatedSchema(options?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
101
|
+
getSchemaValue(): Promise<any>;
|
|
102
|
+
reloadSchema(options: ReloadSchemaOptions): Promise<void>;
|
|
103
|
+
cacheStats(): Promise<CacheStats>;
|
|
104
|
+
clearCache(): Promise<void>;
|
|
105
|
+
cacheLen(): Promise<number>;
|
|
106
|
+
|
|
107
|
+
// Subform methods
|
|
108
|
+
evaluateSubform(options: EvaluateSubformOptions): Promise<void>;
|
|
109
|
+
validateSubform(options: ValidateSubformOptions): Promise<ValidationResult>;
|
|
110
|
+
evaluateDependentsSubform(options: EvaluateDependentsSubformOptions): Promise<any>;
|
|
111
|
+
resolveLayoutSubform(options: ResolveLayoutSubformOptions): Promise<void>;
|
|
112
|
+
getEvaluatedSchemaSubform(options: GetEvaluatedSchemaSubformOptions): Promise<any>;
|
|
113
|
+
getSchemaValueSubform(options: GetSchemaValueSubformOptions): Promise<any>;
|
|
114
|
+
getEvaluatedSchemaWithoutParamsSubform(options: GetEvaluatedSchemaSubformOptions): Promise<any>;
|
|
115
|
+
getEvaluatedSchemaByPathSubform(options: GetEvaluatedSchemaByPathSubformOptions): Promise<any | null>;
|
|
116
|
+
getSubformPaths(): Promise<string[]>;
|
|
117
|
+
hasSubform(subformPath: string): Promise<boolean>;
|
|
118
|
+
|
|
119
|
+
free(): void;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function version(): string;
|
|
123
|
+
|
|
124
|
+
export default JSONEval;
|
package/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @json-eval-rs/bundler
|
|
3
|
+
* JSON Eval RS for modern bundlers (Webpack, Vite, Rollup, Next.js, etc.)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { JSONEvalCore, getVersion } from '@json-eval-rs/webcore';
|
|
7
|
+
import * as wasm from './pkg/json_eval_rs.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* JSONEval class with bundler WASM pre-configured
|
|
11
|
+
*/
|
|
12
|
+
export class JSONEval extends JSONEvalCore {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(wasm, options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create a new JSONEval instance from a cached ParsedSchema
|
|
19
|
+
* @param {string} cacheKey - Cache key to lookup in ParsedSchemaCache
|
|
20
|
+
* @param {object} [context] - Optional context data
|
|
21
|
+
* @param {object} [data] - Optional initial data
|
|
22
|
+
* @returns {JSONEval} New instance
|
|
23
|
+
*/
|
|
24
|
+
static fromCache(cacheKey, context, data) {
|
|
25
|
+
return new JSONEval({
|
|
26
|
+
schema: cacheKey,
|
|
27
|
+
context,
|
|
28
|
+
data,
|
|
29
|
+
fromCache: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get library version
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
export function version() {
|
|
39
|
+
return getVersion(wasm);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Re-export types for convenience
|
|
43
|
+
export * from '@json-eval-rs/webcore';
|
|
44
|
+
|
|
45
|
+
export default JSONEval;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@json-eval-rs/bundler",
|
|
3
|
+
"version": "0.0.29",
|
|
4
|
+
"description": "JSON Eval RS for bundlers (Webpack, Vite, Next.js, etc.) with ergonomic API",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"index.d.ts",
|
|
11
|
+
"pkg/*.js",
|
|
12
|
+
"pkg/*.wasm",
|
|
13
|
+
"pkg/*.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"json",
|
|
17
|
+
"json-logic",
|
|
18
|
+
"schema",
|
|
19
|
+
"validation",
|
|
20
|
+
"wasm",
|
|
21
|
+
"webpack",
|
|
22
|
+
"vite",
|
|
23
|
+
"bundler"
|
|
24
|
+
],
|
|
25
|
+
"author": "Muhamad Rizki",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/byrizki/json-eval-rs.git",
|
|
30
|
+
"directory": "bindings/web/packages/bundler"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@json-eval-rs/webcore": "*"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false
|
|
36
|
+
}
|