ngz-cache-platform-server
Version:
Server platform implementation of ngx-cache
16 lines (14 loc) • 3.49 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/core"),require("ngz-cache-core")):"function"==typeof define&&define.amd?define("ngz-cache-platform-server",["exports","@angular/common","@angular/core","ngz-cache-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["ngz-cache-platform-server"]={},e.ng.common,e.ng.core,e.ngzCacheCore)}(this,(function(e,t,r,o){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function n(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],o=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}var i=function(){function e(e,r){if(this.platformId=e,this.injector=r,!t.isPlatformServer(e))throw new Error("FsCacheService is not supported outside `server` platform!");this.fsStorage=r.get(o.STORAGE)}return Object.defineProperty(e.prototype,"isEnabled",{get:function(){if(!t.isPlatformServer(this.platformId))return!1;try{return this.fsStorage.setItem("test","test"),this.fsStorage.removeItem("test"),!0}catch(e){return!1}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"keys",{get:function(){if(this.isEnabled)return this.fsStorage.keys},enumerable:!1,configurable:!0}),e.prototype.setItem=function(e,t){if(!this.isEnabled)return!1;try{return this.fsStorage.setItem(e,JSON.stringify(t)),!0}catch(e){return!1}},e.prototype.getItem=function(e){if(this.isEnabled){var t=this.fsStorage.getItem(e);return t?JSON.parse(t):void 0}},e.prototype.removeItem=function(e,t){var r,o;if(void 0===t&&(t=!1),this.isEnabled&&(this.fsStorage.removeItem(e),t))try{for(var i=n(this.keys),a=i.next();!a.done;a=i.next()){var s=a.value;0===s.indexOf(e)&&this.fsStorage.removeItem(s)}}catch(e){r={error:e}}finally{try{a&&!a.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}},e.prototype.clear=function(){this.isEnabled&&this.fsStorage.clear()},e}();i.decorators=[{type:r.Injectable}],i.ctorParameters=function(){return[{type:void 0,decorators:[{type:r.Inject,args:[r.PLATFORM_ID]}]},{type:r.Injector}]};var a=function(){function e(e){if(e)throw new Error("ServerCacheModule already loaded; import in SERVER module only.")}return e.forRoot=function(t){return{ngModule:e,providers:t}},e}();a.decorators=[{type:r.NgModule}],a.ctorParameters=function(){return[{type:a,decorators:[{type:r.Optional},{type:r.SkipSelf}]}]},e.FsCacheService=i,e.ServerCacheModule=a,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngz-cache-platform-server.umd.min.js.map