rustica 1.0.0
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/LICENSE +21 -0
- package/README.md +289 -0
- package/dist/form/index.d.ts +60 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +194 -0
- package/dist/form/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +55 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +120 -0
- package/dist/react/index.js.map +1 -0
- package/dist/schema/builders.d.ts +126 -0
- package/dist/schema/builders.d.ts.map +1 -0
- package/dist/schema/builders.js +193 -0
- package/dist/schema/builders.js.map +1 -0
- package/dist/schema/index.d.ts +35 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +42 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/types.d.ts +71 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +5 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/validator/index.d.ts +71 -0
- package/dist/validator/index.d.ts.map +1 -0
- package/dist/validator/index.js +149 -0
- package/dist/validator/index.js.map +1 -0
- package/package.json +71 -0
- package/pkg/.gitignore +1 -0
- package/pkg/.npmignore +3 -0
- package/pkg/README.md +289 -0
- package/pkg/package.json +17 -0
- package/pkg/rustica.d.ts +42 -0
- package/pkg/rustica.js +9 -0
- package/pkg/rustica_bg.js +193 -0
- package/pkg/rustica_bg.wasm +0 -0
- package/pkg/rustica_bg.wasm.d.ts +10 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM interface for validation
|
|
3
|
+
*
|
|
4
|
+
* This module exposes exactly two functions to JavaScript:
|
|
5
|
+
* - validate: validates entire data against schema
|
|
6
|
+
* - validate_at_path: validates data at a specific path
|
|
7
|
+
*
|
|
8
|
+
* Both functions accept and return JSON strings for zero-copy performance
|
|
9
|
+
*/
|
|
10
|
+
export class WasmValidator {
|
|
11
|
+
__destroy_into_raw() {
|
|
12
|
+
const ptr = this.__wbg_ptr;
|
|
13
|
+
this.__wbg_ptr = 0;
|
|
14
|
+
WasmValidatorFinalization.unregister(this);
|
|
15
|
+
return ptr;
|
|
16
|
+
}
|
|
17
|
+
free() {
|
|
18
|
+
const ptr = this.__destroy_into_raw();
|
|
19
|
+
wasm.__wbg_wasmvalidator_free(ptr, 0);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validate data against a schema
|
|
23
|
+
*
|
|
24
|
+
* # Arguments
|
|
25
|
+
* * `schema_json` - JSON string representing the schema AST
|
|
26
|
+
* * `value_json` - JSON string representing the data to validate
|
|
27
|
+
*
|
|
28
|
+
* # Returns
|
|
29
|
+
* JSON string with validation result:
|
|
30
|
+
* - Success: `{"success": true}`
|
|
31
|
+
* - Error: `{"success": false, "errors": [...]}`
|
|
32
|
+
* @param {string} schema_json
|
|
33
|
+
* @param {string} value_json
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
static validate(schema_json, value_json) {
|
|
37
|
+
let deferred3_0;
|
|
38
|
+
let deferred3_1;
|
|
39
|
+
try {
|
|
40
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
41
|
+
const ptr0 = passStringToWasm0(schema_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
42
|
+
const len0 = WASM_VECTOR_LEN;
|
|
43
|
+
const ptr1 = passStringToWasm0(value_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
44
|
+
const len1 = WASM_VECTOR_LEN;
|
|
45
|
+
wasm.wasmvalidator_validate(retptr, ptr0, len0, ptr1, len1);
|
|
46
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
47
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
48
|
+
deferred3_0 = r0;
|
|
49
|
+
deferred3_1 = r1;
|
|
50
|
+
return getStringFromWasm0(r0, r1);
|
|
51
|
+
} finally {
|
|
52
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
53
|
+
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validate data at a specific path in the schema
|
|
58
|
+
*
|
|
59
|
+
* # Arguments
|
|
60
|
+
* * `schema_json` - JSON string representing the schema AST
|
|
61
|
+
* * `value_json` - JSON string representing the data to validate
|
|
62
|
+
* * `path_json` - JSON array of path segments as strings
|
|
63
|
+
*
|
|
64
|
+
* # Returns
|
|
65
|
+
* JSON string with validation result (same format as validate)
|
|
66
|
+
* @param {string} schema_json
|
|
67
|
+
* @param {string} value_json
|
|
68
|
+
* @param {string} path_json
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
static validate_at_path(schema_json, value_json, path_json) {
|
|
72
|
+
let deferred4_0;
|
|
73
|
+
let deferred4_1;
|
|
74
|
+
try {
|
|
75
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
76
|
+
const ptr0 = passStringToWasm0(schema_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
77
|
+
const len0 = WASM_VECTOR_LEN;
|
|
78
|
+
const ptr1 = passStringToWasm0(value_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
79
|
+
const len1 = WASM_VECTOR_LEN;
|
|
80
|
+
const ptr2 = passStringToWasm0(path_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
81
|
+
const len2 = WASM_VECTOR_LEN;
|
|
82
|
+
wasm.wasmvalidator_validate_at_path(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
83
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
84
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
85
|
+
deferred4_0 = r0;
|
|
86
|
+
deferred4_1 = r1;
|
|
87
|
+
return getStringFromWasm0(r0, r1);
|
|
88
|
+
} finally {
|
|
89
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
90
|
+
wasm.__wbindgen_export3(deferred4_0, deferred4_1, 1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (Symbol.dispose) WasmValidator.prototype[Symbol.dispose] = WasmValidator.prototype.free;
|
|
95
|
+
export function __wbg___wbindgen_throw_be289d5034ed271b(arg0, arg1) {
|
|
96
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
97
|
+
}
|
|
98
|
+
const WasmValidatorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
99
|
+
? { register: () => {}, unregister: () => {} }
|
|
100
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmvalidator_free(ptr >>> 0, 1));
|
|
101
|
+
|
|
102
|
+
let cachedDataViewMemory0 = null;
|
|
103
|
+
function getDataViewMemory0() {
|
|
104
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
105
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
106
|
+
}
|
|
107
|
+
return cachedDataViewMemory0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getStringFromWasm0(ptr, len) {
|
|
111
|
+
ptr = ptr >>> 0;
|
|
112
|
+
return decodeText(ptr, len);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let cachedUint8ArrayMemory0 = null;
|
|
116
|
+
function getUint8ArrayMemory0() {
|
|
117
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
118
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
119
|
+
}
|
|
120
|
+
return cachedUint8ArrayMemory0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
124
|
+
if (realloc === undefined) {
|
|
125
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
126
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
127
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
128
|
+
WASM_VECTOR_LEN = buf.length;
|
|
129
|
+
return ptr;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let len = arg.length;
|
|
133
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
134
|
+
|
|
135
|
+
const mem = getUint8ArrayMemory0();
|
|
136
|
+
|
|
137
|
+
let offset = 0;
|
|
138
|
+
|
|
139
|
+
for (; offset < len; offset++) {
|
|
140
|
+
const code = arg.charCodeAt(offset);
|
|
141
|
+
if (code > 0x7F) break;
|
|
142
|
+
mem[ptr + offset] = code;
|
|
143
|
+
}
|
|
144
|
+
if (offset !== len) {
|
|
145
|
+
if (offset !== 0) {
|
|
146
|
+
arg = arg.slice(offset);
|
|
147
|
+
}
|
|
148
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
149
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
150
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
151
|
+
|
|
152
|
+
offset += ret.written;
|
|
153
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
WASM_VECTOR_LEN = offset;
|
|
157
|
+
return ptr;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
161
|
+
cachedTextDecoder.decode();
|
|
162
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
163
|
+
let numBytesDecoded = 0;
|
|
164
|
+
function decodeText(ptr, len) {
|
|
165
|
+
numBytesDecoded += len;
|
|
166
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
167
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
168
|
+
cachedTextDecoder.decode();
|
|
169
|
+
numBytesDecoded = len;
|
|
170
|
+
}
|
|
171
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const cachedTextEncoder = new TextEncoder();
|
|
175
|
+
|
|
176
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
177
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
178
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
179
|
+
view.set(buf);
|
|
180
|
+
return {
|
|
181
|
+
read: arg.length,
|
|
182
|
+
written: buf.length
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let WASM_VECTOR_LEN = 0;
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
let wasm;
|
|
191
|
+
export function __wbg_set_wasm(val) {
|
|
192
|
+
wasm = val;
|
|
193
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_wasmvalidator_free: (a: number, b: number) => void;
|
|
5
|
+
export const wasmvalidator_validate: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
6
|
+
export const wasmvalidator_validate_at_path: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
7
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
8
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
9
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
10
|
+
export const __wbindgen_export3: (a: number, b: number, c: number) => void;
|