bajo 2.20.0 → 2.21.0
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/class/_helper.js +4 -6
- package/class/app.js +3 -3
- package/class/bajo.js +71 -56
- package/docs/App.html +2 -2
- package/docs/Bajo.html +2 -2
- package/docs/Cache.html +1 -1
- package/docs/class__helper.js.html +5 -6
- package/docs/class_app.js.html +8 -5
- package/docs/class_bajo.js.html +100 -62
- package/docs/class_cache.js.html +2 -0
- package/docs/data/search.json +1 -1
- package/docs/global.html +1 -1
- package/docs/lib_freeze.js.html +38 -3
- package/docs/module-Helper.html +1 -1
- package/docs/module-Lib.html +1 -1
- package/lib/freeze.js +38 -3
- package/package.json +9 -13
- package/test/bajo.test.js +0 -1
- package/wiki/CHANGES.md +12 -0
package/docs/Cache.html
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
<!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Class: Cache</title><!--[if lt IE 9]>
|
|
2
2
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
3
|
-
<![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="light"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo API</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="App.html">App</a></div><div class="sidebar-section-children"><a href="Bajo.html">Bajo</a></div><div class="sidebar-section-children"><a href="Base.html">Base</a></div><div class="sidebar-section-children"><a href="Cache.html">Cache</a></div><div class="sidebar-section-children"><a href="Err.html">Err</a></div><div class="sidebar-section-children"><a href="Log.html">Log</a></div><div class="sidebar-section-children"><a href="Plugin.html">Plugin</a></div><div class="sidebar-section-children"><a href="Print.html">Print</a></div><div class="sidebar-section-children"><a href="Tools.html">Tools</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-events"><div>Events</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#event:bajo:afterAll%257Bmethod%257D">bajo:afterAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBootComplete">bajo:afterBootComplete</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBuildCollection">bajo:afterBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterCollectHooks">bajo:afterCollectHooks</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeAll%257Bmethod%257D">bajo:beforeAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeBuildCollection">bajo:beforeBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:after%257Bmethod%257D">{ns}:after{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:beforeAppletRun">{ns}:beforeAppletRun</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:before%257Bmethod%257D">{ns}:before{method}</a></div><div class="sidebar-section-children"><a href="module-Helper%257Bns%257D_afterAppletRun.html">Helper{ns}:afterAppletRun</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-Helper.html">Helper</a></div><div class="sidebar-section-children"><a href="module-Lib.html">Lib</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#TAppConfigHandler">TAppConfigHandler</a></div><div class="sidebar-section-children"><a href="global.html#TAppEnv">TAppEnv</a></div><div class="sidebar-section-children"><a href="global.html#TBajoDataType">TBajoDataType</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatResult">TBajoFormatResult</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatType">TBajoFormatType</a></div><div class="sidebar-section-children"><a href="global.html#TLogJson">TLogJson</a></div><div class="sidebar-section-children"><a href="global.html#TLogLevels">TLogLevels</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathPairs">TNsPathPairs</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathResult">TNsPathResult</a></div><div class="sidebar-section-children"><a href="global.html#TPrintOptions">TPrintOptions</a></div><div class="sidebar-section-children"><a href="global.html#boot">boot</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div><div class="navbar-item"><a id="" href="https://bajo.app" target="">Bajo</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section><header><h1 id="Cache-title" class="has-anchor">Cache</h1><div class="class-description"><p>File-system backed cache helper with TTL-based invalidation.</p></div></header><article><div class="container-overview"><h2 id="constructor" class="has-anchor">Constructor</h2><h3 class="name has-anchor" id="Cache"><span class="type-signature"></span>new Cache<span class="signature">(app)</span></h3><div class="method-member-container flex flex-col w-100 overflow-auto mt-20"><strong>Parameters:</strong><table class="params"><thead><tr><th>Name</th><th>Type</th><th class="last">Description</th></tr></thead><tbody><tr><td class="name"><code>app</code></td><td class="type"><span class="param-type">object</span></td><td class="description last"><p>Application container.</p></td></tr></tbody></table></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line6">line 6</a></li></ul></dd></div></dl></div><h2 id="members" class="subsection-title has-anchor">Members</h2><h3 class="name has-anchor" id="_purgeItem"><span class="type-signature"></span>_purgeItem<span class="type-signature"></span></h3><div class="description"><p>Remove a specific cache namespace or all first-level namespaces.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line106">line 106</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="dispose"><span class="type-signature"></span>dispose<span class="type-signature"></span></h3><div class="description"><p>Dispose internal reference.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line142">line 142</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="getRootDir"><span class="type-signature"></span>getRootDir<span class="type-signature"></span></h3><div class="description"><p>Get root cache directory for this plugin.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line19">line 19</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="load"><span class="type-signature"></span>load<span class="type-signature"></span></h3><div class="description"><p>Load cached content when available and not expired.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line50">line 50</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="prep"><span class="type-signature"></span>prep<span class="type-signature"></span></h3><div class="description"><p>Prepare cache paths for a namespaced key and TTL.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line30">line 30</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="purge"><span class="type-signature"></span>purge<span class="type-signature"></span></h3><div class="description"><p>Purge cache by namespace or remove expired TTL directories.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line125">line 125</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="save"><span class="type-signature"></span>save<span class="type-signature"></span></h3><div class="description"><p>Save a value into cache for the given key and TTL directory.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line75">line 75</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="sync"><span class="type-signature"></span>sync<span class="type-signature"></span></h3><div class="description"><p>Return cached content, and store the fallback value if cache is empty.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line94">line 94</a></li></ul></dd></div></dl></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo API</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div><div class="navbar-item"><a id="" href="https://bajo.app" target="">Bajo</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="App.html">App</a></div><div class="sidebar-section-children"><a href="Bajo.html">Bajo</a></div><div class="sidebar-section-children"><a href="Base.html">Base</a></div><div class="sidebar-section-children"><a href="Cache.html">Cache</a></div><div class="sidebar-section-children"><a href="Err.html">Err</a></div><div class="sidebar-section-children"><a href="Log.html">Log</a></div><div class="sidebar-section-children"><a href="Plugin.html">Plugin</a></div><div class="sidebar-section-children"><a href="Print.html">Print</a></div><div class="sidebar-section-children"><a href="Tools.html">Tools</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-events"><div>Events</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#event:bajo:afterAll%257Bmethod%257D">bajo:afterAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBootComplete">bajo:afterBootComplete</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBuildCollection">bajo:afterBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterCollectHooks">bajo:afterCollectHooks</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeAll%257Bmethod%257D">bajo:beforeAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeBuildCollection">bajo:beforeBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:after%257Bmethod%257D">{ns}:after{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:beforeAppletRun">{ns}:beforeAppletRun</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:before%257Bmethod%257D">{ns}:before{method}</a></div><div class="sidebar-section-children"><a href="module-Helper%257Bns%257D_afterAppletRun.html">Helper{ns}:afterAppletRun</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-Helper.html">Helper</a></div><div class="sidebar-section-children"><a href="module-Lib.html">Lib</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#TAppConfigHandler">TAppConfigHandler</a></div><div class="sidebar-section-children"><a href="global.html#TAppEnv">TAppEnv</a></div><div class="sidebar-section-children"><a href="global.html#TBajoDataType">TBajoDataType</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatResult">TBajoFormatResult</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatType">TBajoFormatType</a></div><div class="sidebar-section-children"><a href="global.html#TLogJson">TLogJson</a></div><div class="sidebar-section-children"><a href="global.html#TLogLevels">TLogLevels</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathPairs">TNsPathPairs</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathResult">TNsPathResult</a></div><div class="sidebar-section-children"><a href="global.html#TPrintOptions">TPrintOptions</a></div><div class="sidebar-section-children"><a href="global.html#boot">boot</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>
|
|
3
|
+
<![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="light"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo API</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="App.html">App</a></div><div class="sidebar-section-children"><a href="Bajo.html">Bajo</a></div><div class="sidebar-section-children"><a href="Base.html">Base</a></div><div class="sidebar-section-children"><a href="Cache.html">Cache</a></div><div class="sidebar-section-children"><a href="Err.html">Err</a></div><div class="sidebar-section-children"><a href="Log.html">Log</a></div><div class="sidebar-section-children"><a href="Plugin.html">Plugin</a></div><div class="sidebar-section-children"><a href="Print.html">Print</a></div><div class="sidebar-section-children"><a href="Tools.html">Tools</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-events"><div>Events</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#event:bajo:afterAll%257Bmethod%257D">bajo:afterAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBootComplete">bajo:afterBootComplete</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBuildCollection">bajo:afterBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterCollectHooks">bajo:afterCollectHooks</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeAll%257Bmethod%257D">bajo:beforeAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeBuildCollection">bajo:beforeBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:after%257Bmethod%257D">{ns}:after{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:beforeAppletRun">{ns}:beforeAppletRun</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:before%257Bmethod%257D">{ns}:before{method}</a></div><div class="sidebar-section-children"><a href="module-Helper%257Bns%257D_afterAppletRun.html">Helper{ns}:afterAppletRun</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-Helper.html">Helper</a></div><div class="sidebar-section-children"><a href="module-Lib.html">Lib</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#TAppConfigHandler">TAppConfigHandler</a></div><div class="sidebar-section-children"><a href="global.html#TAppEnv">TAppEnv</a></div><div class="sidebar-section-children"><a href="global.html#TBajoDataType">TBajoDataType</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatResult">TBajoFormatResult</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatType">TBajoFormatType</a></div><div class="sidebar-section-children"><a href="global.html#TLogJson">TLogJson</a></div><div class="sidebar-section-children"><a href="global.html#TLogLevels">TLogLevels</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathPairs">TNsPathPairs</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathResult">TNsPathResult</a></div><div class="sidebar-section-children"><a href="global.html#TPrintOptions">TPrintOptions</a></div><div class="sidebar-section-children"><a href="global.html#boot">boot</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div><div class="navbar-item"><a id="" href="https://bajo.app" target="">Bajo</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section><header><h1 id="Cache-title" class="has-anchor">Cache</h1><div class="class-description"><p>File-system backed cache helper with TTL-based invalidation.</p></div></header><article><div class="container-overview"><h2 id="constructor" class="has-anchor">Constructor</h2><h3 class="name has-anchor" id="Cache"><span class="type-signature"></span>new Cache<span class="signature">(app)</span></h3><div class="method-member-container flex flex-col w-100 overflow-auto mt-20"><strong>Parameters:</strong><table class="params"><thead><tr><th>Name</th><th>Type</th><th class="last">Description</th></tr></thead><tbody><tr><td class="name"><code>app</code></td><td class="type"><span class="param-type">object</span></td><td class="description last"><p>Application container.</p></td></tr></tbody></table></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line6">line 6</a></li></ul></dd></div></dl></div><h2 id="members" class="subsection-title has-anchor">Members</h2><h3 class="name has-anchor" id="_purgeItem"><span class="type-signature"></span>_purgeItem<span class="type-signature"></span></h3><div class="description"><p>Remove a specific cache namespace or all first-level namespaces.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line108">line 108</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="dispose"><span class="type-signature"></span>dispose<span class="type-signature"></span></h3><div class="description"><p>Dispose internal reference.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line144">line 144</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="getRootDir"><span class="type-signature"></span>getRootDir<span class="type-signature"></span></h3><div class="description"><p>Get root cache directory for this plugin.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line19">line 19</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="load"><span class="type-signature"></span>load<span class="type-signature"></span></h3><div class="description"><p>Load cached content when available and not expired.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line50">line 50</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="prep"><span class="type-signature"></span>prep<span class="type-signature"></span></h3><div class="description"><p>Prepare cache paths for a namespaced key and TTL.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line30">line 30</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="purge"><span class="type-signature"></span>purge<span class="type-signature"></span></h3><div class="description"><p>Purge cache by namespace or remove expired TTL directories.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line127">line 127</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="save"><span class="type-signature"></span>save<span class="type-signature"></span></h3><div class="description"><p>Save a value into cache for the given key and TTL directory.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line75">line 75</a></li></ul></dd></div></dl><h3 class="name has-anchor" id="sync"><span class="type-signature"></span>sync<span class="type-signature"></span></h3><div class="description"><p>Return cached content, and store the fallback value if cache is empty.</p></div><dl class="details"><div class="details-item-container"><dt class="tag-source bold">Source</dt><dd class="tag-source"><ul><li><a href="class_cache.js.html">class/cache.js</a>, <a href="class_cache.js.html#line96">line 96</a></li></ul></dd></div></dl></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo API</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div><div class="navbar-item"><a id="" href="https://bajo.app" target="">Bajo</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="App.html">App</a></div><div class="sidebar-section-children"><a href="Bajo.html">Bajo</a></div><div class="sidebar-section-children"><a href="Base.html">Base</a></div><div class="sidebar-section-children"><a href="Cache.html">Cache</a></div><div class="sidebar-section-children"><a href="Err.html">Err</a></div><div class="sidebar-section-children"><a href="Log.html">Log</a></div><div class="sidebar-section-children"><a href="Plugin.html">Plugin</a></div><div class="sidebar-section-children"><a href="Print.html">Print</a></div><div class="sidebar-section-children"><a href="Tools.html">Tools</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-events"><div>Events</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#event:bajo:afterAll%257Bmethod%257D">bajo:afterAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBootComplete">bajo:afterBootComplete</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBuildCollection">bajo:afterBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterCollectHooks">bajo:afterCollectHooks</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeAll%257Bmethod%257D">bajo:beforeAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeBuildCollection">bajo:beforeBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:after%257Bmethod%257D">{ns}:after{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:beforeAppletRun">{ns}:beforeAppletRun</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:before%257Bmethod%257D">{ns}:before{method}</a></div><div class="sidebar-section-children"><a href="module-Helper%257Bns%257D_afterAppletRun.html">Helper{ns}:afterAppletRun</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-Helper.html">Helper</a></div><div class="sidebar-section-children"><a href="module-Lib.html">Lib</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#TAppConfigHandler">TAppConfigHandler</a></div><div class="sidebar-section-children"><a href="global.html#TAppEnv">TAppEnv</a></div><div class="sidebar-section-children"><a href="global.html#TBajoDataType">TBajoDataType</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatResult">TBajoFormatResult</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatType">TBajoFormatType</a></div><div class="sidebar-section-children"><a href="global.html#TLogJson">TLogJson</a></div><div class="sidebar-section-children"><a href="global.html#TLogLevels">TLogLevels</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathPairs">TNsPathPairs</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathResult">TNsPathResult</a></div><div class="sidebar-section-children"><a href="global.html#TPrintOptions">TPrintOptions</a></div><div class="sidebar-section-children"><a href="global.html#boot">boot</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>
|
|
@@ -17,7 +17,6 @@ import localizedFormat from 'dayjs/plugin/localizedFormat.js'
|
|
|
17
17
|
import weekOfYear from 'dayjs/plugin/weekOfYear.js'
|
|
18
18
|
import freeze from '../lib/freeze.js'
|
|
19
19
|
import findDeep from '../lib/find-deep.js'
|
|
20
|
-
import omitDeep from 'omit-deep'
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* Internal helpers called by Bajo and other classes. It should remains
|
|
@@ -162,8 +161,7 @@ export const lib = {
|
|
|
162
161
|
dayjs,
|
|
163
162
|
aneka,
|
|
164
163
|
freeze,
|
|
165
|
-
findDeep
|
|
166
|
-
omitDeep
|
|
164
|
+
findDeep
|
|
167
165
|
}
|
|
168
166
|
|
|
169
167
|
/**
|
|
@@ -266,6 +264,7 @@ export async function collectConfigHandlers () {
|
|
|
266
264
|
if (!mod) continue
|
|
267
265
|
if (isFunction(mod)) mod = await mod.call(this.app[camelCase(pkg)])
|
|
268
266
|
if (isPlainObject(mod)) mod = [mod]
|
|
267
|
+
mod.forEach(m => set(m, 'ns', camelCase(pkg)))
|
|
269
268
|
this.app.configHandlers = this.app.configHandlers.concat(mod)
|
|
270
269
|
}
|
|
271
270
|
}
|
|
@@ -282,12 +281,12 @@ export async function collectConfigHandlers () {
|
|
|
282
281
|
export async function buildExtConfig () {
|
|
283
282
|
// config merging
|
|
284
283
|
const { defaultsDeep, includes } = this.app.lib.aneka
|
|
285
|
-
const { parseObject
|
|
286
|
-
const { isEmpty, get, isString, without } = this.app.lib._
|
|
284
|
+
const { parseObject } = this.app.lib
|
|
285
|
+
const { isEmpty, get, isString, without, omit } = this.app.lib._
|
|
287
286
|
|
|
288
287
|
let resp = get(this, `app.options.config.${this.ns}`, {})
|
|
289
288
|
if (isEmpty(resp)) resp = await this.readAllConfigs(`${this.dir.data}/config/${this.ns}`)
|
|
290
|
-
resp =
|
|
289
|
+
resp = omit(pick(resp, ['log', 'exitHandler', 'env', 'runtime']), omitted)
|
|
291
290
|
const envs = this.app.envs
|
|
292
291
|
this.config = defaultsDeep({}, this.config, resp, defConfig)
|
|
293
292
|
// language
|
package/docs/class_app.js.html
CHANGED
|
@@ -108,9 +108,9 @@ class App {
|
|
|
108
108
|
/**
|
|
109
109
|
* Config handlers.
|
|
110
110
|
*
|
|
111
|
-
* By default, there are two built-in handlers available: ```.js```
|
|
112
|
-
* and ```.
|
|
113
|
-
* lets you to use ```.
|
|
111
|
+
* By default, there are two built-in handlers available: ```.js```, ```.json```
|
|
112
|
+
* and ```.yml/.yaml```. Use plugins to add more, e.g {@link https://github.com/ardhi/bajo-config|bajo-config}
|
|
113
|
+
* lets you to use ```.toml```.
|
|
114
114
|
*
|
|
115
115
|
* @type {TAppConfigHandler[]}
|
|
116
116
|
*/
|
|
@@ -564,10 +564,13 @@ class App {
|
|
|
564
564
|
/**
|
|
565
565
|
* Helper method to list all supported config formats.
|
|
566
566
|
*
|
|
567
|
+
* @method
|
|
568
|
+
* @param {boolean} [noDot] - If ```true```, it will return the list without dot prefix.
|
|
567
569
|
* @returns {string[]}
|
|
568
570
|
*/
|
|
569
|
-
getConfigFormats = () => {
|
|
570
|
-
|
|
571
|
+
getConfigFormats = (noDot) => {
|
|
572
|
+
const formats = map(this.configHandlers, 'ext')
|
|
573
|
+
return noDot ? formats.map(f => f.slice(1)) : formats
|
|
571
574
|
}
|
|
572
575
|
|
|
573
576
|
/**
|
package/docs/class_bajo.js.html
CHANGED
|
@@ -6,15 +6,14 @@ import increment from 'add-filename-increment'
|
|
|
6
6
|
import fs from 'fs-extra'
|
|
7
7
|
import path from 'path'
|
|
8
8
|
import os from 'os'
|
|
9
|
-
import emptyDir from 'empty-dir'
|
|
10
9
|
import lodash from 'lodash'
|
|
11
10
|
import { createRequire } from 'module'
|
|
12
|
-
import getGlobalPath from 'get-global-path'
|
|
13
11
|
import fastGlob from 'fast-glob'
|
|
14
12
|
import querystring from 'querystring'
|
|
15
13
|
import importModule from '../lib/import-module.js'
|
|
16
14
|
import logLevels from '../lib/log-levels.js'
|
|
17
15
|
import { types as formatTypes, formats } from '../lib/formats.js'
|
|
16
|
+
import * as yaml from 'js-yaml'
|
|
18
17
|
import aneka from 'aneka'
|
|
19
18
|
import {
|
|
20
19
|
buildBaseConfig,
|
|
@@ -32,10 +31,10 @@ const {
|
|
|
32
31
|
isFunction, map, isObject,
|
|
33
32
|
trim, filter, isEmpty, orderBy, pullAt, find, camelCase,
|
|
34
33
|
cloneDeep, isPlainObject, isArray, isString, omit, keys, indexOf,
|
|
35
|
-
last, get, has, values,
|
|
34
|
+
last, get, has, values, pick
|
|
36
35
|
} = lodash
|
|
37
36
|
|
|
38
|
-
const { resolvePath } = aneka
|
|
37
|
+
const { resolvePath, getGlobalModuleDir } = aneka
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* Name based ```{ns}:{path}``` format.
|
|
@@ -79,8 +78,10 @@ class Bajo extends Plugin {
|
|
|
79
78
|
|
|
80
79
|
// by defaualt, only these config formats below are supported.
|
|
81
80
|
app.configHandlers = [
|
|
82
|
-
{ ext: '.js', readHandler: this.fromJs },
|
|
83
|
-
{ ext: '.json', readHandler: this.fromJson, writeHandler: this.toJson }
|
|
81
|
+
{ ns: 'bajo', ext: '.js', readHandler: this.fromJs },
|
|
82
|
+
{ ns: 'bajo', ext: '.json', readHandler: this.fromJson, writeHandler: this.toJson },
|
|
83
|
+
{ ns: 'bajo', ext: '.yaml', readHandler: this.fromYaml, writeHandler: this.toYaml },
|
|
84
|
+
{ ns: 'bajo', ext: '.yml', readHandler: this.fromYml, writeHandler: this.toYml }
|
|
84
85
|
]
|
|
85
86
|
|
|
86
87
|
this.hooks = []
|
|
@@ -501,34 +502,6 @@ class Bajo extends Plugin {
|
|
|
501
502
|
return value
|
|
502
503
|
}
|
|
503
504
|
|
|
504
|
-
/**
|
|
505
|
-
* Get NPM global module directory.
|
|
506
|
-
*
|
|
507
|
-
* @method
|
|
508
|
-
* @param {string} [pkgName] - If provided, return this package global directory. Otherwise the npm global module directory.
|
|
509
|
-
* @param {boolean} [silent=true] - Set to ```false``` to throw exception in case of error. Otherwise silently returns undefined.
|
|
510
|
-
* @returns {string}
|
|
511
|
-
*/
|
|
512
|
-
getGlobalModuleDir = (pkgName, silent = true) => {
|
|
513
|
-
let nodeModulesDir = process.env.BAJO_GLOBAL_MODULE_DIR
|
|
514
|
-
if (!nodeModulesDir) {
|
|
515
|
-
const npmPath = getGlobalPath('npm')
|
|
516
|
-
if (!npmPath) {
|
|
517
|
-
if (silent) return
|
|
518
|
-
throw this.error('cantLocateNpmGlobalDir', { code: 'BAJO_CANT_LOCATE_NPM_GLOBAL_DIR' })
|
|
519
|
-
}
|
|
520
|
-
nodeModulesDir = dropRight(resolvePath(npmPath).split('/'), 1).join('/')
|
|
521
|
-
process.env.BAJO_GLOBAL_MODULE_DIR = nodeModulesDir
|
|
522
|
-
}
|
|
523
|
-
if (!pkgName) return nodeModulesDir
|
|
524
|
-
const dir = `${nodeModulesDir}/${pkgName}`
|
|
525
|
-
if (!fs.existsSync(dir)) {
|
|
526
|
-
if (silent) return
|
|
527
|
-
throw this.error('cantLocateGlobalDir%s', pkgName, { code: 'BAJO_CANT_LOCATE_MODULE_GLOBAL_DIR' })
|
|
528
|
-
}
|
|
529
|
-
return dir
|
|
530
|
-
}
|
|
531
|
-
|
|
532
505
|
/**
|
|
533
506
|
* Get class method by name.
|
|
534
507
|
*
|
|
@@ -545,22 +518,21 @@ class Bajo extends Plugin {
|
|
|
545
518
|
}
|
|
546
519
|
|
|
547
520
|
/**
|
|
548
|
-
* Get module directory
|
|
521
|
+
* Get module directory.
|
|
549
522
|
*
|
|
550
523
|
* @method
|
|
551
524
|
* @param {string} pkgName - Package name to find.
|
|
552
|
-
* @param {
|
|
525
|
+
* @param {boolean} [withGlobalDir=true] - Whether to include the global module directory.
|
|
553
526
|
* @returns {string} Return absolute package directory.
|
|
554
527
|
*/
|
|
555
|
-
getModuleDir = (pkgName, base) => {
|
|
528
|
+
getModuleDir = (pkgName, base, withGlobalDir = true) => {
|
|
556
529
|
const { findDeep } = this.app.lib
|
|
557
530
|
if (pkgName === 'main') return resolvePath(this.app.dir)
|
|
558
531
|
if (base === 'main') base = this.app.dir
|
|
559
532
|
else if (this && this.app && this.app[base]) base = this.app[base].pkgName
|
|
560
533
|
const pkgPath = pkgName + '/package.json'
|
|
561
534
|
const paths = require.resolve.paths(pkgPath)
|
|
562
|
-
|
|
563
|
-
paths.unshift(gdir)
|
|
535
|
+
if (withGlobalDir) paths.push(getGlobalModuleDir())
|
|
564
536
|
paths.unshift(resolvePath(path.join(this.app.dir, 'node_modules')))
|
|
565
537
|
let dir = findDeep(pkgPath, paths)
|
|
566
538
|
if (base && !dir) dir = findDeep(`${base}/node_modules/${pkgPath}`, paths)
|
|
@@ -645,21 +617,6 @@ class Bajo extends Plugin {
|
|
|
645
617
|
return values(result)
|
|
646
618
|
}
|
|
647
619
|
|
|
648
|
-
/**
|
|
649
|
-
* Check whether a directory is empty or not. More info please {@link https://github.com/gulpjs/empty-dir|check here}.
|
|
650
|
-
*
|
|
651
|
-
* @method
|
|
652
|
-
* @async
|
|
653
|
-
* @param {(string|TNsPathPairs)} dir - Directory to check.
|
|
654
|
-
* @param {function} filterFn - Filter function to filter out files that cause false positives.
|
|
655
|
-
* @returns {boolean}
|
|
656
|
-
*/
|
|
657
|
-
isEmptyDir = async (dir, filterFn) => {
|
|
658
|
-
dir = resolvePath(this.app.getPluginFile(dir))
|
|
659
|
-
await fs.exists(dir)
|
|
660
|
-
return await emptyDir(dir, filterFn)
|
|
661
|
-
}
|
|
662
|
-
|
|
663
620
|
/**
|
|
664
621
|
* Check whether log level is within log's app current level.
|
|
665
622
|
*
|
|
@@ -752,7 +709,7 @@ class Bajo extends Plugin {
|
|
|
752
709
|
}
|
|
753
710
|
|
|
754
711
|
/**
|
|
755
|
-
* Read and parse file as config object. Supported types: ```.js``` and ```.
|
|
712
|
+
* Read and parse file as config object. Supported types: ```.js```, ```.json``` and ```.yml/.yaml```.
|
|
756
713
|
* More supports can be added using plugin. {@link https://github.com/ardhi/bajo-config|bajo-config} gives you additional supports for ```.yml```, ```.yaml``` and ```.toml``` file.
|
|
757
714
|
*
|
|
758
715
|
* If file extension is ```.*```, it will be auto detected and parsed accordingly
|
|
@@ -845,20 +802,20 @@ class Bajo extends Plugin {
|
|
|
845
802
|
let ext = path.extname(file)
|
|
846
803
|
const fname = path.dirname(file) + '/' + path.basename(file, ext)
|
|
847
804
|
ext = ext.toLowerCase()
|
|
848
|
-
if (
|
|
849
|
-
const
|
|
850
|
-
return await output(await readHandler.call(this.app[ns], file, parserOpts))
|
|
805
|
+
if (['.js', '.json'].includes(ext)) {
|
|
806
|
+
const item = find(this.app.configHandlers, { ext })
|
|
807
|
+
return await output(await item.readHandler.call(this.app[ns], file, parserOpts))
|
|
851
808
|
}
|
|
852
|
-
if (ext === '.json') return await output(await this.fromJson(file, parserOpts))
|
|
853
809
|
if (!['', '.*'].includes(ext)) {
|
|
854
810
|
const item = find(this.app.configHandlers, { ext })
|
|
855
811
|
if (!item) {
|
|
856
812
|
if (!ignoreError) throw this.error('cantParse%s', file, { code: 'BAJO_CONFIG_NO_PARSER' })
|
|
857
813
|
return await output(defValue)
|
|
858
814
|
}
|
|
859
|
-
return await output(await item.readHandler.call(this.app[ns], file, parserOpts))
|
|
815
|
+
return await output(await item.readHandler.call(this.app[item.ns], file, parserOpts))
|
|
860
816
|
}
|
|
861
|
-
const
|
|
817
|
+
const formats = this.app.getConfigFormats(true)
|
|
818
|
+
const item = pattern ?? `${fname}.{${formats.join(',')}}`
|
|
862
819
|
const files = await fastGlob(item, globOpts ?? {})
|
|
863
820
|
if (files.length === 0) {
|
|
864
821
|
if (!ignoreError) throw this.error('noConfigFileFound', { code: 'BAJO_CONFIG_FILE_NOT_FOUND' })
|
|
@@ -872,7 +829,8 @@ class Bajo extends Plugin {
|
|
|
872
829
|
if (!ignoreError) throw this.error('cantParse%s', f, { code: 'BAJO_CONFIG_NO_PARSER' })
|
|
873
830
|
continue
|
|
874
831
|
}
|
|
875
|
-
|
|
832
|
+
const _ns = ['.js', '.json'].includes(ext) ? ns : item.ns
|
|
833
|
+
config = await item.readHandler.call(this.app[_ns], f, parserOpts)
|
|
876
834
|
if (!isEmpty(config)) break
|
|
877
835
|
}
|
|
878
836
|
return await output(config)
|
|
@@ -926,6 +884,32 @@ class Bajo extends Plugin {
|
|
|
926
884
|
return JSON.parse(content)
|
|
927
885
|
}
|
|
928
886
|
|
|
887
|
+
/**
|
|
888
|
+
* Parse YAML text
|
|
889
|
+
*
|
|
890
|
+
* @method
|
|
891
|
+
* @param {string} text - Text to be parsed
|
|
892
|
+
* @param {object} options - Options object
|
|
893
|
+
* @returns {object} Parsed object
|
|
894
|
+
*/
|
|
895
|
+
fromYaml = (text, options = {}) => {
|
|
896
|
+
const { fs } = this.app.lib
|
|
897
|
+
const content = options.readFromFile ? fs.readFileSync(text, 'utf8') : text
|
|
898
|
+
return yaml.load(content)
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Parse YML text. Alias for fromYaml.
|
|
903
|
+
*
|
|
904
|
+
* @method
|
|
905
|
+
* @param {string} text - Text to be parsed
|
|
906
|
+
* @param {object} options - Options object
|
|
907
|
+
* @returns {object} Parsed object
|
|
908
|
+
*/
|
|
909
|
+
fromYml = (text, options = {}) => {
|
|
910
|
+
return this.fromYaml(text, options)
|
|
911
|
+
}
|
|
912
|
+
|
|
929
913
|
/**
|
|
930
914
|
* Convert data to JSON string.
|
|
931
915
|
*
|
|
@@ -945,6 +929,37 @@ class Bajo extends Plugin {
|
|
|
945
929
|
return content
|
|
946
930
|
}
|
|
947
931
|
|
|
932
|
+
/**
|
|
933
|
+
* Convert object to YAML string
|
|
934
|
+
*
|
|
935
|
+
* @method
|
|
936
|
+
* @param {object} object - Object to be converted
|
|
937
|
+
* @param {object} options - Options object
|
|
938
|
+
* @returns {string} YAML string
|
|
939
|
+
*/
|
|
940
|
+
toYaml = (object, options = {}) => {
|
|
941
|
+
const { omit } = this.app.lib._
|
|
942
|
+
const { fs } = this.app.lib
|
|
943
|
+
const content = yaml.dump(object, omit(options, ['writeToFile']))
|
|
944
|
+
if (options.writeToFile) {
|
|
945
|
+
fs.writeFileSync(options.saveAsFile, content, 'utf8')
|
|
946
|
+
return
|
|
947
|
+
}
|
|
948
|
+
return content
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Convert object to YML string. Alias for toYaml.
|
|
953
|
+
*
|
|
954
|
+
* @method
|
|
955
|
+
* @param {object} object - Object to be converted
|
|
956
|
+
* @param {object} options - Options object
|
|
957
|
+
* @returns {string} YML string
|
|
958
|
+
*/
|
|
959
|
+
toYml = (object, options = {}) => {
|
|
960
|
+
return this.toYaml(object, options)
|
|
961
|
+
}
|
|
962
|
+
|
|
948
963
|
/**
|
|
949
964
|
* Read all config files from path.
|
|
950
965
|
*
|
|
@@ -1025,6 +1040,29 @@ class Bajo extends Plugin {
|
|
|
1025
1040
|
if (printSaved) print.succeed('savedAs%s', path.resolve(fname), { skipSilence: true })
|
|
1026
1041
|
return fname
|
|
1027
1042
|
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Read config using all registered config handlers. The first handler that returns a
|
|
1046
|
+
* valid object or array will be used.
|
|
1047
|
+
*
|
|
1048
|
+
* @param {string} input - The input string to be processed by the config handlers.
|
|
1049
|
+
* @param {string[]} [exts] - Optional array of extensions to filter the config handlers. If provided, only handlers with matching extensions will be used.
|
|
1050
|
+
* @param {object} [options={}] - Options to be passed to the config handlers.
|
|
1051
|
+
* @returns {Object|Array|null} The result from the first successful config handler, or null if none succeed.
|
|
1052
|
+
*/
|
|
1053
|
+
readAsConfig = async (input, exts, options = {}) => {
|
|
1054
|
+
let result
|
|
1055
|
+
const handlers = exts ? this.app.configHandlers.filter(h => exts.includes(h.ext)) : this.app.configHandlers
|
|
1056
|
+
for (const handler of handlers) {
|
|
1057
|
+
if (result) break
|
|
1058
|
+
try {
|
|
1059
|
+
const resp = await handler.readHandler.call(this.app[handler.ns], input, options)
|
|
1060
|
+
if (isPlainObject(resp) || isArray(resp)) result = resp
|
|
1061
|
+
} catch (err) {
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return result
|
|
1065
|
+
}
|
|
1028
1066
|
}
|
|
1029
1067
|
|
|
1030
1068
|
export default Bajo
|
package/docs/class_cache.js.html
CHANGED
|
@@ -80,6 +80,8 @@ class Cache {
|
|
|
80
80
|
const { dir, file } = this.prep(name, ttlDur) ?? {}
|
|
81
81
|
if (!file || !item) return
|
|
82
82
|
fs.ensureDirSync(dir)
|
|
83
|
+
const fileDir = file.split('/').slice(0, -1).join('/')
|
|
84
|
+
if (fileDir) fs.ensureDirSync(fileDir)
|
|
83
85
|
let content = cloneDeep(item)
|
|
84
86
|
if (isArray(item) || isPlainObject(item)) content = JSON.stringify(content)
|
|
85
87
|
fs.writeFileSync(file, content, 'utf8')
|