yeptris 0.6.56 → 0.6.57

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
@@ -22,7 +22,11 @@ const yaml = await dump({ name: "yeptris", langs: ["c", "rust"] });
22
22
  ```
23
23
 
24
24
  - `load(yaml)` — parse to a JavaScript value (malformed input throws
25
- `YamlError` with line/column).
25
+ `YamlError` with line/column). A multi-document stream answers with
26
+ the FIRST document.
27
+ - `loadAll(yaml, options?)` — parse a multi-document stream to an
28
+ array of every document, in stream order (`js-yaml` parity; an
29
+ empty stream answers `[]`).
26
30
  - `loadJSON(yaml)` — the engine's canonical JSON string.
27
31
  - `dump(json)` — JSON text (or any JSON-serializable value) to
28
32
  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 _yeptris_wasm_dump=Module["_yeptris_wasm_dump"]=(a0,a1)=>(_yeptris_wasm_dump=Module["_yeptris_wasm_dump"]=wasmExports["j"])(a0,a1);var _yeptris_wasm_last_error=Module["_yeptris_wasm_last_error"]=()=>(_yeptris_wasm_last_error=Module["_yeptris_wasm_last_error"]=wasmExports["k"])();var _yeptris_wasm_last_error_line=Module["_yeptris_wasm_last_error_line"]=()=>(_yeptris_wasm_last_error_line=Module["_yeptris_wasm_last_error_line"]=wasmExports["l"])();var _yeptris_wasm_last_error_column=Module["_yeptris_wasm_last_error_column"]=()=>(_yeptris_wasm_last_error_column=Module["_yeptris_wasm_last_error_column"]=wasmExports["m"])();var _yeptris_wasm_out=Module["_yeptris_wasm_out"]=()=>(_yeptris_wasm_out=Module["_yeptris_wasm_out"]=wasmExports["n"])();var _yeptris_wasm_out_len=Module["_yeptris_wasm_out_len"]=()=>(_yeptris_wasm_out_len=Module["_yeptris_wasm_out_len"]=wasmExports["o"])();var _yeptris_wasm_out_free=Module["_yeptris_wasm_out_free"]=()=>(_yeptris_wasm_out_free=Module["_yeptris_wasm_out_free"]=wasmExports["p"])();var _yeptris_wasm_free=Module["_yeptris_wasm_free"]=a0=>(_yeptris_wasm_free=Module["_yeptris_wasm_free"]=wasmExports["q"])(a0);var _yeptris_wasm_version=Module["_yeptris_wasm_version"]=()=>(_yeptris_wasm_version=Module["_yeptris_wasm_version"]=wasmExports["r"])();var _malloc=Module["_malloc"]=a0=>(_malloc=Module["_malloc"]=wasmExports["t"])(a0);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 ___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.56",
3
+ "version": "0.6.57",
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
@@ -6,9 +6,19 @@ export declare class YamlError extends Error {
6
6
 
7
7
  /** Parse YAML text and return the document as a JavaScript value
8
8
  * (the engine's canonical JSON, JSON.parse'd). Throws YamlError with
9
- * line/column on malformed input. */
9
+ * line/column on malformed input. A multi-document stream answers
10
+ * with the FIRST document; every document comes from loadAll. */
10
11
  export declare function load(yaml: string): Promise<unknown>;
11
12
 
13
+ /** Parse a multi-document YAML stream and return EVERY document as a
14
+ * JavaScript value, in stream order. An empty or comment-only stream
15
+ * answers []. options is reserved (no options today). Throws
16
+ * YamlError with line/column on malformed input. */
17
+ export declare function loadAll(
18
+ yaml: string,
19
+ options?: Record<string, unknown>,
20
+ ): Promise<unknown[]>;
21
+
12
22
  /** Parse YAML text and return the engine's canonical JSON string. */
13
23
  export declare function loadJSON(yaml: string): Promise<string>;
14
24
 
package/src/index.js CHANGED
@@ -60,6 +60,7 @@ async function mod() {
60
60
  // parse at all).
61
61
  for (const fn of [
62
62
  "_yeptris_wasm_load",
63
+ "_yeptris_wasm_load_all",
63
64
  "_yeptris_wasm_dump",
64
65
  "_yeptris_wasm_out",
65
66
  "_yeptris_wasm_out_len",
@@ -81,12 +82,25 @@ async function mod() {
81
82
 
82
83
  /** Parse YAML text and return the document as a JavaScript value
83
84
  * (the engine's canonical JSON, JSON.parse'd). Throws YamlError with
84
- * line/column on malformed input. */
85
+ * line/column on malformed input. A multi-document stream answers
86
+ * with the FIRST document (the engine's json contract); every
87
+ * document of a stream comes from loadAll. */
85
88
  export async function load(yaml) {
86
89
  const m = await mod();
87
90
  return JSON.parse(run(m, m._yeptris_wasm_load, yaml));
88
91
  }
89
92
 
93
+ /** Parse a multi-document YAML stream and return EVERY document as a
94
+ * JavaScript value, in stream order (js-yaml's loadAll shape). An
95
+ * empty or comment-only stream answers []; an empty document
96
+ * ("---\n---") answers null at its position. options is accepted for
97
+ * call-site symmetry and reserved (load takes none today). Throws
98
+ * YamlError with line/column on malformed input. */
99
+ export async function loadAll(yaml, options) {
100
+ const m = await mod();
101
+ return JSON.parse(run(m, m._yeptris_wasm_load_all, yaml));
102
+ }
103
+
90
104
  /** Parse YAML text and return the engine's canonical JSON string. */
91
105
  export async function loadJSON(yaml) {
92
106
  const m = await mod();
@@ -5,6 +5,7 @@
5
5
  * never holds a heap pointer past the call — the C buffer-lifetime
6
6
  * contract stays internal. */
7
7
  #include <emscripten/emscripten.h>
8
+ #include <stdint.h>
8
9
  #include <stdio.h>
9
10
  #include <stdlib.h>
10
11
  #include <string.h>
@@ -32,7 +33,244 @@ static void capture_error(void) {
32
33
  last_error_column = (int)col;
33
34
  }
34
35
 
35
- /* YAML in -> canonical JSON out (yeptris_serialize_json). */
36
+ static void capture_plain(const char *msg) {
37
+ snprintf(last_error, sizeof last_error, "%s", msg);
38
+ last_error_line = 0;
39
+ last_error_column = 0;
40
+ }
41
+
42
+ static void publish_out(char *out, size_t out_len) {
43
+ g_out = out;
44
+ g_out_len = out_len;
45
+ }
46
+
47
+ /* ---- multi-document streams -------------------------------------------
48
+ *
49
+ * yeptris_parse returns the WHOLE stream as one document set (the DOM
50
+ * forest: yeptris_document_count / yeptris_document_root). The JSON
51
+ * emitter answers for exactly one document (yep_emit_run's dcount==1
52
+ * guard), so per-document JSON is produced by re-typing the forest
53
+ * into a fresh document through the public build API:
54
+ *
55
+ * - scalars copy value + style; plain re-resolves through the same
56
+ * schema resolver exactly like parse, quoted/block forces string
57
+ * — the JSON typing is identical by construction;
58
+ * - explicit tags ride BUILD_TAG;
59
+ * - aliases project to null and anchors drop — which IS the JSON
60
+ * projection law (emit_alias_ex writes null, JSON spells no
61
+ * anchors).
62
+ *
63
+ * The one extra nesting level the wrapper sequence adds is why the
64
+ * recursion cap is the parser's cap + 1. */
65
+
66
+ #define YW_MAX_DEPTH 1001 /* parser default max_depth (1000) + wrapper */
67
+
68
+ typedef struct {
69
+ YeptrisBuildEntry *entries;
70
+ size_t n, cap;
71
+ char *blob;
72
+ size_t blen, bcap;
73
+ int failed; /* 0 ok, else the YeptrisStatus */
74
+ int depth;
75
+ } yw_rec;
76
+
77
+ static int yw_push_entry(yw_rec *r, uint8_t op, uint8_t style, size_t off, uint32_t len) {
78
+ if (r->n == r->cap) {
79
+ size_t ncap = r->cap ? r->cap * 2 : 64;
80
+ YeptrisBuildEntry *ne = (YeptrisBuildEntry *)realloc(r->entries, ncap * sizeof *ne);
81
+ if (ne == NULL) {
82
+ r->failed = YEPTRIS_ERROR_MEMORY;
83
+ return -1;
84
+ }
85
+ r->entries = ne;
86
+ r->cap = ncap;
87
+ }
88
+ YeptrisBuildEntry *e = &r->entries[r->n++];
89
+ e->op = op;
90
+ e->style = style;
91
+ e->reserved = 0;
92
+ e->off = (uint32_t)off;
93
+ e->len = len;
94
+ return 0;
95
+ }
96
+
97
+ static long yw_push_blob(yw_rec *r, const char *p, size_t len) {
98
+ if (r->blen + len > UINT32_MAX) { /* blob offsets are 32-bit */
99
+ r->failed = YEPTRIS_ERROR_MEMORY;
100
+ return -1;
101
+ }
102
+ if (r->blen + len > r->bcap) {
103
+ size_t ncap = r->bcap ? r->bcap : 4096;
104
+ while (ncap < r->blen + len) {
105
+ ncap *= 2;
106
+ }
107
+ char *nb = (char *)realloc(r->blob, ncap);
108
+ if (nb == NULL) {
109
+ r->failed = YEPTRIS_ERROR_MEMORY;
110
+ return -1;
111
+ }
112
+ r->blob = nb;
113
+ r->bcap = ncap;
114
+ }
115
+ if (len > 0) {
116
+ memcpy(r->blob + r->blen, p, len);
117
+ }
118
+ long off = (long)r->blen;
119
+ r->blen += len;
120
+ return off;
121
+ }
122
+
123
+ static int yw_tag_entry(yw_rec *r, YeptrisNode node) {
124
+ size_t tl = 0;
125
+ const char *t = yeptris_node_tag(node, &tl);
126
+ if (t == NULL || tl == 0) {
127
+ return 0;
128
+ }
129
+ long off = yw_push_blob(r, t, tl);
130
+ if (off < 0) {
131
+ return -1;
132
+ }
133
+ return yw_push_entry(r, YEPTRIS_BUILD_TAG, 0, (size_t)off, (uint32_t)tl);
134
+ }
135
+
136
+ /* Records one subtree into the build entry/blob buffers. */
137
+ static int yw_flatten(yw_rec *r, YeptrisNode node) {
138
+ if (r->failed != 0) {
139
+ return -1;
140
+ }
141
+ if (++r->depth > YW_MAX_DEPTH) {
142
+ r->failed = YEPTRIS_ERROR_DEPTH;
143
+ return -1;
144
+ }
145
+ switch (yeptris_node_kind(node)) {
146
+ case YEPTRIS_NODE_ALIAS: {
147
+ /* the JSON projection law: aliases dereference to null */
148
+ long off = yw_push_blob(r, "null", 4);
149
+ if (off < 0 ||
150
+ yw_push_entry(r, YEPTRIS_BUILD_SCALAR, YEPTRIS_STYLE_PLAIN, (size_t)off, 4) != 0) {
151
+ return -1;
152
+ }
153
+ break;
154
+ }
155
+ case YEPTRIS_NODE_SCALAR: {
156
+ size_t vl = 0;
157
+ const char *v = yeptris_node_value(node, &vl);
158
+ /* a parsed empty document root carries STYLE_ANY (no recorded
159
+ * style); the build API only types PLAIN scalars, and ANY
160
+ * means "no recorded style" — i.e. plain — so normalize */
161
+ uint8_t sty = (uint8_t)yeptris_node_style(node);
162
+ if (sty == YEPTRIS_STYLE_ANY) {
163
+ sty = YEPTRIS_STYLE_PLAIN;
164
+ }
165
+ long off = yw_push_blob(r, v ? v : "", vl);
166
+ if (off < 0 || yw_push_entry(r, YEPTRIS_BUILD_SCALAR, sty, (size_t)off, (uint32_t)vl) != 0) {
167
+ return -1;
168
+ }
169
+ if (yw_tag_entry(r, node) != 0) {
170
+ return -1;
171
+ }
172
+ break;
173
+ }
174
+ default: { /* sequence or mapping */
175
+ uint8_t op = yeptris_node_kind(node) == YEPTRIS_NODE_MAPPING ? YEPTRIS_BUILD_MAP
176
+ : YEPTRIS_BUILD_SEQ;
177
+ if (yw_push_entry(r, op, 0, 0, 0) != 0 || yw_tag_entry(r, node) != 0) {
178
+ return -1;
179
+ }
180
+ size_t n = yeptris_node_children(node, NULL, 0);
181
+ if (n > 0) {
182
+ YeptrisNode *kids = (YeptrisNode *)malloc(n * sizeof *kids);
183
+ if (kids == NULL) {
184
+ r->failed = YEPTRIS_ERROR_MEMORY;
185
+ return -1;
186
+ }
187
+ size_t got = yeptris_node_children(node, kids, n);
188
+ for (size_t i = 0; i < got; i++) {
189
+ if (yw_flatten(r, kids[i]) != 0) {
190
+ free(kids);
191
+ return -1;
192
+ }
193
+ }
194
+ free(kids);
195
+ }
196
+ if (yw_push_entry(r, YEPTRIS_BUILD_END, 0, 0, 0) != 0) {
197
+ return -1;
198
+ }
199
+ break;
200
+ }
201
+ }
202
+ r->depth--;
203
+ return 0;
204
+ }
205
+
206
+ static void yw_rec_free(yw_rec *r) {
207
+ free(r->entries);
208
+ free(r->blob);
209
+ r->entries = NULL;
210
+ r->blob = NULL;
211
+ }
212
+
213
+ /* Builds a fresh document from the recorder and serializes it as JSON
214
+ * (engine-owned output buffer). r is freed either way. */
215
+ static char *yw_serialize_rebuilt(yw_rec *r, size_t *out_len) {
216
+ if (r->failed != 0) {
217
+ yw_rec_free(r);
218
+ return NULL;
219
+ }
220
+ YeptrisDocument b = yeptris_document_new();
221
+ if (b == NULL) {
222
+ yw_rec_free(r);
223
+ return NULL;
224
+ }
225
+ YeptrisStatus bst = yeptris_document_build(b, r->entries, r->n, r->blob, r->blen);
226
+ yw_rec_free(r);
227
+ if (bst != YEPTRIS_OK) {
228
+ return NULL;
229
+ }
230
+ char *out = yeptris_serialize_json(b, out_len);
231
+ yeptris_document_free(b);
232
+ return out;
233
+ }
234
+
235
+ /* Builds the stream answer: a JSON array of every document. count==0
236
+ * builds the empty wrapper ("[]"); every other stream wraps its
237
+ * documents in one sequence, which serialize_json spells as the
238
+ * array. */
239
+ static int yeptris_wasm_load_all_answer(YeptrisDocument doc, size_t count) {
240
+ yw_rec r;
241
+ memset(&r, 0, sizeof r);
242
+ if (yw_push_entry(&r, YEPTRIS_BUILD_SEQ, 0, 0, 0) != 0) {
243
+ capture_plain("document rebuild failed");
244
+ return YEPTRIS_ERROR_MEMORY;
245
+ }
246
+ for (size_t i = 0; i < count; i++) {
247
+ YeptrisNode root = yeptris_document_root(doc, i);
248
+ if (root == NULL || yw_flatten(&r, root) != 0) {
249
+ capture_plain(r.failed == YEPTRIS_ERROR_DEPTH ? "document nesting exceeds the rebuild depth cap"
250
+ : "document rebuild failed");
251
+ yw_rec_free(&r);
252
+ return r.failed != 0 ? r.failed : YEPTRIS_ERROR_MEMORY;
253
+ }
254
+ }
255
+ if (yw_push_entry(&r, YEPTRIS_BUILD_END, 0, 0, 0) != 0) {
256
+ capture_plain("document rebuild failed");
257
+ return YEPTRIS_ERROR_MEMORY;
258
+ }
259
+ size_t out_len = 0;
260
+ char *out = yw_serialize_rebuilt(&r, &out_len);
261
+ if (out == NULL) {
262
+ capture_plain("serialization failed");
263
+ return YEPTRIS_ERROR_MEMORY;
264
+ }
265
+ publish_out(out, out_len);
266
+ return YEPTRIS_OK;
267
+ }
268
+
269
+ /* YAML in -> canonical JSON out (yeptris_serialize_json). A
270
+ * multi-document stream answers with the FIRST document — the json.h
271
+ * contract; the emitter only writes dcount==1 forests directly, so
272
+ * bigger streams re-type document 0 through the build API. An empty
273
+ * stream (no documents) keeps the engine's answer: an empty output. */
36
274
  EMSCRIPTEN_KEEPALIVE
37
275
  int yeptris_wasm_load(const char *data, size_t len) {
38
276
  YeptrisStatus st = YEPTRIS_OK;
@@ -42,19 +280,59 @@ int yeptris_wasm_load(const char *data, size_t len) {
42
280
  return (int)st;
43
281
  }
44
282
  size_t out_len = 0;
45
- char *out = yeptris_serialize_json(doc, &out_len);
46
- yeptris_document_free(doc);
283
+ char *out = NULL;
284
+ if (yeptris_document_count(doc) <= 1) {
285
+ out = yeptris_serialize_json(doc, &out_len);
286
+ yeptris_document_free(doc);
287
+ } else {
288
+ yw_rec r;
289
+ memset(&r, 0, sizeof r);
290
+ int rc = 0;
291
+ YeptrisNode root = yeptris_document_root(doc, 0);
292
+ if (root == NULL || yw_flatten(&r, root) != 0) {
293
+ rc = r.failed != 0 ? r.failed : YEPTRIS_ERROR_MEMORY;
294
+ } else {
295
+ out = yw_serialize_rebuilt(&r, &out_len);
296
+ rc = out == NULL ? YEPTRIS_ERROR_MEMORY : YEPTRIS_OK;
297
+ }
298
+ yeptris_document_free(doc);
299
+ if (rc != YEPTRIS_OK) {
300
+ capture_plain(rc == YEPTRIS_ERROR_DEPTH
301
+ ? "document nesting exceeds the rebuild depth cap"
302
+ : "document rebuild failed");
303
+ return rc;
304
+ }
305
+ }
47
306
  if (out == NULL) {
48
307
  snprintf(last_error, sizeof last_error, "serialization failed");
49
308
  last_error_line = 0;
50
309
  last_error_column = 0;
51
310
  return YEPTRIS_ERROR_MEMORY;
52
311
  }
53
- g_out = out;
54
- g_out_len = out_len;
312
+ publish_out(out, out_len);
55
313
  return YEPTRIS_OK;
56
314
  }
57
315
 
316
+ /* YAML in -> a JSON array of every document in the stream (the
317
+ * loadAll answer). An empty stream (and a failed-to-parse-with-OK
318
+ * empty input, the engine's "zero documents" shape) answers "[]";
319
+ * parse errors surface exactly like load's. */
320
+ EMSCRIPTEN_KEEPALIVE
321
+ int yeptris_wasm_load_all(const char *data, size_t len) {
322
+ YeptrisStatus st = YEPTRIS_OK;
323
+ YeptrisDocument doc = yeptris_parse(data, len, &st);
324
+ if (doc == NULL) {
325
+ if (st == YEPTRIS_OK) { /* empty/comment-only stream: no docs */
326
+ return yeptris_wasm_load_all_answer(NULL, 0);
327
+ }
328
+ capture_error();
329
+ return (int)st;
330
+ }
331
+ int rc = yeptris_wasm_load_all_answer(doc, yeptris_document_count(doc));
332
+ yeptris_document_free(doc);
333
+ return rc;
334
+ }
335
+
58
336
  /* JSON in -> canonical YAML out (JSON is a subset of YAML 1.2 flow, so
59
337
  * the one parse engine takes it; the emitter's canonical form is
60
338
  * byte-stable across round trips). */