yeptris 0.6.57 → 0.6.59

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 CHANGED
@@ -7,9 +7,9 @@ Part of the yeptris program: *the best (multiple dimensions)
7
7
  YAML/JSON parser/builder ever* — conformance, performance,
8
8
  safety/hardening, API surfaces, transport correctness, and trust,
9
9
  held simultaneously, in C, Ruby, Rust, and JS. This binding is the
10
- thinnest surface (the WASM module); the recorder bulk-drain and
11
- iterparse are planned next (the engine's PLAN.md, "The best-ever
12
- program").
10
+ thinnest surface (the WASM module); the recorder bulk-drain rides the
11
+ `events()` face, iterparse is planned next (the engine's PLAN.md, "The
12
+ best-ever program").
13
13
 
14
14
  ```js
15
15
  import { load, dump } from "yeptris";
@@ -27,6 +27,15 @@ const yaml = await dump({ name: "yeptris", langs: ["c", "rust"] });
27
27
  - `loadAll(yaml, options?)` — parse a multi-document stream to an
28
28
  array of every document, in stream order (`js-yaml` parity; an
29
29
  empty stream answers `[]`).
30
+ - `events(yaml, options?)` — every event of the stream as an array of
31
+ plain objects, in stream order: the engine's recorder bulk drain
32
+ (one wasm crossing per stream — the fixed 44-byte event records and
33
+ the string arena are read straight from the heap, no per-event
34
+ marshalling). Document boundaries ride the same stream: the
35
+ `document-start`/`-end` events are the `loadAll` boundaries. The
36
+ normalized event vocabulary is shared with the ruby/py/rs faces and
37
+ documented as data in
38
+ [`test/fixtures/events.json`](test/fixtures/events.json).
30
39
  - `loadJSON(yaml)` — the engine's canonical JSON string.
31
40
  - `dump(json)` — JSON text (or any JSON-serializable value) to
32
41
  canonical YAML; JSON is a subset of YAML 1.2 flow, so the one parse
package/dist/yeptris.mjs CHANGED
@@ -5,7 +5,7 @@ var Module = (() => {
5
5
  return (
6
6
  async function(moduleArg = {}) {
7
7
 
8
- var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary;if(ENVIRONMENT_IS_NODE){const{createRequire:createRequire}=await import("module");var require=createRequire(import.meta.url);var fs=require("fs");var nodePath=require("path");if(ENVIRONMENT_IS_WORKER){scriptDirectory=nodePath.dirname(scriptDirectory)+"/"}else{scriptDirectory=require("url").fileURLToPath(new URL("./",import.meta.url))}read_=(filename,binary)=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);return fs.readFileSync(filename,binary?undefined:"utf8")};readBinary=filename=>{var ret=read_(filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}return ret};readAsync=(filename,onload,onerror,binary=true)=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);fs.readFile(filename,binary?undefined:"utf8",(err,data)=>{if(err)onerror(err);else onload(binary?data.buffer:data)})};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow};Module["inspect"]=()=>"[Emscripten Module object]"}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptDir){scriptDirectory=_scriptDir}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=(url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)}}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(typeof WebAssembly!="object"){abort("no native wasm support detected")}var wasmMemory;var ABORT=false;var EXITSTATUS;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAP64,HEAPU64,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b);Module["HEAP64"]=HEAP64=new BigInt64Array(b);Module["HEAPU64"]=HEAPU64=new BigUint64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){if(Module["onAbort"]){Module["onAbort"](what)}what="Aborted("+what+")";err(what);ABORT=true;EXITSTATUS=1;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");var wasmBinaryFile;if(Module["locateFile"]){wasmBinaryFile="yeptris.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}}else{wasmBinaryFile=new URL("yeptris.wasm",import.meta.url).href}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}function getBinaryPromise(binaryFile){if(!wasmBinary&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)){if(typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{if(!response["ok"]){throw"failed to load wasm binary file at '"+binaryFile+"'"}return response["arrayBuffer"]()}).catch(()=>getBinarySync(binaryFile))}}return Promise.resolve().then(()=>getBinarySync(binaryFile))}function instantiateArrayBuffer(binaryFile,imports,receiver){return getBinaryPromise(binaryFile).then(binary=>WebAssembly.instantiate(binary,imports)).then(instance=>instance).then(receiver,reason=>{err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)})}function instantiateAsync(binary,binaryFile,imports,callback){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{var result=WebAssembly.instantiateStreaming(response,imports);return result.then(callback,function(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(binaryFile,imports,callback)})})}return instantiateArrayBuffer(binaryFile,imports,callback)}function createWasm(){var info={"a":wasmImports};function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["g"];updateMemoryViews();addOnInit(wasmExports["h"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);readyPromiseReject(e)}}instantiateAsync(wasmBinary,wasmBinaryFile,info,receiveInstantiationResult).catch(readyPromiseReject);return{}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var noExitRuntime=Module["noExitRuntime"]||true;var getHeapMax=()=>2147483648;var growMemory=size=>{var b=wasmMemory.buffer;var pages=(size-b.byteLength+65535)/65536;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}var alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var ENV={};var getExecutableName=()=>thisProgram||"./this.program";var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8";var env={"USER":"web_user","LOGNAME":"web_user","PATH":"/","PWD":"/","HOME":"/home/web_user","LANG":lang,"_":getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(`${x}=${env[x]}`)}getEnvStrings.strings=strings}return getEnvStrings.strings};var stringToAscii=(str,buffer)=>{for(var i=0;i<str.length;++i){HEAP8[buffer++>>0]=str.charCodeAt(i)}HEAP8[buffer>>0]=0};var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):undefined;var UTF8ArrayToString=(heapOrArray,idx,maxBytesToRead)=>{var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):"";var SYSCALLS={varargs:undefined,get(){var ret=HEAP32[+SYSCALLS.varargs>>2];SYSCALLS.varargs+=4;return ret},getp(){return SYSCALLS.get()},getStr(ptr){var ret=UTF8ToString(ptr);return ret}};var _environ_get=(__environ,environ_buf)=>{var bufSize=0;getEnvStrings().forEach((string,i)=>{var ptr=environ_buf+bufSize;HEAPU32[__environ+i*4>>2]=ptr;stringToAscii(string,ptr);bufSize+=string.length+1});return 0};var _environ_sizes_get=(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;strings.forEach(string=>bufSize+=string.length+1);HEAPU32[penviron_buf_size>>2]=bufSize;return 0};var _fd_close=fd=>52;var MAX_INT53=9007199254740992;var MIN_INT53=-9007199254740992;var bigintToI53Checked=num=>num<MIN_INT53||num>MAX_INT53?NaN:Number(num);function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);return 70}var printCharBuffers=[null,[],[]];var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}};var _fd_write=(fd,iov,iovcnt,pnum)=>{var num=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j<len;j++){printChar(fd,HEAPU8[ptr+j])}num+=len}HEAPU32[pnum>>2]=num;return 0};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var wasmImports={b:_emscripten_resize_heap,e:_environ_get,f:_environ_sizes_get,d:_fd_close,c:_fd_seek,a:_fd_write};var wasmExports=createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["h"])();var _yeptris_wasm_load=Module["_yeptris_wasm_load"]=(a0,a1)=>(_yeptris_wasm_load=Module["_yeptris_wasm_load"]=wasmExports["i"])(a0,a1);var _malloc=Module["_malloc"]=a0=>(_malloc=Module["_malloc"]=wasmExports["j"])(a0);var _yeptris_wasm_load_all=Module["_yeptris_wasm_load_all"]=(a0,a1)=>(_yeptris_wasm_load_all=Module["_yeptris_wasm_load_all"]=wasmExports["k"])(a0,a1);var _yeptris_wasm_dump=Module["_yeptris_wasm_dump"]=(a0,a1)=>(_yeptris_wasm_dump=Module["_yeptris_wasm_dump"]=wasmExports["l"])(a0,a1);var _yeptris_wasm_last_error=Module["_yeptris_wasm_last_error"]=()=>(_yeptris_wasm_last_error=Module["_yeptris_wasm_last_error"]=wasmExports["m"])();var _yeptris_wasm_last_error_line=Module["_yeptris_wasm_last_error_line"]=()=>(_yeptris_wasm_last_error_line=Module["_yeptris_wasm_last_error_line"]=wasmExports["n"])();var _yeptris_wasm_last_error_column=Module["_yeptris_wasm_last_error_column"]=()=>(_yeptris_wasm_last_error_column=Module["_yeptris_wasm_last_error_column"]=wasmExports["o"])();var _yeptris_wasm_out=Module["_yeptris_wasm_out"]=()=>(_yeptris_wasm_out=Module["_yeptris_wasm_out"]=wasmExports["p"])();var _yeptris_wasm_out_len=Module["_yeptris_wasm_out_len"]=()=>(_yeptris_wasm_out_len=Module["_yeptris_wasm_out_len"]=wasmExports["q"])();var _yeptris_wasm_out_free=Module["_yeptris_wasm_out_free"]=()=>(_yeptris_wasm_out_free=Module["_yeptris_wasm_out_free"]=wasmExports["r"])();var _yeptris_wasm_free=Module["_yeptris_wasm_free"]=a0=>(_yeptris_wasm_free=Module["_yeptris_wasm_free"]=wasmExports["s"])(a0);var _yeptris_wasm_version=Module["_yeptris_wasm_version"]=()=>(_yeptris_wasm_version=Module["_yeptris_wasm_version"]=wasmExports["t"])();var ___errno_location=()=>(___errno_location=wasmExports["__errno_location"])();Module["UTF8ToString"]=UTF8ToString;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(){if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();
8
+ var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary;if(ENVIRONMENT_IS_NODE){const{createRequire:createRequire}=await import("module");var require=createRequire(import.meta.url);var fs=require("fs");var nodePath=require("path");if(ENVIRONMENT_IS_WORKER){scriptDirectory=nodePath.dirname(scriptDirectory)+"/"}else{scriptDirectory=require("url").fileURLToPath(new URL("./",import.meta.url))}read_=(filename,binary)=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);return fs.readFileSync(filename,binary?undefined:"utf8")};readBinary=filename=>{var ret=read_(filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}return ret};readAsync=(filename,onload,onerror,binary=true)=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);fs.readFile(filename,binary?undefined:"utf8",(err,data)=>{if(err)onerror(err);else onload(binary?data.buffer:data)})};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow};Module["inspect"]=()=>"[Emscripten Module object]"}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptDir){scriptDirectory=_scriptDir}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=(url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)}}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(typeof WebAssembly!="object"){abort("no native wasm support detected")}var wasmMemory;var ABORT=false;var EXITSTATUS;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAP64,HEAPU64,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b);Module["HEAP64"]=HEAP64=new BigInt64Array(b);Module["HEAPU64"]=HEAPU64=new BigUint64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){if(Module["onAbort"]){Module["onAbort"](what)}what="Aborted("+what+")";err(what);ABORT=true;EXITSTATUS=1;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");var wasmBinaryFile;if(Module["locateFile"]){wasmBinaryFile="yeptris.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}}else{wasmBinaryFile=new URL("yeptris.wasm",import.meta.url).href}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}function getBinaryPromise(binaryFile){if(!wasmBinary&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)){if(typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{if(!response["ok"]){throw"failed to load wasm binary file at '"+binaryFile+"'"}return response["arrayBuffer"]()}).catch(()=>getBinarySync(binaryFile))}}return Promise.resolve().then(()=>getBinarySync(binaryFile))}function instantiateArrayBuffer(binaryFile,imports,receiver){return getBinaryPromise(binaryFile).then(binary=>WebAssembly.instantiate(binary,imports)).then(instance=>instance).then(receiver,reason=>{err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)})}function instantiateAsync(binary,binaryFile,imports,callback){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{var result=WebAssembly.instantiateStreaming(response,imports);return result.then(callback,function(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(binaryFile,imports,callback)})})}return instantiateArrayBuffer(binaryFile,imports,callback)}function createWasm(){var info={"a":wasmImports};function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["g"];updateMemoryViews();addOnInit(wasmExports["h"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);readyPromiseReject(e)}}instantiateAsync(wasmBinary,wasmBinaryFile,info,receiveInstantiationResult).catch(readyPromiseReject);return{}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var noExitRuntime=Module["noExitRuntime"]||true;var getHeapMax=()=>2147483648;var growMemory=size=>{var b=wasmMemory.buffer;var pages=(size-b.byteLength+65535)/65536;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}var alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var ENV={};var getExecutableName=()=>thisProgram||"./this.program";var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8";var env={"USER":"web_user","LOGNAME":"web_user","PATH":"/","PWD":"/","HOME":"/home/web_user","LANG":lang,"_":getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(`${x}=${env[x]}`)}getEnvStrings.strings=strings}return getEnvStrings.strings};var stringToAscii=(str,buffer)=>{for(var i=0;i<str.length;++i){HEAP8[buffer++>>0]=str.charCodeAt(i)}HEAP8[buffer>>0]=0};var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):undefined;var UTF8ArrayToString=(heapOrArray,idx,maxBytesToRead)=>{var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):"";var SYSCALLS={varargs:undefined,get(){var ret=HEAP32[+SYSCALLS.varargs>>2];SYSCALLS.varargs+=4;return ret},getp(){return SYSCALLS.get()},getStr(ptr){var ret=UTF8ToString(ptr);return ret}};var _environ_get=(__environ,environ_buf)=>{var bufSize=0;getEnvStrings().forEach((string,i)=>{var ptr=environ_buf+bufSize;HEAPU32[__environ+i*4>>2]=ptr;stringToAscii(string,ptr);bufSize+=string.length+1});return 0};var _environ_sizes_get=(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;strings.forEach(string=>bufSize+=string.length+1);HEAPU32[penviron_buf_size>>2]=bufSize;return 0};var _fd_close=fd=>52;var MAX_INT53=9007199254740992;var MIN_INT53=-9007199254740992;var bigintToI53Checked=num=>num<MIN_INT53||num>MAX_INT53?NaN:Number(num);function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);return 70}var printCharBuffers=[null,[],[]];var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}};var _fd_write=(fd,iov,iovcnt,pnum)=>{var num=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j<len;j++){printChar(fd,HEAPU8[ptr+j])}num+=len}HEAPU32[pnum>>2]=num;return 0};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var wasmImports={b:_emscripten_resize_heap,e:_environ_get,f:_environ_sizes_get,d:_fd_close,c:_fd_seek,a:_fd_write};var wasmExports=createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["h"])();var _yeptris_wasm_load=Module["_yeptris_wasm_load"]=(a0,a1)=>(_yeptris_wasm_load=Module["_yeptris_wasm_load"]=wasmExports["i"])(a0,a1);var _malloc=Module["_malloc"]=a0=>(_malloc=Module["_malloc"]=wasmExports["j"])(a0);var _yeptris_wasm_load_all=Module["_yeptris_wasm_load_all"]=(a0,a1)=>(_yeptris_wasm_load_all=Module["_yeptris_wasm_load_all"]=wasmExports["k"])(a0,a1);var _yeptris_wasm_dump=Module["_yeptris_wasm_dump"]=(a0,a1)=>(_yeptris_wasm_dump=Module["_yeptris_wasm_dump"]=wasmExports["l"])(a0,a1);var _yeptris_wasm_last_error=Module["_yeptris_wasm_last_error"]=()=>(_yeptris_wasm_last_error=Module["_yeptris_wasm_last_error"]=wasmExports["m"])();var _yeptris_wasm_last_error_line=Module["_yeptris_wasm_last_error_line"]=()=>(_yeptris_wasm_last_error_line=Module["_yeptris_wasm_last_error_line"]=wasmExports["n"])();var _yeptris_wasm_last_error_column=Module["_yeptris_wasm_last_error_column"]=()=>(_yeptris_wasm_last_error_column=Module["_yeptris_wasm_last_error_column"]=wasmExports["o"])();var _yeptris_wasm_out=Module["_yeptris_wasm_out"]=()=>(_yeptris_wasm_out=Module["_yeptris_wasm_out"]=wasmExports["p"])();var _yeptris_wasm_out_len=Module["_yeptris_wasm_out_len"]=()=>(_yeptris_wasm_out_len=Module["_yeptris_wasm_out_len"]=wasmExports["q"])();var _yeptris_wasm_out_free=Module["_yeptris_wasm_out_free"]=()=>(_yeptris_wasm_out_free=Module["_yeptris_wasm_out_free"]=wasmExports["r"])();var _yeptris_wasm_free=Module["_yeptris_wasm_free"]=a0=>(_yeptris_wasm_free=Module["_yeptris_wasm_free"]=wasmExports["s"])(a0);var _yeptris_wasm_version=Module["_yeptris_wasm_version"]=()=>(_yeptris_wasm_version=Module["_yeptris_wasm_version"]=wasmExports["t"])();var _yeptris_wasm_events=Module["_yeptris_wasm_events"]=(a0,a1)=>(_yeptris_wasm_events=Module["_yeptris_wasm_events"]=wasmExports["u"])(a0,a1);var _yeptris_wasm_event_records=Module["_yeptris_wasm_event_records"]=()=>(_yeptris_wasm_event_records=Module["_yeptris_wasm_event_records"]=wasmExports["v"])();var _yeptris_wasm_event_count=Module["_yeptris_wasm_event_count"]=()=>(_yeptris_wasm_event_count=Module["_yeptris_wasm_event_count"]=wasmExports["w"])();var _yeptris_wasm_event_arena=Module["_yeptris_wasm_event_arena"]=()=>(_yeptris_wasm_event_arena=Module["_yeptris_wasm_event_arena"]=wasmExports["x"])();var _yeptris_wasm_event_arena_len=Module["_yeptris_wasm_event_arena_len"]=()=>(_yeptris_wasm_event_arena_len=Module["_yeptris_wasm_event_arena_len"]=wasmExports["y"])();var _yeptris_wasm_events_free=Module["_yeptris_wasm_events_free"]=()=>(_yeptris_wasm_events_free=Module["_yeptris_wasm_events_free"]=wasmExports["z"])();var ___errno_location=()=>(___errno_location=wasmExports["__errno_location"])();Module["UTF8ToString"]=UTF8ToString;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(){if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();
9
9
 
10
10
 
11
11
  return moduleArg.ready
package/dist/yeptris.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeptris",
3
- "version": "0.6.57",
3
+ "version": "0.6.59",
4
4
  "description": "YAML for JavaScript at libyeptris speed (WebAssembly, no fallback)",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -22,6 +22,53 @@ export declare function loadAll(
22
22
  /** Parse YAML text and return the engine's canonical JSON string. */
23
23
  export declare function loadJSON(yaml: string): Promise<string>;
24
24
 
25
+ /** One normalized parse event (the recorder's bulk drain). Absent
26
+ * properties are omitted, never null. */
27
+ export interface YamlEvent {
28
+ /** stream-start | stream-end | document-start | document-end |
29
+ * sequence-start | sequence-end | mapping-start | mapping-end |
30
+ * scalar | alias */
31
+ type: string;
32
+ /** 1-based start mark (0 = the event carries no position, the empty
33
+ * document's null scalar) */
34
+ line: number;
35
+ column: number;
36
+ /** libyaml end_mark semantics: 1-based, column one past the end */
37
+ endLine: number;
38
+ endColumn: number;
39
+ /** scalar content; the alias NAME for type "alias" */
40
+ value?: string;
41
+ /** the node's &anchor, present when written */
42
+ anchor?: string;
43
+ /** the node's tag: the resolved core URI (!!str) or the local form
44
+ * (!custom), present when written */
45
+ tag?: string;
46
+ /** scalars: plain | single | double | literal | folded (absent when
47
+ * the parser recorded no style — the empty document's null scalar) */
48
+ style?: string;
49
+ /** scalars: the resolved kind (str|int|float|bool|null|timestamp|
50
+ * seq|map|binary|merge|value|custom) — the typing SSOT, so hosts
51
+ * never re-scan */
52
+ tagId?: string;
53
+ /** scalars: plain style (the resolver's implicit-typing trigger) */
54
+ implicit?: boolean;
55
+ /** collection starts: flow context */
56
+ flow?: boolean;
57
+ /** document start/end: a --- / ... marker was seen */
58
+ explicit?: boolean;
59
+ }
60
+
61
+ /** Parse YAML text and return EVERY event of the stream, in stream
62
+ * order (the recorder's bulk drain: one wasm crossing per stream, no
63
+ * per-event marshalling). Document boundaries ride the same stream —
64
+ * the document-start/-end events are the loadAll boundaries. options
65
+ * is accepted for call-site symmetry and reserved. Throws YamlError
66
+ * on malformed input. */
67
+ export declare function events(
68
+ yaml: string,
69
+ options?: Record<string, unknown>,
70
+ ): Promise<YamlEvent[]>;
71
+
25
72
  /** Convert JSON text (or any JSON-serializable value) to the engine's
26
73
  * canonical, byte-stable YAML. */
27
74
  export declare function dump(json: string | unknown): Promise<string>;
package/src/index.js CHANGED
@@ -62,6 +62,12 @@ async function mod() {
62
62
  "_yeptris_wasm_load",
63
63
  "_yeptris_wasm_load_all",
64
64
  "_yeptris_wasm_dump",
65
+ "_yeptris_wasm_events",
66
+ "_yeptris_wasm_event_records",
67
+ "_yeptris_wasm_event_count",
68
+ "_yeptris_wasm_event_arena",
69
+ "_yeptris_wasm_event_arena_len",
70
+ "_yeptris_wasm_events_free",
65
71
  "_yeptris_wasm_out",
66
72
  "_yeptris_wasm_out_len",
67
73
  "_yeptris_wasm_out_free",
@@ -107,6 +113,167 @@ export async function loadJSON(yaml) {
107
113
  return run(m, m._yeptris_wasm_load, yaml);
108
114
  }
109
115
 
116
+ // ---- the event face (the recorder's bulk drain) -------------------------
117
+ //
118
+ // The engine ships three event models over the one parse: push (a
119
+ // callback per event), pull (a StAX cursor) and the recorder (fixed
120
+ // 44-byte records plus one copied string arena). Across the wasm
121
+ // boundary the recorder wins: the whole stream drains as TWO spans
122
+ // read straight from the heap — O(1) crossings, no per-event callback
123
+ // marshalling. The record layout is ABI-pinned (events.h, 44B) and
124
+ // this decoder is the JS mirror of the ctypes/FFI readers the
125
+ // ruby/py/rs faces use over the same bytes.
126
+
127
+ // YeptrisEventType (events.h, ABI-pinned order).
128
+ const EV_KINDS = {
129
+ 1: "stream-start",
130
+ 2: "stream-end",
131
+ 3: "document-start",
132
+ 4: "document-end",
133
+ 5: "sequence-start",
134
+ 6: "sequence-end",
135
+ 7: "mapping-start",
136
+ 8: "mapping-end",
137
+ 9: "scalar",
138
+ 10: "alias",
139
+ };
140
+
141
+ // YeptrisScalarStyle (dom.h). 0 = ANY ("no recorded style" — the empty
142
+ // document's null scalar) and spells as an ABSENT style, not a lie.
143
+ const EV_STYLES = {
144
+ 1: "plain",
145
+ 2: "single",
146
+ 3: "double",
147
+ 4: "literal",
148
+ 5: "folded",
149
+ };
150
+
151
+ // YeptrisTagId (resolve.h) — the resolver's typing verdict, spelled as
152
+ // the kind name (the same vocabulary ruby/py/rs consume).
153
+ const EV_TAG_IDS = {
154
+ 0: "str",
155
+ 1: "int",
156
+ 2: "float",
157
+ 3: "bool",
158
+ 4: "null",
159
+ 5: "timestamp",
160
+ 6: "seq",
161
+ 7: "map",
162
+ 8: "binary",
163
+ 9: "merge",
164
+ 10: "value",
165
+ 11: "custom",
166
+ };
167
+
168
+ // YEPTRIS_EF_* flag bits (events.h).
169
+ const EF_FLOW = 1; // collection in flow style
170
+ const EF_EXPLICIT = 2; // document with a --- / ... marker
171
+ const EF_IMPLICIT = 4; // plain (unquoted, un-block) scalar style
172
+
173
+ const EV_RECORD_SIZE = 44; // sizeof(YeptrisEventRecord), ABI-pinned
174
+
175
+ let utf8Decoder = null;
176
+
177
+ function decodeArena(u8, off, len) {
178
+ if (utf8Decoder === null) {
179
+ utf8Decoder = new TextDecoder("utf-8");
180
+ }
181
+ return utf8Decoder.decode(u8.subarray(off, off + len));
182
+ }
183
+
184
+ /** Parse YAML text and return EVERY event of the stream as an array
185
+ * of plain objects, in stream order (leptris/yeptris#886). One event
186
+ * is:
187
+ *
188
+ * { type: "stream-start" | "stream-end" | "document-start" |
189
+ * "document-end" | "sequence-start" | "sequence-end" |
190
+ * "mapping-start" | "mapping-end" | "scalar" | "alias",
191
+ * line, column, // 1-based start mark (0 = no position)
192
+ * endLine, endColumn, // libyaml end_mark: col one past the end
193
+ * value?, // scalar content; the alias NAME for alias
194
+ * anchor?, tag?, // node properties, present when written
195
+ * style?, // scalars: plain|single|double|literal|folded
196
+ * tagId?, // scalars: the resolved kind (str|int|...)
197
+ * implicit?, // scalars: plain style (the typing trigger)
198
+ * flow?, // collection starts: flow context
199
+ * explicit? } // document start/end: --- / ... marker seen
200
+ *
201
+ * Absent properties are omitted, never null. The faces of
202
+ * ruby/py/rs consume the same normalized vocabulary (see
203
+ * test/fixtures/events.json, whose header documents it as data).
204
+ * options is accepted for call-site symmetry and reserved. Throws
205
+ * YamlError on malformed input (position from the recorder's status;
206
+ * its message is the generic "parse failed" — the recorder carries
207
+ * status + position, not the error text). */
208
+ export async function events(yaml, options) {
209
+ const m = await mod();
210
+ const [ptr, len] = cstr(m, yaml);
211
+ try {
212
+ const st = m._yeptris_wasm_events(ptr, len);
213
+ if (st !== 0) {
214
+ throw new YamlError(
215
+ m.UTF8ToString(m._yeptris_wasm_last_error()),
216
+ m._yeptris_wasm_last_error_line(),
217
+ m._yeptris_wasm_last_error_column());
218
+ }
219
+ const n = m._yeptris_wasm_event_count();
220
+ const recs = m._yeptris_wasm_event_records();
221
+ const arena = m._yeptris_wasm_event_arena();
222
+ // Heap views fetched AFTER the call: the feed may have grown the
223
+ // memory, and the exported views are re-bound on growth.
224
+ const u8 = m.HEAPU8;
225
+ const u32 = m.HEAPU32;
226
+ const out = new Array(n);
227
+ for (let i = 0; i < n; i++) {
228
+ const base = recs + i * EV_RECORD_SIZE;
229
+ const p = base >> 2;
230
+ const type = u8[base];
231
+ const flags = u8[base + 2];
232
+ const ev = {
233
+ type: EV_KINDS[type],
234
+ line: u32[p + 1],
235
+ column: u32[p + 2],
236
+ endLine: u32[p + 3],
237
+ endColumn: u32[p + 4],
238
+ };
239
+ const valueLen = u32[p + 6];
240
+ if (valueLen !== 0) {
241
+ ev.value = decodeArena(u8, arena + u32[p + 5], valueLen);
242
+ }
243
+ const anchorLen = u32[p + 8];
244
+ if (anchorLen !== 0) {
245
+ ev.anchor = decodeArena(u8, arena + u32[p + 7], anchorLen);
246
+ }
247
+ const tagLen = u32[p + 10];
248
+ if (tagLen !== 0) {
249
+ ev.tag = decodeArena(u8, arena + u32[p + 9], tagLen);
250
+ }
251
+ if (type === 9) { // scalar
252
+ const style = u8[base + 1];
253
+ if (style !== 0) {
254
+ ev.style = EV_STYLES[style];
255
+ }
256
+ if ((flags & EF_IMPLICIT) !== 0) {
257
+ ev.implicit = true;
258
+ }
259
+ ev.tagId = EV_TAG_IDS[u8[base + 3]];
260
+ }
261
+ if ((flags & EF_FLOW) !== 0) {
262
+ ev.flow = true;
263
+ }
264
+ if ((type === 3 || type === 4) && (flags & EF_EXPLICIT) !== 0) {
265
+ ev.explicit = true;
266
+ }
267
+ out[i] = ev;
268
+ }
269
+ return out;
270
+ } finally {
271
+ // the drain is decoded: release the recorder (nothing retained
272
+ // past this call — the answer left the heap as JS objects)
273
+ m._yeptris_wasm_events_free();
274
+ }
275
+ }
276
+
110
277
  /** Convert JSON text (or any JSON-serializable value) to the engine's
111
278
  * canonical, byte-stable YAML. JSON is a subset of YAML 1.2 flow, so
112
279
  * the one parse engine takes it. */
@@ -13,6 +13,7 @@
13
13
  #include "yeptris/dom.h"
14
14
  #include "yeptris/emit.h"
15
15
  #include "yeptris/error.h"
16
+ #include "yeptris/events.h"
16
17
  #include "yeptris/json.h"
17
18
  #include "yeptris/parse.h"
18
19
  #include "yeptris/version.h"
@@ -385,3 +386,82 @@ void yeptris_wasm_free(void *p) { yeptris_free(p); }
385
386
 
386
387
  EMSCRIPTEN_KEEPALIVE
387
388
  const char *yeptris_wasm_version(void) { return yeptris_version(); }
389
+
390
+ /* ---- events (the recorder bulk drain) ----------------------------------
391
+ *
392
+ * The engine ships three event models over the one parse: push (a
393
+ * callback per event), pull (a StAX cursor) and the recorder (fixed
394
+ * 44-byte records plus one copied string arena). Across the wasm
395
+ * boundary the RECORDER is the fit: the whole stream answers as two
396
+ * spans — the record array and the arena — which the host reads
397
+ * straight from the heap in one pass. That is O(1) crossings per
398
+ * stream; push would cross once per event and pull would need a
399
+ * cursor protocol whose strings die at the next call. This mirrors
400
+ * exactly what the ctypes/FFI readers of the ruby/py/rs faces do with
401
+ * the same record layout.
402
+ *
403
+ * Lifecycle is the load pattern: one C call (feed, final), the drain
404
+ * retained in globals until the host has decoded it, then an explicit
405
+ * free. */
406
+ static YeptrisRecorder g_ev_rec;
407
+ static size_t g_ev_count;
408
+ static size_t g_ev_arena_len;
409
+
410
+ EMSCRIPTEN_KEEPALIVE
411
+ int yeptris_wasm_events(const char *data, size_t len) {
412
+ if (g_ev_rec != NULL) { /* defensive: the previous drain was not freed */
413
+ yeptris_recorder_free(g_ev_rec);
414
+ g_ev_rec = NULL;
415
+ }
416
+ g_ev_count = 0;
417
+ g_ev_arena_len = 0;
418
+ YeptrisRecorder rec = yeptris_recorder_new();
419
+ if (rec == NULL) {
420
+ capture_plain("recorder allocation failed");
421
+ return YEPTRIS_ERROR_MEMORY;
422
+ }
423
+ /* One chunk, final: the recorder v1 buffers to the stream end, so
424
+ * a whole-input feed IS the drain (mid-stream feeds arrive with the
425
+ * engine's resumable stepping and keep this shape). */
426
+ YeptrisStatus st = yeptris_recorder_feed(rec, data, len, 1);
427
+ if (st != YEPTRIS_OK) {
428
+ uint32_t line = 0;
429
+ uint32_t col = 0;
430
+ yeptris_recorder_status(rec, &line, &col);
431
+ /* the recorder carries status + 1-based position, no message
432
+ * string (its errors are parse errors by construction) */
433
+ snprintf(last_error, sizeof last_error, "parse failed");
434
+ last_error_line = (int)line;
435
+ last_error_column = (int)col;
436
+ yeptris_recorder_free(rec);
437
+ return (int)st;
438
+ }
439
+ g_ev_rec = rec;
440
+ yeptris_recorder_records(rec, &g_ev_count);
441
+ yeptris_recorder_arena(rec, &g_ev_arena_len);
442
+ return YEPTRIS_OK;
443
+ }
444
+
445
+ EMSCRIPTEN_KEEPALIVE
446
+ const YeptrisEventRecord *yeptris_wasm_event_records(void) {
447
+ return g_ev_rec != NULL ? yeptris_recorder_records(g_ev_rec, NULL) : NULL;
448
+ }
449
+
450
+ EMSCRIPTEN_KEEPALIVE
451
+ int yeptris_wasm_event_count(void) { return (int)g_ev_count; }
452
+
453
+ EMSCRIPTEN_KEEPALIVE
454
+ const char *yeptris_wasm_event_arena(void) {
455
+ return g_ev_rec != NULL ? yeptris_recorder_arena(g_ev_rec, NULL) : NULL;
456
+ }
457
+
458
+ EMSCRIPTEN_KEEPALIVE
459
+ int yeptris_wasm_event_arena_len(void) { return (int)g_ev_arena_len; }
460
+
461
+ EMSCRIPTEN_KEEPALIVE
462
+ void yeptris_wasm_events_free(void) {
463
+ yeptris_recorder_free(g_ev_rec);
464
+ g_ev_rec = NULL;
465
+ g_ev_count = 0;
466
+ g_ev_arena_len = 0;
467
+ }