2 lines
19 KiB
JavaScript
2 lines
19 KiB
JavaScript
|
import{an as R,z as K,Q as U,aq as Y}from"./entry.aa7356a8.js";import{g as T,a as $,b as I,s as W,c as j,w as b,d as B,f as J}from"./query.0cbfc7c3.js";import{p as H}from"./index.a6ef77ff.js";import{u as M}from"./preview.6387966e.js";import"./index.57e42e18.js";import"./utils.96f61a62.js";const q="memory",G=()=>{const r=new Map;return{name:q,options:{},hasItem(t){return r.has(t)},getItem(t){return r.get(t)||null},getItemRaw(t){return r.get(t)||null},setItem(t,n){r.set(t,n)},setItemRaw(t,n){r.set(t,n)},removeItem(t){r.delete(t)},getKeys(){return Array.from(r.keys())},clear(){r.clear()},dispose(){r.clear()}}};function Z(r){return!r||typeof r.then!="function"?Promise.resolve(r):r}function g(r,...t){try{return Z(r(...t))}catch(n){return Promise.reject(n)}}function F(r){const t=typeof r;return r===null||t!=="object"&&t!=="function"}function V(r){const t=Object.getPrototypeOf(r);return!t||t.isPrototypeOf(Object)}function D(r){if(F(r))return String(r);if(V(r)||Array.isArray(r))return JSON.stringify(r);if(typeof r.toJSON=="function")return D(r.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function z(){if(typeof Buffer===void 0)throw new TypeError("[unstorage] Buffer is not supported!")}const _="base64:";function Q(r){if(typeof r=="string")return r;z();const t=Buffer.from(r).toString("base64");return _+t}function X(r){return typeof r!="string"||!r.startsWith(_)?r:(z(),Buffer.from(r.slice(_.length),"base64"))}const k=["hasItem","getItem","getItemRaw","setItem","setItemRaw","removeItem","getMeta","setMeta","removeMeta","getKeys","clear","mount","unmount"];function ee(r,t){if(t=v(t),!t)return r;const n={...r};for(const i of k)n[i]=(s="",...c)=>r[i](t+s,...c);return n.getKeys=(i="",...s)=>r.getKeys(t+i,...s).then(c=>c.map(u=>u.slice(t.length))),n}function p(r){return r?r.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function v(r){return r=p(r),r?r+":":""}const te="memory",re=()=>{const r=new Map;return{name:te,options:{},hasItem(t){return r.has(t)},getItem(t){return r.get(t)||null},getItemRaw(t){return r.get(t)||null},setItem(t,n){r.set(t,n)},setItemRaw(t,n){r.set(t,n)},removeItem(t){r.delete(t)},getKeys(){return Array.from(r.keys())},clear(){r.clear()},dispose(){r.clear()}}};function ne(r={}){const t={mounts:{"":r.driver||re()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},n=e=>{for(const a of t.mountpoints)if(e.startsWith(a))return{base:a,relativeKey:e.slice(a.length),driver:t.mounts[a]};return{base:"",relativeKey:e,driver:t.mounts[""]}},i=(e,a)=>t.mountpoints.filter(o=>o.startsWith(e)||a&&e.startsWith(o)).map(o=>({relativeBase:e.length>o.length?e.slice(o.length):void 0,mountpoint:o,driver:t.mounts[o]})),s=(e,a)=>{if(t.watching){a=p(a);for(const o of t.watchListeners)o(e,a)}},c=async()=>{if(!t.watching){t.watching=!0;for(const e in t.mounts)t.unwatch[e]=await P(t.mounts[e],s,e)}},u=async()=>{if(t.watching){for(const e in t.unwatch)await t.unwatch[e]();t.unwatch={},t.watching=!1}},h={hasItem(e,a={}){e=p(e);const{relativeKey:o,driver:f}=n(e);return g(f.hasItem,o,a)},getItem(e,a={}){e=p(e);const{relativeKey:o,driver:f}=n(e);return g(f.getItem,o,a).then(m=>R(m))},getItemRaw(e,a={}){e=p(e);const{relativeKey:o,driver:f}=n(e);return f.getItemRaw?g(f.getItemRaw,o,a):g(f.getItem,o,a).then(m=>X(m))},async setItem(e,a,o={}){if(a===void 0)return h.removeItem(e);e=p(e);const{relativeKey:f,driver:m}=n(e);m.setItem&&(await g(m.setItem,f,D(a),o),m.watch||s("update",e))},async setItemRaw(e,a,o={}){if(a===void 0)return h.removeItem(e,o);e=p(e);const{relativeKey:f,driver:m}=n(e);if(m.setItemRaw)await g(m.setItemRaw,f,a,o);else if(m.setItem)await g(m.setItem,f,Q(a),o);else return;m.watch||s("update",e)},async removeItem(e,a={}){typeof a=="boolean"&&(a={removeMata:a}),e=p(e);const{relativeKey:o,driver:f}=n(e);f.removeItem&&(await g(f.removeItem,o,a),a.removeMata&&await g(f.removeItem,o+"$",a),f.watch||s("remove",e))},async getMeta(e,a={}){typeof a=="boolean"&&(a={nativeOnly:a}),e=p(e);const{relativeKey:o,driver:f}=n(e),m=Object.create(null);if(f.getMeta&&Object.assign(m,await g(f.getMeta
|