@batijs/core 0.0.508 → 0.0.509
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.js +1 -1
- package/package.json +2 -2
- package/dist/jiti-W5Y5D52V.js +0 -483
- package/dist/src-UAKFXUB2.js +0 -9
package/dist/src-UAKFXUB2.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createRequire as BATI_core_createRequire } from 'module';
|
|
2
|
-
import { fileURLToPath as BATI_fileURLToPath } from "node:url";
|
|
3
|
-
import { dirname as BATI_dirname } from "node:path";
|
|
4
|
-
const require = BATI_core_createRequire(import.meta.url);
|
|
5
|
-
|
|
6
|
-
const __filename = BATI_fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = BATI_dirname(__filename);
|
|
8
|
-
|
|
9
|
-
import{b as h}from"./chunk-C2T5VISX.js";function i(s){if(!s||!(s instanceof URL)&&typeof s!="string")throw new TypeError("Path must be a non-empty string or URL.")}function U(s){if(typeof s!="string"&&!(s instanceof ArrayBuffer)&&!ArrayBuffer.isView(s))throw new TypeError("File contents must be a string, ArrayBuffer, or ArrayBuffer view.")}function N(s){if(s instanceof Uint8Array)return s;if(typeof s=="string")return z.encode(s);if(s instanceof ArrayBuffer)return new Uint8Array(s);if(ArrayBuffer.isView(s)){let t=s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength);return new Uint8Array(t)}throw new TypeError("Invalid contents type. Expected string or ArrayBuffer.")}var M,z,E,T,A,g,l,O=h(()=>{"use strict";M=new TextDecoder,z=new TextEncoder,E=class extends Error{constructor(t){super(`Method "${t}" does not exist on impl.`)}},T=class extends Error{constructor(t){super(`Method "${t}" is not supported on this impl.`)}},A=class extends Error{constructor(){super("Implementation already set.")}};g=class{type;data;timestamp=Date.now();constructor(t,e){this.type=t,this.data=e}},l=class{#t;#e;#i=new Map;constructor({impl:t}){this.#t=t,this.#e=t}#s(t,...e){for(let r of this.#i.values())r.push(new g("call",{methodName:t,args:e}))}logStart(t){if(!t||typeof t!="string")throw new TypeError("Log name must be a non-empty string.");if(this.#i.has(t))throw new Error(`Log "${t}" already exists.`);this.#i.set(t,[])}logEnd(t){if(this.#i.has(t)){let e=this.#i.get(t);return this.#i.delete(t),e}throw new Error(`Log "${t}" does not exist.`)}isBaseImpl(){return this.#e===this.#t}setImpl(t){if(this.#s("implSet",t),this.#e!==this.#t)throw new A;this.#e=t}resetImpl(){this.#s("implReset"),this.#e=this.#t}#n(t){if(typeof this.#e[t]!="function")throw new E(t)}#o(t,e){if(typeof this.#e[t]!="function")throw new T(e)}#r(t,...e){return this.#s(t,...e),this.#n(t),this.#e[t](...e)}#c(t,...e){return this.#n(t),this.#e[t](...e)}#a(t,e,...r){return this.#s(e,...r),this.#o(t,e),this.#e[t](...r)}async text(t){i(t);let e=await this.#a("bytes","text",t);return e?M.decode(e):void 0}async json(t){i(t);let e=await this.#a("bytes","json",t);return e?JSON.parse(M.decode(e)):void 0}async arrayBuffer(t){return i(t),(await this.#a("bytes","arrayBuffer",t))?.buffer}async bytes(t){return i(t),this.#r("bytes",t)}async write(t,e){i(t),U(e),this.#s("write",t,e);let r=N(e);return this.#c("write",t,r)}async append(t,e){i(t),U(e),this.#s("append",t,e);let r=N(e);return this.#c("append",t,r)}async isFile(t){return i(t),this.#r("isFile",t)}async isDirectory(t){return i(t),this.#r("isDirectory",t)}async createDirectory(t){return i(t),this.#r("createDirectory",t)}async delete(t){return i(t),this.#r("delete",t)}async deleteAll(t){return i(t),this.#r("deleteAll",t)}async*list(t){i(t),yield*await this.#r("list",t)}async*walk(t,{directoryFilter:e=()=>!0,entryFilter:r=()=>!0}={}){i(t),this.#s("walk",t,{directoryFilter:e,entryFilter:r});let n=async function*(o,{directoryFilter:c,entryFilter:f,parentPath:L="",depth:S=1}){let v;try{v=await this.#c("list",o)}catch(a){if(a.code==="ENOENT")return;throw a}for await(let a of v){let u={path:a.name,depth:S,...a};L&&(u.path=`${L}/${u.path}`);let p=f(u);if(p.then&&(p=await p),p&&(yield u),a.isDirectory){let y=c(u);if(y.then&&(y=await y),!y)continue;let j=o instanceof URL?new URL(a.name,o.href.endsWith("/")?o.href:`${o.href}/`):`${o.endsWith("/")?o:`${o}/`}${a.name}`;yield*n(j,{directoryFilter:c,entryFilter:f,parentPath:u.path,depth:S+1})}}}.bind(this);yield*n(t,{directoryFilter:e,entryFilter:r})}async size(t){return i(t),this.#r("size",t)}async lastModified(t){return i(t),this.#r("lastModified",t)}async copy(t,e){return i(t),i(e),this.#r("copy",t,e)}async copyAll(t,e){return i(t),i(e),this.#r("copyAll",t,e)}async move(t,e){return i(t),i(e),this.#r("move",t,e)}async moveAll(t,e){return i(t),i(e),this.#r("moveAll",t,e)}}});var F=h(()=>{"use strict"});var $=h(()=>{"use strict"});var x=h(()=>{"use strict";O();F();$()});function W(s,t){let e=Date.now()-s.lastAttempt,r=Math.max(s.lastAttempt-s.timestamp,1),n=Math.min(r*1.2,t);return e>=n}function _(s,t){return s.age>t}var b,m,B=h(()=>{"use strict";b=class{id=Math.random().toString(36).slice(2);fn;error;timestamp=Date.now();lastAttempt=this.timestamp;resolve;reject;signal;constructor(t,e,r,n,o){this.fn=t,this.error=e,this.timestamp=Date.now(),this.lastAttempt=Date.now(),this.resolve=r,this.reject=n,this.signal=o}get age(){return Date.now()-this.timestamp}},m=class{#t=[];#e;#i;#s;#n;constructor(t,{timeout:e=6e4,maxDelay:r=100}={}){if(typeof t!="function")throw new Error("Missing function to check errors");this.#n=t,this.#e=e,this.#i=r}retry(t,{signal:e}={}){e?.throwIfAborted();let r;try{r=t()}catch(n){return Promise.reject(new Error(`Synchronous error: ${n.message}`,{cause:n}))}return!r||typeof r.then!="function"?Promise.reject(new Error("Result is not a promise.")):Promise.resolve(r).catch(n=>{if(!this.#n(n))throw n;return new Promise((o,c)=>{this.#t.push(new b(t,n,o,c,e)),e?.addEventListener("abort",()=>{c(e.reason)}),this.#o()})})}#o(){clearTimeout(this.#s),this.#s=void 0;let t=this.#t.shift();if(!t)return;let e=()=>{this.#s=setTimeout(()=>this.#o(),0)};if(_(t,this.#e)){t.reject(t.error),e();return}if(!W(t,this.#i)){this.#t.push(t),e();return}t.lastAttempt=Date.now(),Promise.resolve(t.fn()).then(r=>t.resolve(r)).catch(r=>{if(!this.#n(r)){t.reject(r);return}t.lastAttempt=Date.now(),this.#t.push(t)}).finally(()=>this.#o())}}});import w from"path";import V from"fs/promises";import{fileURLToPath as d}from"url";var Y,D,R,I,nt,k=h(()=>{"use strict";x();B();Y=new Set(["ENFILE","EMFILE"]),D=class{name;isFile;isDirectory;isSymlink;constructor(t){this.name=t.name,this.isFile=t.isFile(),this.isDirectory=t.isDirectory(),this.isSymlink=t.isSymbolicLink()}},R=class{#t;#e;constructor({fsp:t=V}={}){this.#t=t,this.#e=new m(e=>Y.has(e.code))}bytes(t){return this.#e.retry(()=>this.#t.readFile(t)).then(e=>new Uint8Array(e.buffer)).catch(e=>{if(e.code!=="ENOENT")throw e})}async write(t,e){let r=Buffer.from(e);return this.#e.retry(()=>this.#t.writeFile(t,r)).catch(n=>{if(n.code==="ENOENT"){let o=w.dirname(t instanceof URL?d(t):t);return this.#t.mkdir(o,{recursive:!0}).then(()=>this.#t.writeFile(t,r))}throw n})}async append(t,e){let r=Buffer.from(e);return this.#e.retry(()=>this.#t.appendFile(t,r)).catch(n=>{if(n.code==="ENOENT"){let o=w.dirname(t instanceof URL?d(t):t);return this.#t.mkdir(o,{recursive:!0}).then(()=>this.#t.appendFile(t,r))}throw n})}isFile(t){return this.#t.stat(t).then(e=>e.isFile()).catch(e=>{if(e.code==="ENOENT")return!1;throw e})}isDirectory(t){return this.#t.stat(t).then(e=>e.isDirectory()).catch(e=>{if(e.code==="ENOENT")return!1;throw e})}async createDirectory(t){await this.#t.mkdir(t,{recursive:!0})}delete(t){return this.#t.rm(t).then(()=>!0).catch(e=>{if(e.code==="ERR_FS_EISDIR")return this.#t.rmdir(t).then(()=>!0);if(e.code==="ENOENT")return!1;throw e})}deleteAll(t){return this.#t.rm(t,{recursive:!0}).then(()=>!0).catch(e=>{if(e.code==="ENOENT")return!1;throw e})}async*list(t){let e=await this.#t.readdir(t,{withFileTypes:!0});for(let r of e)yield new D(r)}size(t){return this.#t.stat(t).then(e=>e.size).catch(e=>{if(e.code!=="ENOENT")throw e})}lastModified(t){return this.#t.stat(t).then(e=>e.mtime).catch(e=>{if(e.code!=="ENOENT")throw e})}copy(t,e){return this.#t.copyFile(t,e)}async copyAll(t,e){if(await this.isFile(t))return this.copy(t,e);let r=t instanceof URL?d(t):t,n=e instanceof URL?d(e):e;await this.createDirectory(e);for await(let o of this.list(t)){let c=w.join(r,o.name),f=w.join(n,o.name);o.isDirectory?await this.copyAll(c,f):await this.copy(c,f)}}move(t,e){return this.#t.stat(t).then(r=>{if(r.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, move '${t}' -> '${e}'`);return this.#t.rename(t,e)})}async moveAll(t,e){return this.#t.rename(t,e)}},I=class extends l{constructor({fsp:t}={}){super({impl:new R({fsp:t})})}},nt=new I});var K=h(()=>{k();x()});K();export{l as Hfs,I as NodeHfs,R as NodeHfsImpl,nt as hfs};
|