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.9 KiB
JavaScript

"use strict";var __zip=(()=>{var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var d=(r,e,t)=>e in r?i(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var h=(r,e)=>{for(var t in e)i(r,t,{get:e[t],enumerable:!0})},m=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of p(e))!w.call(r,s)&&s!==t&&i(r,s,{get:()=>e[s],enumerable:!(o=f(e,s))||o.enumerable});return r};var g=r=>m(i({},"__esModule",{value:!0}),r);var l=(r,e,t)=>d(r,typeof e!="symbol"?e+"":e,t);var x={};h(x,{evaluate:()=>y});var n=class extends Error{constructor(t,o=500){super(t);l(this,"status");this.name="ZipError",this.status=o}};function a(r){return{ok:!1,error:r}}function c(r){if(r instanceof Error)return r.message;if(typeof r=="string")return r;try{return JSON.stringify(r)}catch{return String(r)}}function u(r){return function(t){try{let o=r(t);if(o!==null&&typeof o=="object"&&typeof o.then=="function")throw new n("zip-js: handler returned a Promise. HIP-0105 invocations are synchronous; do async work in HIP-0060 FaaS instead.",500);return o}catch(o){return a(c(o))}}}var y=u(r=>{if(!r?.subject)throw new n("subject required",400);if(!r?.action)throw new n("action required",400);let e=r.resource??"",t=r.context?.role;return r.subject==="root"||t==="admin"?{allow:!0,reason:"admin override"}:r.action==="read"&&e.startsWith("public:")?{allow:!0,reason:"public resource"}:r.action==="write"||r.action==="update"||r.action==="delete"?e.startsWith(`${r.subject}:`)?{allow:!0,reason:"owner"}:{allow:!1,reason:"not owner"}:{allow:!1,reason:"no rule matched"}});return g(x);})();
// zip-js goja trailer: register handlers on globalThis.
if (typeof __zip === "undefined" || typeof __zip.evaluate !== "function") {
throw new Error("zip-js: export 'evaluate' not found in bundle (did you 'export const evaluate = handler(...)'?)");
}
globalThis.evaluate = __zip.evaluate;