yeptris 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 leptris contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # yeptris
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ YAML for JavaScript at [libyeptris](https://github.com/leptris/yeptris)
4
+ speed — the engine compiled to WebAssembly (ES module, no fallback).
5
+
6
+ ```js
7
+ import { load, dump } from "yeptris";
8
+
9
+ const doc = await load("name: yeptris\nlangs:\n- c\n- rust\n");
10
+ // { name: "yeptris", langs: ["c", "rust"] }
11
+
12
+ const yaml = await dump({ name: "yeptris", langs: ["c", "rust"] });
13
+ // the engine's canonical, byte-stable YAML
14
+ ```
15
+
16
+ - `load(yaml)` — parse to a JavaScript value (malformed input throws
17
+ `YamlError` with line/column).
18
+ - `loadJSON(yaml)` — the engine's canonical JSON string.
19
+ - `dump(json)` — JSON text (or any JSON-serializable value) to
20
+ canonical YAML; JSON is a subset of YAML 1.2 flow, so the one parse
21
+ engine takes it.
22
+
23
+ The same model as [teptris-wasm](https://github.com/leptris/teptris-wasm):
24
+ a contained C bridge (`src/yeptris_wasm.c`) over the engine's
25
+ buffer-lifetime contract, compiled by `build.sh` (emcc) from the
26
+ sibling engine checkout, surfaced as an ES module.
27
+
28
+ ## Build and test
29
+
30
+ ```sh
31
+ ./build.sh # ENGINESRC=../yeptris/src by default
32
+ node --test test/test.mjs
33
+ ```
34
+
35
+ CI builds the engine tag and runs the same on every push and PR.
36
+
37
+ ## Releasing
38
+
39
+ `npm publish` runs through the dispatch-only workflow (Trusted
40
+ Publishing — configure `leptris/yeptris-ts` + `release.yml` as the
41
+ package's publisher on npmjs). The first publish is manual; after
42
+ that, dispatch **Release** and the dist build + publish + GitHub
43
+ release run as one train.
@@ -0,0 +1,2 @@
1
+ async function Module(moduleArg={}){var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import("node:module");var require=createRequire(import.meta.url)}var programArgs=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");if(_scriptName.startsWith("file:")){scriptDirectory=require("node:path").dirname(require("node:url").fileURLToPath(_scriptName))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}programArgs=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");class EmscriptenEH{}class EmscriptenSjLj extends EmscriptenEH{}var runtimeInitialized=false;function getMemoryBuffer(){return wasmMemory.buffer}function updateMemoryViews(){if(HEAP8?.buffer?.resizable)return;var b=getMemoryBuffer();HEAP8=new Int8Array(b);HEAPU8=new Uint8Array(b);HEAPU32=new Uint32Array(b)}function preRun(){var preRun=Module["preRun"];if(preRun){if(typeof preRun=="function")preRun=[preRun];onPreRuns.push(...preRun)}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["g"]()}function postRun(){var postRun=Module["postRun"];if(postRun){if(typeof postRun=="function")postRun=[postRun];onPostRuns.push(...postRun)}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("yeptris.wasm")}return new URL("yeptris.wasm",import.meta.url).href}function getBinarySync(file){if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();var instantiateWasm=Module["instantiateWasm"];if(instantiateWasm){return new Promise(resolve=>{instantiateWasm(info,inst=>resolve(receiveInstance(inst)))})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var onPreRuns=[];var noExitRuntime=true;var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var HEAPU8;var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}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,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var ENV={};var getExecutableName=()=>thisProgram;var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(globalThis.navigator?.language??"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 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.codePointAt(i);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;i++}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var HEAPU32;var _environ_get=(__environ,environ_buf)=>{var bufSize=0;var envp=0;for(var string of getEnvStrings()){var ptr=environ_buf+bufSize;HEAPU32[__environ+envp>>2]=ptr;bufSize+=stringToUTF8(string,ptr,Infinity)+1;envp+=4}return 0};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 _environ_sizes_get=(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;for(var string of strings){bufSize+=lengthBytesUTF8(string)+1}HEAPU32[penviron_buf_size>>2]=bufSize;return 0};var _fd_close=fd=>52;var printCharBuffers=[null,[],[]];var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);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 printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer));buffer.length=0}else{buffer.push(curr)}};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):"";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};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["arguments"])programArgs=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var preInit=Module["preInit"];if(preInit){if(typeof preInit=="function")Module["preInit"]=preInit=[preInit];while(preInit.length>0){preInit.shift()()}}}Module["UTF8ToString"]=UTF8ToString;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;var _yeptris_wasm_load,_yeptris_wasm_dump,_yeptris_wasm_last_error,_yeptris_wasm_last_error_line,_yeptris_wasm_last_error_column,_yeptris_wasm_out,_yeptris_wasm_out_len,_yeptris_wasm_free,_yeptris_wasm_version,_malloc,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_yeptris_wasm_load=Module["_yeptris_wasm_load"]=wasmExports["h"];_yeptris_wasm_dump=Module["_yeptris_wasm_dump"]=wasmExports["i"];_yeptris_wasm_last_error=Module["_yeptris_wasm_last_error"]=wasmExports["j"];_yeptris_wasm_last_error_line=Module["_yeptris_wasm_last_error_line"]=wasmExports["k"];_yeptris_wasm_last_error_column=Module["_yeptris_wasm_last_error_column"]=wasmExports["l"];_yeptris_wasm_out=Module["_yeptris_wasm_out"]=wasmExports["m"];_yeptris_wasm_out_len=Module["_yeptris_wasm_out_len"]=wasmExports["n"];_yeptris_wasm_free=Module["_yeptris_wasm_free"]=wasmExports["o"];_yeptris_wasm_version=Module["_yeptris_wasm_version"]=wasmExports["p"];_malloc=Module["_malloc"]=wasmExports["q"];memory=wasmMemory=wasmExports["f"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={b:_emscripten_resize_heap,d:_environ_get,e:_environ_sizes_get,c:_fd_close,a:_fd_write};async function run(){preRun();var setStatus=Module["setStatus"];if(setStatus){setStatus("Running...");await new Promise(resolve=>setTimeout(resolve,1));setTimeout(setStatus,1,"")}if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}var wasmExports;wasmExports=await createWasm();await run();
2
+ ;return Module}export default Module;
Binary file
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "yeptris",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "YAML for JavaScript at libyeptris speed (WebAssembly, no fallback)",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "./build.sh",
15
+ "test": "node --test test/test.mjs"
16
+ },
17
+ "license": "MIT",
18
+ "engines": {
19
+ "node": ">=20"
20
+ }
21
+ }
package/src/index.js ADDED
@@ -0,0 +1,78 @@
1
+ // The public surface: YAML <-> JSON at libyeptris speed.
2
+ // Engine FFI through ../dist/yeptris.mjs (built by build.sh).
3
+
4
+ function cstr(mod, s) {
5
+ const bytes = mod.lengthBytesUTF8(s) + 1;
6
+ const ptr = mod._malloc(bytes);
7
+ mod.stringToUTF8(s, ptr, bytes);
8
+ return ptr;
9
+ }
10
+
11
+ function freeCstr(mod, ptr) {
12
+ mod._yeptris_wasm_free(ptr);
13
+ }
14
+
15
+ class YamlError extends Error {
16
+ constructor(message, line, column) {
17
+ super(line ? `${message} (line ${line}, column ${column})` : message);
18
+ this.name = "YamlError";
19
+ this.line = line;
20
+ this.column = column;
21
+ }
22
+ }
23
+
24
+ function run(mod, fn, input) {
25
+ const ptr = cstr(mod, input);
26
+ try {
27
+ const st = fn(ptr, input.length);
28
+ if (st !== 0) {
29
+ const msg = mod.UTF8ToString(mod._yeptris_wasm_last_error());
30
+ throw new YamlError(
31
+ msg,
32
+ mod._yeptris_wasm_last_error_line(),
33
+ mod._yeptris_wasm_last_error_column());
34
+ }
35
+ const out = mod.UTF8ToString(mod._yeptris_wasm_out());
36
+ return out;
37
+ } finally {
38
+ freeCstr(mod, ptr);
39
+ }
40
+ }
41
+
42
+ let cached = null;
43
+
44
+ async function mod() {
45
+ if (cached) return cached;
46
+ const factory = (await import("../dist/yeptris.mjs")).default;
47
+ cached = await factory();
48
+ return cached;
49
+ }
50
+
51
+ /** Parse YAML text and return the document as a JavaScript value
52
+ * (the engine's canonical JSON, JSON.parse'd). Throws YamlError with
53
+ * line/column on malformed input. */
54
+ export async function load(yaml) {
55
+ const m = await mod();
56
+ return JSON.parse(run(m, m._yeptris_wasm_load, yaml));
57
+ }
58
+
59
+ /** Parse YAML text and return the engine's canonical JSON string. */
60
+ export async function loadJSON(yaml) {
61
+ const m = await mod();
62
+ return run(m, m._yeptris_wasm_load, yaml);
63
+ }
64
+
65
+ /** Convert JSON text (or any JSON-serializable value) to the engine's
66
+ * canonical, byte-stable YAML. JSON is a subset of YAML 1.2 flow, so
67
+ * the one parse engine takes it. */
68
+ export async function dump(json) {
69
+ const m = await mod();
70
+ const text = typeof json === "string" ? json : JSON.stringify(json);
71
+ return run(m, m._yeptris_wasm_dump, text);
72
+ }
73
+
74
+ /** The libyeptris version string. */
75
+ export async function version() {
76
+ const m = await mod();
77
+ return m.UTF8ToString(m._yeptris_wasm_version());
78
+ }