mirror of
https://github.com/hanzoai/zip-js.git
synced 2026-10-30 18:17:04 +00:00
Three end-to-end examples mirroring zip-rs:
- hello — minimal name → greeting handler (1.5 KB built)
- validate-email — port of the canonical validate fixture, byte-equivalent
JSON output to base/plugins/extbench/fixtures/goja-js (1.9 KB)
- policy-eval — realistic IAM/gateway authz decision handler (2.0 KB)
Built JS is committed so test harnesses + downstream consumers don't
depend on the toolchain. scripts/build-example.mjs is the monorepo
build driver (aliases @hanzo/zip to the local dist); end users use
the published npx zip-js build instead.
scripts/verify-examples.mjs loads each built bundle into a fresh V8
context and asserts byte-for-byte JSON output matches the canonical
reference strings — the same shape extbench compares.
7 lines
1.9 KiB
JavaScript
7 lines
1.9 KiB
JavaScript
"use strict";var __zip=(()=>{var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var d=(e,t,r)=>t in e?i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var g=(e,t)=>{for(var r in t)i(e,r,{get:t[r],enumerable:!0})},h=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of p(t))!c.call(e,a)&&a!==r&&i(e,a,{get:()=>t[a],enumerable:!(n=m(t,a))||n.enumerable});return e};var w=e=>h(i({},"__esModule",{value:!0}),e);var l=(e,t,r)=>d(e,typeof t!="symbol"?t+"":t,r);var x={};g(x,{validate:()=>y});var o=class extends Error{constructor(r,n=500){super(r);l(this,"status");this.name="ZipError",this.status=n}};function s(e){return{ok:!1,error:e}}function u(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function f(e){return function(r){try{let n=e(r);if(n!==null&&typeof n=="object"&&typeof n.then=="function")throw new o("zip-js: handler returned a Promise. HIP-0105 invocations are synchronous; do async work in HIP-0060 FaaS instead.",500);return n}catch(n){return s(u(n))}}}var y=f(e=>{if(e===null||typeof e!="object")throw new o("input must be an object",400);let t=e.email,r=e.age;if(typeof t!="string"||t.length===0)throw new o("email required",400);if(typeof r!="number"||r<0||r>150)throw new o("age out of range",400);let n=t.trim().toLowerCase(),a=n.indexOf("@");if(a<=0||a===n.length-1)throw new o("email shape",400);if(n.substring(a+1).indexOf(".")<0)throw new o("email domain",400);return{ok:!0,email:n,age:r}});return w(x);})();
|
|
// zip-js goja trailer: register handlers on globalThis.
|
|
if (typeof __zip === "undefined" || typeof __zip.validate !== "function") {
|
|
throw new Error("zip-js: export 'validate' not found in bundle (did you 'export const validate = handler(...)'?)");
|
|
}
|
|
globalThis.validate = __zip.validate;
|