@laravel/stream-vue 0.3.1 → 0.3.2
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.d.ts +1 -1
- package/dist/index.es.js +13 -13
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare const useJsonStream: <TJsonData = null>(url: string, options?: Om
|
|
|
50
50
|
cancel: () => void;
|
|
51
51
|
clearData: () => void;
|
|
52
52
|
data: Readonly<TJsonData | null>;
|
|
53
|
-
|
|
53
|
+
strData: Readonly<Ref<string, string>>;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export declare const useStream: <TJsonData = null>(url: string, options?: StreamOptions) => {
|
package/dist/index.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ref as S, onMounted as x, onUnmounted as O, watch as q, readonly as
|
|
1
|
+
import { ref as S, onMounted as x, onUnmounted as O, watch as q, readonly as v } from "vue";
|
|
2
2
|
const M = "data: ", $ = (t, {
|
|
3
3
|
eventName: e = "update",
|
|
4
4
|
endSignal: r = "</stream>",
|
|
5
5
|
glue: l = " ",
|
|
6
|
-
replace:
|
|
6
|
+
replace: w = !1,
|
|
7
7
|
onMessage: b = () => null,
|
|
8
8
|
onComplete: D = () => null,
|
|
9
9
|
onError: E = () => null
|
|
@@ -21,7 +21,7 @@ const M = "data: ", $ = (t, {
|
|
|
21
21
|
g(), D();
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
w && h(), f.value.push(
|
|
25
25
|
a.data.startsWith(M) ? a.data.substring(M.length) : a.data
|
|
26
26
|
), d.value = f.value.join(l), b(a);
|
|
27
27
|
}, j = (a) => {
|
|
@@ -41,8 +41,8 @@ const M = "data: ", $ = (t, {
|
|
|
41
41
|
a !== s && (g(), n());
|
|
42
42
|
}
|
|
43
43
|
), {
|
|
44
|
-
message:
|
|
45
|
-
messageParts:
|
|
44
|
+
message: v(d),
|
|
45
|
+
messageParts: v(f),
|
|
46
46
|
close: g,
|
|
47
47
|
clearMessage: h
|
|
48
48
|
};
|
|
@@ -74,7 +74,7 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
|
|
|
74
74
|
P(t).filter((r) => r !== e)
|
|
75
75
|
), I(t) || (A.delete(t), i.delete(t));
|
|
76
76
|
}), V = (t, e = {}) => {
|
|
77
|
-
const r = e.id ?? X(), l = S(L(r)),
|
|
77
|
+
const r = e.id ?? X(), l = S(L(r)), w = (() => {
|
|
78
78
|
var s;
|
|
79
79
|
const n = {
|
|
80
80
|
"Content-Type": "application/json",
|
|
@@ -106,7 +106,7 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
|
|
|
106
106
|
method: "POST",
|
|
107
107
|
signal: a.signal,
|
|
108
108
|
headers: {
|
|
109
|
-
...
|
|
109
|
+
...w,
|
|
110
110
|
...e.headers ?? {}
|
|
111
111
|
},
|
|
112
112
|
body: JSON.stringify(n)
|
|
@@ -162,21 +162,21 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
|
|
|
162
162
|
}), O(() => {
|
|
163
163
|
f(), window.removeEventListener("beforeunload", c), I(r) || c();
|
|
164
164
|
}), {
|
|
165
|
-
data:
|
|
166
|
-
jsonData:
|
|
167
|
-
isFetching:
|
|
168
|
-
isStreaming:
|
|
165
|
+
data: v(b),
|
|
166
|
+
jsonData: v(D),
|
|
167
|
+
isFetching: v(E),
|
|
168
|
+
isStreaming: v(d),
|
|
169
169
|
id: r,
|
|
170
170
|
send: g,
|
|
171
171
|
cancel: c,
|
|
172
172
|
clearData: y
|
|
173
173
|
};
|
|
174
174
|
}, B = (t, e = {}) => {
|
|
175
|
-
const { jsonData: r, data: l, ...
|
|
175
|
+
const { jsonData: r, data: l, ...w } = V(t, {
|
|
176
176
|
...e,
|
|
177
177
|
json: !0
|
|
178
178
|
});
|
|
179
|
-
return { data: r,
|
|
179
|
+
return { data: r, strData: l, ...w };
|
|
180
180
|
};
|
|
181
181
|
export {
|
|
182
182
|
$ as useEventStream,
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(u,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(u=typeof globalThis<"u"?globalThis:u||self,n(u.LaravelStreamVue={},u.Vue))})(this,function(u,n){"use strict";const M="data: ",q=(t,{eventName:e="update",endSignal:r="</stream>",glue:o=" ",replace:w=!1,onMessage:F=()=>null,onComplete:L=()=>null,onError:E=()=>null}={})=>{const h=n.ref(""),m=n.ref([]),d=Array.isArray(e)?e:[e];let c=null;const g=()=>{h.value="",m.value=[]},S=(a=!1)=>{d.forEach(l=>{c==null||c.removeEventListener(l,b)}),c==null||c.close(),c=null,a&&g()},b=a=>{if([r,`${M}${r}`].includes(a.data)){S(),L();return}w&&g(),m.value.push(a.data.startsWith(M)?a.data.substring(M.length):a.data),h.value=m.value.join(o),F(a)},T=a=>{E(a),S()},s=()=>{g(),c=new EventSource(t),d.forEach(a=>{c.addEventListener(a,b)}),c.addEventListener("error",T)};return n.onMounted(()=>{s()}),n.onUnmounted(()=>{S()}),n.watch(()=>t,(a,l)=>{a!==l&&(S(),s())}),{message:n.readonly(h),messageParts:n.readonly(m),close:S,clearMessage:g}},x="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let I=(t=21)=>{let e="",r=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=x[r[t]&63];return e};const j=new Map,f=new Map,D=t=>{const e=j.get(t);if(e)return e;const r={controller:new AbortController,data:"",isFetching:!1,isStreaming:!1,jsonData:null};return j.set(t,r),r},C=t=>(f.has(t)||f.set(t,[]),f.get(t)),R=t=>{var e;return f.has(t)&&((e=f.get(t))==null?void 0:e.length)},V=(t,e)=>(C(t).push(e),()=>{f.set(t,C(t).filter(r=>r!==e)),R(t)||(j.delete(t),f.delete(t))}),P=(t,e={})=>{const r=e.id??I(),o=n.ref(D(r)),w=(()=>{var l;const s={"Content-Type":"application/json","X-STREAM-ID":r},a=e.csrfToken??((l=document.querySelector('meta[name="csrf-token"]'))==null?void 0:l.getAttribute("content"));return a&&(s["X-CSRF-TOKEN"]=a),s})(),F=n.ref(o.value.data),L=n.ref(o.value.jsonData),E=n.ref(o.value.isFetching),h=n.ref(o.value.isStreaming);let m;const d=s=>{var l;j.set(r,{...D(r),...s});const a=D(r);(l=f.get(r))==null||l.forEach(i=>i(a))},c=()=>{var s;o.value.controller.abort(),(E||h)&&((s=e.onCancel)==null||s.call(e)),d({isFetching:!1,isStreaming:!1})},g=(s={})=>{const a=new AbortController;d({isFetching:!0,controller:a}),fetch(t,{method:"POST",signal:a.signal,headers:{...w,...e.headers??{}},body:JSON.stringify(s)}).then(async l=>{var i;if(!l.ok){const y=await l.text();throw new Error(y)}if(!l.body)throw new Error("ReadableStream not yet supported in this browser.");return(i=e.onResponse)==null||i.call(e,l),d({isFetching:!1,isStreaming:!0}),T(l.body.getReader())}).catch(l=>{var i,y;d({isFetching:!1,isStreaming:!1}),(i=e.onError)==null||i.call(e,l),(y=e.onFinish)==null||y.call(e)})},S=s=>{c(),g(s),b()},b=()=>{d({data:"",jsonData:null})},T=(s,a="")=>s.read().then(({done:l,value:i})=>{var k,O,J;const y=new TextDecoder("utf-8").decode(i),A=a+y;(k=e.onData)==null||k.call(e,y);const v={data:A};if(!l)return d(v),T(s,A);if(v.isStreaming=!1,e.json)try{v.jsonData=JSON.parse(A)}catch(X){(O=e.onError)==null||O.call(e,X)}return d(v),(J=e.onFinish)==null||J.call(e),""});return n.onMounted(()=>{m=V(r,s=>{o.value=D(r),E.value=s.isFetching,h.value=s.isStreaming,F.value=s.data,L.value=s.jsonData}),window.addEventListener("beforeunload",c),e.initialInput&&g(e.initialInput)}),n.onUnmounted(()=>{m(),window.removeEventListener("beforeunload",c),R(r)||c()}),{data:n.readonly(F),jsonData:n.readonly(L),isFetching:n.readonly(E),isStreaming:n.readonly(h),id:r,send:S,cancel:c,clearData:b}},N=(t,e={})=>{const{jsonData:r,data:o,...w}=P(t,{...e,json:!0});return{data:r,
|
|
1
|
+
(function(u,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(u=typeof globalThis<"u"?globalThis:u||self,n(u.LaravelStreamVue={},u.Vue))})(this,function(u,n){"use strict";const M="data: ",q=(t,{eventName:e="update",endSignal:r="</stream>",glue:o=" ",replace:w=!1,onMessage:F=()=>null,onComplete:L=()=>null,onError:E=()=>null}={})=>{const h=n.ref(""),m=n.ref([]),d=Array.isArray(e)?e:[e];let c=null;const g=()=>{h.value="",m.value=[]},S=(a=!1)=>{d.forEach(l=>{c==null||c.removeEventListener(l,b)}),c==null||c.close(),c=null,a&&g()},b=a=>{if([r,`${M}${r}`].includes(a.data)){S(),L();return}w&&g(),m.value.push(a.data.startsWith(M)?a.data.substring(M.length):a.data),h.value=m.value.join(o),F(a)},T=a=>{E(a),S()},s=()=>{g(),c=new EventSource(t),d.forEach(a=>{c.addEventListener(a,b)}),c.addEventListener("error",T)};return n.onMounted(()=>{s()}),n.onUnmounted(()=>{S()}),n.watch(()=>t,(a,l)=>{a!==l&&(S(),s())}),{message:n.readonly(h),messageParts:n.readonly(m),close:S,clearMessage:g}},x="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let I=(t=21)=>{let e="",r=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=x[r[t]&63];return e};const j=new Map,f=new Map,D=t=>{const e=j.get(t);if(e)return e;const r={controller:new AbortController,data:"",isFetching:!1,isStreaming:!1,jsonData:null};return j.set(t,r),r},C=t=>(f.has(t)||f.set(t,[]),f.get(t)),R=t=>{var e;return f.has(t)&&((e=f.get(t))==null?void 0:e.length)},V=(t,e)=>(C(t).push(e),()=>{f.set(t,C(t).filter(r=>r!==e)),R(t)||(j.delete(t),f.delete(t))}),P=(t,e={})=>{const r=e.id??I(),o=n.ref(D(r)),w=(()=>{var l;const s={"Content-Type":"application/json","X-STREAM-ID":r},a=e.csrfToken??((l=document.querySelector('meta[name="csrf-token"]'))==null?void 0:l.getAttribute("content"));return a&&(s["X-CSRF-TOKEN"]=a),s})(),F=n.ref(o.value.data),L=n.ref(o.value.jsonData),E=n.ref(o.value.isFetching),h=n.ref(o.value.isStreaming);let m;const d=s=>{var l;j.set(r,{...D(r),...s});const a=D(r);(l=f.get(r))==null||l.forEach(i=>i(a))},c=()=>{var s;o.value.controller.abort(),(E||h)&&((s=e.onCancel)==null||s.call(e)),d({isFetching:!1,isStreaming:!1})},g=(s={})=>{const a=new AbortController;d({isFetching:!0,controller:a}),fetch(t,{method:"POST",signal:a.signal,headers:{...w,...e.headers??{}},body:JSON.stringify(s)}).then(async l=>{var i;if(!l.ok){const y=await l.text();throw new Error(y)}if(!l.body)throw new Error("ReadableStream not yet supported in this browser.");return(i=e.onResponse)==null||i.call(e,l),d({isFetching:!1,isStreaming:!0}),T(l.body.getReader())}).catch(l=>{var i,y;d({isFetching:!1,isStreaming:!1}),(i=e.onError)==null||i.call(e,l),(y=e.onFinish)==null||y.call(e)})},S=s=>{c(),g(s),b()},b=()=>{d({data:"",jsonData:null})},T=(s,a="")=>s.read().then(({done:l,value:i})=>{var k,O,J;const y=new TextDecoder("utf-8").decode(i),A=a+y;(k=e.onData)==null||k.call(e,y);const v={data:A};if(!l)return d(v),T(s,A);if(v.isStreaming=!1,e.json)try{v.jsonData=JSON.parse(A)}catch(X){(O=e.onError)==null||O.call(e,X)}return d(v),(J=e.onFinish)==null||J.call(e),""});return n.onMounted(()=>{m=V(r,s=>{o.value=D(r),E.value=s.isFetching,h.value=s.isStreaming,F.value=s.data,L.value=s.jsonData}),window.addEventListener("beforeunload",c),e.initialInput&&g(e.initialInput)}),n.onUnmounted(()=>{m(),window.removeEventListener("beforeunload",c),R(r)||c()}),{data:n.readonly(F),jsonData:n.readonly(L),isFetching:n.readonly(E),isStreaming:n.readonly(h),id:r,send:S,cancel:c,clearData:b}},N=(t,e={})=>{const{jsonData:r,data:o,...w}=P(t,{...e,json:!0});return{data:r,strData:o,...w}};u.useEventStream=q,u.useJsonStream=N,u.useStream=P,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|