@httpstate/typescript 0.0.14 → 0.0.15
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 +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var v=(n,t)=>{for(var e in t)i(n,e,{get:t[e],enumerable:!0})},m=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of u(t))!p.call(n,r)&&r!==e&&i(n,r,{get:()=>t[r],enumerable:!(s=l(t,r))||s.enumerable});return n};var b=n=>m(i({},"__esModule",{value:!0}),n);var h={};v(h,{default:()=>f,get:()=>a,load:()=>d,read:()=>g,set:()=>o,write:()=>c});module.exports=b(h);var a=async n=>{let t=await fetch("https://httpstate.com/"+n);if(t.status===200)return await t.text()},d=async()=>{for(let n of document.querySelectorAll("[httpState],[httpstate]")){let t=n.getAttribute("httpState")||n.getAttribute("httpstate"),e=globalThis.httpState(t).on("change",s=>n.innerHTML=s.data);e.emit(await e.get())}},g=async n=>a(n),o=async(n,t)=>(await fetch("https://httpstate.com/"+n,{body:t,method:"POST"})).status,c=async(n,t)=>o(n,t),E=n=>{let t={addEventListener:(e,s)=>t.et.addEventListener(e,s),data:void 0,emit:e=>(t.et.dispatchEvent(Object.assign(new Event("change"),{data:e})),t),et:new EventTarget,get:async()=>a(n),off:(e,s)=>(t.removeEventListener(e,s),t),on:(e,s)=>(t.addEventListener(e,s),t),read:async()=>g(n),removeEventListener:(e,s)=>t.et.removeEventListener(e,s),set:async e=>o(n,e),write:async e=>c(n,e),ws:new WebSocket("wss://httpstate.com/"+n)};return t.ws.addEventListener("close",e=>console.log("close",e)),t.ws.addEventListener("error",e=>console.log("error",e)),t.ws.addEventListener("message",async e=>{t.data=await e.data.text(),t.emit(t.data)}),t.ws.addEventListener("open",()=>t.ws.send(JSON.stringify(["open",n]))),t.ws.interval=setInterval(()=>t.ws.send(JSON.stringify(["ping"])),32768),t},f=E;typeof document<"u"&&typeof window<"u"&&globalThis===window&&globalThis.addEventListener("load",async()=>{globalThis.httpstate&&(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
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n
|
|
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 const state:HttpState = (globalThis as any).httpState(uuid)\n .on('change', (e:Event&{ data:string }) => node.innerHTML = e.data);\n\n state.emit(await state.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\nexport type HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n emit(data:undefined|string):HttpState;\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 emit:(data:string) => {\n _.et.dispatchEvent(Object.assign(new Event('change'), { data }));\n\n return _;\n },\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 _.ws.addEventListener('close', e => console.log('close', e));\n _.ws.addEventListener('error', e => console.log('error', e));\n _.ws.addEventListener('message', async e => {\n _.data = await e.data.text();\n\n _.emit(_.data);\n });\n _.ws.addEventListener('open', () => _.ws.send(JSON.stringify(['open', uuid])));\n\n (_.ws as any).interval = setInterval(() => _.ws.send(JSON.stringify(['ping'])), 1024*32);\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n && globalThis === window\n)\n globalThis.addEventListener('load', async () => {\n if((globalThis as any).httpstate)\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 await load();\n }, { once:true });\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,EAEhFC,EAAmB,WAAmB,UAAUH,CAAI,EACvD,GAAG,SAAWI,GAA4BF,EAAK,UAAYE,EAAE,IAAI,EAEpED,EAAM,KAAK,MAAMA,EAAM,IAAI,CAAC,CAC9B,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,EAkB/HC,EAAwCN,GAA0B,CACtE,IAAMO,EAAc,CAClB,iBAAiB,CAACC,EAAaC,IAAqDF,EAAE,GAAG,iBAAiBC,EAAMC,CAAQ,EACxH,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B,UAAU,QAC7B,WAAmB,SACtB,GAEF,MAAMX,EAAK,CACb,EAAG,CAAE,KAAK,EAAK,CAAC","names":["index_exports","__export","index_default","get","load","read","set","write","__toCommonJS","uuid","response","node","state","e","data","httpState","_","type","callback"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,7 @@ declare const write: (uuid: string, data: string) => Promise<number>;
|
|
|
6
6
|
type HttpState = {
|
|
7
7
|
addEventListener(type: string, callback: null | EventListenerOrEventListenerObject): void;
|
|
8
8
|
data?: undefined | string;
|
|
9
|
+
emit(data: undefined | string): HttpState;
|
|
9
10
|
et: EventTarget;
|
|
10
11
|
get(): Promise<undefined | string>;
|
|
11
12
|
off(type: string, callback: null | EventListenerOrEventListenerObject): HttpState;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ declare const write: (uuid: string, data: string) => Promise<number>;
|
|
|
6
6
|
type HttpState = {
|
|
7
7
|
addEventListener(type: string, callback: null | EventListenerOrEventListenerObject): void;
|
|
8
8
|
data?: undefined | string;
|
|
9
|
+
emit(data: undefined | string): HttpState;
|
|
9
10
|
et: EventTarget;
|
|
10
11
|
get(): Promise<undefined | string>;
|
|
11
12
|
off(type: string, callback: null | EventListenerOrEventListenerObject): HttpState;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=async n=>{let t=await fetch("https://httpstate.com/"+n);if(t.status===200)return await t.text()},a=async()=>{for(let n of document.querySelectorAll("[httpState],[httpstate]")){let t=n.getAttribute("httpState")||n.getAttribute("httpstate"),e=globalThis.httpState(t).on("change",s=>n.innerHTML=s.data);e.
|
|
1
|
+
var r=async n=>{let t=await fetch("https://httpstate.com/"+n);if(t.status===200)return await t.text()},a=async()=>{for(let n of document.querySelectorAll("[httpState],[httpstate]")){let t=n.getAttribute("httpState")||n.getAttribute("httpstate"),e=globalThis.httpState(t).on("change",s=>n.innerHTML=s.data);e.emit(await e.get())}},o=async n=>r(n),i=async(n,t)=>(await fetch("https://httpstate.com/"+n,{body:t,method:"POST"})).status,d=async(n,t)=>i(n,t),g=n=>{let t={addEventListener:(e,s)=>t.et.addEventListener(e,s),data:void 0,emit:e=>(t.et.dispatchEvent(Object.assign(new Event("change"),{data:e})),t),et:new EventTarget,get:async()=>r(n),off:(e,s)=>(t.removeEventListener(e,s),t),on:(e,s)=>(t.addEventListener(e,s),t),read:async()=>o(n),removeEventListener:(e,s)=>t.et.removeEventListener(e,s),set:async e=>i(n,e),write:async e=>d(n,e),ws:new WebSocket("wss://httpstate.com/"+n)};return t.ws.addEventListener("close",e=>console.log("close",e)),t.ws.addEventListener("error",e=>console.log("error",e)),t.ws.addEventListener("message",async e=>{t.data=await e.data.text(),t.emit(t.data)}),t.ws.addEventListener("open",()=>t.ws.send(JSON.stringify(["open",n]))),t.ws.interval=setInterval(()=>t.ws.send(JSON.stringify(["ping"])),32768),t},c=g;typeof document<"u"&&typeof window<"u"&&globalThis===window&&globalThis.addEventListener("load",async()=>{globalThis.httpstate&&(globalThis.httpState=globalThis.httpstate=Object.assign(globalThis.httpstate.default,globalThis.httpstate)),await a()},{once:!0});export{c as default,r as get,a as load,o as read,i as set,d as write};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n
|
|
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 const state:HttpState = (globalThis as any).httpState(uuid)\n .on('change', (e:Event&{ data:string }) => node.innerHTML = e.data);\n\n state.emit(await state.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\nexport type HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n emit(data:undefined|string):HttpState;\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 emit:(data:string) => {\n _.et.dispatchEvent(Object.assign(new Event('change'), { data }));\n\n return _;\n },\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 _.ws.addEventListener('close', e => console.log('close', e));\n _.ws.addEventListener('error', e => console.log('error', e));\n _.ws.addEventListener('message', async e => {\n _.data = await e.data.text();\n\n _.emit(_.data);\n });\n _.ws.addEventListener('open', () => _.ws.send(JSON.stringify(['open', uuid])));\n\n (_.ws as any).interval = setInterval(() => _.ws.send(JSON.stringify(['ping'])), 1024*32);\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n && globalThis === window\n)\n globalThis.addEventListener('load', async () => {\n if((globalThis as any).httpstate)\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 await load();\n }, { once:true });\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,SAAS,iBAAiB,yBAAyB,EAAG,CACtE,IAAMH,EAAmBG,EAAK,aAAa,WAAW,GAAGA,EAAK,aAAa,WAAW,EAEhFC,EAAmB,WAAmB,UAAUJ,CAAI,EACvD,GAAG,SAAWK,GAA4BF,EAAK,UAAYE,EAAE,IAAI,EAEpED,EAAM,KAAK,MAAMA,EAAM,IAAI,CAAC,CAC9B,CACF,EAEaE,EAAkD,MAAON,GAA0CD,EAAIC,CAAI,EAE3GO,EAAoD,MAAOP,EAAaQ,KACzD,MAAM,MAAM,yBAA2BR,EAAM,CAAE,KAAKQ,EAAM,OAAO,MAAO,CAAC,GAEnF,OAGLC,EAAsD,MAAOT,EAAaQ,IAAgCD,EAAIP,EAAMQ,CAAI,EAkB/HE,E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W,KAClB,aAAe,QAElB,WAAW,iBAAiB,OAAQ,SAAY,CAC1C,WAAmB,YACpB,WAAmB,UAAa,WAAmB,UAAY,OAAO,OACpE,WAAmB,UAAU,QAC7B,WAAmB,SACtB,GAEF,MAAMR,EAAK,CACb,EAAG,CAAE,KAAK,EAAK,CAAC","names":["get","uuid","response","load","node","state","e","read","set","data","write","httpState","_","type","callback","index_default"]}
|
package/dist/index.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var httpstate=(()=>{var i=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var httpstate=(()=>{var i=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var v=(n,t)=>{for(var e in t)i(n,e,{get:t[e],enumerable:!0})},m=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of u(t))!p.call(n,r)&&r!==e&&i(n,r,{get:()=>t[r],enumerable:!(s=l(t,r))||s.enumerable});return n};var b=n=>m(i({},"__esModule",{value:!0}),n);var h={};v(h,{default:()=>f,get:()=>a,load:()=>d,read:()=>g,set:()=>o,write:()=>c});var a=async n=>{let t=await fetch("https://httpstate.com/"+n);if(t.status===200)return await t.text()},d=async()=>{for(let n of document.querySelectorAll("[httpState],[httpstate]")){let t=n.getAttribute("httpState")||n.getAttribute("httpstate"),e=globalThis.httpState(t).on("change",s=>n.innerHTML=s.data);e.emit(await e.get())}},g=async n=>a(n),o=async(n,t)=>(await fetch("https://httpstate.com/"+n,{body:t,method:"POST"})).status,c=async(n,t)=>o(n,t),E=n=>{let t={addEventListener:(e,s)=>t.et.addEventListener(e,s),data:void 0,emit:e=>(t.et.dispatchEvent(Object.assign(new Event("change"),{data:e})),t),et:new EventTarget,get:async()=>a(n),off:(e,s)=>(t.removeEventListener(e,s),t),on:(e,s)=>(t.addEventListener(e,s),t),read:async()=>g(n),removeEventListener:(e,s)=>t.et.removeEventListener(e,s),set:async e=>o(n,e),write:async e=>c(n,e),ws:new WebSocket("wss://httpstate.com/"+n)};return t.ws.addEventListener("close",e=>console.log("close",e)),t.ws.addEventListener("error",e=>console.log("error",e)),t.ws.addEventListener("message",async e=>{t.data=await e.data.text(),t.emit(t.data)}),t.ws.addEventListener("open",()=>t.ws.send(JSON.stringify(["open",n]))),t.ws.interval=setInterval(()=>t.ws.send(JSON.stringify(["ping"])),32768),t},f=E;typeof document<"u"&&typeof window<"u"&&globalThis===window&&globalThis.addEventListener("load",async()=>{globalThis.httpstate&&(globalThis.httpState=globalThis.httpstate=Object.assign(globalThis.httpstate.default,globalThis.httpstate)),await d()},{once:!0});return b(h);})();
|
|
2
2
|
//# sourceMappingURL=index.global.js.map
|
package/dist/index.global.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// HTTP State, https://httpstate.com/\n// Copyright (C) Alex Morales, 2026\n
|
|
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 const state:HttpState = (globalThis as any).httpState(uuid)\n .on('change', (e:Event&{ data:string }) => node.innerHTML = e.data);\n\n state.emit(await state.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\nexport type HttpState = {\n addEventListener(type:string, callback:null|EventListenerOrEventListenerObject):void;\n data?:undefined|string;\n emit(data:undefined|string):HttpState;\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 emit:(data:string) => {\n _.et.dispatchEvent(Object.assign(new Event('change'), { data }));\n\n return _;\n },\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 _.ws.addEventListener('close', e => console.log('close', e));\n _.ws.addEventListener('error', e => console.log('error', e));\n _.ws.addEventListener('message', async e => {\n _.data = await e.data.text();\n\n _.emit(_.data);\n });\n _.ws.addEventListener('open', () => _.ws.send(JSON.stringify(['open', uuid])));\n\n (_.ws as any).interval = setInterval(() => _.ws.send(JSON.stringify(['ping'])), 1024*32);\n\n return _;\n};\n\nexport default httpState;\n\nif(\n typeof document !== 'undefined'\n && typeof window !== 'undefined'\n && globalThis === window\n)\n globalThis.addEventListener('load', async () => {\n if((globalThis as any).httpstate)\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 await load();\n }, { once:true });\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,EAEhFC,EAAmB,WAAmB,UAAUH,CAAI,EACvD,GAAG,SAAWI,GAA4BF,EAAK,UAAYE,EAAE,IAAI,EAEpED,EAAM,KAAK,MAAMA,EAAM,IAAI,CAAC,CAC9B,CACF,EAEaN,EAAkD,MAAOG,GAA0CL,EAAIK,CAAI,EAE3GF,EAAoD,MAAOE,EAAaK,KACzD,MAAM,MAAM,yBAA2BL,EAAM,CAAE,KAAKK,EAAM,OAAO,MAAO,CAAC,GAEnF,OAGLN,EAAsD,MAAOC,EAAaK,IAAgCP,EAAIE,EAAMK,CAAI,EAkB/HC,EAAwCN,GAA0B,CACtE,IAAMO,EAAc,CAClB,iBAAiB,CAACC,EAAaC,IAAqDF,EAAE,GAAG,iBAAiBC,EAAMC,CAAQ,EACxH,KAAK,OACL,KAAMJ,IACJE,EAAE,GAAG,cAAc,OAAO,OAAO,IAAI,MAAM,QAAQ,EAAG,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AAC","names":["index_exports","__export","index_default","get","load","read","set","write","uuid","response","node","state","e","data","httpState","_","type","callback"]}
|
package/package.json
CHANGED