@mikestools/usefilesystem 0.0.2 → 0.0.4

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.
@@ -1 +1 @@
1
- (function(m,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],p):(m=typeof globalThis<"u"?globalThis:m||self,p(m.usefilesystem={},m.Vue))})(this,(function(m,p){"use strict";function j(){const y={name:"",path:"/",createdAt:Date.now(),files:new Map,directories:new Map},u=new Set;function g(e,t,n){for(const r of u)r(e,t,n)}function h(e){const t=e.split(/[/\\]/).filter(r=>r.length>0&&r!=="."),n=[];for(const r of t)r===".."?n.pop():n.push(r);return"/"+n.join("/")}function l(e){const t=h(e);return{segments:t.split("/").filter(r=>r.length>0),normalized:t}}function d(e){const{segments:t}=l(e);if(t.length===0)return{parentPath:"/",name:""};const n=t[t.length-1]??"";return{parentPath:"/"+t.slice(0,-1).join("/"),name:n}}function s(e,t=!1){const{segments:n}=l(e);let r=y;for(const o of n){let i=r.directories.get(o);if(!i){if(!t)return;i={name:o,path:r.path==="/"?`/${o}`:`${r.path}/${o}`,createdAt:Date.now(),files:new Map,directories:new Map},r.directories.set(o,i),g("create",i.path,"directory")}r=i}return r}function w(e){return new TextEncoder().encode(e)}function A(e){return new TextDecoder().decode(e)}function x(e){const t=e.split(".").pop()?.toLowerCase()??"";return{txt:"text/plain",html:"text/html",htm:"text/html",css:"text/css",js:"text/javascript",mjs:"text/javascript",ts:"text/typescript",tsx:"text/typescript",json:"application/json",xml:"application/xml",csv:"text/csv",md:"text/markdown",yaml:"text/yaml",yml:"text/yaml",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",svg:"image/svg+xml",webp:"image/webp",ico:"image/x-icon",pdf:"application/pdf",zip:"application/zip",gz:"application/gzip",tar:"application/x-tar",woff:"font/woff",woff2:"font/woff2",ttf:"font/ttf",otf:"font/otf",mp3:"audio/mpeg",wav:"audio/wav",mp4:"video/mp4",webm:"video/webm"}[t]??"application/octet-stream"}function S(e){return new Uint8Array(e)}function f(e,t,n={}){const{parentPath:r,name:o}=d(e),{normalized:i}=l(e);if(!o)return{success:!1,error:"Invalid file path: no filename specified"};const c=s(r,!0);if(!c)return{success:!1,error:`Failed to create parent directory: ${r}`};const a=c.files.get(o);if(a&&n.overwrite===!1)return{success:!1,error:`File already exists: ${i}`};const z=typeof t=="string"?w(t):S(t),B=Date.now(),X={name:o,path:i,content:z,size:z.length,mimeType:n.mimeType??x(o),createdAt:a?.createdAt??B,modifiedAt:B};return c.files.set(o,X),g(a?"modify":"create",i,"file"),{success:!0}}function v(e,t){const n=P(e,{encoding:"binary"}),r=typeof t=="string"?w(t):t;if(n===void 0)return f(e,r);const o=n,i=new Uint8Array(o.length+r.length);return i.set(o,0),i.set(r,o.length),f(e,i)}function P(e,t={}){const{parentPath:n,name:r}=d(e),i=s(n)?.files.get(r);return i?(t.encoding??"utf8")==="binary"?S(i.content):A(i.content):void 0}function T(e){const{parentPath:t,name:n}=d(e),o=s(t)?.files.get(n);if(o)return{name:o.name,path:o.path,size:o.size,mimeType:o.mimeType,createdAt:o.createdAt,modifiedAt:o.modifiedAt}}function M(e){return T(e)!==void 0||F(e)}function R(e){return T(e)!==void 0}function F(e){return s(e)!==void 0}function D(e){const{parentPath:t,name:n}=d(e),{normalized:r}=l(e),o=s(t);return o?o.files.has(n)?(o.files.delete(n),g("delete",r,"file"),{success:!0}):{success:!1,error:`File not found: ${r}`}:{success:!1,error:`Parent directory not found: ${t}`}}function O(e,t,n={}){const r=P(e,{encoding:"binary"});if(r===void 0)return{success:!1,error:`Source file not found: ${e}`};const o=T(e);return f(t,r,{mimeType:o?.mimeType,overwrite:n.overwrite})}function C(e,t,n={}){const r=O(e,t,{overwrite:n.overwrite});return r.success?D(e):r}function U(e,t){return C(e,t,{overwrite:!1})}function L(e){return s(e,!0)?{success:!0}:{success:!1,error:`Failed to create directory: ${e}`}}function G(e){const{parentPath:t,name:n}=d(e),{normalized:r}=l(e);if(r==="/")return{success:!1,error:"Cannot remove root directory"};const o=s(t);if(!o)return{success:!1,error:`Parent directory not found: ${t}`};const i=o.directories.get(n);return i?i.files.size>0||i.directories.size>0?{success:!1,error:`Directory not empty: ${r}`}:(o.directories.delete(n),g("delete",r,"directory"),{success:!0}):{success:!1,error:`Directory not found: ${r}`}}function W(e){const{parentPath:t,name:n}=d(e),{normalized:r}=l(e);if(r==="/")return{success:!1,error:"Cannot remove root directory"};const o=s(t);return o?o.directories.get(n)?(o.directories.delete(n),g("delete",r,"directory"),{success:!0}):{success:!1,error:`Directory not found: ${r}`}:{success:!1,error:`Parent directory not found: ${t}`}}function E(e,t={}){const{recursive:n=!1,filesOnly:r=!1,directoriesOnly:o=!1}=t,i=e==="/"||e===""?y:s(e);if(!i)return[];const c=[];if(!o)for(const a of i.files.values())c.push({name:a.name,path:a.path,type:"file",size:a.size});if(!r){for(const a of i.directories.values())if(c.push({name:a.name,path:a.path,type:"directory"}),n){const z=E(a.path,t);c.push(...z)}}return c}function k(e){const t=s(e);if(t)return{name:t.name,path:t.path,createdAt:t.createdAt}}function b(){const e=[];function t(n){for(const r of n.files.values())e.push(r);for(const r of n.directories.values())t(r)}return t(y),e}function $(){return b().map(e=>e.path)}function q(){let e=0,t=0,n=0;function r(o){for(const i of o.files.values())e++,n+=i.size;for(const i of o.directories.values())t++,r(i)}return r(y),{totalFiles:e,totalDirectories:t,totalSize:n}}function N(){y.files.clear(),y.directories.clear(),g("delete","/","directory")}function I(e){const t=$(),n=e.replace(/\./g,"\\.").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*"),r=new RegExp(`^${n}$`);return t.filter(o=>r.test(o))}function V(e){const t=e.startsWith(".")?e:`.${e}`;return $().filter(n=>n.endsWith(t))}function H(e){return u.add(e),()=>{u.delete(e)}}function K(){const e={};for(const t of b()){const n=btoa(Array.from(t.content,r=>String.fromCharCode(r)).join(""));e[t.path]={content:n,mimeType:t.mimeType}}return e}function Q(e){N();for(const[t,{content:n,mimeType:r}]of Object.entries(e)){const o=atob(n),i=Uint8Array.from(o,c=>c.charCodeAt(0));f(t,i,{mimeType:r})}}return{writeFile:f,appendFile:v,readFile:P,stat:T,exists:M,isFile:R,isDirectory:F,remove:D,copy:O,move:C,rename:U,mkdir:L,rmdir:G,rmdirRecursive:W,list:E,statDirectory:k,getAllFiles:b,getAllPaths:$,getStats:q,clear:N,find:I,findByExtension:V,watch:H,toJSON:K,fromJSON:Q}}function J(y={}){const{adapter:u,autoPersist:g=!1}=y,h=j(),l=p.shallowRef(0);function d(){l.value++,g&&u&&x()}h.watch(()=>{d()});const s=p.computed(()=>(l.value,h.getStats())),w=p.computed(()=>s.value.totalFiles),A=p.computed(()=>s.value.totalSize);async function x(){if(!u)throw new Error("No storage adapter configured");const f=h.toJSON(),v=new TextEncoder().encode(JSON.stringify(f));await u.save("filesystem",v)}async function S(){if(!u)throw new Error("No storage adapter configured");const f=await u.load("filesystem");if(f){const v=JSON.parse(new TextDecoder().decode(f));h.fromJSON(v),d()}}return{...h,stats:s,fileCount:w,totalSize:A,persist:x,restore:S}}m.createFileSystem=j,m.useFileSystem=J,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(F,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],v):(F=typeof globalThis<"u"?globalThis:F||self,v(F.usefilesystem={},F.Vue))})(this,(function(F,v){"use strict";function oe(){const g={name:"",path:"/",createdAt:Date.now(),files:new Map,directories:new Map},p=new Set;function S(e,t,n){for(const r of p)r(e,t,n)}function u(e){const t=e.split(/[/\\]/).filter(r=>r.length>0&&r!=="."),n=[];for(const r of t)r===".."?n.pop():n.push(r);return"/"+n.join("/")}function l(e){const t=u(e);return{segments:t.split("/").filter(r=>r.length>0),normalized:t}}function y(e){const{segments:t}=l(e);if(t.length===0)return{parentPath:"/",name:""};const n=t[t.length-1]??"";return{parentPath:"/"+t.slice(0,-1).join("/"),name:n}}function d(e,t=!1){const{segments:n}=l(e);let r=g;for(const o of n){let c=r.directories.get(o);if(!c){if(!t)return;c={name:o,path:r.path==="/"?`/${o}`:`${r.path}/${o}`,createdAt:Date.now(),files:new Map,directories:new Map},r.directories.set(o,c),S("create",c.path,"directory")}r=c}return r}function f(e){return new TextEncoder().encode(e)}function C(e){return new TextDecoder().decode(e)}function L(e){const t=e.split(".").pop()?.toLowerCase()??"";return{txt:"text/plain",html:"text/html",htm:"text/html",css:"text/css",js:"text/javascript",mjs:"text/javascript",ts:"text/typescript",tsx:"text/typescript",json:"application/json",xml:"application/xml",csv:"text/csv",md:"text/markdown",yaml:"text/yaml",yml:"text/yaml",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",svg:"image/svg+xml",webp:"image/webp",ico:"image/x-icon",pdf:"application/pdf",zip:"application/zip",gz:"application/gzip",tar:"application/x-tar",woff:"font/woff",woff2:"font/woff2",ttf:"font/ttf",otf:"font/otf",mp3:"audio/mpeg",wav:"audio/wav",mp4:"video/mp4",webm:"video/webm"}[t]??"application/octet-stream"}function E(e){return new Uint8Array(e)}function N(e){const t=e.lastIndexOf(".");return t<=0||t===e.length-1?"":e.slice(t)}function P(e){return e.startsWith("text/")||e==="application/json"||e==="application/xml"||e==="application/javascript"||e==="application/typescript"||e.endsWith("+xml")||e.endsWith("+json")}function M(e){const{segments:t}=l(e);return t.length}function B(e){let t=0;for(const n of e.files.values())t+=n.size;for(const n of e.directories.values())t+=B(n);return t}function T(e,t,n={}){const{parentPath:r,name:o}=y(e),{normalized:c}=l(e);if(!o)return{success:!1,error:"Invalid file path: no filename specified"};const m=d(r,!0);if(!m)return{success:!1,error:`Failed to create parent directory: ${r}`};const w=m.files.get(o);if(w&&n.overwrite===!1)return{success:!1,error:`File already exists: ${c}`};const x=typeof t=="string"?f(t):E(t),k=Date.now(),ne={name:o,path:c,content:x,size:x.length,mimeType:n.mimeType??L(o),createdAt:w?.createdAt??k,modifiedAt:k};return m.files.set(o,ne),S(w?"modify":"create",c,"file"),{success:!0}}function K(e,t){const n=R(e,{encoding:"binary"}),r=typeof t=="string"?f(t):t;if(n===void 0)return T(e,r);const o=n,c=new Uint8Array(o.length+r.length);return c.set(o,0),c.set(r,o.length),T(e,c)}function R(e,t={}){const{parentPath:n,name:r}=y(e),c=d(n)?.files.get(r);return c?(t.encoding??"utf8")==="binary"?E(c.content):C(c.content):void 0}function z(e){const{parentPath:t,name:n}=y(e),o=d(t)?.files.get(n);if(!o)return;const c=N(o.name),m=P(o.mimeType);return{name:o.name,path:o.path,size:o.size,mimeType:o.mimeType,createdAt:o.createdAt,modifiedAt:o.modifiedAt,extension:c,isText:m,isBinary:!m,parentPath:t,depth:M(o.path)}}function H(e){return z(e)!==void 0||O(e)}function Q(e){return z(e)!==void 0}function O(e){return d(e)!==void 0}function j(e){const{parentPath:t,name:n}=y(e),{normalized:r}=l(e),o=d(t);return o?o.files.has(n)?(o.files.delete(n),S("delete",r,"file"),{success:!0}):{success:!1,error:`File not found: ${r}`}:{success:!1,error:`Parent directory not found: ${t}`}}function J(e,t,n={}){const r=R(e,{encoding:"binary"});if(r===void 0)return{success:!1,error:`Source file not found: ${e}`};const o=z(e);return T(t,r,{mimeType:o?.mimeType,overwrite:n.overwrite})}function G(e,t,n={}){const r=J(e,t,{overwrite:n.overwrite});return r.success?j(e):r}function V(e,t){return G(e,t,{overwrite:!1})}function I(e){return d(e,!0)?{success:!0}:{success:!1,error:`Failed to create directory: ${e}`}}function X(e){const{parentPath:t,name:n}=y(e),{normalized:r}=l(e);if(r==="/")return{success:!1,error:"Cannot remove root directory"};const o=d(t);if(!o)return{success:!1,error:`Parent directory not found: ${t}`};const c=o.directories.get(n);return c?c.files.size>0||c.directories.size>0?{success:!1,error:`Directory not empty: ${r}`}:(o.directories.delete(n),S("delete",r,"directory"),{success:!0}):{success:!1,error:`Directory not found: ${r}`}}function Z(e){const{parentPath:t,name:n}=y(e),{normalized:r}=l(e);if(r==="/")return{success:!1,error:"Cannot remove root directory"};const o=d(t);return o?o.directories.get(n)?(o.directories.delete(n),S("delete",r,"directory"),{success:!0}):{success:!1,error:`Directory not found: ${r}`}:{success:!1,error:`Parent directory not found: ${t}`}}function D(e,t={}){const{recursive:n=!1,filesOnly:r=!1,directoriesOnly:o=!1}=t,c=e==="/"||e===""?g:d(e);if(!c)return[];const m=[];if(!o)for(const w of c.files.values())m.push({name:w.name,path:w.path,type:"file",size:w.size});if(!r){for(const w of c.directories.values())if(m.push({name:w.name,path:w.path,type:"directory"}),n){const x=D(w.path,t);m.push(...x)}}return m}function _(e){const{normalized:t}=l(e),n=t==="/"?g:d(e);if(!n)return;const{parentPath:r}=y(t);return{name:n.name||"/",path:n.path,createdAt:n.createdAt,parentPath:t==="/"?"/":r,depth:M(n.path),fileCount:n.files.size,directoryCount:n.directories.size,totalSize:B(n)}}function U(){const e=[];function t(n){for(const r of n.files.values())e.push(r);for(const r of n.directories.values())t(r)}return t(g),e}function W(){return U().map(e=>e.path)}function Y(){let e=0,t=0,n=0;function r(o){for(const c of o.files.values())e++,n+=c.size;for(const c of o.directories.values())t++,r(c)}return r(g),{totalFiles:e,totalDirectories:t,totalSize:n}}function q(){g.files.clear(),g.directories.clear(),S("delete","/","directory")}function ee(e){const t=W(),n=e.replace(/\./g,"\\.").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*"),r=new RegExp(`^${n}$`);return t.filter(o=>r.test(o))}function te(e){const t=e.startsWith(".")?e:`.${e}`;return W().filter(n=>n.endsWith(t))}function i(e,t){if(!t){const b=e;return p.add(b),()=>{p.delete(b)}}const{pattern:n,events:r,type:o="all",debounce:c,path:m,recursive:w=!1}=t;let x,k=[];function ne(b,h){const $=h.replace(/\./g,"\\.").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*");return new RegExp(`^${$}$`).test(b)}function ae(b,h,$){if(r&&!r.includes(b)||o!=="all"&&o!==$||n&&!ne(h,n))return!1;if(m){const A=m.endsWith("/")?m.slice(0,-1):m;if(w){if(!h.startsWith(A+"/")&&h!==A)return!1}else if((h.substring(0,h.lastIndexOf("/"))||"/")!==A)return!1}return!0}function fe(){const b=e;for(const h of k)b(h);k=[]}const ie=(b,h,$)=>{if(!ae(b,h,$))return;let A;b!=="delete"&&($==="file"?A=z(h):A=_(h));const re={event:b,path:h,type:$,timestamp:Date.now(),metadata:A};c!==void 0&&c>0?(k.push(re),x&&clearTimeout(x),x=setTimeout(fe,c)):e(re)};return p.add(ie),()=>{p.delete(ie),x&&clearTimeout(x),k=[]}}function s(){const e={};for(const t of U()){const n=btoa(Array.from(t.content,r=>String.fromCharCode(r)).join(""));e[t.path]={content:n,mimeType:t.mimeType}}return e}function a(e){q();for(const[t,{content:n,mimeType:r}]of Object.entries(e)){const o=atob(n),c=Uint8Array.from(o,m=>m.charCodeAt(0));T(t,c,{mimeType:r})}}return{writeFile:T,appendFile:K,readFile:R,stat:z,exists:H,isFile:Q,isDirectory:O,remove:j,copy:J,move:G,rename:V,mkdir:I,rmdir:X,rmdirRecursive:Z,list:D,statDirectory:_,getAllFiles:U,getAllPaths:W,getStats:Y,clear:q,find:ee,findByExtension:te,watch:i,toJSON:s,fromJSON:a}}function se(g={}){const{adapter:p,autoPersist:S=!1,maxSize:u,maxFiles:l,maxFileSize:y,warnAtPercentage:d=90}=g,f=oe(),C=v.shallowRef(0),L=new Set;function E(){C.value++,S&&p&&R();const i=N();if(i.percentage>=d)for(const s of L)s(i)}function N(){const s=f.getStats().totalSize,a=u??Number.MAX_SAFE_INTEGER,e=Math.max(0,a-s),t=u?s/u*100:0;return{quota:a,usage:s,available:e,percentage:Math.min(100,t)}}f.watch(()=>{E()});const P=v.computed(()=>(C.value,f.getStats())),M=v.computed(()=>P.value.totalFiles),B=v.computed(()=>P.value.totalSize),T=v.computed(()=>(C.value,N())),K=v.computed(()=>T.value.percentage>=d);async function R(){if(!p)throw new Error("No storage adapter configured");const i=f.toJSON(),s=new TextEncoder().encode(JSON.stringify(i));await p.save("filesystem",s)}async function z(){if(!p)throw new Error("No storage adapter configured");const i=await p.load("filesystem");if(i){const s=JSON.parse(new TextDecoder().decode(i));f.fromJSON(s),E()}}async function H(i,s){const a=s??`/${i.name}`;try{const e=await i.arrayBuffer(),t=new Uint8Array(e);return f.writeFile(a,t,{mimeType:i.type||void 0})}catch(e){return{success:!1,error:e instanceof Error?e.message:"Failed to import file"}}}async function Q(i,s="/"){const e=(s.endsWith("/")?s.slice(0,-1):s)||"";for(const t of Array.from(i)){const n=e===""?`/${t.name}`:`${e}/${t.name}`,r=await H(t,n);if(!r.success)return r}return{success:!0}}function O(i){return i.byteOffset===0&&i.byteLength===i.buffer.byteLength?i.buffer:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)}function j(i){const s=f.readFile(i,{encoding:"binary"});if(s===void 0)return;const a=f.stat(i);return new Blob([O(s)],{type:a?.mimeType})}function J(i){const s=f.readFile(i,{encoding:"binary"});if(s===void 0)return;const a=f.stat(i);if(a)return new File([O(s)],a.name,{type:a.mimeType,lastModified:a.modifiedAt})}function G(i){const s=j(i);if(s)return URL.createObjectURL(s)}function V(i){URL.revokeObjectURL(i)}function I(i,s){const a=j(i);if(!a)return!1;const e=f.stat(i),t=s??e?.name??"download",n=URL.createObjectURL(a),r=document.createElement("a");return r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>URL.revokeObjectURL(n),1e3),!0}function X(i){i.forEach((s,a)=>{setTimeout(()=>I(s),a*100)})}const Z=64*1024,D=3;function _(i,s={}){const a=f.readFile(i,{encoding:"binary"});if(a===void 0)return;const e=s.chunkSize??Z,t=s.highWaterMark??D;let n=0;return new ReadableStream({pull(r){if(n>=a.length){r.close();return}const o=a.slice(n,n+e);r.enqueue(o),n+=e}},new CountQueuingStrategy({highWaterMark:t}))}function U(i,s={}){const a=[],e=s.highWaterMark??D;return new WritableStream({write(t){a.push(t)},close(){const t=a.reduce((o,c)=>o+c.length,0),n=new Uint8Array(t);let r=0;for(const o of a)n.set(o,r),r+=o.length;f.writeFile(i,n,{mimeType:s.mimeType,overwrite:s.overwrite})},abort(){a.length=0}},new CountQueuingStrategy({highWaterMark:e}))}async function W(i,s,a={}){const e=[],t=new WritableStream({write(n){e.push(n)}});try{await s.pipeTo(t);const n=e.reduce((c,m)=>c+m.length,0),r=new Uint8Array(n);let o=0;for(const c of e)r.set(c,o),o+=c.length;return f.writeFile(i,r,a)}catch(n){return{success:!1,error:n instanceof Error?n.message:"Stream read failed"}}}function Y(i,s={}){const a=f.readFile(i,{encoding:"binary"});if(a===void 0)return;const e=f.stat(i),t=new Headers(s.headers);return e?.mimeType&&!t.has("Content-Type")&&t.set("Content-Type",e.mimeType),t.set("Content-Length",String(a.length)),new Response(O(a),{...s,headers:t})}async function q(i){const s=f.readFile(i,{encoding:"binary"});if(s===void 0)return;const a=await crypto.subtle.digest("SHA-256",O(s));return Array.from(new Uint8Array(a)).map(t=>t.toString(16).padStart(2,"0")).join("")}function ee(i){return L.add(i),()=>{L.delete(i)}}function te(){const i=[];let s=!1,a=!1;const e={writeFile(t,n,r){return s||a||i.push({type:"writeFile",path:t,content:n,options:r}),e},remove(t){return s||a||i.push({type:"remove",path:t}),e},mkdir(t){return s||a||i.push({type:"mkdir",path:t}),e},copy(t,n){return s||a||i.push({type:"copy",source:t,destination:n}),e},move(t,n){return s||a||i.push({type:"move",source:t,destination:n}),e},commit(){if(s)return{success:!1,error:"Transaction already committed"};if(a)return{success:!1,error:"Transaction was rolled back"};const t=f.toJSON();for(const n of i){let r;switch(n.type){case"writeFile":if(y!==void 0){const o=typeof n.content=="string"?new TextEncoder().encode(n.content).length:n.content.length;if(o>y)return f.fromJSON(t),{success:!1,error:`File size ${o} exceeds maximum ${y}`}}if(l!==void 0){const o=f.getStats().totalFiles;if((!f.exists(n.path)||!f.isFile(n.path))&&o>=l)return f.fromJSON(t),{success:!1,error:`Maximum file count ${l} reached`}}r=f.writeFile(n.path,n.content,n.options);break;case"remove":r=f.remove(n.path);break;case"mkdir":r=f.mkdir(n.path);break;case"copy":r=f.copy(n.source,n.destination);break;case"move":r=f.move(n.source,n.destination);break}if(!r.success)return f.fromJSON(t),{success:!1,error:`Transaction failed at ${n.type}: ${r.error}`};if(u!==void 0){const o=f.getStats().totalSize;if(o>u)return f.fromJSON(t),{success:!1,error:`Total size ${o} exceeds maximum ${u}`}}}return s=!0,E(),{success:!0}},rollback(){!s&&!a&&(a=!0,i.length=0)}};return e}return{...f,stats:P,fileCount:M,totalSize:B,persist:R,restore:z,upload:H,uploads:Q,toBlob:j,toFile:J,createObjectURL:G,revokeObjectURL:V,download:I,downloads:X,createReadStream:_,createWriteStream:U,writeFromStream:W,toResponse:Y,computeChecksum:q,storageEstimate:T,isNearCapacity:K,onStorageWarning:ee,beginTransaction:te}}function ce(){let g;async function p(){return g||(g=await navigator.storage.getDirectory()),g}function S(u){return u.byteOffset===0&&u.byteLength===u.buffer.byteLength?u.buffer:u.buffer.slice(u.byteOffset,u.byteOffset+u.byteLength)}return{async save(u,l){const f=await(await(await p()).getFileHandle(u,{create:!0})).createWritable();await f.write(S(l)),await f.close()},async load(u){try{const f=await(await(await(await p()).getFileHandle(u)).getFile()).arrayBuffer();return new Uint8Array(f)}catch{return}},async remove(u){try{await(await p()).removeEntry(u)}catch{}},async list(){const u=await p(),l=[],y=u;for await(const[d]of y)l.push(d);return l},async clear(){const u=await p(),l=[],y=u;for await(const[d]of y)l.push(d);for(const d of l)await u.removeEntry(d,{recursive:!0})}}}F.createFileSystem=oe,F.createOPFSAdapter=ce,F.useFileSystem=se,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikestools/usefilesystem",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Vue 3 composables for in-memory virtual filesystem and ZIP archive operations",
5
5
  "type": "module",
6
6
  "main": "./dist/usefilesystem.umd.cjs",
@@ -49,46 +49,38 @@
49
49
  "vue": "^3.3.0"
50
50
  },
51
51
  "scripts": {
52
- "dev": "vite --config configs/vite.showcase.config.ts",
53
- "build": "npm run clean dist && vite build && npm run show",
54
- "build:showcase": "vite build --config configs/vite.showcase.config.ts",
52
+ "build": "npm run clean dist && vite build",
55
53
  "check": "npm run decache && vue-tsc",
56
- "check:showcase": "npm run decache && vue-tsc -p configs/tsconfig.showcase.json",
57
54
  "test": "npm run decache && vitest run --no-cache",
58
55
  "format": "npm run decache && eslint . --fix",
59
- "show": "npm run build:showcase && npm run copy dist/showcase/index.html showcase.html && npm run clean dist/showcase",
60
56
  "clean": "node -e \"try{require('fs').rmSync(process.argv[1],{recursive:true,force:true});console.log(`Deleted: ${process.argv[1]}`)}catch(e){throw e}\"",
61
57
  "copy": "node -e \"try{require('fs').cpSync(process.argv[1],process.argv[2],{force:true});console.log(`Copied: ${process.argv[1]} to ${process.argv[2]}`)}catch(e){throw e}\"",
62
58
  "decache": "node -e \"const fs=require('fs');['.eslintcache','node_modules/.vite','node_modules/.vitest','node_modules/.cache'].forEach(p=>{try{fs.rmSync(p,{recursive:true,force:true});console.log(`Cleared: ${p}`)}catch(e){}})\"",
63
- "prepublishOnly": "npm run check && npm run format && npm test && npm run show && npm run build"
59
+ "prepublishOnly": "npm run check && npm run format && npm test && npm run build"
64
60
  },
65
61
  "devDependencies": {
66
- "@eslint/js": "^9.39.1",
67
- "@mikestools/usebootstrap": "^0.0.5",
68
- "@mikestools/usedatabase": "^0.0.1",
69
- "@mikestools/usetable": "^0.0.1",
70
- "@mikestools/usetools": "^0.0.10",
62
+ "@eslint/js": "^9.39.2",
71
63
  "@popperjs/core": "^2.11.8",
72
64
  "@types/bootstrap": "^5.2.10",
73
- "@types/node": "^24.10.1",
74
- "@vitejs/plugin-vue": "^6.0.2",
75
- "@vitest/eslint-plugin": "^1.5.1",
65
+ "@types/node": "^25.0.3",
66
+ "@vitejs/plugin-vue": "^6.0.3",
67
+ "@vitest/eslint-plugin": "^1.6.3",
76
68
  "@vue/test-utils": "^2.4.6",
77
69
  "bootstrap": "^5.3.8",
78
70
  "bootstrap-icons": "^1.13.1",
79
- "eslint": "^9.39.1",
71
+ "eslint": "^9.39.2",
80
72
  "eslint-plugin-vue": "^10.6.2",
81
73
  "globals": "^16.5.0",
82
74
  "happy-dom": "^20.0.11",
83
75
  "jiti": "^2.6.1",
84
- "sass": "^1.94.2",
76
+ "sass": "^1.97.1",
85
77
  "typescript": "^5.9.3",
86
- "typescript-eslint": "^8.48.1",
87
- "vite": "^7.2.6",
78
+ "typescript-eslint": "^8.50.1",
79
+ "vite": "^7.3.0",
88
80
  "vite-plugin-dts": "^4.5.4",
89
81
  "vite-plugin-singlefile": "^2.3.0",
90
82
  "vite-svg-loader": "^5.1.0",
91
- "vitest": "^4.0.15",
92
- "vue-tsc": "^3.1.6"
83
+ "vitest": "^4.0.16",
84
+ "vue-tsc": "^3.2.1"
93
85
  }
94
86
  }