@httpstate/typescript 0.0.5 → 0.0.7

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/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},v=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of c(t))!p.call(e,r)&&r!==n&&i(e,r,{get:()=>t[r],enumerable:!(s=u(t,r))||s.enumerable});return e};var b=e=>v(i({},"__esModule",{value:!0}),e);var h={};m(h,{default:()=>E,get:()=>o,load:()=>d,read:()=>g,set:()=>a,write:()=>l});module.exports=b(h);var o=async e=>{let t=await fetch("https://httpstate.com/"+e);if(t.status===200)return await t.text()},d=async()=>{for(let e of document.querySelectorAll("[httpState],[httpstate]")){let t=e.getAttribute("httpState")||e.getAttribute("httpstate");console.log("node.uuid",t)}},g=async e=>o(e),a=async(e,t)=>(await fetch("https://httpstate.com/"+e,{body:t,method:"POST"})).status,l=async(e,t)=>a(e,t),f=e=>{let t={addEventListener:(n,s)=>t.et.addEventListener(n,s),data:void 0,et:new EventTarget,get:async()=>o(e),off:(n,s)=>(t.removeEventListener(n,s),t),on:(n,s)=>(t.addEventListener(n,s),t),read:async()=>g(e),removeEventListener:(n,s)=>t.et.removeEventListener(n,s),set:async n=>a(e,n),write:async n=>l(e,n)};return t},E=f;typeof document<"u"&&typeof window<"u"&&(console.log("we do some magic ..."),console.log("-",globalThis===window),console.log("-",globalThis.httpstate),globalThis===window&&globalThis.httpstate&&(console.log("do the binding yo ..."),globalThis.httpstate=Object.assign(globalThis.httpstate.default,globalThis.httpstate)),window.addEventListener("load",d));0&&(module.exports={get,load,read,set,write});
1
+ "use strict";var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var n in t)r(e,n,{get:t[n],enumerable:!0})},m=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of u(t))!p.call(e,i)&&i!==n&&r(e,i,{get:()=>t[i],enumerable:!(s=c(t,i))||s.enumerable});return e};var v=e=>m(r({},"__esModule",{value:!0}),e);var f={};b(f,{default:()=>E,get:()=>a,load:()=>d,read:()=>g,set:()=>o,write:()=>l});module.exports=v(f);var a=async e=>{let t=await fetch("https://httpstate.com/"+e);if(t.status===200)return await t.text()},d=async()=>{for(let e of document.querySelectorAll("[httpState],[httpstate]")){let t=e.getAttribute("httpState")||e.getAttribute("httpstate");console.log("node.uuid",t);let n=globalThis.httpState(t).on("change",s=>e.innerHTML=s.data);n.et.dispatchEvent(Object.assign(new Event("change"),{data:await n.get()}))}},g=async e=>a(e),o=async(e,t)=>(await fetch("https://httpstate.com/"+e,{body:t,method:"POST"})).status,l=async(e,t)=>o(e,t),h=e=>{let t={addEventListener:(n,s)=>t.et.addEventListener(n,s),data:void 0,et:new EventTarget,get:async()=>a(e),off:(n,s)=>(t.removeEventListener(n,s),t),on:(n,s)=>(t.addEventListener(n,s),t),read:async()=>g(e),removeEventListener:(n,s)=>t.et.removeEventListener(n,s),set:async n=>o(e,n),write:async n=>l(e,n),ws:new WebSocket("wss://httpstate.com/"+e)};return t},E=h;typeof document<"u"&&typeof window<"u"&&(console.log("we do some magic ..."),console.log("-",globalThis===window),console.log("-",globalThis.httpstate),globalThis===window&&globalThis.addEventListener("load",async()=>{globalThis.httpstate&&(console.log("do the binding yo ..."),globalThis.httpState=globalThis.httpstate=Object.assign(globalThis.httpstate.default,globalThis.httpstate)),await d()},{once:!0}));0&&(module.exports={get,load,read,set,write});
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n// \n// Unless otherwise stated in particular files or directories, this software is free software.\n// You can redistribute it and/or modify it under the terms of the GNU Affero\n// General Public License as published by the Free Software Foundation, either\n// version 3 of the License, or (at your option) any later version.\n\nexport const get:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid);\n\n if(response.status === 200)\n return await response.text();\n};\n\nexport const load:() => Promise<void> = async ():Promise<void> => {\n for(const node of document.querySelectorAll('[httpState],[httpstate]')) {\n const uuid:null|string = node.getAttribute('httpState')||node.getAttribute('httpstate');\n\n console.log('node.uuid', uuid);\n\n // const ui = httpState(uuid)\n // .on('change', e => node.innerHTML = e.data);\n\n // ui.et.dispatchEvent(Object.assign(new Event('change'), { data:await ui.get() }));\n }\n};\n\nexport const read:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => get(uuid);\n\nexport const set:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid, { body:data, method:'POST' });\n\n return response.status;\n};\n\nexport const write:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => set(uuid, data);\n\n// httpState\ntype HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n et:EventTarget;\n get():Promise<undefined|string>;\n off(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n on(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n read():Promise<undefined|string>;\n removeEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n set(data:string):Promise<number>;\n write(data:string):Promise<number>;\n};\n\nconst httpState:(uuid:string) => HttpState = (uuid:string):HttpState => {\n const _:HttpState = {\n addEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.addEventListener(type, callback),\n data:undefined,\n et:new EventTarget(),\n get:async ():Promise<undefined|string> => get(uuid),\n off:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.removeEventListener(type, callback);\n\n return _;\n },\n on:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.addEventListener(type, callback);\n\n return _;\n },\n read:async ():Promise<undefined|string> => read(uuid),\n removeEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.removeEventListener(type, callback),\n set:async (data:string):Promise<number> => set(uuid, data),\n write:async (data:string):Promise<number> => write(uuid, data),\n // ws:new WebSocket('wss://httpstate.com/' + uuid)\n };\n\n // ...\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n) {\n console.log('we do some magic ...');\n console.log('-', globalThis === window);\n console.log('-', (globalThis as any).httpstate);\n\n if(\n globalThis === window\n && (globalThis as any).httpstate\n ) {\n console.log('do the binding yo ...');\n\n (globalThis as any).httpstate = Object.assign(\n (globalThis as any).httpstate.default,\n (globalThis as any).httpstate\n );\n }\n\n window.addEventListener('load', load);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,QAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,QAAAC,EAAA,UAAAC,IAAA,eAAAC,EAAAR,GAQO,IAAMG,EAAiD,MAAOM,GAA0C,CAC7G,IAAMC,EAAoB,MAAM,MAAM,yBAA2BD,CAAI,EAErE,GAAGC,EAAS,SAAW,IACrB,OAAO,MAAMA,EAAS,KAAK,CAC/B,EAEaN,EAA2B,SAA0B,CAChE,QAAUO,KAAQ,SAAS,iBAAiB,yBAAyB,EAAG,CACtE,IAAMF,EAAmBE,EAAK,aAAa,WAAW,GAAGA,EAAK,aAAa,WAAW,EAEtF,QAAQ,IAAI,YAAaF,CAAI,CAM/B,CACF,EAEaJ,EAAkD,MAAOI,GAA0CN,EAAIM,CAAI,EAE3GH,EAAoD,MAAOG,EAAaG,KACzD,MAAM,MAAM,yBAA2BH,EAAM,CAAE,KAAKG,EAAM,OAAO,MAAO,CAAC,GAEnF,OAGLL,EAAsD,MAAOE,EAAaG,IAAgCN,EAAIG,EAAMG,CAAI,EAgB/HC,EAAwCJ,GAA0B,CACtE,IAAMK,EAAc,CAClB,iBAAiB,CAACC,EAAaC,IAAqDF,EAAE,GAAG,iBAAiBC,EAAMC,CAAQ,EACxH,KAAK,OACL,GAAG,IAAI,YACP,IAAI,SAAsCb,EAAIM,CAAI,EAClD,IAAI,CAACM,EAAaC,KAChBF,EAAE,oBAAoBC,EAAMC,CAAQ,EAE7BF,GAET,GAAG,CAACC,EAAaC,KACfF,EAAE,iBAAiBC,EAAMC,CAAQ,EAE1BF,GAET,KAAK,SAAsCT,EAAKI,CAAI,EACpD,oBAAoB,CAACM,EAAaC,IAAqDF,EAAE,GAAG,oBAAoBC,EAAMC,CAAQ,EAC9H,IAAI,MAAOJ,GAAgCN,EAAIG,EAAMG,CAAI,EACzD,MAAM,MAAOA,GAAgCL,EAAME,EAAMG,CAAI,CAE/D,EAIA,OAAOE,CACT,EAEOZ,EAAQW,EAGV,OAAO,SAAa,KACpB,OAAO,OAAW,MAErB,QAAQ,IAAI,sBAAsB,EAClC,QAAQ,IAAI,IAAK,aAAe,MAAM,EACtC,QAAQ,IAAI,IAAM,WAAmB,SAAS,EAGzC,aAAe,QACd,WAAmB,YAEvB,QAAQ,IAAI,uBAAuB,EAElC,WAAmB,UAAY,OAAO,OACpC,WAAmB,UAAU,QAC7B,WAAmB,SACtB,GAGF,OAAO,iBAAiB,OAAQT,CAAI","names":["index_exports","__export","index_default","get","load","read","set","write","__toCommonJS","uuid","response","node","data","httpState","_","type","callback"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n// \n// Unless otherwise stated in particular files or directories, this software is free software.\n// You can redistribute it and/or modify it under the terms of the GNU Affero\n// General Public License as published by the Free Software Foundation, either\n// version 3 of the License, or (at your option) any later version.\n\nexport const get:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid);\n\n if(response.status === 200)\n return await response.text();\n};\n\nexport const load:() => Promise<void> = async ():Promise<void> => {\n for(const node of document.querySelectorAll('[httpState],[httpstate]')) {\n const uuid:null|string = node.getAttribute('httpState')||node.getAttribute('httpstate');\n\n console.log('node.uuid', uuid);\n\n const ui:HttpState = (globalThis as any).httpState(uuid)\n .on('change', (e:Event&{ data:string }) => node.innerHTML = e.data);\n\n ui.et.dispatchEvent(Object.assign(new Event('change'), { data:await ui.get() }));\n }\n};\n\nexport const read:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => get(uuid);\n\nexport const set:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid, { body:data, method:'POST' });\n\n return response.status;\n};\n\nexport const write:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => set(uuid, data);\n\n// httpState\ntype HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n et:EventTarget;\n get():Promise<undefined|string>;\n off(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n on(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n read():Promise<undefined|string>;\n removeEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n set(data:string):Promise<number>;\n write(data:string):Promise<number>;\n ws:WebSocket;\n};\n\nconst httpState:(uuid:string) => HttpState = (uuid:string):HttpState => {\n const _:HttpState = {\n addEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.addEventListener(type, callback),\n data:undefined,\n et:new EventTarget(),\n get:async ():Promise<undefined|string> => get(uuid),\n off:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.removeEventListener(type, callback);\n\n return _;\n },\n on:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.addEventListener(type, callback);\n\n return _;\n },\n read:async ():Promise<undefined|string> => read(uuid),\n removeEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.removeEventListener(type, callback),\n set:async (data:string):Promise<number> => set(uuid, data),\n write:async (data:string):Promise<number> => write(uuid, data),\n ws:new WebSocket('wss://httpstate.com/' + uuid)\n };\n\n // ...\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n) {\n console.log('we do some magic ...');\n console.log('-', globalThis === window);\n console.log('-', (globalThis as any).httpstate);\n\n if(globalThis === window) {\n globalThis.addEventListener('load', async () => {\n if((globalThis as any).httpstate) {\n console.log('do the binding yo ...');\n\n (globalThis as any).httpState = (globalThis as any).httpstate = Object.assign(\n (globalThis as any).httpstate.default,\n (globalThis as any).httpstate\n );\n }\n\n await load();\n }, { once:true });\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,QAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,QAAAC,EAAA,UAAAC,IAAA,eAAAC,EAAAR,GAQO,IAAMG,EAAiD,MAAOM,GAA0C,CAC7G,IAAMC,EAAoB,MAAM,MAAM,yBAA2BD,CAAI,EAErE,GAAGC,EAAS,SAAW,IACrB,OAAO,MAAMA,EAAS,KAAK,CAC/B,EAEaN,EAA2B,SAA0B,CAChE,QAAUO,KAAQ,SAAS,iBAAiB,yBAAyB,EAAG,CACtE,IAAMF,EAAmBE,EAAK,aAAa,WAAW,GAAGA,EAAK,aAAa,WAAW,EAEtF,QAAQ,IAAI,YAAaF,CAAI,EAE7B,IAAMG,EAAgB,WAAmB,UAAUH,CAAI,EACpD,GAAG,SAAWI,GAA4BF,EAAK,UAAYE,EAAE,IAAI,EAEpED,EAAG,GAAG,cAAc,OAAO,OAAO,IAAI,MAAM,QAAQ,EAAG,CAAE,KAAK,MAAMA,EAAG,IAAI,CAAE,CAAC,CAAC,CACjF,CACF,EAEaP,EAAkD,MAAOI,GAA0CN,EAAIM,CAAI,EAE3GH,EAAoD,MAAOG,EAAaK,KACzD,MAAM,MAAM,yBAA2BL,EAAM,CAAE,KAAKK,EAAM,OAAO,MAAO,CAAC,GAEnF,OAGLP,EAAsD,MAAOE,EAAaK,IAAgCR,EAAIG,EAAMK,CAAI,EAiB/HC,EAAwCN,GAA0B,CACtE,IAAMO,EAAc,CAClB,iBAAiB,CAACC,EAAaC,IAAqDF,EAAE,GAAG,iBAAiBC,EAAMC,CAAQ,EACxH,KAAK,OACL,GAAG,IAAI,YACP,IAAI,SAAsCf,EAAIM,CAAI,EAClD,IAAI,CAACQ,EAAaC,KAChBF,EAAE,oBAAoBC,EAAMC,CAAQ,EAE7BF,GAET,GAAG,CAACC,EAAaC,KACfF,EAAE,iBAAiBC,EAAMC,CAAQ,EAE1BF,GAET,KAAK,SAAsCX,EAAKI,CAAI,EACpD,oBAAoB,CAACQ,EAAaC,IAAqDF,EAAE,GAAG,oBAAoBC,EAAMC,CAAQ,EAC9H,IAAI,MAAOJ,GAAgCR,EAAIG,EAAMK,CAAI,EACzD,MAAM,MAAOA,GAAgCP,EAAME,EAAMK,CAAI,EAC7D,GAAG,IAAI,UAAU,uBAAyBL,CAAI,CAChD,EAIA,OAAOO,CACT,EAEOd,EAAQa,EAGV,OAAO,SAAa,KACpB,OAAO,OAAW,MAErB,QAAQ,IAAI,sBAAsB,EAClC,QAAQ,IAAI,IAAK,aAAe,MAAM,EACtC,QAAQ,IAAI,IAAM,WAAmB,SAAS,EAE3C,aAAe,QAChB,WAAW,iBAAiB,OAAQ,SAAY,CAC1C,WAAmB,YACrB,QAAQ,IAAI,uBAAuB,EAElC,WAAmB,UAAa,WAAmB,UAAY,OAAO,OACpE,WAAmB,UAAU,QAC7B,WAAmB,SACtB,GAGF,MAAMX,EAAK,CACb,EAAG,CAAE,KAAK,EAAK,CAAC","names":["index_exports","__export","index_default","get","load","read","set","write","__toCommonJS","uuid","response","node","ui","e","data","httpState","_","type","callback"]}
package/dist/index.d.cts CHANGED
@@ -14,6 +14,7 @@ type HttpState = {
14
14
  removeEventListener(type: string, callback: null | EventListenerOrEventListenerObject): void;
15
15
  set(data: string): Promise<number>;
16
16
  write(data: string): Promise<number>;
17
+ ws: WebSocket;
17
18
  };
18
19
  declare const httpState: (uuid: string) => HttpState;
19
20
 
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ type HttpState = {
14
14
  removeEventListener(type: string, callback: null | EventListenerOrEventListenerObject): void;
15
15
  set(data: string): Promise<number>;
16
16
  write(data: string): Promise<number>;
17
+ ws: WebSocket;
17
18
  };
18
19
  declare const httpState: (uuid: string) => HttpState;
19
20
 
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- var r=async e=>{let t=await fetch("https://httpstate.com/"+e);if(t.status===200)return await t.text()},o=async()=>{for(let e of document.querySelectorAll("[httpState],[httpstate]")){let t=e.getAttribute("httpState")||e.getAttribute("httpstate");console.log("node.uuid",t)}},a=async e=>r(e),i=async(e,t)=>(await fetch("https://httpstate.com/"+e,{body:t,method:"POST"})).status,d=async(e,t)=>i(e,t),g=e=>{let t={addEventListener:(n,s)=>t.et.addEventListener(n,s),data:void 0,et:new EventTarget,get:async()=>r(e),off:(n,s)=>(t.removeEventListener(n,s),t),on:(n,s)=>(t.addEventListener(n,s),t),read:async()=>a(e),removeEventListener:(n,s)=>t.et.removeEventListener(n,s),set:async n=>i(e,n),write:async n=>d(e,n)};return t},l=g;typeof document<"u"&&typeof window<"u"&&(console.log("we do some magic ..."),console.log("-",globalThis===window),console.log("-",globalThis.httpstate),globalThis===window&&globalThis.httpstate&&(console.log("do the binding yo ..."),globalThis.httpstate=Object.assign(globalThis.httpstate.default,globalThis.httpstate)),window.addEventListener("load",o));export{l as default,r as get,o as load,a as read,i as set,d as write};
1
+ var i=async t=>{let e=await fetch("https://httpstate.com/"+t);if(e.status===200)return await e.text()},a=async()=>{for(let t of document.querySelectorAll("[httpState],[httpstate]")){let e=t.getAttribute("httpState")||t.getAttribute("httpstate");console.log("node.uuid",e);let n=globalThis.httpState(e).on("change",s=>t.innerHTML=s.data);n.et.dispatchEvent(Object.assign(new Event("change"),{data:await n.get()}))}},o=async t=>i(t),r=async(t,e)=>(await fetch("https://httpstate.com/"+t,{body:e,method:"POST"})).status,d=async(t,e)=>r(t,e),g=t=>{let e={addEventListener:(n,s)=>e.et.addEventListener(n,s),data:void 0,et:new EventTarget,get:async()=>i(t),off:(n,s)=>(e.removeEventListener(n,s),e),on:(n,s)=>(e.addEventListener(n,s),e),read:async()=>o(t),removeEventListener:(n,s)=>e.et.removeEventListener(n,s),set:async n=>r(t,n),write:async n=>d(t,n),ws:new WebSocket("wss://httpstate.com/"+t)};return e},l=g;typeof document<"u"&&typeof window<"u"&&(console.log("we do some magic ..."),console.log("-",globalThis===window),console.log("-",globalThis.httpstate),globalThis===window&&globalThis.addEventListener("load",async()=>{globalThis.httpstate&&(console.log("do the binding yo ..."),globalThis.httpState=globalThis.httpstate=Object.assign(globalThis.httpstate.default,globalThis.httpstate)),await a()},{once:!0}));export{l as default,i as get,a as load,o as read,r as set,d as write};
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n// \n// Unless otherwise stated in particular files or directories, this software is free software.\n// You can redistribute it and/or modify it under the terms of the GNU Affero\n// General Public License as published by the Free Software Foundation, either\n// version 3 of the License, or (at your option) any later version.\n\nexport const get:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid);\n\n if(response.status === 200)\n return await response.text();\n};\n\nexport const load:() => Promise<void> = async ():Promise<void> => {\n for(const node of document.querySelectorAll('[httpState],[httpstate]')) {\n const uuid:null|string = node.getAttribute('httpState')||node.getAttribute('httpstate');\n\n console.log('node.uuid', uuid);\n\n // const ui = httpState(uuid)\n // .on('change', e => node.innerHTML = e.data);\n\n // ui.et.dispatchEvent(Object.assign(new Event('change'), { data:await ui.get() }));\n }\n};\n\nexport const read:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => get(uuid);\n\nexport const set:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid, { body:data, method:'POST' });\n\n return response.status;\n};\n\nexport const write:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => set(uuid, data);\n\n// httpState\ntype HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n et:EventTarget;\n get():Promise<undefined|string>;\n off(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n on(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n read():Promise<undefined|string>;\n removeEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n set(data:string):Promise<number>;\n write(data:string):Promise<number>;\n};\n\nconst httpState:(uuid:string) => HttpState = (uuid:string):HttpState => {\n const _:HttpState = {\n addEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.addEventListener(type, callback),\n data:undefined,\n et:new EventTarget(),\n get:async ():Promise<undefined|string> => get(uuid),\n off:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.removeEventListener(type, callback);\n\n return _;\n },\n on:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.addEventListener(type, callback);\n\n return _;\n },\n read:async ():Promise<undefined|string> => read(uuid),\n removeEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.removeEventListener(type, callback),\n set:async (data:string):Promise<number> => set(uuid, data),\n write:async (data:string):Promise<number> => write(uuid, data),\n // ws:new WebSocket('wss://httpstate.com/' + uuid)\n };\n\n // ...\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n) {\n console.log('we do some magic ...');\n console.log('-', globalThis === window);\n console.log('-', (globalThis as any).httpstate);\n\n if(\n globalThis === window\n && (globalThis as any).httpstate\n ) {\n console.log('do the binding yo ...');\n\n (globalThis as any).httpstate = Object.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Q,IAAI,sBAAsB,EAClC,QAAQ,IAAI,IAAK,aAAe,MAAM,EACtC,QAAQ,IAAI,IAAM,WAAmB,SAAS,EAGzC,aAAe,QACd,WAAmB,YAEvB,QAAQ,IAAI,uBAAuB,EAElC,WAAmB,UAAY,OAAO,OACpC,WAAmB,UAAU,QAC7B,WAAmB,SACtB,GAGF,OAAO,iBAAiB,OAAQN,CAAI","names":["get","uuid","response","load","node","read","set","data","write","httpState","_","type","callback","index_default"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n// \n// Unless otherwise stated in particular files or directories, this software is free software.\n// You can redistribute it and/or modify it under the terms of the GNU Affero\n// General Public License as published by the Free Software Foundation, either\n// version 3 of the License, or (at your option) any later version.\n\nexport const get:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid);\n\n if(response.status === 200)\n return await response.text();\n};\n\nexport const load:() => Promise<void> = async ():Promise<void> => {\n for(const node of document.querySelectorAll('[httpState],[httpstate]')) {\n const uuid:null|string = node.getAttribute('httpState')||node.getAttribute('httpstate');\n\n console.log('node.uuid', uuid);\n\n const ui:HttpState = (globalThis as any).httpState(uuid)\n .on('change', (e:Event&{ data:string }) => node.innerHTML = e.data);\n\n ui.et.dispatchEvent(Object.assign(new Event('change'), { data:await ui.get() }));\n }\n};\n\nexport const read:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => get(uuid);\n\nexport const set:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid, { body:data, method:'POST' });\n\n return response.status;\n};\n\nexport const write:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => set(uuid, data);\n\n// httpState\ntype HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n et:EventTarget;\n get():Promise<undefined|string>;\n off(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n on(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n read():Promise<undefined|string>;\n removeEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n set(data:string):Promise<number>;\n write(data:string):Promise<number>;\n ws:WebSocket;\n};\n\nconst httpState:(uuid:string) => HttpState = (uuid:string):HttpState => {\n const _:HttpState = {\n addEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.addEventListener(type, callback),\n data:undefined,\n et:new EventTarget(),\n get:async ():Promise<undefined|string> => get(uuid),\n off:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.removeEventListener(type, callback);\n\n return _;\n },\n on:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.addEventListener(type, callback);\n\n return _;\n },\n read:async ():Promise<undefined|string> => read(uuid),\n removeEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.removeEventListener(type, callback),\n set:async (data:string):Promise<number> => set(uuid, data),\n write:async (data:string):Promise<number> => write(uuid, data),\n ws:new WebSocket('wss://httpstate.com/' + uuid)\n };\n\n // ...\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n) {\n console.log('we do some magic ...');\n console.log('-', globalThis === window);\n console.log('-', (globalThis as any).httpstate);\n\n if(globalThis === window) {\n globalThis.addEventListener('load', async () => {\n if((globalThis as any).httpstate) {\n console.log('do the binding yo ...');\n\n (globalThis as any).httpState = (globalThis as any).httpstate = Object.assign(\n (globalThis as any).httpstate.default,\n (globalThis as any).httpstate\n );\n }\n\n await load();\n }, { once:true });\n }\n}\n"],"mappings":"AAQO,IAAMA,EAAiD,MAAOC,GAA0C,CAC7G,IAAMC,EAAoB,MAAM,MAAM,yBAA2BD,CAAI,EAErE,GAAGC,EAAS,SAAW,IACrB,OAAO,MAAMA,EAAS,KAAK,CAC/B,EAEaC,EAA2B,SAA0B,CAChE,QAAUC,KAAQ,S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AAQ,IAAI,IAAK,aAAe,MAAM,EACtC,QAAQ,IAAI,IAAM,WAAmB,SAAS,EAE3C,aAAe,QAChB,WAAW,iBAAiB,OAAQ,SAAY,CAC1C,WAAmB,YACrB,QAAQ,IAAI,uBAAuB,EAElC,WAAmB,UAAa,WAAmB,UAAY,OAAO,OACpE,WAAmB,UAAU,QAC7B,WAAmB,SACtB,GAGF,MAAMR,EAAK,CACb,EAAG,CAAE,KAAK,EAAK,CAAC","names":["get","uuid","response","load","node","ui","e","read","set","data","write","httpState","_","type","callback","index_default"]}
@@ -1,2 +1,2 @@
1
- "use strict";var httpstate=(()=>{var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},v=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of c(t))!p.call(e,r)&&r!==n&&i(e,r,{get:()=>t[r],enumerable:!(s=u(t,r))||s.enumerable});return e};var b=e=>v(i({},"__esModule",{value:!0}),e);var h={};m(h,{default:()=>E,get:()=>o,load:()=>d,read:()=>g,set:()=>a,write:()=>l});var o=async e=>{let t=await fetch("https://httpstate.com/"+e);if(t.status===200)return await t.text()},d=async()=>{for(let e of document.querySelectorAll("[httpState],[httpstate]")){let t=e.getAttribute("httpState")||e.getAttribute("httpstate");console.log("node.uuid",t)}},g=async e=>o(e),a=async(e,t)=>(await fetch("https://httpstate.com/"+e,{body:t,method:"POST"})).status,l=async(e,t)=>a(e,t),f=e=>{let t={addEventListener:(n,s)=>t.et.addEventListener(n,s),data:void 0,et:new EventTarget,get:async()=>o(e),off:(n,s)=>(t.removeEventListener(n,s),t),on:(n,s)=>(t.addEventListener(n,s),t),read:async()=>g(e),removeEventListener:(n,s)=>t.et.removeEventListener(n,s),set:async n=>a(e,n),write:async n=>l(e,n)};return t},E=f;typeof document<"u"&&typeof window<"u"&&(console.log("we do some magic ..."),console.log("-",globalThis===window),console.log("-",globalThis.httpstate),globalThis===window&&globalThis.httpstate&&(console.log("do the binding yo ..."),globalThis.httpstate=Object.assign(globalThis.httpstate.default,globalThis.httpstate)),window.addEventListener("load",d));return b(h);})();
1
+ "use strict";var httpstate=(()=>{var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var n in t)r(e,n,{get:t[n],enumerable:!0})},m=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of u(t))!p.call(e,i)&&i!==n&&r(e,i,{get:()=>t[i],enumerable:!(s=c(t,i))||s.enumerable});return e};var v=e=>m(r({},"__esModule",{value:!0}),e);var f={};b(f,{default:()=>E,get:()=>a,load:()=>d,read:()=>g,set:()=>o,write:()=>l});var a=async e=>{let t=await fetch("https://httpstate.com/"+e);if(t.status===200)return await t.text()},d=async()=>{for(let e of document.querySelectorAll("[httpState],[httpstate]")){let t=e.getAttribute("httpState")||e.getAttribute("httpstate");console.log("node.uuid",t);let n=globalThis.httpState(t).on("change",s=>e.innerHTML=s.data);n.et.dispatchEvent(Object.assign(new Event("change"),{data:await n.get()}))}},g=async e=>a(e),o=async(e,t)=>(await fetch("https://httpstate.com/"+e,{body:t,method:"POST"})).status,l=async(e,t)=>o(e,t),h=e=>{let t={addEventListener:(n,s)=>t.et.addEventListener(n,s),data:void 0,et:new EventTarget,get:async()=>a(e),off:(n,s)=>(t.removeEventListener(n,s),t),on:(n,s)=>(t.addEventListener(n,s),t),read:async()=>g(e),removeEventListener:(n,s)=>t.et.removeEventListener(n,s),set:async n=>o(e,n),write:async n=>l(e,n),ws:new WebSocket("wss://httpstate.com/"+e)};return t},E=h;typeof document<"u"&&typeof window<"u"&&(console.log("we do some magic ..."),console.log("-",globalThis===window),console.log("-",globalThis.httpstate),globalThis===window&&globalThis.addEventListener("load",async()=>{globalThis.httpstate&&(console.log("do the binding yo ..."),globalThis.httpState=globalThis.httpstate=Object.assign(globalThis.httpstate.default,globalThis.httpstate)),await d()},{once:!0}));return v(f);})();
2
2
  //# sourceMappingURL=index.global.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n// \n// Unless otherwise stated in particular files or directories, this software is free software.\n// You can redistribute it and/or modify it under the terms of the GNU Affero\n// General Public License as published by the Free Software Foundation, either\n// version 3 of the License, or (at your option) any later version.\n\nexport const get:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid);\n\n if(response.status === 200)\n return await response.text();\n};\n\nexport const load:() => Promise<void> = async ():Promise<void> => {\n for(const node of document.querySelectorAll('[httpState],[httpstate]')) {\n const uuid:null|string = node.getAttribute('httpState')||node.getAttribute('httpstate');\n\n console.log('node.uuid', uuid);\n\n // const ui = httpState(uuid)\n // .on('change', e => node.innerHTML = e.data);\n\n // ui.et.dispatchEvent(Object.assign(new Event('change'), { data:await ui.get() }));\n }\n};\n\nexport const read:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => get(uuid);\n\nexport const set:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid, { body:data, method:'POST' });\n\n return response.status;\n};\n\nexport const write:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => set(uuid, data);\n\n// httpState\ntype HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n et:EventTarget;\n get():Promise<undefined|string>;\n off(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n on(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n read():Promise<undefined|string>;\n removeEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n set(data:string):Promise<number>;\n write(data:string):Promise<number>;\n};\n\nconst httpState:(uuid:string) => HttpState = (uuid:string):HttpState => {\n const _:HttpState = {\n addEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.addEventListener(type, callback),\n data:undefined,\n et:new EventTarget(),\n get:async ():Promise<undefined|string> => get(uuid),\n off:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.removeEventListener(type, callback);\n\n return _;\n },\n on:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.addEventListener(type, callback);\n\n return _;\n },\n read:async ():Promise<undefined|string> => read(uuid),\n removeEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.removeEventListener(type, callback),\n set:async (data:string):Promise<number> => set(uuid, data),\n write:async (data:string):Promise<number> => write(uuid, data),\n // ws:new WebSocket('wss://httpstate.com/' + uuid)\n };\n\n // ...\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n) {\n console.log('we do some magic ...');\n console.log('-', globalThis === window);\n console.log('-', (globalThis as any).httpstate);\n\n if(\n globalThis === window\n && (globalThis as any).httpstate\n ) {\n console.log('do the binding yo ...');\n\n (globalThis as any).httpstate = Object.assign(\n (globalThis as any).httpstate.default,\n (globalThis as any).httpstate\n );\n }\n\n window.addEventListener('load', load);\n}\n"],"mappings":"6bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,QAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,QAAAC,EAAA,UAAAC,IAQO,IAAMJ,EAAiD,MAAOK,GAA0C,CAC7G,IAAMC,EAAoB,MAAM,MAAM,yBAA2BD,CAAI,EAErE,GAAGC,EAAS,SAAW,IACrB,OAAO,MAAMA,EAAS,KAAK,CAC/B,EAEaL,EAA2B,SAA0B,CAChE,QAAUM,KAAQ,SAAS,iBAAiB,yBAAyB,EAAG,CACtE,IAAMF,EAAmBE,EAAK,aAAa,WAAW,GAAGA,EAAK,aAAa,WAAW,EAEtF,QAAQ,IAAI,YAAaF,CAAI,CAM/B,CACF,EAEaH,EAAkD,MAAOG,GAA0CL,EAAIK,CAAI,EAE3GF,EAAoD,MAAOE,EAAaG,KACzD,MAAM,MAAM,yBAA2BH,EAAM,CAAE,KAAKG,EAAM,OAAO,MAAO,CAAC,GAEnF,OAGLJ,EAAsD,MAAOC,EAAaG,IAAgCL,EAAIE,EAAMG,CAAI,EAgB/HC,EAAwCJ,GAA0B,CACtE,IAAMK,EAAc,CAClB,iBAAiB,CAACC,EAAaC,IAAqDF,EAAE,GAAG,iBAAiBC,EAAMC,CAAQ,EACxH,KAAK,OACL,GAAG,IAAI,YACP,IAAI,SAAsCZ,EAAIK,CAAI,EAClD,IAAI,CAACM,EAAaC,KAChBF,EAAE,oBAAoBC,EAAMC,CAAQ,EAE7BF,GAET,GAAG,CAACC,EAAaC,KACfF,EAAE,iBAAiBC,EAAMC,CAAQ,EAE1BF,GAET,KAAK,SAAsCR,EAAKG,CAAI,EACpD,oBAAoB,CAACM,EAAaC,IAAqDF,EAAE,GAAG,oBAAoBC,EAAMC,CAAQ,EAC9H,IAAI,MAAOJ,GAAgCL,EAAIE,EAAMG,CAAI,EACzD,MAAM,MAAOA,GAAgCJ,EAAMC,EAAMG,CAAI,CAE/D,EAIA,OAAOE,CACT,EAEOX,EAAQU,EAGV,OAAO,SAAa,KACpB,OAAO,OAAW,MAErB,QAAQ,IAAI,sBAAsB,EAClC,QAAQ,IAAI,IAAK,aAAe,MAAM,EACtC,QAAQ,IAAI,IAAM,WAAmB,SAAS,EAGzC,aAAe,QACd,WAAmB,YAEvB,QAAQ,IAAI,uBAAuB,EAElC,WAAmB,UAAY,OAAO,OACpC,WAAmB,UAAU,QAC7B,WAAmB,SACtB,GAGF,OAAO,iBAAiB,OAAQR,CAAI","names":["index_exports","__export","index_default","get","load","read","set","write","uuid","response","node","data","httpState","_","type","callback"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n// \n// Unless otherwise stated in particular files or directories, this software is free software.\n// You can redistribute it and/or modify it under the terms of the GNU Affero\n// General Public License as published by the Free Software Foundation, either\n// version 3 of the License, or (at your option) any later version.\n\nexport const get:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid);\n\n if(response.status === 200)\n return await response.text();\n};\n\nexport const load:() => Promise<void> = async ():Promise<void> => {\n for(const node of document.querySelectorAll('[httpState],[httpstate]')) {\n const uuid:null|string = node.getAttribute('httpState')||node.getAttribute('httpstate');\n\n console.log('node.uuid', uuid);\n\n const ui:HttpState = (globalThis as any).httpState(uuid)\n .on('change', (e:Event&{ data:string }) => node.innerHTML = e.data);\n\n ui.et.dispatchEvent(Object.assign(new Event('change'), { data:await ui.get() }));\n }\n};\n\nexport const read:(uuid:string) => Promise<undefined|string> = async (uuid:string):Promise<undefined|string> => get(uuid);\n\nexport const set:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => {\n const response:Response = await fetch('https://httpstate.com/' + uuid, { body:data, method:'POST' });\n\n return response.status;\n};\n\nexport const write:(uuid:string, data:string) => Promise<number> = async (uuid:string, data:string):Promise<number> => set(uuid, data);\n\n// httpState\ntype HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n et:EventTarget;\n get():Promise<undefined|string>;\n off(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n on(type:string, callback:null|EventListenerOrEventListenerObject):HttpState;\n read():Promise<undefined|string>;\n removeEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n set(data:string):Promise<number>;\n write(data:string):Promise<number>;\n ws:WebSocket;\n};\n\nconst httpState:(uuid:string) => HttpState = (uuid:string):HttpState => {\n const _:HttpState = {\n addEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.addEventListener(type, callback),\n data:undefined,\n et:new EventTarget(),\n get:async ():Promise<undefined|string> => get(uuid),\n off:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.removeEventListener(type, callback);\n\n return _;\n },\n on:(type:string, callback:null|EventListenerOrEventListenerObject) => {\n _.addEventListener(type, callback);\n\n return _;\n },\n read:async ():Promise<undefined|string> => read(uuid),\n removeEventListener:(type:string, callback:null|EventListenerOrEventListenerObject) => _.et.removeEventListener(type, callback),\n set:async (data:string):Promise<number> => set(uuid, data),\n write:async (data:string):Promise<number> => write(uuid, data),\n ws:new WebSocket('wss://httpstate.com/' + uuid)\n };\n\n // ...\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n) {\n console.log('we do some magic ...');\n console.log('-', globalThis === window);\n console.log('-', (globalThis as any).httpstate);\n\n if(globalThis === window) {\n globalThis.addEventListener('load', async () => {\n if((globalThis as any).httpstate) {\n console.log('do the binding yo ...');\n\n (globalThis as any).httpState = (globalThis as any).httpstate = Object.assign(\n (globalThis as any).httpstate.default,\n (globalThis as any).httpstate\n );\n }\n\n await load();\n }, { once:true });\n }\n}\n"],"mappings":"6bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,QAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,QAAAC,EAAA,UAAAC,IAQO,IAAMJ,EAAiD,MAAOK,GAA0C,CAC7G,IAAMC,EAAoB,MAAM,MAAM,yBAA2BD,CAAI,EAErE,GAAGC,EAAS,SAAW,IACrB,OAAO,MAAMA,EAAS,KAAK,CAC/B,EAEaL,EAA2B,SAA0B,CAChE,QAAUM,KAAQ,SAAS,iBAAiB,yBAAyB,EAAG,CACtE,IAAMF,EAAmBE,EAAK,aAAa,WAAW,GAAGA,EAAK,aAAa,WAAW,EAEtF,QAAQ,IAAI,YAAaF,CAAI,EAE7B,IAAMG,EAAgB,WAAmB,UAAUH,CAAI,EACpD,GAAG,SAAWI,GAA4BF,EAAK,UAAYE,EAAE,IAAI,EAEpED,EAAG,GAAG,cAAc,OAAO,OAAO,IAAI,MAAM,QAAQ,EAAG,CAAE,KAAK,MAAMA,E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","load","read","set","write","uuid","response","node","ui","e","data","httpState","_","type","callback"]}
package/package.json CHANGED
@@ -23,5 +23,5 @@
23
23
  },
24
24
  "type": "module",
25
25
  "types": "dist/index.d.ts",
26
- "version": "0.0.5"
26
+ "version": "0.0.7"
27
27
  }