@laravel/stream-vue 0.3.2 → 0.3.3

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/README.md CHANGED
@@ -60,6 +60,7 @@ const { data } = useStream("chat", {
60
60
  initialInput: undefined,
61
61
  headers: undefined,
62
62
  csrfToken: undefined,
63
+ credentials: undefined,
63
64
  onResponse: (response: Response) => void,
64
65
  onData: (data: string) => void,
65
66
  onCancel: () => void,
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ declare type StreamOptions = {
23
23
  headers?: Record<string, string>;
24
24
  csrfToken?: string;
25
25
  json?: boolean;
26
+ credentials?: RequestCredentials;
26
27
  onResponse?: (response: Response) => void;
27
28
  onData?: (data: string) => void;
28
29
  onCancel?: () => void;
package/dist/index.es.js CHANGED
@@ -10,41 +10,41 @@ const M = "data: ", $ = (t, {
10
10
  } = {}) => {
11
11
  const d = S(""), f = S([]), u = Array.isArray(e) ? e : [e];
12
12
  let c = null;
13
- const h = () => {
13
+ const g = () => {
14
14
  d.value = "", f.value = [];
15
- }, g = (a = !1) => {
15
+ }, h = (a = !1) => {
16
16
  u.forEach((s) => {
17
17
  c == null || c.removeEventListener(s, y);
18
- }), c == null || c.close(), c = null, a && h();
18
+ }), c == null || c.close(), c = null, a && g();
19
19
  }, y = (a) => {
20
20
  if ([r, `${M}${r}`].includes(a.data)) {
21
- g(), D();
21
+ h(), D();
22
22
  return;
23
23
  }
24
- w && h(), f.value.push(
24
+ w && g(), 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) => {
28
- E(a), g();
28
+ E(a), h();
29
29
  }, n = () => {
30
- h(), c = new EventSource(t), u.forEach((a) => {
30
+ g(), c = new EventSource(t), u.forEach((a) => {
31
31
  c.addEventListener(a, y);
32
32
  }), c.addEventListener("error", j);
33
33
  };
34
34
  return x(() => {
35
35
  n();
36
36
  }), O(() => {
37
- g();
37
+ h();
38
38
  }), q(
39
39
  () => t,
40
40
  (a, s) => {
41
- a !== s && (g(), n());
41
+ a !== s && (h(), n());
42
42
  }
43
43
  ), {
44
44
  message: v(d),
45
45
  messageParts: v(f),
46
- close: g,
47
- clearMessage: h
46
+ close: h,
47
+ clearMessage: g
48
48
  };
49
49
  }, N = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
50
50
  let X = (t = 21) => {
@@ -53,7 +53,7 @@ let X = (t = 21) => {
53
53
  e += N[r[t] & 63];
54
54
  return e;
55
55
  };
56
- const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
56
+ const A = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), L = (t) => {
57
57
  const e = A.get(t);
58
58
  if (e)
59
59
  return e;
@@ -65,14 +65,14 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
65
65
  jsonData: null
66
66
  };
67
67
  return A.set(t, r), r;
68
- }, P = (t) => (i.has(t) || i.set(t, []), i.get(t)), I = (t) => {
68
+ }, P = (t) => (o.has(t) || o.set(t, []), o.get(t)), I = (t) => {
69
69
  var e;
70
- return i.has(t) && ((e = i.get(t)) == null ? void 0 : e.length);
70
+ return o.has(t) && ((e = o.get(t)) == null ? void 0 : e.length);
71
71
  }, K = (t, e) => (P(t).push(e), () => {
72
- i.set(
72
+ o.set(
73
73
  t,
74
74
  P(t).filter((r) => r !== e)
75
- ), I(t) || (A.delete(t), i.delete(t));
75
+ ), I(t) || (A.delete(t), o.delete(t));
76
76
  }), V = (t, e = {}) => {
77
77
  const r = e.id ?? X(), l = S(L(r)), w = (() => {
78
78
  var s;
@@ -90,14 +90,14 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
90
90
  ...n
91
91
  });
92
92
  const a = L(r);
93
- (s = i.get(r)) == null || s.forEach((o) => o(a));
93
+ (s = o.get(r)) == null || s.forEach((i) => i(a));
94
94
  }, c = () => {
95
95
  var n;
96
96
  l.value.controller.abort(), (E || d) && ((n = e.onCancel) == null || n.call(e)), u({
97
97
  isFetching: !1,
98
98
  isStreaming: !1
99
99
  });
100
- }, h = (n = {}) => {
100
+ }, g = (n = {}) => {
101
101
  const a = new AbortController();
102
102
  u({
103
103
  isFetching: !0,
@@ -109,9 +109,10 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
109
109
  ...w,
110
110
  ...e.headers ?? {}
111
111
  },
112
- body: JSON.stringify(n)
112
+ body: JSON.stringify(n),
113
+ credentials: e.credentials ?? "same-origin"
113
114
  }).then(async (s) => {
114
- var o;
115
+ var i;
115
116
  if (!s.ok) {
116
117
  const m = await s.text();
117
118
  throw new Error(m);
@@ -120,27 +121,27 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
120
121
  throw new Error(
121
122
  "ReadableStream not yet supported in this browser."
122
123
  );
123
- return (o = e.onResponse) == null || o.call(e, s), u({
124
+ return (i = e.onResponse) == null || i.call(e, s), u({
124
125
  isFetching: !1,
125
126
  isStreaming: !0
126
127
  }), j(s.body.getReader());
127
128
  }).catch((s) => {
128
- var o, m;
129
+ var i, m;
129
130
  u({
130
131
  isFetching: !1,
131
132
  isStreaming: !1
132
- }), (o = e.onError) == null || o.call(e, s), (m = e.onFinish) == null || m.call(e);
133
+ }), (i = e.onError) == null || i.call(e, s), (m = e.onFinish) == null || m.call(e);
133
134
  });
134
- }, g = (n) => {
135
- c(), h(n), y();
135
+ }, h = (n) => {
136
+ c(), g(n), y();
136
137
  }, y = () => {
137
138
  u({
138
139
  data: "",
139
140
  jsonData: null
140
141
  });
141
- }, j = (n, a = "") => n.read().then(({ done: s, value: o }) => {
142
+ }, j = (n, a = "") => n.read().then(({ done: s, value: i }) => {
142
143
  var R, T, k;
143
- const m = new TextDecoder("utf-8").decode(o), C = a + m;
144
+ const m = new TextDecoder("utf-8").decode(i), C = a + m;
144
145
  (R = e.onData) == null || R.call(e, m);
145
146
  const F = {
146
147
  data: C
@@ -158,7 +159,7 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
158
159
  return x(() => {
159
160
  f = K(r, (n) => {
160
161
  l.value = L(r), E.value = n.isFetching, d.value = n.isStreaming, b.value = n.data, D.value = n.jsonData;
161
- }), window.addEventListener("beforeunload", c), e.initialInput && h(e.initialInput);
162
+ }), window.addEventListener("beforeunload", c), e.initialInput && g(e.initialInput);
162
163
  }), O(() => {
163
164
  f(), window.removeEventListener("beforeunload", c), I(r) || c();
164
165
  }), {
@@ -167,7 +168,7 @@ const A = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), L = (t) => {
167
168
  isFetching: v(E),
168
169
  isStreaming: v(d),
169
170
  id: r,
170
- send: g,
171
+ send: h,
171
172
  cancel: c,
172
173
  clearData: y
173
174
  };
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,strData:o,...w}};u.useEventStream=q,u.useJsonStream=N,u.useStream=P,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(i,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(i=typeof globalThis<"u"?globalThis:i||self,n(i.LaravelStreamVue={},i.Vue))})(this,function(i,n){"use strict";const M="data: ",q=(t,{eventName:e="update",endSignal:r="</stream>",glue:d=" ",replace:w=!1,onMessage:F=()=>null,onComplete:L=()=>null,onError:E=()=>null}={})=>{const h=n.ref(""),m=n.ref([]),o=Array.isArray(e)?e:[e];let c=null;const g=()=>{h.value="",m.value=[]},S=(a=!1)=>{o.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(d),F(a)},T=a=>{E(a),S()},s=()=>{g(),c=new EventSource(t),o.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(),d=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(d.value.data),L=n.ref(d.value.jsonData),E=n.ref(d.value.isFetching),h=n.ref(d.value.isStreaming);let m;const o=s=>{var l;j.set(r,{...D(r),...s});const a=D(r);(l=f.get(r))==null||l.forEach(u=>u(a))},c=()=>{var s;d.value.controller.abort(),(E||h)&&((s=e.onCancel)==null||s.call(e)),o({isFetching:!1,isStreaming:!1})},g=(s={})=>{const a=new AbortController;o({isFetching:!0,controller:a}),fetch(t,{method:"POST",signal:a.signal,headers:{...w,...e.headers??{}},body:JSON.stringify(s),credentials:e.credentials??"same-origin"}).then(async l=>{var u;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(u=e.onResponse)==null||u.call(e,l),o({isFetching:!1,isStreaming:!0}),T(l.body.getReader())}).catch(l=>{var u,y;o({isFetching:!1,isStreaming:!1}),(u=e.onError)==null||u.call(e,l),(y=e.onFinish)==null||y.call(e)})},S=s=>{c(),g(s),b()},b=()=>{o({data:"",jsonData:null})},T=(s,a="")=>s.read().then(({done:l,value:u})=>{var k,O,J;const y=new TextDecoder("utf-8").decode(u),A=a+y;(k=e.onData)==null||k.call(e,y);const v={data:A};if(!l)return o(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 o(v),(J=e.onFinish)==null||J.call(e),""});return n.onMounted(()=>{m=V(r,s=>{d.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:d,...w}=P(t,{...e,json:!0});return{data:r,strData:d,...w}};i.useEventStream=q,i.useJsonStream=N,i.useStream=P,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laravel/stream-vue",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Laravel streaming hooks for Vue",
5
5
  "keywords": [
6
6
  "laravel",