atmx-web 0.78.0 ā 0.79.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/dist/atmx.es.js +4 -4
- package/dist/atmx.umd.js +2 -2
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/atmx.es.js
CHANGED
|
@@ -69,7 +69,7 @@ function i(e, t) {
|
|
|
69
69
|
if (!n) return;
|
|
70
70
|
let i = Array.isArray(n) ? n : Object.values(n);
|
|
71
71
|
i.forEach((t) => {
|
|
72
|
-
let n = `${e}.${t.name}`, i = t.parameters?.
|
|
72
|
+
let n = `${e}.${t.name}`, i = t.parameters?.filter((e) => e.source === "body") || [], a = i.length === 1 ? i[0].name : null;
|
|
73
73
|
r.set(n, {
|
|
74
74
|
id: t.id,
|
|
75
75
|
namespace: e,
|
|
@@ -78,7 +78,7 @@ function i(e, t) {
|
|
|
78
78
|
pathTemplate: t.path,
|
|
79
79
|
isStream: t.isStream || !1,
|
|
80
80
|
auth: t.auth || null,
|
|
81
|
-
bodyParam:
|
|
81
|
+
bodyParam: a
|
|
82
82
|
});
|
|
83
83
|
}), console.log(`š£ļø ATMX Router: Mapped ${i.length} endpoints for '${e}'.`);
|
|
84
84
|
}
|
|
@@ -472,7 +472,7 @@ function N(e) {
|
|
|
472
472
|
...i,
|
|
473
473
|
...n.args
|
|
474
474
|
}), l = c;
|
|
475
|
-
r.bodyParam && c[r.bodyParam] !== void 0 && (l = c[r.bodyParam]);
|
|
475
|
+
r.bodyParam && c[r.bodyParam] !== void 0 && typeof c[r.bodyParam] == "object" && (l = c[r.bodyParam]);
|
|
476
476
|
let u = {}, d = e.getAttribute("ax-headers");
|
|
477
477
|
if (d) try {
|
|
478
478
|
u = Function("return (" + d + ");")() || {};
|
|
@@ -654,7 +654,7 @@ var B = class extends HTMLElement {
|
|
|
654
654
|
typeof window < "u" && !customElements.get("ax-engine-status") && customElements.define("ax-engine-status", B);
|
|
655
655
|
//#endregion
|
|
656
656
|
//#region src/index.ts
|
|
657
|
-
var V = "0.
|
|
657
|
+
var V = "0.79.0", H = new class {
|
|
658
658
|
version = V;
|
|
659
659
|
initialized = !1;
|
|
660
660
|
debug = !1;
|
package/dist/atmx.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.atmx={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=function(e){return e[e.Complete=0]=`Complete`,e[e.NetworkSuccess=1]=`NetworkSuccess`,e[e.CacheHit=2]=`CacheHit`,e[e.CacheHitAndFetching=3]=`CacheHitAndFetching`,e[e.Error=4]=`Error`,e}({}),n=new Map;function r(e){window.axiom_web_callback=(r,i,a,o,s,c,l)=>{let u=n.get(r);if(!u){o&&e.axiom_free_memory(o,s),c&&e.axiom_free_memory(c,l);return}let d=null,f=null;if(o!==0&&s>0){let t=new Uint8Array(e.memory.buffer);d=new Uint8Array(t.subarray(o,o+s)),e.axiom_free_memory(o,s)}if(c!==0&&l>0){let t=new Uint8Array(e.memory.buffer),n=new Uint8Array(t.subarray(c,c+l));f=new TextDecoder().decode(n),e.axiom_free_memory(c,l)}if(i===t.Complete){u.onComplete(),n.delete(r);return}if(i===t.Error){let e;if(f)try{e=JSON.parse(f)}catch(t){e={stage:`ffiBoundary`,category:`runtime`,code:`JsonParseFailure`,message:`Parse failed: ${t}`,retryable:!1}}else e={stage:`runtime`,category:`unknown`,code:a.toString(),message:`Internal Wasm error`,retryable:!1};u.onResponse({eventType:i,error:e}),u.onComplete(),n.delete(r);return}if(d)try{let e=new TextDecoder().decode(d),a=JSON.parse(e);u.onResponse({eventType:i,data:a,isFetching:i===t.CacheHitAndFetching,isStreamChunk:u.isStream}),!u.isStream&&i===t.NetworkSuccess&&(u.onComplete(),n.delete(r))}catch(e){console.error(`ATMX: Failed to parse JSON response from Axiom`,e)}}}var i=new Map;function a(e,t){let n=t?.ir?.endpoints;if(!n)return;let r=Array.isArray(n)?n:Object.values(n);r.forEach(t=>{let n=`${e}.${t.name}`,r=t.parameters?.
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.atmx={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=function(e){return e[e.Complete=0]=`Complete`,e[e.NetworkSuccess=1]=`NetworkSuccess`,e[e.CacheHit=2]=`CacheHit`,e[e.CacheHitAndFetching=3]=`CacheHitAndFetching`,e[e.Error=4]=`Error`,e}({}),n=new Map;function r(e){window.axiom_web_callback=(r,i,a,o,s,c,l)=>{let u=n.get(r);if(!u){o&&e.axiom_free_memory(o,s),c&&e.axiom_free_memory(c,l);return}let d=null,f=null;if(o!==0&&s>0){let t=new Uint8Array(e.memory.buffer);d=new Uint8Array(t.subarray(o,o+s)),e.axiom_free_memory(o,s)}if(c!==0&&l>0){let t=new Uint8Array(e.memory.buffer),n=new Uint8Array(t.subarray(c,c+l));f=new TextDecoder().decode(n),e.axiom_free_memory(c,l)}if(i===t.Complete){u.onComplete(),n.delete(r);return}if(i===t.Error){let e;if(f)try{e=JSON.parse(f)}catch(t){e={stage:`ffiBoundary`,category:`runtime`,code:`JsonParseFailure`,message:`Parse failed: ${t}`,retryable:!1}}else e={stage:`runtime`,category:`unknown`,code:a.toString(),message:`Internal Wasm error`,retryable:!1};u.onResponse({eventType:i,error:e}),u.onComplete(),n.delete(r);return}if(d)try{let e=new TextDecoder().decode(d),a=JSON.parse(e);u.onResponse({eventType:i,data:a,isFetching:i===t.CacheHitAndFetching,isStreamChunk:u.isStream}),!u.isStream&&i===t.NetworkSuccess&&(u.onComplete(),n.delete(r))}catch(e){console.error(`ATMX: Failed to parse JSON response from Axiom`,e)}}}var i=new Map;function a(e,t){let n=t?.ir?.endpoints;if(!n)return;let r=Array.isArray(n)?n:Object.values(n);r.forEach(t=>{let n=`${e}.${t.name}`,r=t.parameters?.filter(e=>e.source===`body`)||[],a=r.length===1?r[0].name:null;i.set(n,{id:t.id,namespace:e,name:t.name,method:t.method?t.method.toUpperCase():`GET`,pathTemplate:t.path,isStream:t.isStream||!1,auth:t.auth||null,bodyParam:a})}),console.log(`š£ļø ATMX Router: Mapped ${r.length} endpoints for '${e}'.`)}function o(e){return i.get(e.trim())||null}function s(e,t){let n=e.pathTemplate,r={...t},i=n.match(/\{([^}]+)\}/g);if(i&&i.forEach(e=>{let t=e.replace(/[{}]/g,``);r[t]!==void 0&&(n=n.replace(e,encodeURIComponent(String(r[t]))),delete r[t])}),e.method===`GET`&&Object.keys(r).length>0){let e=new URLSearchParams;for(let[t,n]of Object.entries(r))n!=null&&e.append(t,String(n));let t=n.includes(`?`)?`&`:`?`;n+=`${t}${e.toString()}`;for(let e of Object.keys(r))delete r[e]}return{path:n,remainingArgs:r}}var c=`let wasm_bindgen = (function(exports) {
|
|
2
2
|
let script_src;
|
|
3
3
|
if (typeof document !== 'undefined' && document.currentScript !== null) {
|
|
4
4
|
script_src = new URL(document.currentScript.src, location.href).toString();
|
|
@@ -884,4 +884,4 @@
|
|
|
884
884
|
return Object.assign(__wbg_init, { initSync }, exports);
|
|
885
885
|
})({ __proto__: null });
|
|
886
886
|
`,l=null;function u(e){if(e.length===0)return 0;let t=l.axiom_malloc(e.length);return new Uint8Array(l.memory.buffer).set(e,t),t}function d(e){if(!e)return{ptr:0,len:0};let t=new TextEncoder().encode(e);return{ptr:u(t),len:t.length}}function f(){return`https://atmx.axiomcore.dev/latest/axiom_runtime.wasm`}async function p(e){let t=performance.now(),n={ok:!1,contracts:{},initDurationMs:0};try{if(!window.wasm_bindgen){let e=document.createElement(`script`);e.type=`text/javascript`,e.text=`${c}\nwindow.wasm_bindgen = wasm_bindgen;`,document.head.appendChild(e)}let t=window.wasm_bindgen,i=`${f()}?t=${Date.now()}`;try{l=await t(fetch(i))}catch(e){throw{stage:`ffiBoundary`,category:`network`,code:`WasmFetchFailed`,message:`Failed to download WASM engine: ${e.message}`,retryable:!0}}r(l),setInterval(()=>{l&&l.axiom_process_responses()},16);let o=d(``),s=l.axiom_wasm_initialize(o.ptr,o.len);if(l.axiom_free_memory(o.ptr,o.len),s!==0)throw{stage:`runtime`,category:`server`,code:`InitFailed`,message:`Engine init failed (Code: ${s})`,retryable:!1};for(let[t,r]of Object.entries(e.contracts))try{let i=await fetch(r.contractUrl);if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.arrayBuffer(),s=0;try{let e=new TextDecoder().decode(o),n=JSON.parse(e),r=n?.ir?.endpoints;r&&(s=Array.isArray(r)?r.length:Object.keys(r).length),a(t,n)}catch(e){console.error(`ATMX: Failed to parse .axiom contract for '${t}'`,e)}let c=new Uint8Array(o),f=u(c),p=d(t),m=d(r.baseUrl),h=l.axiom_wasm_load_contract(p.ptr,p.len,m.ptr,m.len,f,c.length,0,0,0,0);if(l.axiom_free_memory(f,c.length),l.axiom_free_memory(p.ptr,p.len),l.axiom_free_memory(m.ptr,m.len),h!==0&&h!==-1)throw Error(`Load error (Code: ${h})`);e.debug&&console.log(`%cš Axiom Contract Loaded: ${t} (${s} endpoints)`,`color: #10b981; font-weight: bold;`),n.contracts[t]={loaded:!0,endpointCount:s},document.dispatchEvent(new CustomEvent(`atmx:contract-loaded`,{detail:{namespace:t,endpointCount:s}}))}catch(e){n.contracts[t]={loaded:!1,endpointCount:0,error:e.message},console.error(`ATMX: Contract failed for ${t}`,e)}n.ok=!0}catch(e){n.ok=!1,n.error=e.stage?e:{stage:`runtime`,category:`unknown`,code:`FatalError`,message:e.message||String(e),retryable:!1}}return n.initDurationMs=Math.round(performance.now()-t),n}function m(e,t,n){if(!l)return;let r=d(e),i=d(t),a=d(n);l.axiom_wasm_set_auth_token(r.ptr,r.len,i.ptr,i.len,a.ptr,a.len),l.axiom_free_memory(r.ptr,r.len),l.axiom_free_memory(i.ptr,i.len),l.axiom_free_memory(a.ptr,a.len)}function h(e,t){if(!l)return;let n=d(e),r=d(t);l.axiom_wasm_clear_auth_token(n.ptr,n.len,r.ptr,r.len),l.axiom_free_memory(n.ptr,n.len),l.axiom_free_memory(r.ptr,r.len)}function g(e,t){if(!l)return;let n=new TextEncoder().encode(JSON.stringify(t)),r=u(n);l.axiom_wasm_send_stream_message(e,r,n.length),l.axiom_free_memory(r,n.length)}function _(e,t,n={}){if(e)try{let r=Object.keys(n),i=Object.values(n);return Function(`$data`,`$error`,`$state`,...r,`return (${e});`)(t.data||{},t.error||{},t,...i)}catch(t){console.error(`ATMX Eval Error: ${e}`,t);return}}function v(e,t,n={}){if(e)try{let r=Object.keys(n),i=Object.values(n);Function(`$data`,`$error`,`$state`,...r,e)(t.data||{},t.error||{},t,...i)}catch(t){console.error(`ATMX Action Error: ${e}`,t)}}function y(e,t){b(e,t,!0,{})}function b(e,t,n,r){if(!(!n&&(e.hasAttribute(`ax-query`)||e.hasAttribute(`ax-mutate`)))){if(e.hasAttribute(`ax-for`)){x(e,t,r);return}if(e.hasAttribute(`ax-when`)&&(e.getAttribute(`ax-when`).split(`,`).map(e=>e.trim()).includes(t.state)?(e.removeAttribute(`hidden`),e.style.removeProperty(`display`)):(e.setAttribute(`hidden`,`true`),e.style.setProperty(`display`,`none`,`important`))),e.hasAttribute(`ax-if`)&&(_(e.getAttribute(`ax-if`),t,r)?(e.removeAttribute(`hidden`),e.style.removeProperty(`display`)):(e.setAttribute(`hidden`,``),e.style.setProperty(`display`,`none`,`important`))),e.hasAttribute(`ax-text`)){let n=_(e.getAttribute(`ax-text`),t,r);e.textContent=n==null?``:String(n)}if(e.hasAttribute(`ax-error-for`)){let n=e.getAttribute(`ax-error-for`),r=``;if(t.state===`error`&&t.error?.code===`ValidationError`){let e=(t.error.details||``).split(`
|
|
887
|
-
`);for(let t of e)if(t.startsWith(n+`:`)){r=t.substring(n.length+1).trim();break}}r?(e.textContent=r,e.removeAttribute(`hidden`),e.style.removeProperty(`display`)):(e.setAttribute(`hidden`,``),e.style.setProperty(`display`,`none`,`important`))}Array.from(e.attributes).forEach(n=>{if(n.name.startsWith(`ax-bind:`)){let i=n.name.substring(8),a=_(n.value,t,r);a===!1||a==null?e.removeAttribute(i):e.setAttribute(i,a===!0?i:String(a))}}),Array.from(e.children).forEach(e=>{b(e,t,!1,r)})}}function x(e,t,n){e.style.display=`none`,e.hasAttribute(`data-ax-for-id`)||e.setAttribute(`data-ax-for-id`,Math.random().toString(36).substr(2,9));let r=e.getAttribute(`data-ax-for-id`),i=e.getAttribute(`ax-for`).match(/^\s*(?:(?:\(\s*([\w\$]+)\s*,\s*([\w\$]+)\s*\))|([\w\$]+))\s+in\s+(.+)$/);if(!i)return;let a=i[1]||i[3],o=i[2],s=i[4],c=_(s,t,n),l=e.parentElement;if(!l)return;let u=Array.from(l.querySelectorAll(`[data-ax-clone-of="${r}"]`));if(!c||!Array.isArray(c)){u.forEach(e=>e.remove());return}let d=e.getAttribute(`ax-key`),f=[];c.forEach((i,s)=>{let c={...n,[a]:i};o&&(c[o]=s);let p=String(s);d&&(p=String(_(d,t,c)));let m=u.find(e=>e.getAttribute(`data-ax-key`)===p);m||(m=e.cloneNode(!0),m.removeAttribute(`ax-for`),m.style.removeProperty(`display`),m.style.length===0&&m.removeAttribute(`style`),m.setAttribute(`data-ax-clone-of`,r),m.setAttribute(`data-ax-key`,p)),l.insertBefore(m,e),b(m,t,!1,c),f.push(m)}),u.forEach(e=>{f.includes(e)||e.remove()})}var S=new WeakMap;function C(e){return S.has(e)||S.set(e,{state:`idle`,isFetching:!1,isMutating:!1,source:null,data:null,error:null}),S.get(e)}function w(e){let t=e.parentElement;for(;t;){if(t.hasAttribute(`ax-query`)||t.hasAttribute(`ax-mutate`)){let e=S.get(t);if(e&&e.data)return e.data}t=t.parentElement}return{}}function T(e,t){let n=C(e);Object.assign(n,t),t.state===`loading`&&(n.isFetching=!0),t.state===`mutating`&&(n.isMutating=!0),(t.state===`success`||t.state===`data`&&t.isFetching===!1)&&(n.isFetching=!1,n.isMutating=!1),S.set(e,n),y(e,n)}var E=0,D=class{key;route;args;state;listeners=new Set;currentReqId=null;constructor(e,t,n){this.key=e,this.route=t,this.args=n,this.state={state:`idle`,isFetching:!1,source:null,data:null,error:null}}subscribe(e){this.listeners.add(e),e(this.state)}update(e){this.state={...this.state,...e},this.listeners.forEach(e=>e(this.state))}fetch(e=!1){if(this.state.isFetching&&!e)return;this.update({state:this.state.data?`data`:`loading`,isFetching:!0,error:null});let r=++E;this.currentReqId=r;let{path:i,remainingArgs:a}=s(this.route,this.args),o=new Uint8Array;Object.keys(a).length>0&&(o=new TextEncoder().encode(JSON.stringify(a))),U.debug&&(console.groupCollapsed(`%cā WASM QUERY [#${r}]`,`color: #7c3aed; font-weight: bold;`),console.log(`Namespace:`,this.route.namespace),console.log(`Endpoint ID:`,this.route.id),console.log(`Path:`,i),console.groupEnd()),n.set(r,{isStream:this.route.isStream,onResponse:e=>{if(this.currentReqId===r){if(U.debug){let t=e.eventType===1?`NetworkSuccess`:e.eventType===2?`CacheHit`:e.eventType===3?`CacheHitAndFetching`:e.eventType===4?`Error`:`Complete`;console.groupCollapsed(`%cā WASM RESP [#${r}]`,`color: #059669; font-weight: bold;`),console.log(`Event Type:`,t),e.data&&console.log(`Data:`,e.data),e.error&&console.log(`Error:`,e.error),console.groupEnd()}if(e.eventType===t.Error){this.update({state:`error`,error:e.error,isFetching:!1});return}if(e.data){let n=`network`,r=!1;e.eventType===t.CacheHit?(n=`cache`,r=!1):e.eventType===t.CacheHitAndFetching?(n=`cache`,r=!0):e.eventType===t.NetworkSuccess&&(n=`network`,r=!1),this.update({state:`data`,data:e.data,source:n,isFetching:r})}}},onComplete:()=>{this.currentReqId===r&&(U.debug&&console.log(`%cā Stream Complete [#${r}]`,`color: #94a3b8;`),this.update({isFetching:!1}))}});let c=d(this.route.namespace),f=d(this.route.method),p=d(i),m=u(o),h=d(``),g=d(``);l.axiom_wasm_call(r,c.ptr,c.len,this.route.id,f.ptr,f.len,p.ptr,p.len,h.ptr,h.len,g.ptr,g.len,m,o.length),l.axiom_free_memory(c.ptr,c.len),l.axiom_free_memory(f.ptr,f.len),l.axiom_free_memory(p.ptr,p.len),l.axiom_free_memory(h.ptr,h.len),l.axiom_free_memory(g.ptr,g.len)}},O=new Map,k=0;function A(e,t){let n=`ax-on:${t}`;e.hasAttribute(n)&&v(e.getAttribute(n),C(e))}function j(e,t,n){if(!U.debug)return;let r=e===`OUT`?`#7c3aed`:`#059669`;console.groupCollapsed(`%c${e===`OUT`?`ā WASM CALL`:`ā WASM RESP`} [#${t}]`,`color: ${r}; font-weight: bold;`),console.log(`Details:`,n),console.groupEnd()}function M(e,t){let n=t.trim().match(/^([\w\.\-]+)(?:\((.*)\))?$/);if(!n)return null;let r=n[1],i={};if(n[2]&&n[2].trim()!==``)try{if(e){let t=C(e),r=t.data||w(e);i=Function(`$data`,`$state`,`return (${n[2]});`)(r,t)||{}}else i=Function(`return (${n[2]});`)()||{}}catch(e){console.error(`ATMX Scope Error in "${t}":`,e)}return{target:r,args:i}}function N(e){let t=e.getAttribute(`ax-query`);if(!t)return;let n=M(e,t);if(!n)return;let r=o(n.target);if(!r){T(e,{state:`error`,error:{message:`Route not found: ${n.target}`}});return}let i=`${r.namespace}:${r.id}:${JSON.stringify(n.args)}`,a=O.get(i);a||(a=new D(i,r,n.args),O.set(i,a)),e._axListener||(e._axListener=t=>{T(e,t),(t.state===`data`||t.state===`error`)&&(A(e,t.state),e.dispatchEvent(new CustomEvent(`atmx:${t.state}`,{bubbles:!0,detail:t.data||t.error})))},a.subscribe(e._axListener)),a.fetch()}function P(e){let t=e.getAttribute(`ax-mutate`);if(!t)return;let n=M(e,t);if(!n)return;let r=o(n.target);if(!r){T(e,{state:`error`,error:{message:`Route not found: ${n.target}`}}),A(e,`error`);return}T(e,{state:`mutating`,error:null,data:null}),A(e,`mutating`);let i={};e instanceof HTMLFormElement&&new FormData(e).forEach((t,n)=>{let r=e.elements.namedItem(n),a=!1;r instanceof HTMLInputElement?a=r.type===`number`:r instanceof RadioNodeList&&r.length>0&&(a=r[0].type===`number`);let o=a&&t!==``?Number(t):t;if(n.includes(`.`)){let e=n.split(`.`),t=i;for(let n=0;n<e.length-1;n++)t[e[n]]||(t[e[n]]={}),t=t[e[n]];t[e[e.length-1]]=o}else i[n]=o});let{path:a,remainingArgs:c}=s(r,{...i,...n.args}),l=c;r.bodyParam&&c[r.bodyParam]!==void 0&&(l=c[r.bodyParam]);let u={},d=e.getAttribute(`ax-headers`);if(d)try{u=Function(`return (`+d+`);`)()||{}}catch(e){console.error(`ATMX: Invalid ax-headers syntax`,e)}let f=Object.entries(u).some(([e,t])=>e.toLowerCase()===`content-type`&&t.includes(`application/x-www-form-urlencoded`)),p=new Uint8Array;if(Object.keys(l).length>0)if(f){let e=new URLSearchParams;for(let[t,n]of Object.entries(l))e.append(t,String(n));p=new TextEncoder().encode(e.toString())}else p=new TextEncoder().encode(JSON.stringify(l));F(e,r.namespace,r.id,r.method,a,p,r.isStream,!0,u,f)}function F(e,t,r,i,a,o,s,c,f={},p=!1){let m=++k;j(`OUT`,m,{namespace:t,endpointId:r,method:i,path:a,headers:f,payload:o.length>0?p?new TextDecoder().decode(o):JSON.parse(new TextDecoder().decode(o)):null}),n.set(m,{isStream:s,onResponse:t=>I(e,t,c,m),onComplete:()=>{U.debug&&console.log(`%cā Stream Complete [#${m}]`,`color: #94a3b8;`)}});let h=d(t),g=d(i),_=d(a),v=d(``),y=d(Object.keys(f).length>0?JSON.stringify(f):``),b=u(o);l.axiom_wasm_call(m,h.ptr,h.len,r,g.ptr,g.len,_.ptr,_.len,v.ptr,v.len,y.ptr,y.len,b,o.length),l.axiom_free_memory(h.ptr,h.len),l.axiom_free_memory(g.ptr,g.len),l.axiom_free_memory(_.ptr,_.len),l.axiom_free_memory(v.ptr,v.len),l.axiom_free_memory(y.ptr,y.len),b&&l.axiom_free_memory(b,o.length)}function I(e,n,r,i){if(j(`IN`,i,{eventType:t[n.eventType],data:n.data,error:n.error}),n.eventType===t.Error){T(e,{state:`error`,error:n.error,isFetching:!1,isMutating:!1}),A(e,`error`),e.dispatchEvent(new CustomEvent(`atmx:error`,{bubbles:!0,detail:n.error}));return}if(n.data){let i=`network`,a=!1;n.eventType===t.CacheHit?i=`cache`:n.eventType===t.CacheHitAndFetching?(i=`cache`,a=!0):n.eventType===t.NetworkSuccess&&(i=`network`);let s=r?`success`:`data`;if(T(e,{state:s,data:n.data,source:i,isFetching:a,isMutating:!1}),r){let t=e.getAttribute(`ax-store-token`);if(t){let n=_(t,C(e));if(n){let t=o(M(e,e.getAttribute(`ax-mutate`)).target),r=e.getAttribute(`ax-token-header`)||`Authorization`;U.setAuthToken(t?.namespace||`default`,r,n)}}if(e.hasAttribute(`ax-clear-token`)){let t=o(M(e,e.getAttribute(`ax-mutate`)).target),n=e.getAttribute(`ax-token-header`)||`Authorization`;U.clearAuthToken(t?.namespace||`default`,n)}let n=e.getAttribute(`ax-refresh`);if(n){let e=n.split(`,`).map(e=>e.trim());for(let[t,n]of O.entries()){let t=`${n.route.namespace}.${n.route.name}`;e.includes(t)&&n.fetch(!0)}}}A(e,s),e.dispatchEvent(new CustomEvent(r?`atmx:success`:`atmx:data`,{bubbles:!0,detail:n.data}))}}var L=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){let t=e.target;t.hasAttribute(`ax-query`)&&N(t),L.unobserve(t)}})});function R(e){e.querySelectorAll(`[\\:ax-query], [\\:ax-mutate]`).forEach(e=>{if(e.hasAttribute(`:ax-query`)){let t=_(e.getAttribute(`:ax-query`),C(e));t&&e.setAttribute(`ax-query`,String(t)),e.removeAttribute(`:ax-query`)}if(e.hasAttribute(`:ax-mutate`)){let t=_(e.getAttribute(`:ax-mutate`),C(e));t&&e.setAttribute(`ax-mutate`,String(t)),e.removeAttribute(`:ax-mutate`)}})}function z(e=document){R(e),e.querySelectorAll(`[ax-query]`).forEach(e=>{let t=e;T(t,{});let n=t.getAttribute(`ax-trigger`)||`load`;n===`load`?N(t):n===`intersect`?L.observe(t):t.addEventListener(n,e=>{e.preventDefault(),N(t)})}),e.querySelectorAll(`[ax-mutate]`).forEach(e=>{let t=e;T(t,{});let n=t.tagName===`FORM`?`submit`:`click`;t.addEventListener(n,e=>{(t.tagName===`A`||t.tagName===`BUTTON`||t.tagName===`FORM`)&&e.preventDefault(),P(t)})}),e.querySelectorAll(`[ax-trigger="refresh"]`).forEach(e=>{let t=e;t.addEventListener(`click`,e=>{e.preventDefault();let n=t.closest(`[ax-query]`);if(n){let e=M(n,n.getAttribute(`ax-query`));if(e){let t=o(e.target);if(t){let r=`${t.namespace}:${t.id}:${JSON.stringify(e.args)}`,i=O.get(r);i?i.fetch(!0):N(n)}}}})})}function B(){new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e instanceof HTMLElement&&z(e)})})}).observe(document.body,{childList:!0,subtree:!0})}var V=class extends HTMLElement{constructor(){super()}connectedCallback(){let e=this.getAttribute(`loading-text`)||`Initializing...`,t=this.getAttribute(`ready-text`)||`Online`,n=this.getAttribute(`error-text`)||`Failed to Connect`;this.renderState(`loading`,e,`text-amber-500 animate-pulse`),document.addEventListener(`atmx:ready`,()=>{this.renderState(`ready`,t,`text-green-600`)}),document.addEventListener(`atmx:error`,e=>{let t=e;t.detail&&t.detail.stage===`runtime`&&this.renderState(`error`,`${n}: ${t.detail.message}`,`text-red-600`)})}renderState(e,t,n){this.setAttribute(`data-state`,e);let r=this.querySelectorAll(`[data-ax-when]`);r.length>0?r.forEach(t=>{t.getAttribute(`data-ax-when`)===e?t.removeAttribute(`hidden`):t.setAttribute(`hidden`,``)}):(this.innerText=t,this.getAttribute(`class`)||(this.className=`text-xs font-bold ${n}`))}};typeof window<`u`&&!customElements.get(`ax-engine-status`)&&customElements.define(`ax-engine-status`,V);var H=`0.78.0`,U=new class{version=H;initialized=!1;debug=!1;async init(e){if(this.initialized)return{ok:!0,contracts:{},initDurationMs:0};let t=await p(e);return t.ok?(this.debug=e.debug||!1,B(),z(document.body),this.initialized=!0,this.debug&&console.log(`%cš ATMX Debug Mode: Enabled`,`color: #2563eb; font-weight: bold;`),console.log(`ā
ATMX v${this.version} Online (${t.initDurationMs}ms). Reactive Engine Started.`),document.dispatchEvent(new CustomEvent(`atmx:ready`,{detail:t}))):(console.error(`ā ATMX Initialization Failed:`,t.error),document.dispatchEvent(new CustomEvent(`atmx:error`,{detail:t.error}))),t}triggerQuery(e){let t=typeof e==`string`?document.querySelector(e):e;t&&t instanceof HTMLElement&&t.hasAttribute(`ax-query`)&&N(t)}on(e,t){document.addEventListener(`atmx:${e}`,t)}setAuthToken(e,t,n){m(e,t,n)}sendStreamMessage(e,t){g(e,t)}clearAuthToken(e,t){h(e,t)}connect(e){let t=M(null,e);if(!t)return;let n=o(t.target);if(!n)return;let r=`${n.namespace}:${n.id}:${JSON.stringify(t.args)}`,i=O.get(r);i||(i=new D(r,n,t.args),O.set(r,i)),i.fetch()}disconnect(e){let t=M(null,e);if(!t)return;let r=o(t.target);if(!r)return;let i=`${r.namespace}:${r.id}:${JSON.stringify(t.args)}`,a=O.get(i);a&&(a.currentReqId&&n.delete(a.currentReqId),O.delete(i),this.debug&&console.log(`š ATMX Disconnected Stream: ${e}`))}send(e,t){let n=M(null,e);if(!n)return;let r=o(n.target);if(!r)return;let i=`${r.namespace}:${r.id}:${JSON.stringify(n.args)}`,a=O.get(i);a&&a.currentReqId?g(a.currentReqId,t):console.warn(`ATMX: Cannot send message, stream not active for ${e}`)}};typeof window<`u`&&(window.atmx=U),e.ATMX_VERSION=H,e.allocBytes=u,e.allocString=d,e.atmx=U,e.buildRequestPath=s,e.clearAuthToken=h,e.initWasm=p,e.pendingRequests=n,e.resolveRoute=o,e.sendStreamMessage=g,e.setAuthToken=m,Object.defineProperty(e,`wasmEngine`,{enumerable:!0,get:function(){return l}})});
|
|
887
|
+
`);for(let t of e)if(t.startsWith(n+`:`)){r=t.substring(n.length+1).trim();break}}r?(e.textContent=r,e.removeAttribute(`hidden`),e.style.removeProperty(`display`)):(e.setAttribute(`hidden`,``),e.style.setProperty(`display`,`none`,`important`))}Array.from(e.attributes).forEach(n=>{if(n.name.startsWith(`ax-bind:`)){let i=n.name.substring(8),a=_(n.value,t,r);a===!1||a==null?e.removeAttribute(i):e.setAttribute(i,a===!0?i:String(a))}}),Array.from(e.children).forEach(e=>{b(e,t,!1,r)})}}function x(e,t,n){e.style.display=`none`,e.hasAttribute(`data-ax-for-id`)||e.setAttribute(`data-ax-for-id`,Math.random().toString(36).substr(2,9));let r=e.getAttribute(`data-ax-for-id`),i=e.getAttribute(`ax-for`).match(/^\s*(?:(?:\(\s*([\w\$]+)\s*,\s*([\w\$]+)\s*\))|([\w\$]+))\s+in\s+(.+)$/);if(!i)return;let a=i[1]||i[3],o=i[2],s=i[4],c=_(s,t,n),l=e.parentElement;if(!l)return;let u=Array.from(l.querySelectorAll(`[data-ax-clone-of="${r}"]`));if(!c||!Array.isArray(c)){u.forEach(e=>e.remove());return}let d=e.getAttribute(`ax-key`),f=[];c.forEach((i,s)=>{let c={...n,[a]:i};o&&(c[o]=s);let p=String(s);d&&(p=String(_(d,t,c)));let m=u.find(e=>e.getAttribute(`data-ax-key`)===p);m||(m=e.cloneNode(!0),m.removeAttribute(`ax-for`),m.style.removeProperty(`display`),m.style.length===0&&m.removeAttribute(`style`),m.setAttribute(`data-ax-clone-of`,r),m.setAttribute(`data-ax-key`,p)),l.insertBefore(m,e),b(m,t,!1,c),f.push(m)}),u.forEach(e=>{f.includes(e)||e.remove()})}var S=new WeakMap;function C(e){return S.has(e)||S.set(e,{state:`idle`,isFetching:!1,isMutating:!1,source:null,data:null,error:null}),S.get(e)}function w(e){let t=e.parentElement;for(;t;){if(t.hasAttribute(`ax-query`)||t.hasAttribute(`ax-mutate`)){let e=S.get(t);if(e&&e.data)return e.data}t=t.parentElement}return{}}function T(e,t){let n=C(e);Object.assign(n,t),t.state===`loading`&&(n.isFetching=!0),t.state===`mutating`&&(n.isMutating=!0),(t.state===`success`||t.state===`data`&&t.isFetching===!1)&&(n.isFetching=!1,n.isMutating=!1),S.set(e,n),y(e,n)}var E=0,D=class{key;route;args;state;listeners=new Set;currentReqId=null;constructor(e,t,n){this.key=e,this.route=t,this.args=n,this.state={state:`idle`,isFetching:!1,source:null,data:null,error:null}}subscribe(e){this.listeners.add(e),e(this.state)}update(e){this.state={...this.state,...e},this.listeners.forEach(e=>e(this.state))}fetch(e=!1){if(this.state.isFetching&&!e)return;this.update({state:this.state.data?`data`:`loading`,isFetching:!0,error:null});let r=++E;this.currentReqId=r;let{path:i,remainingArgs:a}=s(this.route,this.args),o=new Uint8Array;Object.keys(a).length>0&&(o=new TextEncoder().encode(JSON.stringify(a))),U.debug&&(console.groupCollapsed(`%cā WASM QUERY [#${r}]`,`color: #7c3aed; font-weight: bold;`),console.log(`Namespace:`,this.route.namespace),console.log(`Endpoint ID:`,this.route.id),console.log(`Path:`,i),console.groupEnd()),n.set(r,{isStream:this.route.isStream,onResponse:e=>{if(this.currentReqId===r){if(U.debug){let t=e.eventType===1?`NetworkSuccess`:e.eventType===2?`CacheHit`:e.eventType===3?`CacheHitAndFetching`:e.eventType===4?`Error`:`Complete`;console.groupCollapsed(`%cā WASM RESP [#${r}]`,`color: #059669; font-weight: bold;`),console.log(`Event Type:`,t),e.data&&console.log(`Data:`,e.data),e.error&&console.log(`Error:`,e.error),console.groupEnd()}if(e.eventType===t.Error){this.update({state:`error`,error:e.error,isFetching:!1});return}if(e.data){let n=`network`,r=!1;e.eventType===t.CacheHit?(n=`cache`,r=!1):e.eventType===t.CacheHitAndFetching?(n=`cache`,r=!0):e.eventType===t.NetworkSuccess&&(n=`network`,r=!1),this.update({state:`data`,data:e.data,source:n,isFetching:r})}}},onComplete:()=>{this.currentReqId===r&&(U.debug&&console.log(`%cā Stream Complete [#${r}]`,`color: #94a3b8;`),this.update({isFetching:!1}))}});let c=d(this.route.namespace),f=d(this.route.method),p=d(i),m=u(o),h=d(``),g=d(``);l.axiom_wasm_call(r,c.ptr,c.len,this.route.id,f.ptr,f.len,p.ptr,p.len,h.ptr,h.len,g.ptr,g.len,m,o.length),l.axiom_free_memory(c.ptr,c.len),l.axiom_free_memory(f.ptr,f.len),l.axiom_free_memory(p.ptr,p.len),l.axiom_free_memory(h.ptr,h.len),l.axiom_free_memory(g.ptr,g.len)}},O=new Map,k=0;function A(e,t){let n=`ax-on:${t}`;e.hasAttribute(n)&&v(e.getAttribute(n),C(e))}function j(e,t,n){if(!U.debug)return;let r=e===`OUT`?`#7c3aed`:`#059669`;console.groupCollapsed(`%c${e===`OUT`?`ā WASM CALL`:`ā WASM RESP`} [#${t}]`,`color: ${r}; font-weight: bold;`),console.log(`Details:`,n),console.groupEnd()}function M(e,t){let n=t.trim().match(/^([\w\.\-]+)(?:\((.*)\))?$/);if(!n)return null;let r=n[1],i={};if(n[2]&&n[2].trim()!==``)try{if(e){let t=C(e),r=t.data||w(e);i=Function(`$data`,`$state`,`return (${n[2]});`)(r,t)||{}}else i=Function(`return (${n[2]});`)()||{}}catch(e){console.error(`ATMX Scope Error in "${t}":`,e)}return{target:r,args:i}}function N(e){let t=e.getAttribute(`ax-query`);if(!t)return;let n=M(e,t);if(!n)return;let r=o(n.target);if(!r){T(e,{state:`error`,error:{message:`Route not found: ${n.target}`}});return}let i=`${r.namespace}:${r.id}:${JSON.stringify(n.args)}`,a=O.get(i);a||(a=new D(i,r,n.args),O.set(i,a)),e._axListener||(e._axListener=t=>{T(e,t),(t.state===`data`||t.state===`error`)&&(A(e,t.state),e.dispatchEvent(new CustomEvent(`atmx:${t.state}`,{bubbles:!0,detail:t.data||t.error})))},a.subscribe(e._axListener)),a.fetch()}function P(e){let t=e.getAttribute(`ax-mutate`);if(!t)return;let n=M(e,t);if(!n)return;let r=o(n.target);if(!r){T(e,{state:`error`,error:{message:`Route not found: ${n.target}`}}),A(e,`error`);return}T(e,{state:`mutating`,error:null,data:null}),A(e,`mutating`);let i={};e instanceof HTMLFormElement&&new FormData(e).forEach((t,n)=>{let r=e.elements.namedItem(n),a=!1;r instanceof HTMLInputElement?a=r.type===`number`:r instanceof RadioNodeList&&r.length>0&&(a=r[0].type===`number`);let o=a&&t!==``?Number(t):t;if(n.includes(`.`)){let e=n.split(`.`),t=i;for(let n=0;n<e.length-1;n++)t[e[n]]||(t[e[n]]={}),t=t[e[n]];t[e[e.length-1]]=o}else i[n]=o});let{path:a,remainingArgs:c}=s(r,{...i,...n.args}),l=c;r.bodyParam&&c[r.bodyParam]!==void 0&&typeof c[r.bodyParam]==`object`&&(l=c[r.bodyParam]);let u={},d=e.getAttribute(`ax-headers`);if(d)try{u=Function(`return (`+d+`);`)()||{}}catch(e){console.error(`ATMX: Invalid ax-headers syntax`,e)}let f=Object.entries(u).some(([e,t])=>e.toLowerCase()===`content-type`&&t.includes(`application/x-www-form-urlencoded`)),p=new Uint8Array;if(Object.keys(l).length>0)if(f){let e=new URLSearchParams;for(let[t,n]of Object.entries(l))e.append(t,String(n));p=new TextEncoder().encode(e.toString())}else p=new TextEncoder().encode(JSON.stringify(l));F(e,r.namespace,r.id,r.method,a,p,r.isStream,!0,u,f)}function F(e,t,r,i,a,o,s,c,f={},p=!1){let m=++k;j(`OUT`,m,{namespace:t,endpointId:r,method:i,path:a,headers:f,payload:o.length>0?p?new TextDecoder().decode(o):JSON.parse(new TextDecoder().decode(o)):null}),n.set(m,{isStream:s,onResponse:t=>I(e,t,c,m),onComplete:()=>{U.debug&&console.log(`%cā Stream Complete [#${m}]`,`color: #94a3b8;`)}});let h=d(t),g=d(i),_=d(a),v=d(``),y=d(Object.keys(f).length>0?JSON.stringify(f):``),b=u(o);l.axiom_wasm_call(m,h.ptr,h.len,r,g.ptr,g.len,_.ptr,_.len,v.ptr,v.len,y.ptr,y.len,b,o.length),l.axiom_free_memory(h.ptr,h.len),l.axiom_free_memory(g.ptr,g.len),l.axiom_free_memory(_.ptr,_.len),l.axiom_free_memory(v.ptr,v.len),l.axiom_free_memory(y.ptr,y.len),b&&l.axiom_free_memory(b,o.length)}function I(e,n,r,i){if(j(`IN`,i,{eventType:t[n.eventType],data:n.data,error:n.error}),n.eventType===t.Error){T(e,{state:`error`,error:n.error,isFetching:!1,isMutating:!1}),A(e,`error`),e.dispatchEvent(new CustomEvent(`atmx:error`,{bubbles:!0,detail:n.error}));return}if(n.data){let i=`network`,a=!1;n.eventType===t.CacheHit?i=`cache`:n.eventType===t.CacheHitAndFetching?(i=`cache`,a=!0):n.eventType===t.NetworkSuccess&&(i=`network`);let s=r?`success`:`data`;if(T(e,{state:s,data:n.data,source:i,isFetching:a,isMutating:!1}),r){let t=e.getAttribute(`ax-store-token`);if(t){let n=_(t,C(e));if(n){let t=o(M(e,e.getAttribute(`ax-mutate`)).target),r=e.getAttribute(`ax-token-header`)||`Authorization`;U.setAuthToken(t?.namespace||`default`,r,n)}}if(e.hasAttribute(`ax-clear-token`)){let t=o(M(e,e.getAttribute(`ax-mutate`)).target),n=e.getAttribute(`ax-token-header`)||`Authorization`;U.clearAuthToken(t?.namespace||`default`,n)}let n=e.getAttribute(`ax-refresh`);if(n){let e=n.split(`,`).map(e=>e.trim());for(let[t,n]of O.entries()){let t=`${n.route.namespace}.${n.route.name}`;e.includes(t)&&n.fetch(!0)}}}A(e,s),e.dispatchEvent(new CustomEvent(r?`atmx:success`:`atmx:data`,{bubbles:!0,detail:n.data}))}}var L=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){let t=e.target;t.hasAttribute(`ax-query`)&&N(t),L.unobserve(t)}})});function R(e){e.querySelectorAll(`[\\:ax-query], [\\:ax-mutate]`).forEach(e=>{if(e.hasAttribute(`:ax-query`)){let t=_(e.getAttribute(`:ax-query`),C(e));t&&e.setAttribute(`ax-query`,String(t)),e.removeAttribute(`:ax-query`)}if(e.hasAttribute(`:ax-mutate`)){let t=_(e.getAttribute(`:ax-mutate`),C(e));t&&e.setAttribute(`ax-mutate`,String(t)),e.removeAttribute(`:ax-mutate`)}})}function z(e=document){R(e),e.querySelectorAll(`[ax-query]`).forEach(e=>{let t=e;T(t,{});let n=t.getAttribute(`ax-trigger`)||`load`;n===`load`?N(t):n===`intersect`?L.observe(t):t.addEventListener(n,e=>{e.preventDefault(),N(t)})}),e.querySelectorAll(`[ax-mutate]`).forEach(e=>{let t=e;T(t,{});let n=t.tagName===`FORM`?`submit`:`click`;t.addEventListener(n,e=>{(t.tagName===`A`||t.tagName===`BUTTON`||t.tagName===`FORM`)&&e.preventDefault(),P(t)})}),e.querySelectorAll(`[ax-trigger="refresh"]`).forEach(e=>{let t=e;t.addEventListener(`click`,e=>{e.preventDefault();let n=t.closest(`[ax-query]`);if(n){let e=M(n,n.getAttribute(`ax-query`));if(e){let t=o(e.target);if(t){let r=`${t.namespace}:${t.id}:${JSON.stringify(e.args)}`,i=O.get(r);i?i.fetch(!0):N(n)}}}})})}function B(){new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e instanceof HTMLElement&&z(e)})})}).observe(document.body,{childList:!0,subtree:!0})}var V=class extends HTMLElement{constructor(){super()}connectedCallback(){let e=this.getAttribute(`loading-text`)||`Initializing...`,t=this.getAttribute(`ready-text`)||`Online`,n=this.getAttribute(`error-text`)||`Failed to Connect`;this.renderState(`loading`,e,`text-amber-500 animate-pulse`),document.addEventListener(`atmx:ready`,()=>{this.renderState(`ready`,t,`text-green-600`)}),document.addEventListener(`atmx:error`,e=>{let t=e;t.detail&&t.detail.stage===`runtime`&&this.renderState(`error`,`${n}: ${t.detail.message}`,`text-red-600`)})}renderState(e,t,n){this.setAttribute(`data-state`,e);let r=this.querySelectorAll(`[data-ax-when]`);r.length>0?r.forEach(t=>{t.getAttribute(`data-ax-when`)===e?t.removeAttribute(`hidden`):t.setAttribute(`hidden`,``)}):(this.innerText=t,this.getAttribute(`class`)||(this.className=`text-xs font-bold ${n}`))}};typeof window<`u`&&!customElements.get(`ax-engine-status`)&&customElements.define(`ax-engine-status`,V);var H=`0.79.0`,U=new class{version=H;initialized=!1;debug=!1;async init(e){if(this.initialized)return{ok:!0,contracts:{},initDurationMs:0};let t=await p(e);return t.ok?(this.debug=e.debug||!1,B(),z(document.body),this.initialized=!0,this.debug&&console.log(`%cš ATMX Debug Mode: Enabled`,`color: #2563eb; font-weight: bold;`),console.log(`ā
ATMX v${this.version} Online (${t.initDurationMs}ms). Reactive Engine Started.`),document.dispatchEvent(new CustomEvent(`atmx:ready`,{detail:t}))):(console.error(`ā ATMX Initialization Failed:`,t.error),document.dispatchEvent(new CustomEvent(`atmx:error`,{detail:t.error}))),t}triggerQuery(e){let t=typeof e==`string`?document.querySelector(e):e;t&&t instanceof HTMLElement&&t.hasAttribute(`ax-query`)&&N(t)}on(e,t){document.addEventListener(`atmx:${e}`,t)}setAuthToken(e,t,n){m(e,t,n)}sendStreamMessage(e,t){g(e,t)}clearAuthToken(e,t){h(e,t)}connect(e){let t=M(null,e);if(!t)return;let n=o(t.target);if(!n)return;let r=`${n.namespace}:${n.id}:${JSON.stringify(t.args)}`,i=O.get(r);i||(i=new D(r,n,t.args),O.set(r,i)),i.fetch()}disconnect(e){let t=M(null,e);if(!t)return;let r=o(t.target);if(!r)return;let i=`${r.namespace}:${r.id}:${JSON.stringify(t.args)}`,a=O.get(i);a&&(a.currentReqId&&n.delete(a.currentReqId),O.delete(i),this.debug&&console.log(`š ATMX Disconnected Stream: ${e}`))}send(e,t){let n=M(null,e);if(!n)return;let r=o(n.target);if(!r)return;let i=`${r.namespace}:${r.id}:${JSON.stringify(n.args)}`,a=O.get(i);a&&a.currentReqId?g(a.currentReqId,t):console.warn(`ATMX: Cannot send message, stream not active for ${e}`)}};typeof window<`u`&&(window.atmx=U),e.ATMX_VERSION=H,e.allocBytes=u,e.allocString=d,e.atmx=U,e.buildRequestPath=s,e.clearAuthToken=h,e.initWasm=p,e.pendingRequests=n,e.resolveRoute=o,e.sendStreamMessage=g,e.setAuthToken=m,Object.defineProperty(e,`wasmEngine`,{enumerable:!0,get:function(){return l}})});
|
package/dist/index.d.ts
CHANGED