@laravel/stream-vue 0.3.4 → 0.3.8

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 CHANGED
@@ -17,9 +17,9 @@ declare type EventStreamResult = {
17
17
  clearMessage: () => void;
18
18
  };
19
19
 
20
- declare type StreamOptions = {
20
+ declare type StreamOptions<TSendBody extends Record<string, any> = {}> = {
21
21
  id?: string;
22
- initialInput?: Record<string, any>;
22
+ initialInput?: TSendBody;
23
23
  headers?: Record<string, string>;
24
24
  csrfToken?: string;
25
25
  json?: boolean;
@@ -44,24 +44,24 @@ declare type StreamOptions = {
44
44
  */
45
45
  export declare const useEventStream: (url: string, { eventName, endSignal, glue, replace, onMessage, onComplete, onError, }?: EventStreamOptions) => EventStreamResult;
46
46
 
47
- export declare const useJsonStream: <TJsonData = null>(url: string, options?: Omit<StreamOptions, "json">) => {
47
+ export declare const useJsonStream: <TJsonData = null, TSendBody extends Record<string, any> = {}>(url: string, options?: Omit<StreamOptions<TSendBody>, "json">) => {
48
48
  isFetching: Readonly<Ref<boolean>>;
49
49
  isStreaming: Readonly<Ref<boolean>>;
50
50
  id: string;
51
- send: (body: Record<string, any>) => void;
51
+ send: (body: TSendBody) => void;
52
52
  cancel: () => void;
53
53
  clearData: () => void;
54
54
  data: Readonly<TJsonData | null>;
55
55
  strData: Readonly<Ref<string, string>>;
56
56
  };
57
57
 
58
- export declare const useStream: <TJsonData = null>(url: string, options?: StreamOptions) => {
58
+ export declare const useStream: <TSendBody extends Record<string, any> = {}, TJsonData = null>(url: string, options?: StreamOptions<TSendBody>) => {
59
59
  data: Readonly<Ref<string>>;
60
60
  jsonData: Readonly<TJsonData | null>;
61
61
  isFetching: Readonly<Ref<boolean>>;
62
62
  isStreaming: Readonly<Ref<boolean>>;
63
63
  id: string;
64
- send: (body: Record<string, any>) => void;
64
+ send: (body: TSendBody) => void;
65
65
  cancel: () => void;
66
66
  clearData: () => void;
67
67
  };
package/dist/index.es.js CHANGED
@@ -148,7 +148,7 @@ const w = /* @__PURE__ */ new Map(), K = (t, e) => {
148
148
  isFetching: !1,
149
149
  isStreaming: !1
150
150
  });
151
- }, u = (r = {}) => {
151
+ }, u = (r) => {
152
152
  const o = new AbortController(), g = {
153
153
  method: "POST",
154
154
  signal: o.signal,
@@ -156,7 +156,7 @@ const w = /* @__PURE__ */ new Map(), K = (t, e) => {
156
156
  ...i,
157
157
  ...e.headers ?? {}
158
158
  },
159
- body: JSON.stringify(r),
159
+ body: JSON.stringify(r ?? {}),
160
160
  credentials: e.credentials ?? "same-origin"
161
161
  }, k = G(n, g);
162
162
  k !== !1 && (s({
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(f,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],s):(f=typeof globalThis<"u"?globalThis:f||self,s(f.LaravelStreamVue={},f.Vue))})(this,function(f,s){"use strict";const T="data: ",J=(t,{eventName:e="update",endSignal:n="</stream>",glue:a=" ",replace:u=!1,onMessage:j=()=>null,onComplete:k=()=>null,onError:y=()=>null}={})=>{const m=s.ref(""),g=s.ref([]),C=Array.isArray(e)?e:[e];let o=null;const c=()=>{m.value="",g.value=[]},h=(r=!1)=>{C.forEach(l=>{o==null||o.removeEventListener(l,v)}),o==null||o.close(),o=null,r&&c()},v=r=>{if([n,`${T}${n}`].includes(r.data)){h(),k();return}u&&c(),g.value.push(r.data.startsWith(T)?r.data.substring(T.length):r.data),m.value=g.value.join(a),j(r)},B=r=>{y(r),h()},D=()=>{c(),o=new EventSource(t),C.forEach(r=>{o.addEventListener(r,v)}),o.addEventListener("error",B)};return s.onMounted(()=>{D()}),s.onUnmounted(()=>{h()}),s.watch(()=>t,(r,l)=>{r!==l&&(h(),D())}),{message:s.readonly(m),messageParts:s.readonly(g),close:h,clearMessage:c}},x="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let I=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=x[n[t]&63];return e};const b=new Map,V=(t,e)=>{b.has(t)||b.set(t,{onData:[],onError:[],onFinish:[],onResponse:[],onCancel:[],onBeforeSend:[]});const n=b.get(t);return e.onData&&n.onData.push(e.onData),e.onError&&n.onError.push(e.onError),e.onFinish&&n.onFinish.push(e.onFinish),e.onResponse&&n.onResponse.push(e.onResponse),e.onCancel&&n.onCancel.push(e.onCancel),e.onBeforeSend&&n.onBeforeSend.push(e.onBeforeSend),()=>{$(t,e)}},E=(t,e,...n)=>{const a=b.get(t);return a?a[e].map(u=>u(...n)):[]},p=t=>{E(t,"onFinish")},A=(t,e)=>{E(t,"onError",e)},N=(t,e)=>{E(t,"onResponse",e)},X=t=>{E(t,"onCancel")},K=(t,e)=>{E(t,"onData",e)},W=(t,e)=>{const n=E(t,"onBeforeSend",e);for(const a of n){if(a===!1)return!1;if(a!==null&&typeof a=="object")return a}return null},$=(t,e)=>{const n=b.get(t);n&&(e.onData&&(n.onData=n.onData.filter(a=>a!==e.onData)),e.onError&&(n.onError=n.onError.filter(a=>a!==e.onError)),e.onFinish&&(n.onFinish=n.onFinish.filter(a=>a!==e.onFinish)),e.onResponse&&(n.onResponse=n.onResponse.filter(a=>a!==e.onResponse)),e.onCancel&&(n.onCancel=n.onCancel.filter(a=>a!==e.onCancel)),e.onBeforeSend&&(n.onBeforeSend=n.onBeforeSend.filter(a=>a!==e.onBeforeSend)))},F=new Map,d=new Map,R=t=>{const e=F.get(t);if(e)return e;const n={controller:new AbortController,data:"",isFetching:!1,isStreaming:!1,jsonData:null};return F.set(t,n),n},P=t=>(d.has(t)||d.set(t,[]),d.get(t)),q=t=>{var e;return d.has(t)&&((e=d.get(t))==null?void 0:e.length)},G=(t,e)=>(P(t).push(e),()=>{d.set(t,P(t).filter(n=>n!==e)),q(t)||(F.delete(t),d.delete(t))}),H=(t,e)=>{var a;F.set(t,{...R(t),...e});const n=R(t);(a=d.get(t))==null||a.forEach(u=>u(n))},O=(t,e={})=>{const n=e.id??I(),a=s.ref(R(n)),u=(()=>{var S;const r={"Content-Type":"application/json","X-STREAM-ID":n},l=e.csrfToken??((S=document.querySelector('meta[name="csrf-token"]'))==null?void 0:S.getAttribute("content"));return l&&(r["X-CSRF-TOKEN"]=l),r})(),j=s.ref(a.value.data),k=s.ref(a.value.jsonData),y=s.ref(a.value.isFetching),m=s.ref(a.value.isStreaming);let g,C;const o=r=>{H(n,r)},c=()=>{a.value.controller.abort(),(y||m)&&X(n),o({isFetching:!1,isStreaming:!1})},h=(r={})=>{const l=new AbortController,S={method:"POST",signal:l.signal,headers:{...u,...e.headers??{}},body:JSON.stringify(r),credentials:e.credentials??"same-origin"},L=W(n,S);L!==!1&&(o({isFetching:!0,controller:l}),fetch(t,L??S).then(async i=>{if(!i.ok){const w=await i.text();throw new Error(w)}if(!i.body)throw new Error("ReadableStream not yet supported in this browser.");return N(n,i),o({isFetching:!1,isStreaming:!0}),D(i.body.getReader())}).catch(i=>{o({isFetching:!1,isStreaming:!1}),A(n,i),p(n)}))},v=r=>{c(),h(r),B()},B=()=>{o({data:"",jsonData:null})},D=(r,l="")=>r.read().then(({done:S,value:L})=>{const i=new TextDecoder("utf-8").decode(L),w=l+i;K(n,i);const M={data:w};if(!S)return o(M),D(r,w);if(M.isStreaming=!1,e.json)try{M.jsonData=JSON.parse(w)}catch(U){A(n,U)}return o(M),p(n),""});return s.onMounted(()=>{g=G(n,r=>{a.value=R(n),y.value=r.isFetching,m.value=r.isStreaming,j.value=r.data,k.value=r.jsonData}),C=V(n,e),window.addEventListener("beforeunload",c),e.initialInput&&h(e.initialInput)}),s.onUnmounted(()=>{g(),C(),window.removeEventListener("beforeunload",c),q(n)||c()}),{data:s.readonly(j),jsonData:s.readonly(k),isFetching:s.readonly(y),isStreaming:s.readonly(m),id:n,send:v,cancel:c,clearData:B}},Q=(t,e={})=>{const{jsonData:n,data:a,...u}=O(t,{...e,json:!0});return{data:n,strData:a,...u}};f.useEventStream=J,f.useJsonStream=Q,f.useStream=O,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
1
+ (function(f,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],s):(f=typeof globalThis<"u"?globalThis:f||self,s(f.LaravelStreamVue={},f.Vue))})(this,function(f,s){"use strict";const T="data: ",J=(t,{eventName:e="update",endSignal:n="</stream>",glue:a=" ",replace:u=!1,onMessage:j=()=>null,onComplete:k=()=>null,onError:y=()=>null}={})=>{const m=s.ref(""),g=s.ref([]),C=Array.isArray(e)?e:[e];let o=null;const c=()=>{m.value="",g.value=[]},h=(r=!1)=>{C.forEach(l=>{o==null||o.removeEventListener(l,v)}),o==null||o.close(),o=null,r&&c()},v=r=>{if([n,`${T}${n}`].includes(r.data)){h(),k();return}u&&c(),g.value.push(r.data.startsWith(T)?r.data.substring(T.length):r.data),m.value=g.value.join(a),j(r)},B=r=>{y(r),h()},D=()=>{c(),o=new EventSource(t),C.forEach(r=>{o.addEventListener(r,v)}),o.addEventListener("error",B)};return s.onMounted(()=>{D()}),s.onUnmounted(()=>{h()}),s.watch(()=>t,(r,l)=>{r!==l&&(h(),D())}),{message:s.readonly(m),messageParts:s.readonly(g),close:h,clearMessage:c}},x="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let I=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=x[n[t]&63];return e};const b=new Map,V=(t,e)=>{b.has(t)||b.set(t,{onData:[],onError:[],onFinish:[],onResponse:[],onCancel:[],onBeforeSend:[]});const n=b.get(t);return e.onData&&n.onData.push(e.onData),e.onError&&n.onError.push(e.onError),e.onFinish&&n.onFinish.push(e.onFinish),e.onResponse&&n.onResponse.push(e.onResponse),e.onCancel&&n.onCancel.push(e.onCancel),e.onBeforeSend&&n.onBeforeSend.push(e.onBeforeSend),()=>{$(t,e)}},E=(t,e,...n)=>{const a=b.get(t);return a?a[e].map(u=>u(...n)):[]},p=t=>{E(t,"onFinish")},A=(t,e)=>{E(t,"onError",e)},N=(t,e)=>{E(t,"onResponse",e)},X=t=>{E(t,"onCancel")},K=(t,e)=>{E(t,"onData",e)},W=(t,e)=>{const n=E(t,"onBeforeSend",e);for(const a of n){if(a===!1)return!1;if(a!==null&&typeof a=="object")return a}return null},$=(t,e)=>{const n=b.get(t);n&&(e.onData&&(n.onData=n.onData.filter(a=>a!==e.onData)),e.onError&&(n.onError=n.onError.filter(a=>a!==e.onError)),e.onFinish&&(n.onFinish=n.onFinish.filter(a=>a!==e.onFinish)),e.onResponse&&(n.onResponse=n.onResponse.filter(a=>a!==e.onResponse)),e.onCancel&&(n.onCancel=n.onCancel.filter(a=>a!==e.onCancel)),e.onBeforeSend&&(n.onBeforeSend=n.onBeforeSend.filter(a=>a!==e.onBeforeSend)))},F=new Map,d=new Map,R=t=>{const e=F.get(t);if(e)return e;const n={controller:new AbortController,data:"",isFetching:!1,isStreaming:!1,jsonData:null};return F.set(t,n),n},P=t=>(d.has(t)||d.set(t,[]),d.get(t)),q=t=>{var e;return d.has(t)&&((e=d.get(t))==null?void 0:e.length)},G=(t,e)=>(P(t).push(e),()=>{d.set(t,P(t).filter(n=>n!==e)),q(t)||(F.delete(t),d.delete(t))}),H=(t,e)=>{var a;F.set(t,{...R(t),...e});const n=R(t);(a=d.get(t))==null||a.forEach(u=>u(n))},O=(t,e={})=>{const n=e.id??I(),a=s.ref(R(n)),u=(()=>{var S;const r={"Content-Type":"application/json","X-STREAM-ID":n},l=e.csrfToken??((S=document.querySelector('meta[name="csrf-token"]'))==null?void 0:S.getAttribute("content"));return l&&(r["X-CSRF-TOKEN"]=l),r})(),j=s.ref(a.value.data),k=s.ref(a.value.jsonData),y=s.ref(a.value.isFetching),m=s.ref(a.value.isStreaming);let g,C;const o=r=>{H(n,r)},c=()=>{a.value.controller.abort(),(y||m)&&X(n),o({isFetching:!1,isStreaming:!1})},h=r=>{const l=new AbortController,S={method:"POST",signal:l.signal,headers:{...u,...e.headers??{}},body:JSON.stringify(r??{}),credentials:e.credentials??"same-origin"},L=W(n,S);L!==!1&&(o({isFetching:!0,controller:l}),fetch(t,L??S).then(async i=>{if(!i.ok){const w=await i.text();throw new Error(w)}if(!i.body)throw new Error("ReadableStream not yet supported in this browser.");return N(n,i),o({isFetching:!1,isStreaming:!0}),D(i.body.getReader())}).catch(i=>{o({isFetching:!1,isStreaming:!1}),A(n,i),p(n)}))},v=r=>{c(),h(r),B()},B=()=>{o({data:"",jsonData:null})},D=(r,l="")=>r.read().then(({done:S,value:L})=>{const i=new TextDecoder("utf-8").decode(L),w=l+i;K(n,i);const M={data:w};if(!S)return o(M),D(r,w);if(M.isStreaming=!1,e.json)try{M.jsonData=JSON.parse(w)}catch(U){A(n,U)}return o(M),p(n),""});return s.onMounted(()=>{g=G(n,r=>{a.value=R(n),y.value=r.isFetching,m.value=r.isStreaming,j.value=r.data,k.value=r.jsonData}),C=V(n,e),window.addEventListener("beforeunload",c),e.initialInput&&h(e.initialInput)}),s.onUnmounted(()=>{g(),C(),window.removeEventListener("beforeunload",c),q(n)||c()}),{data:s.readonly(j),jsonData:s.readonly(k),isFetching:s.readonly(y),isStreaming:s.readonly(m),id:n,send:v,cancel:c,clearData:B}},Q=(t,e={})=>{const{jsonData:n,data:a,...u}=O(t,{...e,json:!0});return{data:n,strData:a,...u}};f.useEventStream=J,f.useJsonStream=Q,f.useStream=O,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,68 +1,68 @@
1
1
  {
2
- "name": "@laravel/stream-vue",
3
- "version": "0.3.4",
4
- "description": "Laravel streaming hooks for Vue",
5
- "keywords": [
6
- "laravel",
7
- "stream",
8
- "use-stream",
9
- "server-sent-events",
10
- "sse",
11
- "vue",
12
- "composables"
13
- ],
14
- "homepage": "https://github.com/laravel/stream/tree/main/packages/vue#readme",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/laravel/stream.git"
18
- },
19
- "bugs": {
20
- "url": "https://github.com/laravel/stream/issues"
21
- },
22
- "license": "MIT",
23
- "author": {
24
- "name": "Taylor Otwell"
25
- },
26
- "type": "module",
27
- "main": "dist/index.umd.js",
28
- "module": "dist/index.es.js",
29
- "types": "dist/index.d.ts",
30
- "exports": {
31
- ".": {
32
- "types": "./dist/index.d.ts",
33
- "import": "./dist/index.es.js",
34
- "require": "./dist/index.umd.js"
2
+ "name": "@laravel/stream-vue",
3
+ "version": "0.3.8",
4
+ "description": "Laravel streaming hooks for Vue",
5
+ "keywords": [
6
+ "laravel",
7
+ "stream",
8
+ "use-stream",
9
+ "server-sent-events",
10
+ "sse",
11
+ "vue",
12
+ "composables"
13
+ ],
14
+ "homepage": "https://github.com/laravel/stream/tree/main/packages/vue#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/laravel/stream.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/laravel/stream/issues"
21
+ },
22
+ "license": "MIT",
23
+ "author": {
24
+ "name": "Taylor Otwell"
25
+ },
26
+ "type": "module",
27
+ "main": "dist/index.umd.js",
28
+ "module": "dist/index.es.js",
29
+ "types": "dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.es.js",
34
+ "require": "./dist/index.umd.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "scripts": {
41
+ "build": "vite build",
42
+ "lint": "eslint --config eslint.config.mjs \"src/**/*.ts\"",
43
+ "prepublish": "pnpm run build",
44
+ "release": "vitest --run && npm publish",
45
+ "test": "vitest",
46
+ "format": "prettier --write ."
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^22.14.0",
50
+ "@typescript-eslint/eslint-plugin": "^8.21.0",
51
+ "@typescript-eslint/parser": "^8.21.0",
52
+ "@vitejs/plugin-vue": "^5.0.0",
53
+ "eslint": "^9.0.0",
54
+ "jsdom": "^26.0.0",
55
+ "msw": "^2.8.2",
56
+ "prettier": "^3.5.3",
57
+ "typescript": "^5.3.0",
58
+ "vite": "^5.4.19",
59
+ "vite-plugin-dts": "^4.5.3",
60
+ "vitest": "^3.1.1"
61
+ },
62
+ "peerDependencies": {
63
+ "vue": "^3.0.0"
64
+ },
65
+ "dependencies": {
66
+ "nanoid": "^5.1.5"
35
67
  }
36
- },
37
- "files": [
38
- "dist"
39
- ],
40
- "devDependencies": {
41
- "@types/node": "^22.14.0",
42
- "@typescript-eslint/eslint-plugin": "^8.21.0",
43
- "@typescript-eslint/parser": "^8.21.0",
44
- "@vitejs/plugin-vue": "^5.0.0",
45
- "eslint": "^9.0.0",
46
- "jsdom": "^26.0.0",
47
- "msw": "^2.8.2",
48
- "prettier": "^3.5.3",
49
- "typescript": "^5.3.0",
50
- "vite": "^5.4.19",
51
- "vite-plugin-dts": "^4.5.3",
52
- "vitest": "^3.1.1"
53
- },
54
- "peerDependencies": {
55
- "vue": "^3.0.0"
56
- },
57
- "dependencies": {
58
- "nanoid": "^5.1.5"
59
- },
60
- "scripts": {
61
- "build": "vite build",
62
- "lint": "eslint --config eslint.config.mjs \"src/**/*.ts\"",
63
- "prepublish": "pnpm run build",
64
- "release": "vitest --run && git push --follow-tags && pnpm publish",
65
- "test": "vitest",
66
- "format": "prettier --write ."
67
- }
68
- }
68
+ }