jellyschema
Advanced tools
Comparing version 0.11.10 to 0.12.0-next-0-12-7554e23f31009f636bca310dbfafbfa5d708612d
@@ -1,2 +0,3 @@ | ||
var wasm; | ||
let wasm; | ||
const { TextDecoder } = require(String.raw`util`); | ||
@@ -32,336 +33,245 @@ const heap = new Array(32); | ||
} | ||
/** | ||
* Generates JSON and UI schema object | ||
* | ||
* ```js | ||
* { | ||
* \"jsonSchema\": {...}, | ||
* \"uiSchema\": {...} | ||
* } | ||
* ``` | ||
* | ||
* # Arguments | ||
* | ||
* * `schema` - Jelly Schema as an object or a string | ||
* | ||
* # Throws | ||
* | ||
* If the input schema is invalid or in case of internal error (serialization). | ||
* @param {any} arg0 | ||
* @returns {any} | ||
*/ | ||
module.exports.generateJsonAndUiSchema = function(arg0) { | ||
try { | ||
return takeObject(wasm.generateJsonAndUiSchema(addBorrowedObject(arg0))); | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
let cachedTextDecoder = new TextDecoder('utf-8'); | ||
} | ||
let cachegetUint8Memory = null; | ||
function getUint8Memory() { | ||
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) { | ||
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer); | ||
} | ||
return cachegetUint8Memory; | ||
} | ||
}; | ||
function getStringFromWasm(ptr, len) { | ||
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len)); | ||
} | ||
/** | ||
* @param {any} arg0 | ||
* @param {any} arg1 | ||
* @param {boolean} arg2 | ||
* @returns {any} | ||
*/ | ||
module.exports.fillDefaultValues = function(arg0, arg1, arg2) { | ||
try { | ||
return takeObject(wasm.fillDefaultValues(addBorrowedObject(arg0), addBorrowedObject(arg1), arg2)); | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
heap[stack_pointer++] = undefined; | ||
heap[idx] = obj; | ||
return idx; | ||
} | ||
} | ||
let WASM_VECTOR_LEN = 0; | ||
}; | ||
let cachegetNodeBufferMemory = null; | ||
function getNodeBufferMemory() { | ||
if (cachegetNodeBufferMemory === null || cachegetNodeBufferMemory.buffer !== wasm.memory.buffer) { | ||
cachegetNodeBufferMemory = Buffer.from(wasm.memory.buffer); | ||
} | ||
return cachegetNodeBufferMemory; | ||
} | ||
const TextDecoder = require('util').TextDecoder; | ||
function passStringToWasm(arg) { | ||
let cachedTextDecoder = new TextDecoder('utf-8'); | ||
const size = Buffer.byteLength(arg); | ||
const ptr = wasm.__wbindgen_malloc(size); | ||
getNodeBufferMemory().write(arg, ptr, size); | ||
WASM_VECTOR_LEN = size; | ||
return ptr; | ||
} | ||
let cachegetUint8Memory = null; | ||
function getUint8Memory() { | ||
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) { | ||
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer); | ||
} | ||
return cachegetUint8Memory; | ||
let cachegetInt32Memory = null; | ||
function getInt32Memory() { | ||
if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) { | ||
cachegetInt32Memory = new Int32Array(wasm.memory.buffer); | ||
} | ||
return cachegetInt32Memory; | ||
} | ||
function getStringFromWasm(ptr, len) { | ||
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len)); | ||
function getArrayU8FromWasm(ptr, len) { | ||
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
let cachegetUint32Memory = null; | ||
function getUint32Memory() { | ||
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) { | ||
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer); | ||
} | ||
return cachegetUint32Memory; | ||
} | ||
/** | ||
*/ | ||
class JellySchema { | ||
module.exports.__wbg_error_4bb6c2a97407129a = function(arg0, arg1) { | ||
let varg0 = getStringFromWasm(arg0, arg1); | ||
static __wrap(ptr) { | ||
const obj = Object.create(JellySchema.prototype); | ||
obj.ptr = ptr; | ||
varg0 = varg0.slice(); | ||
wasm.__wbindgen_free(arg0, arg1 * 1); | ||
console.error(varg0); | ||
}; | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
heap[idx] = obj; | ||
return idx; | ||
return obj; | ||
} | ||
module.exports.__wbg_new_59cb74e423758ede = function() { | ||
return addHeapObject(new Error()); | ||
}; | ||
free() { | ||
const ptr = this.ptr; | ||
this.ptr = 0; | ||
const TextEncoder = require('util').TextEncoder; | ||
let cachedTextEncoder = new TextEncoder('utf-8'); | ||
let WASM_VECTOR_LEN = 0; | ||
let passStringToWasm; | ||
if (typeof cachedTextEncoder.encodeInto === 'function') { | ||
passStringToWasm = function(arg) { | ||
let size = arg.length; | ||
let ptr = wasm.__wbindgen_malloc(size); | ||
let writeOffset = 0; | ||
while (true) { | ||
const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size); | ||
const { read, written } = cachedTextEncoder.encodeInto(arg, view); | ||
arg = arg.substring(read); | ||
writeOffset += written; | ||
if (arg.length === 0) { | ||
break; | ||
} | ||
ptr = wasm.__wbindgen_realloc(ptr, size, size * 2); | ||
size *= 2; | ||
} | ||
WASM_VECTOR_LEN = writeOffset; | ||
return ptr; | ||
}; | ||
} else { | ||
passStringToWasm = function(arg) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
const ptr = wasm.__wbindgen_malloc(buf.length); | ||
getUint8Memory().set(buf, ptr); | ||
WASM_VECTOR_LEN = buf.length; | ||
return ptr; | ||
}; | ||
wasm.__wbg_jellyschema_free(ptr); | ||
} | ||
let cachegetUint32Memory = null; | ||
function getUint32Memory() { | ||
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) { | ||
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer); | ||
/** | ||
* Instantiate new JellySchema object. | ||
* | ||
* # Arguments | ||
* | ||
* * `schema` - JellySchema as a string or an object. | ||
* | ||
* # Throws | ||
* | ||
* Constructor throws in case of invalid `schema` argument value. | ||
* @param {any} schema | ||
* @returns {JellySchema} | ||
*/ | ||
constructor(schema) { | ||
try { | ||
const ret = wasm.jellyschema_constructor(addBorrowedObject(schema)); | ||
return JellySchema.__wrap(ret); | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
} | ||
return cachegetUint32Memory; | ||
} | ||
module.exports.__wbg_stack_558ba5917b466edd = function(ret, arg0) { | ||
const retptr = passStringToWasm(getObject(arg0).stack); | ||
const retlen = WASM_VECTOR_LEN; | ||
const mem = getUint32Memory(); | ||
mem[ret / 4] = retptr; | ||
mem[ret / 4 + 1] = retlen; | ||
}; | ||
module.exports.__wbg_getTime_ece6079ef900687a = function(arg0) { | ||
return getObject(arg0).getTime(); | ||
}; | ||
module.exports.__wbg_new0_7a2568f251003178 = function() { | ||
return addHeapObject(new Date()); | ||
}; | ||
module.exports.__wbg_new_c485e81233f857dc = function(arg0, arg1) { | ||
let varg0 = getStringFromWasm(arg0, arg1); | ||
return addHeapObject(new Function(varg0)); | ||
}; | ||
module.exports.__wbg_call_5dd2903e2041df91 = function(arg0, arg1) { | ||
return addHeapObject(getObject(arg0).call(getObject(arg1))); | ||
}; | ||
module.exports.__wbg_self_593d5fcdf47729c1 = function(arg0) { | ||
return addHeapObject(getObject(arg0).self); | ||
}; | ||
module.exports.__wbg_crypto_0255f439f7c7cf2e = function(arg0) { | ||
return addHeapObject(getObject(arg0).crypto); | ||
}; | ||
module.exports.__wbg_getRandomValues_00289894188ac3d8 = function(arg0) { | ||
return addHeapObject(getObject(arg0).getRandomValues); | ||
}; | ||
function getArrayU8FromWasm(ptr, len) { | ||
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len); | ||
/** | ||
* Validate data against JellySchema. | ||
* | ||
* # Arguments | ||
* | ||
* * `data` - A JSON object. | ||
* @param {any} data | ||
* @returns {boolean} | ||
*/ | ||
validate(data) { | ||
try { | ||
const ret = wasm.jellyschema_validate(this.ptr, addBorrowedObject(data)); | ||
return ret !== 0; | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
} | ||
} | ||
/** | ||
* Return last validation errors. | ||
* | ||
* # Throws | ||
* | ||
* In case of internal error only (serialization). | ||
* @returns {any} | ||
*/ | ||
errors() { | ||
const ret = wasm.jellyschema_errors(this.ptr); | ||
return takeObject(ret); | ||
} | ||
} | ||
module.exports.JellySchema = JellySchema; | ||
module.exports.__wbg_getRandomValues_957b4e930554e3a0 = function(arg0, arg1, arg2) { | ||
let varg1 = getArrayU8FromWasm(arg1, arg2); | ||
getObject(arg0).getRandomValues(varg1); | ||
}; | ||
module.exports.__wbindgen_string_new = function(arg0, arg1) { | ||
const ret = getStringFromWasm(arg0, arg1); | ||
return addHeapObject(ret); | ||
}; | ||
module.exports.__wbg_require_1d9cd4e0b19bc7a1 = function(arg0, arg1) { | ||
let varg0 = getStringFromWasm(arg0, arg1); | ||
return addHeapObject(require(varg0)); | ||
}; | ||
module.exports.__wbindgen_json_serialize = function(arg0, arg1) { | ||
const ret = JSON.stringify(getObject(arg1)); | ||
const ret0 = passStringToWasm(ret); | ||
const ret1 = WASM_VECTOR_LEN; | ||
getInt32Memory()[arg0 / 4 + 0] = ret0; | ||
getInt32Memory()[arg0 / 4 + 1] = ret1; | ||
}; | ||
module.exports.__wbg_randomFillSync_516d812ff22b7f58 = function(arg0, arg1, arg2) { | ||
let varg1 = getArrayU8FromWasm(arg1, arg2); | ||
getObject(arg0).randomFillSync(varg1); | ||
}; | ||
module.exports.__wbindgen_is_undefined = function(arg0) { | ||
const ret = getObject(arg0) === undefined; | ||
return ret; | ||
}; | ||
module.exports.__wbindgen_string_new = function(p, l) { return addHeapObject(getStringFromWasm(p, l)); }; | ||
module.exports.__wbindgen_json_parse = function(arg0, arg1) { | ||
const ret = JSON.parse(getStringFromWasm(arg0, arg1)); | ||
return addHeapObject(ret); | ||
}; | ||
module.exports.__wbindgen_is_undefined = function(i) { return getObject(i) === undefined ? 1 : 0; }; | ||
module.exports.__wbg_new_59cb74e423758ede = function() { | ||
const ret = new Error(); | ||
return addHeapObject(ret); | ||
}; | ||
module.exports.__wbindgen_is_string = function(i) { return typeof(getObject(i)) === 'string' ? 1 : 0; }; | ||
module.exports.__wbg_stack_558ba5917b466edd = function(arg0, arg1) { | ||
const ret = getObject(arg1).stack; | ||
const ret0 = passStringToWasm(ret); | ||
const ret1 = WASM_VECTOR_LEN; | ||
getInt32Memory()[arg0 / 4 + 0] = ret0; | ||
getInt32Memory()[arg0 / 4 + 1] = ret1; | ||
}; | ||
module.exports.__wbindgen_string_get = function(i, len_ptr) { | ||
let obj = getObject(i); | ||
if (typeof(obj) !== 'string') return 0; | ||
const ptr = passStringToWasm(obj); | ||
getUint32Memory()[len_ptr / 4] = WASM_VECTOR_LEN; | ||
return ptr; | ||
}; | ||
module.exports.__wbg_error_4bb6c2a97407129a = function(arg0, arg1) { | ||
const v0 = getStringFromWasm(arg0, arg1).slice(); | ||
wasm.__wbindgen_free(arg0, arg1 * 1); | ||
console.error(v0); | ||
}; | ||
module.exports.__wbindgen_json_parse = function(ptr, len) { return addHeapObject(JSON.parse(getStringFromWasm(ptr, len))); }; | ||
module.exports.__wbindgen_object_drop_ref = function(arg0) { | ||
takeObject(arg0); | ||
}; | ||
module.exports.__wbindgen_json_serialize = function(idx, ptrptr) { | ||
const ptr = passStringToWasm(JSON.stringify(getObject(idx))); | ||
getUint32Memory()[ptrptr / 4] = ptr; | ||
return WASM_VECTOR_LEN; | ||
}; | ||
module.exports.__wbg_getRandomValues_1ef11e888e5228e9 = function(arg0, arg1, arg2) { | ||
getObject(arg0).getRandomValues(getArrayU8FromWasm(arg1, arg2)); | ||
}; | ||
module.exports.__wbindgen_jsval_eq = function(a, b) { return getObject(a) === getObject(b) ? 1 : 0; }; | ||
module.exports.__wbg_randomFillSync_1b52c8482374c55b = function(arg0, arg1, arg2) { | ||
getObject(arg0).randomFillSync(getArrayU8FromWasm(arg1, arg2)); | ||
}; | ||
module.exports.__wbindgen_rethrow = function(idx) { throw takeObject(idx); }; | ||
module.exports.__wbg_new_3a746f2619705add = function(arg0, arg1) { | ||
const ret = new Function(getStringFromWasm(arg0, arg1)); | ||
return addHeapObject(ret); | ||
}; | ||
module.exports.__wbindgen_throw = function(ptr, len) { | ||
throw new Error(getStringFromWasm(ptr, len)); | ||
}; | ||
module.exports.__wbg_call_f54d3a6dadb199ca = function(arg0, arg1) { | ||
const ret = getObject(arg0).call(getObject(arg1)); | ||
return addHeapObject(ret); | ||
}; | ||
function freeJellySchema(ptr) { | ||
module.exports.__wbindgen_jsval_eq = function(arg0, arg1) { | ||
const ret = getObject(arg0) === getObject(arg1); | ||
return ret; | ||
}; | ||
wasm.__wbg_jellyschema_free(ptr); | ||
} | ||
/** | ||
*/ | ||
class JellySchema { | ||
module.exports.__wbg_self_ac379e780a0d8b94 = function(arg0) { | ||
const ret = getObject(arg0).self; | ||
return addHeapObject(ret); | ||
}; | ||
free() { | ||
const ptr = this.ptr; | ||
this.ptr = 0; | ||
freeJellySchema(ptr); | ||
} | ||
module.exports.__wbg_require_6461b1e9a0d7c34a = function(arg0, arg1) { | ||
const ret = require(getStringFromWasm(arg0, arg1)); | ||
return addHeapObject(ret); | ||
}; | ||
/** | ||
* Instantiates new JellySchema object | ||
* | ||
* # Arguments | ||
* | ||
* * `schema` - JellySchema as a string or an object | ||
* | ||
* # Throws | ||
* | ||
* Constructor throws in case of invalid `schema` argument value. | ||
* @param {any} arg0 | ||
* @returns {} | ||
*/ | ||
constructor(arg0) { | ||
try { | ||
this.ptr = wasm.jellyschema_constructor(addBorrowedObject(arg0)); | ||
module.exports.__wbg_crypto_1e4302b85d4f64a2 = function(arg0) { | ||
const ret = getObject(arg0).crypto; | ||
return addHeapObject(ret); | ||
}; | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
module.exports.__wbg_getRandomValues_1b4ba144162a5c9e = function(arg0) { | ||
const ret = getObject(arg0).getRandomValues; | ||
return addHeapObject(ret); | ||
}; | ||
} | ||
module.exports.__wbindgen_is_string = function(arg0) { | ||
const ret = typeof(getObject(arg0)) === 'string'; | ||
return ret; | ||
}; | ||
} | ||
/** | ||
* Fills missing `default` values | ||
* | ||
* # Arguments | ||
* | ||
* * `data` - JSON value (string, object, array, ...) | ||
* * `include_optional` - if `false` only required properties are filled in otherwise | ||
* optional properties are filled too | ||
* @param {any} arg0 | ||
* @param {boolean} arg1 | ||
* @returns {any} | ||
*/ | ||
fillDefaultValues(arg0, arg1) { | ||
try { | ||
return takeObject(wasm.jellyschema_fillDefaultValues(this.ptr, addBorrowedObject(arg0), arg1)); | ||
module.exports.__wbindgen_string_get = function(arg0, arg1) { | ||
const obj = getObject(arg0); | ||
if (typeof(obj) !== 'string') return 0; | ||
const ptr = passStringToWasm(obj); | ||
getUint32Memory()[arg1 / 4] = WASM_VECTOR_LEN; | ||
const ret = ptr; | ||
return ret; | ||
}; | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
module.exports.__wbindgen_throw = function(arg0, arg1) { | ||
throw new Error(getStringFromWasm(arg0, arg1)); | ||
}; | ||
} | ||
module.exports.__wbindgen_rethrow = function(arg0) { | ||
throw takeObject(arg0); | ||
}; | ||
wasm = require('./jellyschema_wasm'); | ||
} | ||
/** | ||
* Validates data against JellySchema | ||
* | ||
* # Arguments | ||
* | ||
* * `data` - A JSON object | ||
* @param {any} arg0 | ||
* @returns {boolean} | ||
*/ | ||
validate(arg0) { | ||
try { | ||
return (wasm.jellyschema_validate(this.ptr, addBorrowedObject(arg0))) !== 0; | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
} | ||
} | ||
/** | ||
* Generates JSON Schema & UI Schema object | ||
* | ||
* ```js | ||
* { | ||
* \"jsonSchema\": {...}, | ||
* \"uiSchema\": {...} | ||
* } | ||
* ``` | ||
* | ||
* # Throws | ||
* | ||
* In case of internal error only (serialization). | ||
* @returns {any} | ||
*/ | ||
jsonAndUiSchema() { | ||
return takeObject(wasm.jellyschema_jsonAndUiSchema(this.ptr)); | ||
} | ||
/** | ||
* Returns last validation errors | ||
* | ||
* # Throws | ||
* | ||
* In case of internal error only (serialization). | ||
* @returns {any} | ||
*/ | ||
errors() { | ||
return takeObject(wasm.jellyschema_errors(this.ptr)); | ||
} | ||
} | ||
module.exports.JellySchema = JellySchema; | ||
module.exports.__wbindgen_object_drop_ref = function(i) { dropObject(i); }; | ||
wasm = require('./jellyschema_wasm'); | ||
@@ -5,3 +5,3 @@ | ||
let imports = {}; | ||
imports['./jellyschema'] = require('./jellyschema_main'); | ||
imports['./jellyschema.js'] = require('./jellyschema_main.js'); | ||
@@ -8,0 +8,0 @@ const wasmModule = new WebAssembly.Module(bytes); |
/* tslint:disable */ | ||
/** | ||
* Generates JSON and UI schema object | ||
*/ | ||
export class JellySchema { | ||
free(): void; | ||
/** | ||
* Instantiate new JellySchema object. | ||
* | ||
* ```js | ||
* { | ||
* \"jsonSchema\": {...}, | ||
* \"uiSchema\": {...} | ||
* } | ||
* ``` | ||
* | ||
* # Arguments | ||
* | ||
* * `schema` - Jelly Schema as an object or a string | ||
* * `schema` - JellySchema as a string or an object. | ||
* | ||
* # Throws | ||
* | ||
* If the input schema is invalid or in case of internal error (serialization). | ||
* @param {any} arg0 | ||
* @returns {any} | ||
* Constructor throws in case of invalid `schema` argument value. | ||
* @param {any} schema | ||
* @returns {JellySchema} | ||
*/ | ||
export function generateJsonAndUiSchema(arg0: any): any; | ||
constructor(schema: any); | ||
/** | ||
* @param {any} arg0 | ||
* @param {any} arg1 | ||
* @param {boolean} arg2 | ||
* @returns {any} | ||
* Validate data against JellySchema. | ||
* | ||
* # Arguments | ||
* | ||
* * `data` - A JSON object. | ||
* @param {any} data | ||
* @returns {boolean} | ||
*/ | ||
export function fillDefaultValues(arg0: any, arg1: any, arg2: boolean): any; | ||
validate(data: any): boolean; | ||
/** | ||
* Return last validation errors. | ||
* | ||
* # Throws | ||
* | ||
* In case of internal error only (serialization). | ||
* @returns {any} | ||
*/ | ||
export class JellySchema { | ||
free(): void; | ||
constructor(arg0: any); | ||
fillDefaultValues(arg0: any, arg1: boolean): any; | ||
validate(arg0: any): boolean; | ||
jsonAndUiSchema(): any; | ||
errors(): any; | ||
} |
@@ -1,2 +0,2 @@ | ||
import * as wasm from './jellyschema_bg'; | ||
import * as wasm from './jellyschema_bg.wasm'; | ||
@@ -32,223 +32,104 @@ const heap = new Array(32); | ||
} | ||
/** | ||
* Generates JSON and UI schema object | ||
* | ||
* ```js | ||
* { | ||
* \"jsonSchema\": {...}, | ||
* \"uiSchema\": {...} | ||
* } | ||
* ``` | ||
* | ||
* # Arguments | ||
* | ||
* * `schema` - Jelly Schema as an object or a string | ||
* | ||
* # Throws | ||
* | ||
* If the input schema is invalid or in case of internal error (serialization). | ||
* @param {any} arg0 | ||
* @returns {any} | ||
*/ | ||
export function generateJsonAndUiSchema(arg0) { | ||
try { | ||
return takeObject(wasm.generateJsonAndUiSchema(addBorrowedObject(arg0))); | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
let cachedTextDecoder = new TextDecoder('utf-8'); | ||
} | ||
let cachegetUint8Memory = null; | ||
function getUint8Memory() { | ||
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) { | ||
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer); | ||
} | ||
return cachegetUint8Memory; | ||
} | ||
/** | ||
* @param {any} arg0 | ||
* @param {any} arg1 | ||
* @param {boolean} arg2 | ||
* @returns {any} | ||
*/ | ||
export function fillDefaultValues(arg0, arg1, arg2) { | ||
try { | ||
return takeObject(wasm.fillDefaultValues(addBorrowedObject(arg0), addBorrowedObject(arg1), arg2)); | ||
function getStringFromWasm(ptr, len) { | ||
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len)); | ||
} | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
heap[stack_pointer++] = undefined; | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
} | ||
heap[idx] = obj; | ||
return idx; | ||
} | ||
} | ||
let WASM_VECTOR_LEN = 0; | ||
let cachedTextDecoder = new TextDecoder('utf-8'); | ||
let cachedTextEncoder = new TextEncoder('utf-8'); | ||
let cachegetUint8Memory = null; | ||
function getUint8Memory() { | ||
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) { | ||
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer); | ||
} | ||
return cachegetUint8Memory; | ||
} | ||
let passStringToWasm; | ||
if (typeof cachedTextEncoder.encodeInto === 'function') { | ||
passStringToWasm = function(arg) { | ||
function getStringFromWasm(ptr, len) { | ||
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len)); | ||
} | ||
export function __wbg_error_4bb6c2a97407129a(arg0, arg1) { | ||
let varg0 = getStringFromWasm(arg0, arg1); | ||
let size = arg.length; | ||
let ptr = wasm.__wbindgen_malloc(size); | ||
let offset = 0; | ||
{ | ||
const mem = getUint8Memory(); | ||
for (; offset < arg.length; offset++) { | ||
const code = arg.charCodeAt(offset); | ||
if (code > 0x7F) break; | ||
mem[ptr + offset] = code; | ||
} | ||
} | ||
varg0 = varg0.slice(); | ||
wasm.__wbindgen_free(arg0, arg1 * 1); | ||
if (offset !== arg.length) { | ||
arg = arg.slice(offset); | ||
ptr = wasm.__wbindgen_realloc(ptr, size, size = offset + arg.length * 3); | ||
const view = getUint8Memory().subarray(ptr + offset, ptr + size); | ||
const ret = cachedTextEncoder.encodeInto(arg, view); | ||
console.error(varg0); | ||
} | ||
offset += ret.written; | ||
} | ||
WASM_VECTOR_LEN = offset; | ||
return ptr; | ||
}; | ||
} else { | ||
passStringToWasm = function(arg) { | ||
function addHeapObject(obj) { | ||
if (heap_next === heap.length) heap.push(heap.length + 1); | ||
const idx = heap_next; | ||
heap_next = heap[idx]; | ||
heap[idx] = obj; | ||
return idx; | ||
} | ||
export function __wbg_new_59cb74e423758ede() { | ||
return addHeapObject(new Error()); | ||
} | ||
let cachedTextEncoder = new TextEncoder('utf-8'); | ||
let WASM_VECTOR_LEN = 0; | ||
let passStringToWasm; | ||
if (typeof cachedTextEncoder.encodeInto === 'function') { | ||
passStringToWasm = function(arg) { | ||
let size = arg.length; | ||
let ptr = wasm.__wbindgen_malloc(size); | ||
let writeOffset = 0; | ||
while (true) { | ||
const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size); | ||
const { read, written } = cachedTextEncoder.encodeInto(arg, view); | ||
arg = arg.substring(read); | ||
writeOffset += written; | ||
if (arg.length === 0) { | ||
break; | ||
} | ||
ptr = wasm.__wbindgen_realloc(ptr, size, size * 2); | ||
size *= 2; | ||
let size = arg.length; | ||
let ptr = wasm.__wbindgen_malloc(size); | ||
let offset = 0; | ||
{ | ||
const mem = getUint8Memory(); | ||
for (; offset < arg.length; offset++) { | ||
const code = arg.charCodeAt(offset); | ||
if (code > 0x7F) break; | ||
mem[ptr + offset] = code; | ||
} | ||
WASM_VECTOR_LEN = writeOffset; | ||
return ptr; | ||
}; | ||
} else { | ||
passStringToWasm = function(arg) { | ||
} | ||
const buf = cachedTextEncoder.encode(arg); | ||
const ptr = wasm.__wbindgen_malloc(buf.length); | ||
getUint8Memory().set(buf, ptr); | ||
WASM_VECTOR_LEN = buf.length; | ||
return ptr; | ||
}; | ||
} | ||
let cachegetUint32Memory = null; | ||
function getUint32Memory() { | ||
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) { | ||
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer); | ||
if (offset !== arg.length) { | ||
const buf = cachedTextEncoder.encode(arg.slice(offset)); | ||
ptr = wasm.__wbindgen_realloc(ptr, size, size = offset + buf.length); | ||
getUint8Memory().set(buf, ptr + offset); | ||
offset += buf.length; | ||
} | ||
return cachegetUint32Memory; | ||
} | ||
WASM_VECTOR_LEN = offset; | ||
return ptr; | ||
}; | ||
} | ||
export function __wbg_stack_558ba5917b466edd(ret, arg0) { | ||
const retptr = passStringToWasm(getObject(arg0).stack); | ||
const retlen = WASM_VECTOR_LEN; | ||
const mem = getUint32Memory(); | ||
mem[ret / 4] = retptr; | ||
mem[ret / 4 + 1] = retlen; | ||
let cachegetInt32Memory = null; | ||
function getInt32Memory() { | ||
if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) { | ||
cachegetInt32Memory = new Int32Array(wasm.memory.buffer); | ||
} | ||
export function __wbg_getTime_ece6079ef900687a(arg0) { | ||
return getObject(arg0).getTime(); | ||
} | ||
export function __wbg_new0_7a2568f251003178() { | ||
return addHeapObject(new Date()); | ||
} | ||
export function __wbg_new_c485e81233f857dc(arg0, arg1) { | ||
let varg0 = getStringFromWasm(arg0, arg1); | ||
return addHeapObject(new Function(varg0)); | ||
} | ||
export function __wbg_call_5dd2903e2041df91(arg0, arg1) { | ||
return addHeapObject(getObject(arg0).call(getObject(arg1))); | ||
} | ||
export function __wbg_self_593d5fcdf47729c1(arg0) { | ||
return addHeapObject(getObject(arg0).self); | ||
} | ||
export function __wbg_crypto_0255f439f7c7cf2e(arg0) { | ||
return addHeapObject(getObject(arg0).crypto); | ||
} | ||
export function __wbg_getRandomValues_00289894188ac3d8(arg0) { | ||
return addHeapObject(getObject(arg0).getRandomValues); | ||
} | ||
function getArrayU8FromWasm(ptr, len) { | ||
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
export function __wbg_getRandomValues_957b4e930554e3a0(arg0, arg1, arg2) { | ||
let varg1 = getArrayU8FromWasm(arg1, arg2); | ||
getObject(arg0).getRandomValues(varg1); | ||
} | ||
export function __wbg_require_1d9cd4e0b19bc7a1(arg0, arg1) { | ||
let varg0 = getStringFromWasm(arg0, arg1); | ||
return addHeapObject(require(varg0)); | ||
} | ||
export function __wbg_randomFillSync_516d812ff22b7f58(arg0, arg1, arg2) { | ||
let varg1 = getArrayU8FromWasm(arg1, arg2); | ||
getObject(arg0).randomFillSync(varg1); | ||
} | ||
export function __wbindgen_string_new(p, l) { return addHeapObject(getStringFromWasm(p, l)); } | ||
export function __wbindgen_is_undefined(i) { return getObject(i) === undefined ? 1 : 0; } | ||
export function __wbindgen_is_string(i) { return typeof(getObject(i)) === 'string' ? 1 : 0; } | ||
export function __wbindgen_string_get(i, len_ptr) { | ||
let obj = getObject(i); | ||
if (typeof(obj) !== 'string') return 0; | ||
const ptr = passStringToWasm(obj); | ||
getUint32Memory()[len_ptr / 4] = WASM_VECTOR_LEN; | ||
return ptr; | ||
return cachegetInt32Memory; | ||
} | ||
export function __wbindgen_json_parse(ptr, len) { return addHeapObject(JSON.parse(getStringFromWasm(ptr, len))); } | ||
export function __wbindgen_json_serialize(idx, ptrptr) { | ||
const ptr = passStringToWasm(JSON.stringify(getObject(idx))); | ||
getUint32Memory()[ptrptr / 4] = ptr; | ||
return WASM_VECTOR_LEN; | ||
function getArrayU8FromWasm(ptr, len) { | ||
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len); | ||
} | ||
export function __wbindgen_jsval_eq(a, b) { return getObject(a) === getObject(b) ? 1 : 0; } | ||
export function __wbindgen_rethrow(idx) { throw takeObject(idx); } | ||
export function __wbindgen_throw(ptr, len) { | ||
throw new Error(getStringFromWasm(ptr, len)); | ||
let cachegetUint32Memory = null; | ||
function getUint32Memory() { | ||
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) { | ||
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer); | ||
} | ||
return cachegetUint32Memory; | ||
} | ||
function freeJellySchema(ptr) { | ||
wasm.__wbg_jellyschema_free(ptr); | ||
} | ||
/** | ||
@@ -258,14 +139,21 @@ */ | ||
static __wrap(ptr) { | ||
const obj = Object.create(JellySchema.prototype); | ||
obj.ptr = ptr; | ||
return obj; | ||
} | ||
free() { | ||
const ptr = this.ptr; | ||
this.ptr = 0; | ||
freeJellySchema(ptr); | ||
wasm.__wbg_jellyschema_free(ptr); | ||
} | ||
/** | ||
* Instantiates new JellySchema object | ||
* Instantiate new JellySchema object. | ||
* | ||
* # Arguments | ||
* | ||
* * `schema` - JellySchema as a string or an object | ||
* * `schema` - JellySchema as a string or an object. | ||
* | ||
@@ -275,88 +163,154 @@ * # Throws | ||
* Constructor throws in case of invalid `schema` argument value. | ||
* @param {any} arg0 | ||
* @returns {} | ||
* @param {any} schema | ||
* @returns {JellySchema} | ||
*/ | ||
constructor(arg0) { | ||
constructor(schema) { | ||
try { | ||
this.ptr = wasm.jellyschema_constructor(addBorrowedObject(arg0)); | ||
const ret = wasm.jellyschema_constructor(addBorrowedObject(schema)); | ||
return JellySchema.__wrap(ret); | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
} | ||
} | ||
/** | ||
* Fills missing `default` values | ||
* Validate data against JellySchema. | ||
* | ||
* # Arguments | ||
* | ||
* * `data` - JSON value (string, object, array, ...) | ||
* * `include_optional` - if `false` only required properties are filled in otherwise | ||
* optional properties are filled too | ||
* @param {any} arg0 | ||
* @param {boolean} arg1 | ||
* @returns {any} | ||
* * `data` - A JSON object. | ||
* @param {any} data | ||
* @returns {boolean} | ||
*/ | ||
fillDefaultValues(arg0, arg1) { | ||
validate(data) { | ||
try { | ||
return takeObject(wasm.jellyschema_fillDefaultValues(this.ptr, addBorrowedObject(arg0), arg1)); | ||
const ret = wasm.jellyschema_validate(this.ptr, addBorrowedObject(data)); | ||
return ret !== 0; | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
} | ||
} | ||
/** | ||
* Validates data against JellySchema | ||
* Return last validation errors. | ||
* | ||
* # Arguments | ||
* # Throws | ||
* | ||
* * `data` - A JSON object | ||
* @param {any} arg0 | ||
* @returns {boolean} | ||
* In case of internal error only (serialization). | ||
* @returns {any} | ||
*/ | ||
validate(arg0) { | ||
try { | ||
return (wasm.jellyschema_validate(this.ptr, addBorrowedObject(arg0))) !== 0; | ||
errors() { | ||
const ret = wasm.jellyschema_errors(this.ptr); | ||
return takeObject(ret); | ||
} | ||
} | ||
} finally { | ||
heap[stack_pointer++] = undefined; | ||
export const __wbindgen_string_new = function(arg0, arg1) { | ||
const ret = getStringFromWasm(arg0, arg1); | ||
return addHeapObject(ret); | ||
}; | ||
} | ||
export const __wbindgen_json_serialize = function(arg0, arg1) { | ||
const ret = JSON.stringify(getObject(arg1)); | ||
const ret0 = passStringToWasm(ret); | ||
const ret1 = WASM_VECTOR_LEN; | ||
getInt32Memory()[arg0 / 4 + 0] = ret0; | ||
getInt32Memory()[arg0 / 4 + 1] = ret1; | ||
}; | ||
} | ||
/** | ||
* Generates JSON Schema & UI Schema object | ||
* | ||
* ```js | ||
* { | ||
* \"jsonSchema\": {...}, | ||
* \"uiSchema\": {...} | ||
* } | ||
* ``` | ||
* | ||
* # Throws | ||
* | ||
* In case of internal error only (serialization). | ||
* @returns {any} | ||
*/ | ||
jsonAndUiSchema() { | ||
return takeObject(wasm.jellyschema_jsonAndUiSchema(this.ptr)); | ||
} | ||
/** | ||
* Returns last validation errors | ||
* | ||
* # Throws | ||
* | ||
* In case of internal error only (serialization). | ||
* @returns {any} | ||
*/ | ||
errors() { | ||
return takeObject(wasm.jellyschema_errors(this.ptr)); | ||
} | ||
} | ||
export const __wbindgen_is_undefined = function(arg0) { | ||
const ret = getObject(arg0) === undefined; | ||
return ret; | ||
}; | ||
export function __wbindgen_object_drop_ref(i) { dropObject(i); } | ||
export const __wbindgen_json_parse = function(arg0, arg1) { | ||
const ret = JSON.parse(getStringFromWasm(arg0, arg1)); | ||
return addHeapObject(ret); | ||
}; | ||
export const __wbg_new_59cb74e423758ede = function() { | ||
const ret = new Error(); | ||
return addHeapObject(ret); | ||
}; | ||
export const __wbg_stack_558ba5917b466edd = function(arg0, arg1) { | ||
const ret = getObject(arg1).stack; | ||
const ret0 = passStringToWasm(ret); | ||
const ret1 = WASM_VECTOR_LEN; | ||
getInt32Memory()[arg0 / 4 + 0] = ret0; | ||
getInt32Memory()[arg0 / 4 + 1] = ret1; | ||
}; | ||
export const __wbg_error_4bb6c2a97407129a = function(arg0, arg1) { | ||
const v0 = getStringFromWasm(arg0, arg1).slice(); | ||
wasm.__wbindgen_free(arg0, arg1 * 1); | ||
console.error(v0); | ||
}; | ||
export const __wbindgen_object_drop_ref = function(arg0) { | ||
takeObject(arg0); | ||
}; | ||
export const __wbg_getRandomValues_1ef11e888e5228e9 = function(arg0, arg1, arg2) { | ||
getObject(arg0).getRandomValues(getArrayU8FromWasm(arg1, arg2)); | ||
}; | ||
export const __wbg_randomFillSync_1b52c8482374c55b = function(arg0, arg1, arg2) { | ||
getObject(arg0).randomFillSync(getArrayU8FromWasm(arg1, arg2)); | ||
}; | ||
export const __wbg_new_3a746f2619705add = function(arg0, arg1) { | ||
const ret = new Function(getStringFromWasm(arg0, arg1)); | ||
return addHeapObject(ret); | ||
}; | ||
export const __wbg_call_f54d3a6dadb199ca = function(arg0, arg1) { | ||
const ret = getObject(arg0).call(getObject(arg1)); | ||
return addHeapObject(ret); | ||
}; | ||
export const __wbindgen_jsval_eq = function(arg0, arg1) { | ||
const ret = getObject(arg0) === getObject(arg1); | ||
return ret; | ||
}; | ||
export const __wbg_self_ac379e780a0d8b94 = function(arg0) { | ||
const ret = getObject(arg0).self; | ||
return addHeapObject(ret); | ||
}; | ||
export const __wbg_require_6461b1e9a0d7c34a = function(arg0, arg1) { | ||
const ret = require(getStringFromWasm(arg0, arg1)); | ||
return addHeapObject(ret); | ||
}; | ||
export const __wbg_crypto_1e4302b85d4f64a2 = function(arg0) { | ||
const ret = getObject(arg0).crypto; | ||
return addHeapObject(ret); | ||
}; | ||
export const __wbg_getRandomValues_1b4ba144162a5c9e = function(arg0) { | ||
const ret = getObject(arg0).getRandomValues; | ||
return addHeapObject(ret); | ||
}; | ||
export const __wbindgen_is_string = function(arg0) { | ||
const ret = typeof(getObject(arg0)) === 'string'; | ||
return ret; | ||
}; | ||
export const __wbindgen_string_get = function(arg0, arg1) { | ||
const obj = getObject(arg0); | ||
if (typeof(obj) !== 'string') return 0; | ||
const ptr = passStringToWasm(obj); | ||
getUint32Memory()[arg1 / 4] = WASM_VECTOR_LEN; | ||
const ret = ptr; | ||
return ret; | ||
}; | ||
export const __wbindgen_throw = function(arg0, arg1) { | ||
throw new Error(getStringFromWasm(arg0, arg1)); | ||
}; | ||
export const __wbindgen_rethrow = function(arg0) { | ||
throw takeObject(arg0); | ||
}; | ||
{ | ||
"name": "jellyschema", | ||
"collaborators": [ | ||
"Robert Vojta <robert@balena.io>", | ||
"Cyryl Płotnicki <cyryl@balena.io>" | ||
"Robert Vojta <robert@balena.io>" | ||
], | ||
"description": "Configuration DSL", | ||
"version": "0.11.10", | ||
"description": "Jelly Schema", | ||
"version": "0.12.0-next-0-12-7554e23f31009f636bca310dbfafbfa5d708612d", | ||
"license": "Apache-2.0", | ||
@@ -10,0 +9,0 @@ "repository": { |
# Jelly Schema | ||
[![Build Status](https://travis-ci.org/balena-io-modules/jellyschema.svg?branch=master)](https://travis-ci.org/balena-io-modules/jellyschema) | ||
[![Current Release](https://img.shields.io/github/tag/balena-io-modules/jellyschema.svg?style=flat-square)](https://github.com/balena-io-modules/jellyschema/tags) | ||
@@ -14,13 +13,7 @@ [![License](https://img.shields.io/github/license/balena-io-modules/jellyschema.svg?style=flat-square)](https://github.com/balena-io-modules/jellyschema/blob/master/LICENSE) | ||
* transform Jelly Schema into the JSON Schema & UI Schema objects with custom extensions | ||
* parse Jelly Schema | ||
* validate JSON data against Jelly Schema | ||
* validate JSON data against Jelly Schema. | ||
Current crate status is **experimental**. | ||
## Goal | ||
`jellyschema` crate is one small piece of the [balena.io] configuration project. This project has | ||
no public / open specification yet, but we're working on it and it will be public once finished. | ||
## Supported platforms | ||
@@ -33,86 +26,13 @@ | ||
**NOTE:** Not all features are available in the NPM package. Check the | ||
[`wasm.rs`](./src/wasm.rs) module for more details. | ||
## Documentation | ||
* [Specification] | ||
* [How to add a new data type] | ||
* [API documentation] | ||
* [Examples] | ||
* [Changelog] | ||
* [Maintainer documentation] | ||
## Usage | ||
### Rust | ||
Add as a dependency to your `Cargo.toml`: | ||
``` | ||
[dependencies] | ||
jellyschema = "0" | ||
``` | ||
Evaluate simple JSON: | ||
```rust | ||
let input_schema: serde_yaml::Value = serde_yaml::from_str( | ||
include_str!("configuration.yml")). | ||
unwrap(); | ||
let (json_schema, ui_object) = Generator::with(input_schema)?.generate(); | ||
``` | ||
### Javascript | ||
Install via npm | ||
``` | ||
npm install --save jellyschema | ||
``` | ||
Generate simple JSON Schema & UI Object Schema: | ||
```js | ||
const jellyschema = require('jellyschema'); | ||
const initialValue = ` | ||
title: demo | ||
version: 1 | ||
properties: | ||
- network: | ||
title: Network | ||
properties: | ||
- ssid: | ||
title: Network SSID | ||
type: string | ||
minLength: 1 | ||
maxLength: 32 | ||
- passphrase: | ||
title: Network Key | ||
type: password | ||
minLength: 8 | ||
`; | ||
var schema = new jels.JellySchema(initialValue); | ||
const result = schema.jsonAndUiSchema(); | ||
console.log(JSON.stringify(result, null, 2)); | ||
console.log(schema.validate({network: { ssid: 'foo', passphrase: 123 }})); | ||
console.log(schema.errors()); | ||
``` | ||
An example of using this module in nodeJS is available in the `examples/node` folder: | ||
```bash | ||
cd examples/node | ||
npm install | ||
npm start | ||
``` | ||
An example of using this module in the browser is available in the `examples/browser` folder: | ||
```bash | ||
cd examples/browser | ||
npm install | ||
npm start | ||
``` | ||
Open `localhost:8080` in your browser. | ||
## Support | ||
@@ -136,2 +56,4 @@ | ||
[Changelog]: ./CHANGELOG.md | ||
[Maintainer documentation]: ./docs/MAINTAINER.md | ||
[Specification]: ./docs/specification.md | ||
[How to add a new data type]: ./docs/add-data-type.md | ||
[Examples]: ./examples/ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
1502350
535
57
4
3