Files
zeekay a86165b198 feat: hello + validate-email + policy-eval examples
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.
2026-05-18 22:04:15 -07:00

7 lines
1.5 KiB
JavaScript

"use strict";var __zip=(()=>{var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var h=(e,r,t)=>r in e?i(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var g=(e,r)=>{for(var t in r)i(e,t,{get:r[t],enumerable:!0})},d=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of c(r))!m.call(e,s)&&s!==t&&i(e,s,{get:()=>r[s],enumerable:!(n=p(r,s))||n.enumerable});return e};var x=e=>d(i({},"__esModule",{value:!0}),e);var l=(e,r,t)=>h(e,typeof r!="symbol"?r+"":r,t);var E={};g(E,{hello:()=>y});var o=class extends Error{constructor(t,n=500){super(t);l(this,"status");this.name="ZipError",this.status=n}};function a(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(t){try{let n=e(t);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 a(u(n))}}}var y=f(e=>{if(!e?.name)throw new o("name required",400);return{greeting:`hello, ${e.name}!`}});return x(E);})();
// zip-js goja trailer: register handlers on globalThis.
if (typeof __zip === "undefined" || typeof __zip.hello !== "function") {
throw new Error("zip-js: export 'hello' not found in bundle (did you 'export const hello = handler(...)'?)");
}
globalThis.hello = __zip.hello;