file-mapping
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,1 +0,1 @@ | ||
var T=Object.create;var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var y=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},g=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of b(n))!x.call(e,i)&&i!==t&&u(e,i,{get:()=>n[i],enumerable:!(r=f(n,i))||r.enumerable});return e};var m=(e,n,t)=>(t=e!=null?T(_(e)):{},g(n||!e||!e.__esModule?u(t,"default",{value:e,enumerable:!0}):t,e)),S=e=>g(u({},"__esModule",{value:!0}),e);var P={};y(P,{Mapping:()=>h,default:()=>L,mapping:()=>w});module.exports=S(P);var v=m(require("events")),c=m(require("fs"));function w(e,n,t){let r=c.default.existsSync(e)?JSON.parse(c.default.readFileSync(e,"utf8")):n,i=Promise.resolve(!0),s=0,p={get:(a,o)=>{let d=a[o];return typeof d=="object"&&d!==null&&(a[o]=new Proxy(d,p)),a[o]},set:(a,o,d)=>(a[o]=d,s++,(async()=>(await i,s!==0&&(i=new Promise(l=>{c.default.writeFileSync(e,JSON.stringify(r),"utf8"),s=0,l(!0),t&&t(r,s)}))))(),!0)};return new Proxy(r,p)}var h=class extends v.default{constructor(t,r){super();this._written=0;this._file=t,this._data=this.map(t,r)._data}get data(){return this._data}get file(){return this._file}get written(){return this._written}map(t,r){return this._data=w(t,r,(i,s)=>{this._written++,this.emit("write",i,s)}),this._file=t,this}},L=h;0&&(module.exports={Mapping,mapping}); | ||
var f=Object.create;var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var y=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},g=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of x(n))!S.call(e,i)&&i!==t&&u(e,i,{get:()=>n[i],enumerable:!(r=b(n,i))||r.enumerable});return e};var l=(e,n,t)=>(t=e!=null?f(_(e)):{},g(n||!e||!e.__esModule?u(t,"default",{value:e,enumerable:!0}):t,e)),L=e=>g(u({},"__esModule",{value:!0}),e);var O={};y(O,{Mapping:()=>h,default:()=>P,mapping:()=>v});module.exports=L(O);var w=l(require("events")),c=l(require("fs"));function v(e,n,t){let r=c.default.existsSync(e)?JSON.parse(c.default.readFileSync(e,"utf8")):n,i=Promise.resolve(!0),o=0,p=new Set,m={get:(s,a)=>{let d=s[a];return typeof d=="object"&&d!==null&&!p.has(s[a])&&(console.log("create proxy for",s[a]),s[a]=new Proxy(d,m),p.add(s[a])),s[a]},set:(s,a,d)=>(s[a]=d,o++,(async()=>(await i,o!==0&&(i=new Promise(T=>{c.default.writeFileSync(e,JSON.stringify(r),"utf8"),o=0,T(!0),t&&t(r,o)}))))(),!0)};return new Proxy(r,m)}var h=class extends w.default{constructor(t,r){super();this._written=0;this._file=t,this._data=this.map(t,r)._data}get data(){return this._data}get file(){return this._file}get written(){return this._written}map(t,r){return this._data=v(t,r,(i,o)=>{this._written++,this.emit("write",i,o)}),this._file=t,this}},P=h;0&&(module.exports={Mapping,mapping}); |
{ | ||
"name": "file-mapping", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A library that maps JSON file and in-memory data, and using lazy-writing strategy to reduce disk I/O.", | ||
@@ -5,0 +5,0 @@ "author": "JacobLinCool <jacoblincool@gmail.com> (https://github.com/JacobLinCool)", |
@@ -39,7 +39,7 @@ # File Mapping | ||
const data = mapping("./data.json", {}, (data, changes) => { | ||
console.log(`write ${changes.length} changes into disk`, data); | ||
console.log(`write ${changes.length} changes into disk`, data); | ||
}); | ||
for (let i = 0; i < 1000; i++) { | ||
data[`key-${i}`] = `value-${i}`; | ||
data[`key-${i}`] = `value-${i}`; | ||
} | ||
@@ -59,8 +59,8 @@ ``` | ||
mapping.on("write", (data, changes) => { | ||
console.log(`write ${changes.length} changes into disk`, data); | ||
console.log(`write ${changes.length} changes into disk`, data); | ||
}); | ||
for (let i = 0; i < 1000; i++) { | ||
data[`key-${i}`] = `value-${i}`; | ||
data[`key-${i}`] = `value-${i}`; | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8480
74