@lunora/container 1.0.0-alpha.69 → 1.0.0-alpha.70

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.
Files changed (2) hide show
  1. package/dist/bridge.mjs +1 -1
  2. package/package.json +2 -2
package/dist/bridge.mjs CHANGED
@@ -1 +1 @@
1
- import{LunoraError as p}from"@lunora/errors";const m=r=>{let t="";for(let c=0;c<r.length;c+=32768)t+=String.fromCharCode(...r.subarray(c,c+32768));return btoa(t)},R=r=>{const t=atob(r),o=new Uint8Array(t.length);for(let c=0;c<t.length;c+=1)o[c]=t.codePointAt(c)??0;return o},f="$lunora.wire$",w=64,E=1024,g="__proto__",j={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},O={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},U=r=>{if(r===null||typeof r!="object")return!1;const t=Object.getPrototypeOf(r);return t===null||t===Object.prototype},d=(r,t=0)=>{if(t>w)throw new RangeError(`wire-codec: value nesting exceeds the ${w}-level limit`);if(r===void 0)return[f,"undefined"];if(r===null)return null;const o=typeof r;if(o==="bigint")return[f,"bigint",r.toString()];if(o==="number"){const e=r;return Number.isNaN(e)?[f,"nan"]:e===1/0?[f,"inf"]:e===-1/0?[f,"-inf"]:e}if(o!=="object")return r;if(r instanceof Date)return[f,"date",d(r.getTime(),t+1)];if(r instanceof Error){const e=r,n={};for(const i of Object.keys(e)){if(e[i]===void 0)continue;const u=d(e[i],t+1);i===g?Object.defineProperty(n,i,{configurable:!0,enumerable:!0,value:u,writable:!0}):n[i]=u}const a=[f,"error",String(e.name),String(e.message),n];return e.cause!==void 0&&a.push(d(e.cause,t+1)),a}if(r instanceof URL)return[f,"url",r.href];if(r instanceof Map)return[f,"map",[...r.entries()].map(([e,n])=>[d(e,t+1),d(n,t+1)])];if(r instanceof Set)return[f,"set",[...r].map(e=>d(e,t+1))];if(r instanceof ArrayBuffer)return[f,"bytes",m(new Uint8Array(r)),"ArrayBuffer"];if(ArrayBuffer.isView(r)){const e=r,n=e.constructor.name,a=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return n==="Uint8Array"?[f,"bytes",m(a)]:[f,"bytes",m(a),n]}if(Array.isArray(r)){const e=r.map(n=>d(n,t+1));return e.length>0&&e[0]===f?[f,"arr",e]:e}if(!U(r)){const e=r.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${e} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const c=r,s={};for(const e of Object.keys(c)){const n=c[e];if(n===void 0)continue;const a=d(n,t+1);e===g?Object.defineProperty(s,e,{configurable:!0,enumerable:!0,value:a,writable:!0}):s[e]=a}return s},b=(r,t=0)=>{if(t>w)throw new RangeError(`wire-codec: value nesting exceeds the ${w}-level limit`);if(r===null||typeof r!="object")return r;if(Array.isArray(r)){if(r[0]===f)switch(r[1]){case"-inf":return-1/0;case"arr":return r[2].map(e=>b(e,t+1));case"bigint":{const e=r[2];if(typeof e!="string"||e.length>E||!/^-?\d+$/.test(e))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${E} digits)`);return BigInt(e)}case"date":{const e=b(r[2],t+1);if(typeof e!="number")throw new TypeError("wire-codec: malformed date — epoch must be a number");return new Date(e)}case"map":{const e=r[2];return new Map(e.map(n=>{if(!Array.isArray(n)||n.length!==2)throw new TypeError("wire-codec: malformed map entry — expected a [key, value] pair");return[b(n[0],t+1),b(n[1],t+1)]}))}case"set":return new Set(r[2].map(e=>b(e,t+1)));case"url":{const e=r[2];if(typeof e!="string")throw new TypeError("wire-codec: malformed url — href must be a string");return new URL(e)}case"error":{const e=r[2],n=r[3];if(typeof e!="string"||typeof n!="string")throw new TypeError("wire-codec: malformed error — name and message must be strings");const a=(Object.hasOwn(O,e)?O[e]:void 0)??Error,i=new a(n);i.name!==e&&Object.defineProperty(i,"name",{configurable:!0,value:e,writable:!0});const u=b(r[4],t+1);if(u===null||typeof u!="object"||Array.isArray(u))throw new TypeError("wire-codec: malformed error — props must be an object");for(const y of Object.keys(u))y===g?Object.defineProperty(i,y,{configurable:!0,enumerable:!0,value:u[y],writable:!0}):i[y]=u[y];return r.length>5&&Object.defineProperty(i,"cause",{configurable:!0,value:b(r[5],t+1),writable:!0}),i}case"bytes":{const e=r[2];if(typeof e!="string")throw new TypeError("wire-codec: malformed bytes — payload must be a base64 string");const n=R(e);if(m(n)!==e)throw new TypeError("wire-codec: malformed bytes — payload must be canonical padded base64");const a=r[3]??"Uint8Array";if(a==="ArrayBuffer")return n.buffer.byteLength===n.byteLength?n.buffer:n.slice().buffer;const i=Object.hasOwn(j,a)?j[a]:void 0;return i?new i(n.slice().buffer):n}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return r.map(e=>b(e,t+1))}return r.map(s=>b(s,t+1))}const o=r,c={};for(const s of Object.keys(o)){const e=b(o[s],t+1);s===g?Object.defineProperty(c,s,{configurable:!0,enumerable:!0,value:e,writable:!0}):c[s]=e}return c},B="/_lunora/rpc";class S extends p{constructor(t,o){super(t,o,{name:"ContainerBridgeError"})}}const k=(r,t)=>{let o=r;for(;o.endsWith("/");)o=o.slice(0,-1);return`${o}${t}`},T=(r,t)=>new Error(`createContainerBridge: request to "${r}" failed (status ${String(t.status)}${t.statusText?` ${t.statusText}`:""})`),$=async(r,t)=>{try{return await r.json()}catch{throw r.ok?new p("INTERNAL",`createContainerBridge: request to "${t}" returned a non-JSON response (status ${String(r.status)})`):T(t,r)}},N=r=>{if(typeof r.baseUrl!="string"||r.baseUrl.length===0)throw new TypeError("createContainerBridge: `baseUrl` must be a non-empty Worker URL (e.g. https://my-app.workers.dev) — is the URL env var set?");const t=r.fetch??globalThis.fetch,o=async(s,e={},n)=>{if(typeof t!="function")throw new TypeError("createContainerBridge: no `fetch` available — pass `fetch` in options for this runtime.");const a={"content-type":"application/json"};r.token!==void 0&&(a.authorization=`Bearer ${r.token}`);const i=await t(k(r.baseUrl,B),{body:JSON.stringify({args:d(e),functionPath:s,shardKey:n}),headers:a,method:"POST"}),u=await $(i,s);if(typeof u=="object"&&u!==null&&"error"in u){const{error:y}=u;if(typeof y=="object"&&y!==null){const{code:h,message:A}=y;if(typeof h=="string"&&typeof A=="string")throw new S(h,A)}let l;try{l=JSON.stringify(y)}catch{l=String(y)}throw new p("INTERNAL",`createContainerBridge: request to "${s}" returned a malformed error envelope (status ${String(i.status)}): ${l}`)}if(!i.ok)throw T(s,i);return b(u.result)};return{action:o,call:o,mutation:o,query:o,run:async(s,e,n)=>o(s.__lunoraRef,e,n)}};export{S as ContainerBridgeError,N as createContainerBridge};
1
+ import{LunoraError as h}from"@lunora/errors";const g=r=>{let t="";for(let s=0;s<r.length;s+=32768)t+=String.fromCharCode(...r.subarray(s,s+32768));return btoa(t)},R=r=>{const t=atob(r),o=new Uint8Array(t.length);for(let s=0;s<t.length;s+=1)o[s]=t.codePointAt(s)??0;return o},f="$lunora.wire$",m=64,w=1024,p="__proto__",j={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},O={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},U=r=>{if(r===null||typeof r!="object")return!1;const t=Object.getPrototypeOf(r);return t===null||t===Object.prototype},d=(r,t=0)=>{if(t>m)throw new RangeError(`wire-codec: value nesting exceeds the ${m}-level limit`);if(r===void 0)return[f,"undefined"];if(r===null)return null;const o=typeof r;if(o==="bigint"){const e=r.toString();if(e.length>w)throw new RangeError(`wire-codec: over-long bigint (max ${w} digits)`);return[f,"bigint",e]}if(o==="number"){const e=r;return Number.isNaN(e)?[f,"nan"]:e===1/0?[f,"inf"]:e===-1/0?[f,"-inf"]:e}if(o!=="object")return r;if(r instanceof Date)return[f,"date",d(r.getTime(),t+1)];if(r instanceof Error){const e=r,n=d(Object.fromEntries(Object.keys(e).map(a=>[a,e[a]])),t+1),c=[f,"error",String(e.name),String(e.message),n];return e.cause!==void 0&&c.push(d(e.cause,t+1)),c}if(r instanceof URL)return[f,"url",r.href];if(r instanceof Map)return[f,"map",[...r.entries()].map(([e,n])=>[d(e,t+1),d(n,t+1)])];if(r instanceof Set)return[f,"set",[...r].map(e=>d(e,t+1))];if(r instanceof ArrayBuffer)return[f,"bytes",g(new Uint8Array(r)),"ArrayBuffer"];if(ArrayBuffer.isView(r)){const e=r,n=e.constructor.name,c=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return n==="Uint8Array"?[f,"bytes",g(c)]:[f,"bytes",g(c),n]}if(Array.isArray(r)){const e=r.map(n=>d(n,t+1));return e.length>0&&e[0]===f?[f,"arr",e]:e}if(!U(r)){const e=r.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${e} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const s=r,i={};for(const e of Object.keys(s)){const n=s[e];if(n===void 0)continue;const c=d(n,t+1);e===p?Object.defineProperty(i,e,{configurable:!0,enumerable:!0,value:c,writable:!0}):i[e]=c}return i},b=(r,t=0)=>{if(t>m)throw new RangeError(`wire-codec: value nesting exceeds the ${m}-level limit`);if(r===null||typeof r!="object")return r;if(Array.isArray(r)){if(r[0]===f)switch(r[1]){case"-inf":return-1/0;case"arr":return r[2].map(e=>b(e,t+1));case"bigint":{const e=r[2];if(typeof e!="string"||e.length>w||!/^-?\d+$/.test(e))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${w} digits)`);return BigInt(e)}case"date":{const e=b(r[2],t+1);if(typeof e!="number")throw new TypeError("wire-codec: malformed date — epoch must be a number");return new Date(e)}case"map":{const e=r[2];return new Map(e.map(n=>{if(!Array.isArray(n)||n.length!==2)throw new TypeError("wire-codec: malformed map entry — expected a [key, value] pair");return[b(n[0],t+1),b(n[1],t+1)]}))}case"set":return new Set(r[2].map(e=>b(e,t+1)));case"url":{const e=r[2];if(typeof e!="string")throw new TypeError("wire-codec: malformed url — href must be a string");return new URL(e)}case"error":{const e=r[2],n=r[3];if(typeof e!="string"||typeof n!="string")throw new TypeError("wire-codec: malformed error — name and message must be strings");const c=(Object.hasOwn(O,e)?O[e]:void 0)??Error,a=new c(n);a.name!==e&&Object.defineProperty(a,"name",{configurable:!0,value:e,writable:!0});const y=b(r[4],t+1);if(y===null||typeof y!="object"||Array.isArray(y))throw new TypeError("wire-codec: malformed error — props must be an object");for(const u of Object.keys(y))u===p?Object.defineProperty(a,u,{configurable:!0,enumerable:!0,value:y[u],writable:!0}):a[u]=y[u];return r.length>5&&Object.defineProperty(a,"cause",{configurable:!0,value:b(r[5],t+1),writable:!0}),a}case"bytes":{const e=r[2];if(typeof e!="string")throw new TypeError("wire-codec: malformed bytes — payload must be a base64 string");const n=R(e);if(g(n)!==e)throw new TypeError("wire-codec: malformed bytes — payload must be canonical padded base64");const c=r[3]??"Uint8Array";if(c==="ArrayBuffer")return n.buffer.byteLength===n.byteLength?n.buffer:n.slice().buffer;const a=Object.hasOwn(j,c)?j[c]:void 0;return a?new a(n.slice().buffer):n}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return r.map(e=>b(e,t+1))}return r.map(i=>b(i,t+1))}const o=r,s={};for(const i of Object.keys(o)){const e=b(o[i],t+1);i===p?Object.defineProperty(s,i,{configurable:!0,enumerable:!0,value:e,writable:!0}):s[i]=e}return s},B="/_lunora/rpc";class S extends h{constructor(t,o){super(t,o,{name:"ContainerBridgeError"})}}const $=(r,t)=>{let o=r;for(;o.endsWith("/");)o=o.slice(0,-1);return`${o}${t}`},T=(r,t)=>new Error(`createContainerBridge: request to "${r}" failed (status ${String(t.status)}${t.statusText?` ${t.statusText}`:""})`),k=async(r,t)=>{try{return await r.json()}catch{throw r.ok?new h("INTERNAL",`createContainerBridge: request to "${t}" returned a non-JSON response (status ${String(r.status)})`):T(t,r)}},N=r=>{if(typeof r.baseUrl!="string"||r.baseUrl.length===0)throw new TypeError("createContainerBridge: `baseUrl` must be a non-empty Worker URL (e.g. https://my-app.workers.dev) — is the URL env var set?");const t=r.fetch??globalThis.fetch,o=async(i,e={},n)=>{if(typeof t!="function")throw new TypeError("createContainerBridge: no `fetch` available — pass `fetch` in options for this runtime.");const c={"content-type":"application/json"};r.token!==void 0&&(c.authorization=`Bearer ${r.token}`);const a=await t($(r.baseUrl,B),{body:JSON.stringify({args:d(e),functionPath:i,shardKey:n}),headers:c,method:"POST"}),y=await k(a,i);if(typeof y=="object"&&y!==null&&"error"in y){const{error:u}=y;if(typeof u=="object"&&u!==null){const{code:A,message:E}=u;if(typeof A=="string"&&typeof E=="string")throw new S(A,E)}let l;try{l=JSON.stringify(u)}catch{l=String(u)}throw new h("INTERNAL",`createContainerBridge: request to "${i}" returned a malformed error envelope (status ${String(a.status)}): ${l}`)}if(!a.ok)throw T(i,a);return b(y.result)};return{action:o,call:o,mutation:o,query:o,run:async(i,e,n)=>o(i.__lunoraRef,e,n)}};export{S as ContainerBridgeError,N as createContainerBridge};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/container",
3
- "version": "1.0.0-alpha.69",
3
+ "version": "1.0.0-alpha.70",
4
4
  "description": "Cloudflare Containers for Lunora: defineContainer, generated Container DO classes, and the ctx.containers action surface",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@cloudflare/sandbox": "1.0.0",
64
- "@lunora/errors": "1.0.0-alpha.50"
64
+ "@lunora/errors": "1.0.0-alpha.51"
65
65
  },
66
66
  "engines": {
67
67
  "node": "^22.15.0 || >=24.11.0"