Socket
Socket
Sign inDemoInstall

@ngx-pwa/local-storage

Package Overview
Dependencies
0
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0-beta.7 to 6.0.0-rc.0

src/tokens.d.ts

251

bundles/local-storage.umd.js

@@ -11,2 +11,21 @@ (function (global, factory) {

*/
var LOCAL_STORAGE_PREFIX = new i0.InjectionToken('localStoragePrefix', { providedIn: 'root', factory: function () { return ''; } });
/**
* @record
*/
/**
* @param {?} config
* @return {?}
*/
function localStorageProviders(config) {
return [
config.prefix ? { provide: LOCAL_STORAGE_PREFIX, useValue: config.prefix } : []
];
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var IndexedDBDatabase = /** @class */ (function () {

@@ -16,3 +35,5 @@ /**

*/
function IndexedDBDatabase() {
function IndexedDBDatabase(prefix) {
if (prefix === void 0) { prefix = null; }
this.prefix = prefix;
/**

@@ -34,2 +55,8 @@ * IndexedDB database name for local storage

this.dataPath = 'value';
if (prefix) {
this.dbName = prefix + "_" + this.dbName;
}
if (prefix) {
this.dbName = prefix + "_" + this.dbName;
}
/* Creating the RxJS ReplaySubject */

@@ -283,4 +310,6 @@ this.database = new rxjs.ReplaySubject();

/** @nocollapse */
IndexedDBDatabase.ctorParameters = function () { return []; };
/** @nocollapse */ IndexedDBDatabase.ngInjectableDef = i0.defineInjectable({ factory: function IndexedDBDatabase_Factory() { return new IndexedDBDatabase(); }, token: IndexedDBDatabase, providedIn: "root" });
IndexedDBDatabase.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [LOCAL_STORAGE_PREFIX,] },] },
]; };
/** @nocollapse */ IndexedDBDatabase.ngInjectableDef = i0.defineInjectable({ factory: function IndexedDBDatabase_Factory() { return new IndexedDBDatabase(i0.inject(LOCAL_STORAGE_PREFIX, 8)); }, token: IndexedDBDatabase, providedIn: "root" });
return IndexedDBDatabase;

@@ -294,5 +323,10 @@ }());

var LocalStorageDatabase = /** @class */ (function () {
function LocalStorageDatabase() {
function LocalStorageDatabase(userPrefix) {
if (userPrefix === void 0) { userPrefix = null; }
this.userPrefix = userPrefix;
/* Initializing native localStorage right now to be able to check its support on class instanciation */
this.localStorage = localStorage;
this.prefix = '';
if (userPrefix) {
this.prefix = userPrefix + "_";
}
}

@@ -317,3 +351,3 @@ /**

function (key) {
var /** @type {?} */ unparsedData = this.localStorage.getItem(key);
var /** @type {?} */ unparsedData = localStorage.getItem("" + this.prefix + key);
var /** @type {?} */ parsedData = null;

@@ -349,3 +383,3 @@ if (unparsedData != null) {

function (key, data) {
this.localStorage.setItem(key, JSON.stringify(data));
localStorage.setItem("" + this.prefix + key, JSON.stringify(data));
return rxjs.of(true);

@@ -369,3 +403,3 @@ };

function (key) {
this.localStorage.removeItem(key);
localStorage.removeItem("" + this.prefix + key);
return rxjs.of(true);

@@ -386,3 +420,3 @@ };

function () {
this.localStorage.clear();
localStorage.clear();
return rxjs.of(true);

@@ -395,3 +429,7 @@ };

];
/** @nocollapse */ LocalStorageDatabase.ngInjectableDef = i0.defineInjectable({ factory: function LocalStorageDatabase_Factory() { return new LocalStorageDatabase(); }, token: LocalStorageDatabase, providedIn: "root" });
/** @nocollapse */
LocalStorageDatabase.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [LOCAL_STORAGE_PREFIX,] },] },
]; };
/** @nocollapse */ LocalStorageDatabase.ngInjectableDef = i0.defineInjectable({ factory: function LocalStorageDatabase_Factory() { return new LocalStorageDatabase(i0.inject(LOCAL_STORAGE_PREFIX, 8)); }, token: LocalStorageDatabase, providedIn: "root" });
return LocalStorageDatabase;

@@ -501,12 +539,13 @@ }());

* @param {?} platformId
* @param {?} prefix
* @return {?}
*/
function localDatabaseFactory(platformId) {
function localDatabaseFactory(platformId, prefix) {
if (_angular_common.isPlatformBrowser(platformId) && ('indexedDB' in window) && (indexedDB !== undefined) && (indexedDB !== null)) {
/* Try with IndexedDB in modern browsers */
return new IndexedDBDatabase();
return new IndexedDBDatabase(prefix);
}
else if (_angular_common.isPlatformBrowser(platformId) && ('localStorage' in window) && (localStorage !== undefined) && (localStorage !== null)) {
/* Try with localStorage in old browsers (IE9) */
return new LocalStorageDatabase();
return new LocalStorageDatabase(prefix);
}

@@ -529,6 +568,9 @@ else {

useFactory: localDatabaseFactory,
deps: [i0.PLATFORM_ID]
deps: [
i0.PLATFORM_ID,
[new i0.Optional(), LOCAL_STORAGE_PREFIX]
]
},] },
];
/** @nocollapse */ LocalDatabase.ngInjectableDef = i0.defineInjectable({ factory: function LocalDatabase_Factory() { return localDatabaseFactory(i0.inject(i0.PLATFORM_ID)); }, token: LocalDatabase, providedIn: "root" });
/** @nocollapse */ LocalDatabase.ngInjectableDef = i0.defineInjectable({ factory: function LocalDatabase_Factory() { return localDatabaseFactory(i0.inject(i0.PLATFORM_ID), i0.inject(LOCAL_STORAGE_PREFIX, 8)); }, token: LocalDatabase, providedIn: "root" });
return LocalDatabase;

@@ -550,3 +592,7 @@ }());

* @param data JSON data to validate
* @param schema Subset of JSON Schema
* @param schema Subset of JSON Schema.
* Types are enforced to validate everything:
* each value MUST have 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* Not all validation features are supported: just follow the interface.
* @returns If data is valid : true, if it is invalid : false, and throws if the schema is invalid

@@ -557,3 +603,7 @@ */

* @param {?} data JSON data to validate
* @param {?} schema Subset of JSON Schema
* @param {?} schema Subset of JSON Schema.
* Types are enforced to validate everything:
* each value MUST have 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* Not all validation features are supported: just follow the interface.
* @return {?} If data is valid : true, if it is invalid : false, and throws if the schema is invalid

@@ -564,34 +614,35 @@ */

* @param {?} data JSON data to validate
* @param {?} schema Subset of JSON Schema
* @param {?} schema Subset of JSON Schema.
* Types are enforced to validate everything:
* each value MUST have 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* Not all validation features are supported: just follow the interface.
* @return {?} If data is valid : true, if it is invalid : false, and throws if the schema is invalid
*/
function (data, schema) {
if (!this.isObjectNotNull(schema)) {
throw new Error("A schema must be an object (unlike spec, booleans are not supported to enforce strict types).");
}
if (((!schema.hasOwnProperty('const') && !schema.hasOwnProperty('enum') && !schema.hasOwnProperty('type'))
/** @todo When TS 2.8, explore if this is possible with conditional types */
if (((!(schema.hasOwnProperty('const') && schema.const !== undefined)
&& !(schema.hasOwnProperty('enum') && schema.enum != null) && !(schema.hasOwnProperty('type') && schema.type != null))
|| schema.type === 'array' || schema.type === 'object')
&& !schema.hasOwnProperty('properties') && !schema.hasOwnProperty('items')) {
&& !(schema.hasOwnProperty('properties') && schema.properties != null) && !(schema.hasOwnProperty('items') && schema.items != null)) {
throw new Error("Each value must have a 'type' or 'properties' or 'items' or 'const' or 'enum', to enforce strict types.");
}
if (schema.hasOwnProperty('const') && (data !== schema.const)) {
if (schema.hasOwnProperty('const') && schema.const !== undefined && (data !== schema.const)) {
return false;
}
if (schema.hasOwnProperty('enum') && !this.validateEnum(data, schema)) {
if (!this.validateEnum(data, schema)) {
return false;
}
if (schema.hasOwnProperty('type') && !this.validateType(data, schema)) {
if (!this.validateType(data, schema)) {
return false;
}
if (schema.hasOwnProperty('items') && !this.validateItems(data, schema)) {
if (!this.validateItems(data, schema)) {
return false;
}
if (schema.hasOwnProperty('properties')) {
if (schema.hasOwnProperty('required') && !this.validateRequired(data, schema)) {
return false;
}
if (!this.validateProperties(data, schema)) {
return false;
}
if (!this.validateProperties(data, schema)) {
return false;
}
if (!this.validateRequired(data, schema)) {
return false;
}
return true;

@@ -621,8 +672,8 @@ };

function (data, schema) {
if (!schema.hasOwnProperty('properties') || (schema.properties == null)) {
return true;
}
if (!this.isObjectNotNull(data)) {
return false;
}
if (!schema.properties || !this.isObjectNotNull(schema.properties)) {
throw new Error("'properties' must be a schema object.");
}
/**

@@ -656,13 +707,10 @@ * Check if the object doesn't have more properties than expected

function (data, schema) {
if (!schema.hasOwnProperty('required') || (schema.required == null)) {
return true;
}
if (!this.isObjectNotNull(data)) {
return false;
}
if (!Array.isArray(schema.required)) {
throw new Error("'required' field must be an array. Note that since JSON Schema draft 6, booleans are not supported anymore.");
}
for (var _i = 0, _a = schema.required; _i < _a.length; _i++) {
var requiredProp = _a[_i];
if (typeof requiredProp !== 'string') {
throw new Error("'required' array must contain strings only.");
}
/* Checks if the property is present in the schema 'properties' */

@@ -690,4 +738,4 @@ if (!schema.properties || !schema.properties.hasOwnProperty(requiredProp)) {

function (data, schema) {
if (!Array.isArray(schema.enum)) {
throw new Error("'enum' must be an array.");
if (!schema.hasOwnProperty('enum') || (schema.enum == null)) {
return true;
}

@@ -708,24 +756,20 @@ /** @todo Move to ES2016 .includes() ? */

function (data, schema) {
if (Array.isArray(schema.type)) {
return this.validateTypeList(data, schema);
if (!schema.hasOwnProperty('type') || (schema.type == null)) {
return true;
}
if (typeof schema.type !== 'string') {
throw new Error("'type' must be a string (arrays of types are not supported yet).");
switch (schema.type) {
case 'null':
return data === null;
case 'string':
return this.validateString(data, schema);
case 'number':
case 'integer':
return this.validateNumber(data, schema);
case 'boolean':
return typeof data === 'boolean';
case 'object':
return typeof data === 'object';
case 'array':
return Array.isArray(data);
}
if ((schema.type === 'null') && (data !== null)) {
return false;
}
if (schema.type === 'string') {
return this.validateString(data, schema);
}
if ((schema.type === 'number') || (schema.type === 'integer')) {
return this.validateNumber(data, schema);
}
if ((schema.type === 'boolean') && (typeof data !== 'boolean')) {
return false;
}
if ((schema.type === 'object') && (typeof data !== 'object')) {
return false;
}
return true;
};

@@ -737,3 +781,3 @@ /**

*/
JSONValidator.prototype.validateTypeList = /**
JSONValidator.prototype.validateItems = /**
* @param {?} data

@@ -744,26 +788,10 @@ * @param {?} schema

function (data, schema) {
var /** @type {?} */ types = /** @type {?} */ (schema.type);
var /** @type {?} */ typesTests = [];
for (var _i = 0, types_1 = types; _i < types_1.length; _i++) {
var type = types_1[_i];
typesTests.push(this.validateType(data, { type: type }));
if (!schema.hasOwnProperty('items') || (schema.items == null)) {
return true;
}
return (typesTests.indexOf(true) !== -1);
};
/**
* @param {?} data
* @param {?} schema
* @return {?}
*/
JSONValidator.prototype.validateItems = /**
* @param {?} data
* @param {?} schema
* @return {?}
*/
function (data, schema) {
if (!Array.isArray(data)) {
return false;
}
if (schema.hasOwnProperty('maxItems')) {
if ((typeof schema.maxItems !== 'number') || !Number.isInteger(schema.maxItems) || schema.maxItems < 0) {
if (schema.hasOwnProperty('maxItems') && (schema.maxItems != null)) {
if (!Number.isInteger(schema.maxItems) || schema.maxItems < 0) {
throw new Error("'maxItems' must be a non-negative integer.");

@@ -775,4 +803,4 @@ }

}
if (schema.hasOwnProperty('minItems')) {
if ((typeof schema.minItems !== 'number') || !Number.isInteger(schema.minItems) || schema.minItems < 0) {
if (schema.hasOwnProperty('minItems') && (schema.minItems != null)) {
if (!Number.isInteger(schema.minItems) || schema.minItems < 0) {
throw new Error("'minItems' must be a non-negative integer.");

@@ -784,6 +812,3 @@ }

}
if (schema.hasOwnProperty('uniqueItems')) {
if (typeof schema.uniqueItems !== 'boolean') {
throw new Error("'minItems' must be a boolean.");
}
if (schema.hasOwnProperty('uniqueItems') && (schema.uniqueItems != null)) {
if (schema.uniqueItems) {

@@ -799,5 +824,2 @@ var /** @type {?} */ dataSet = new Set(data);

}
if (!schema.items || !this.isObjectNotNull(schema.items)) {
throw new Error("'items' must be a schema object.");
}
for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {

@@ -847,4 +869,4 @@ var value = data_1[_i];

}
if (schema.hasOwnProperty('maxLength')) {
if ((typeof schema.maxLength !== 'number') || !Number.isInteger(schema.maxLength) || schema.maxLength < 0) {
if (schema.hasOwnProperty('maxLength') && (schema.maxLength != null)) {
if (!Number.isInteger(schema.maxLength) || schema.maxLength < 0) {
throw new Error("'maxLength' must be a non-negative integer.");

@@ -856,4 +878,4 @@ }

}
if (schema.hasOwnProperty('minLength')) {
if ((typeof schema.minLength !== 'number') || !Number.isInteger(schema.minLength) || schema.minLength < 0) {
if (schema.hasOwnProperty('minLength') && (schema.minLength != null)) {
if (!Number.isInteger(schema.minLength) || schema.minLength < 0) {
throw new Error("'minLength' must be a non-negative integer.");

@@ -865,6 +887,3 @@ }

}
if (schema.hasOwnProperty('pattern')) {
if (typeof schema.pattern !== 'string') {
throw new Error("'pattern' must be a string with a valid RegExp.");
}
if (schema.hasOwnProperty('pattern') && (schema.pattern != null)) {
var /** @type {?} */ regularExpression = new RegExp(schema.pattern);

@@ -894,4 +913,4 @@ if (!regularExpression.test(data)) {

}
if (schema.hasOwnProperty('multipleOf')) {
if ((typeof schema.multipleOf !== 'number') || schema.multipleOf <= 0) {
if (schema.hasOwnProperty('multipleOf') && (schema.multipleOf != null)) {
if (schema.multipleOf <= 0) {
throw new Error("'multipleOf' must be a number strictly greater than 0.");

@@ -903,6 +922,3 @@ }

}
if (schema.hasOwnProperty('maximum')) {
if (typeof schema.maximum !== 'number') {
throw new Error("'maximum' must be a number.");
}
if (schema.hasOwnProperty('maximum') && (schema.maximum != null)) {
if (data > schema.maximum) {

@@ -912,6 +928,3 @@ return false;

}
if (schema.hasOwnProperty('exclusiveMaximum')) {
if (typeof schema.exclusiveMaximum !== 'number') {
throw new Error("'exclusiveMaximum' must be a number.");
}
if (schema.hasOwnProperty('exclusiveMaximum') && (schema.exclusiveMaximum != null)) {
if (data >= schema.exclusiveMaximum) {

@@ -921,6 +934,3 @@ return false;

}
if (schema.hasOwnProperty('minimum')) {
if (typeof schema.minimum !== 'number') {
throw new Error("'minimum' must be a number.");
}
if (schema.hasOwnProperty('minimum') && (schema.minimum != null)) {
if (data < schema.minimum) {

@@ -930,6 +940,3 @@ return false;

}
if (schema.hasOwnProperty('exclusiveMinimum')) {
if (typeof schema.exclusiveMinimum !== 'number') {
throw new Error("'exclusiveMinimum' must be a number.");
}
if (schema.hasOwnProperty('exclusiveMinimum') && (schema.exclusiveMinimum != null)) {
if (data <= schema.exclusiveMinimum) {

@@ -1141,2 +1148,4 @@ return false;

exports.LocalStorage = LocalStorage;
exports.localStorageProviders = localStorageProviders;
exports.LOCAL_STORAGE_PREFIX = LOCAL_STORAGE_PREFIX;
exports.ɵa = localDatabaseFactory;

@@ -1143,0 +1152,0 @@

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common","rxjs","rxjs/operators"],t):t((e.ngxPWA=e.ngxPWA||{},e.ngxPWA.localStorage=e.ngxPWA.localStorage||{}),e.ng.core,e.ng.common,e.Rx,e.Rx.operators)}(this,function(e,t,r,n,o){"use strict";function i(e){return r.isPlatformBrowser(e)&&"indexedDB"in window&&void 0!==indexedDB&&null!==indexedDB?new a:r.isPlatformBrowser(e)&&"localStorage"in window&&void 0!==localStorage&&null!==localStorage?new s:new u}var a=function(){function e(){this.dbName="ngStorage",this.objectStoreName="localStorage",this.keyPath="key",this.dataPath="value",this.database=new n.ReplaySubject,this.connect()}return e.prototype.getItem=function(e){var t=this;return this.transaction().pipe(o.map(function(t){return t.get(e)}),o.mergeMap(function(e){var r=n.fromEvent(e,"success").pipe(o.map(function(e){return e.target.result}),o.map(function(e){return e&&t.dataPath in e?e[t.dataPath]:null}));return n.race(r,t.toErrorObservable(e,"getter")).pipe(o.first())}),o.first())},e.prototype.setItem=function(e,t){var r=this;return null==t?n.of(!0):this.getItem(e).pipe(o.map(function(e){return null==e?"add":"put"}),o.mergeMap(function(i){return r.transaction("readwrite").pipe(o.mergeMap(function(a){var s;switch(i){case"add":s=a.add((u={},u[r.dataPath]=t,u),e);break;case"put":default:s=a.put((p={},p[r.dataPath]=t,p),e)}return n.race(r.toSuccessObservable(s),r.toErrorObservable(s,"setter")).pipe(o.first());var u,p}))}),o.first())},e.prototype.removeItem=function(e){var t=this;return this.getItem(e).pipe(o.mergeMap(function(r){return null!=r?t.transaction("readwrite").pipe(o.mergeMap(function(r){var i=r.delete(e);return n.race(t.toSuccessObservable(i),t.toErrorObservable(i,"remover")).pipe(o.first())})):n.of(!0)}),o.first())},e.prototype.clear=function(){var e=this;return this.transaction("readwrite").pipe(o.mergeMap(function(t){var r=t.clear();return n.race(e.toSuccessObservable(r),e.toErrorObservable(r,"clearer")).pipe(o.first())}),o.first())},e.prototype.connect=function(){var e=this,t=indexedDB.open(this.dbName);n.fromEvent(t,"upgradeneeded").pipe(o.first()).subscribe(function(t){var r=t.target.result;r.objectStoreNames.contains(e.objectStoreName)||r.createObjectStore(e.objectStoreName)});var r=n.fromEvent(t,"success");n.race(r,this.toErrorObservable(t,"connection")).pipe(o.first()).subscribe(function(t){e.database.next(t.target.result)},function(t){e.database.error(t)})},e.prototype.transaction=function(e){var t=this;return void 0===e&&(e="readonly"),this.database.pipe(o.map(function(r){return r.transaction([t.objectStoreName],e).objectStore(t.objectStoreName)}))},e.prototype.toSuccessObservable=function(e){return n.fromEvent(e,"success").pipe(o.map(function(){return!0}))},e.prototype.toErrorObservable=function(e,t){return void 0===t&&(t=""),n.fromEvent(e,"error").pipe(o.mergeMap(function(r){return n.throwError(new Error("IndexedDB "+t+" issue : "+e.error.message+"."))}))},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[]},e.ngInjectableDef=t.defineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),s=function(){function e(){this.localStorage=localStorage}return e.prototype.getItem=function(e){var t=this.localStorage.getItem(e),r=null;if(null!=t)try{r=JSON.parse(t)}catch(e){return n.throwError(new Error("Invalid data in localStorage."))}return n.of(r)},e.prototype.setItem=function(e,t){return this.localStorage.setItem(e,JSON.stringify(t)),n.of(!0)},e.prototype.removeItem=function(e){return this.localStorage.removeItem(e),n.of(!0)},e.prototype.clear=function(){return this.localStorage.clear(),n.of(!0)},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ngInjectableDef=t.defineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),u=function(){function e(){this.localStorage=new Map}return e.prototype.getItem=function(e){var t=this.localStorage.get(e);return n.of(void 0!==t?t:null)},e.prototype.setItem=function(e,t){return this.localStorage.set(e,t),n.of(!0)},e.prototype.removeItem=function(e){return this.localStorage.delete(e),n.of(!0)},e.prototype.clear=function(){return this.localStorage.clear(),n.of(!0)},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ngInjectableDef=t.defineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),p=function(){function e(){}return e.decorators=[{type:t.Injectable,args:[{providedIn:"root",useFactory:i,deps:[t.PLATFORM_ID]}]}],e.ngInjectableDef=t.defineInjectable({factory:function(){return i(t.inject(t.PLATFORM_ID))},token:e,providedIn:"root"}),e}(),c=function(){function e(){}return e.prototype.validate=function(e,t){if(!this.isObjectNotNull(t))throw new Error("A schema must be an object (unlike spec, booleans are not supported to enforce strict types).");if(!((t.hasOwnProperty("const")||t.hasOwnProperty("enum")||t.hasOwnProperty("type"))&&"array"!==t.type&&"object"!==t.type||t.hasOwnProperty("properties")||t.hasOwnProperty("items")))throw new Error("Each value must have a 'type' or 'properties' or 'items' or 'const' or 'enum', to enforce strict types.");if(t.hasOwnProperty("const")&&e!==t.const)return!1;if(t.hasOwnProperty("enum")&&!this.validateEnum(e,t))return!1;if(t.hasOwnProperty("type")&&!this.validateType(e,t))return!1;if(t.hasOwnProperty("items")&&!this.validateItems(e,t))return!1;if(t.hasOwnProperty("properties")){if(t.hasOwnProperty("required")&&!this.validateRequired(e,t))return!1;if(!this.validateProperties(e,t))return!1}return!0},e.prototype.isObjectNotNull=function(e){return null!==e&&"object"==typeof e},e.prototype.validateProperties=function(e,t){if(!this.isObjectNotNull(e))return!1;if(!t.properties||!this.isObjectNotNull(t.properties))throw new Error("'properties' must be a schema object.");if(Object.keys(t.properties).length!==Object.keys(e).length)return!1;for(var r in t.properties)if(t.properties.hasOwnProperty(r)&&e.hasOwnProperty(r)&&!this.validate(e[r],t.properties[r]))return!1;return!0},e.prototype.validateRequired=function(e,t){if(!this.isObjectNotNull(e))return!1;if(!Array.isArray(t.required))throw new Error("'required' field must be an array. Note that since JSON Schema draft 6, booleans are not supported anymore.");for(var r=0,n=t.required;r<n.length;r++){var o=n[r];if("string"!=typeof o)throw new Error("'required' array must contain strings only.");if(!t.properties||!t.properties.hasOwnProperty(o))throw new Error("'required' properties must be described in 'properties' too.");if(!e.hasOwnProperty(o))return!1}return!0},e.prototype.validateEnum=function(e,t){if(!Array.isArray(t.enum))throw new Error("'enum' must be an array.");return-1!==t.enum.indexOf(e)},e.prototype.validateType=function(e,t){if(Array.isArray(t.type))return this.validateTypeList(e,t);if("string"!=typeof t.type)throw new Error("'type' must be a string (arrays of types are not supported yet).");return("null"!==t.type||null===e)&&("string"===t.type?this.validateString(e,t):"number"===t.type||"integer"===t.type?this.validateNumber(e,t):("boolean"!==t.type||"boolean"==typeof e)&&("object"!==t.type||"object"==typeof e))},e.prototype.validateTypeList=function(e,t){for(var r=[],n=0,o=t.type;n<o.length;n++){var i=o[n];r.push(this.validateType(e,{type:i}))}return-1!==r.indexOf(!0)},e.prototype.validateItems=function(e,t){if(!Array.isArray(e))return!1;if(t.hasOwnProperty("maxItems")){if("number"!=typeof t.maxItems||!Number.isInteger(t.maxItems)||t.maxItems<0)throw new Error("'maxItems' must be a non-negative integer.");if(e.length>t.maxItems)return!1}if(t.hasOwnProperty("minItems")){if("number"!=typeof t.minItems||!Number.isInteger(t.minItems)||t.minItems<0)throw new Error("'minItems' must be a non-negative integer.");if(e.length<t.minItems)return!1}if(t.hasOwnProperty("uniqueItems")){if("boolean"!=typeof t.uniqueItems)throw new Error("'minItems' must be a boolean.");if(t.uniqueItems){var r=new Set(e);if(e.length!==r.size)return!1}}if(Array.isArray(t.items))return this.validateItemsList(e,t);if(!t.items||!this.isObjectNotNull(t.items))throw new Error("'items' must be a schema object.");for(var n=0,o=e;n<o.length;n++){var i=o[n];if(!this.validate(i,t.items))return!1}return!0},e.prototype.validateItemsList=function(e,t){var r=t.items;if(e.length!==r.length)return!1;for(var n=0;n<r.length;n+=1)if(!this.validate(e[n],r[n]))return!1;return!0},e.prototype.validateString=function(e,t){if("string"!=typeof e)return!1;if(t.hasOwnProperty("maxLength")){if("number"!=typeof t.maxLength||!Number.isInteger(t.maxLength)||t.maxLength<0)throw new Error("'maxLength' must be a non-negative integer.");if(e.length>t.maxLength)return!1}if(t.hasOwnProperty("minLength")){if("number"!=typeof t.minLength||!Number.isInteger(t.minLength)||t.minLength<0)throw new Error("'minLength' must be a non-negative integer.");if(e.length<t.minLength)return!1}if(t.hasOwnProperty("pattern")){if("string"!=typeof t.pattern)throw new Error("'pattern' must be a string with a valid RegExp.");if(!new RegExp(t.pattern).test(e))return!1}return!0},e.prototype.validateNumber=function(e,t){if("number"!=typeof e)return!1;if("integer"===t.type&&!Number.isInteger(e))return!1;if(t.hasOwnProperty("multipleOf")){if("number"!=typeof t.multipleOf||t.multipleOf<=0)throw new Error("'multipleOf' must be a number strictly greater than 0.");if(!Number.isInteger(e/t.multipleOf))return!1}if(t.hasOwnProperty("maximum")){if("number"!=typeof t.maximum)throw new Error("'maximum' must be a number.");if(e>t.maximum)return!1}if(t.hasOwnProperty("exclusiveMaximum")){if("number"!=typeof t.exclusiveMaximum)throw new Error("'exclusiveMaximum' must be a number.");if(e>=t.exclusiveMaximum)return!1}if(t.hasOwnProperty("minimum")){if("number"!=typeof t.minimum)throw new Error("'minimum' must be a number.");if(e<t.minimum)return!1}if(t.hasOwnProperty("exclusiveMinimum")){if("number"!=typeof t.exclusiveMinimum)throw new Error("'exclusiveMinimum' must be a number.");if(e<=t.exclusiveMinimum)return!1}return!0},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ngInjectableDef=t.defineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),f=function(){function e(e,t){this.database=e,this.jsonValidator=t,this.getItemOptionsDefault={schema:null}}return e.prototype.getItem=function(e,t){var r=this;return void 0===t&&(t=this.getItemOptionsDefault),this.database.getItem(e).pipe(o.mergeMap(function(e){if(t.schema&&null!==e){var o=!0;try{o=r.jsonValidator.validate(e,t.schema)}catch(e){return n.throwError(e)}if(!o)return n.throwError(new Error("JSON invalid"))}return n.of(e)}))},e.prototype.setItem=function(e,t){return this.database.setItem(e,t)},e.prototype.removeItem=function(e){return this.database.removeItem(e)},e.prototype.clear=function(){return this.database.clear()},e.prototype.setItemSubscribe=function(e,t){this.setItem(e,t).subscribe(function(){},function(){})},e.prototype.removeItemSubscribe=function(e){this.removeItem(e).subscribe(function(){},function(){})},e.prototype.clearSubscribe=function(){this.clear().subscribe(function(){},function(){})},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:p},{type:c}]},e.ngInjectableDef=t.defineInjectable({factory:function(){return new e(t.inject(p),t.inject(c))},token:e,providedIn:"root"}),e}();e.LocalDatabase=p,e.IndexedDBDatabase=a,e.LocalStorageDatabase=s,e.MockLocalDatabase=u,e.JSONValidator=c,e.LocalStorage=f,e.ɵa=i,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common","rxjs","rxjs/operators"],t):t((e.ngxPWA=e.ngxPWA||{},e.ngxPWA.localStorage=e.ngxPWA.localStorage||{}),e.ng.core,e.ng.common,e.Rx,e.Rx.operators)}(this,function(e,t,r,n,o){"use strict";function i(e,t){return r.isPlatformBrowser(e)&&"indexedDB"in window&&void 0!==indexedDB&&null!==indexedDB?new u(t):r.isPlatformBrowser(e)&&"localStorage"in window&&void 0!==localStorage&&null!==localStorage?new s(t):new c}var a=new t.InjectionToken("localStoragePrefix",{providedIn:"root",factory:function(){return""}}),u=function(){function e(e){void 0===e&&(e=null),this.prefix=e,this.dbName="ngStorage",this.objectStoreName="localStorage",this.keyPath="key",this.dataPath="value",e&&(this.dbName=e+"_"+this.dbName),e&&(this.dbName=e+"_"+this.dbName),this.database=new n.ReplaySubject,this.connect()}return e.prototype.getItem=function(e){var t=this;return this.transaction().pipe(o.map(function(t){return t.get(e)}),o.mergeMap(function(e){var r=n.fromEvent(e,"success").pipe(o.map(function(e){return e.target.result}),o.map(function(e){return e&&t.dataPath in e?e[t.dataPath]:null}));return n.race(r,t.toErrorObservable(e,"getter")).pipe(o.first())}),o.first())},e.prototype.setItem=function(e,t){var r=this;return null==t?n.of(!0):this.getItem(e).pipe(o.map(function(e){return null==e?"add":"put"}),o.mergeMap(function(i){return r.transaction("readwrite").pipe(o.mergeMap(function(a){var u;switch(i){case"add":u=a.add((s={},s[r.dataPath]=t,s),e);break;case"put":default:u=a.put((c={},c[r.dataPath]=t,c),e)}return n.race(r.toSuccessObservable(u),r.toErrorObservable(u,"setter")).pipe(o.first());var s,c}))}),o.first())},e.prototype.removeItem=function(e){var t=this;return this.getItem(e).pipe(o.mergeMap(function(r){return null!=r?t.transaction("readwrite").pipe(o.mergeMap(function(r){var i=r.delete(e);return n.race(t.toSuccessObservable(i),t.toErrorObservable(i,"remover")).pipe(o.first())})):n.of(!0)}),o.first())},e.prototype.clear=function(){var e=this;return this.transaction("readwrite").pipe(o.mergeMap(function(t){var r=t.clear();return n.race(e.toSuccessObservable(r),e.toErrorObservable(r,"clearer")).pipe(o.first())}),o.first())},e.prototype.connect=function(){var e=this,t=indexedDB.open(this.dbName);n.fromEvent(t,"upgradeneeded").pipe(o.first()).subscribe(function(t){var r=t.target.result;r.objectStoreNames.contains(e.objectStoreName)||r.createObjectStore(e.objectStoreName)});var r=n.fromEvent(t,"success");n.race(r,this.toErrorObservable(t,"connection")).pipe(o.first()).subscribe(function(t){e.database.next(t.target.result)},function(t){e.database.error(t)})},e.prototype.transaction=function(e){var t=this;return void 0===e&&(e="readonly"),this.database.pipe(o.map(function(r){return r.transaction([t.objectStoreName],e).objectStore(t.objectStoreName)}))},e.prototype.toSuccessObservable=function(e){return n.fromEvent(e,"success").pipe(o.map(function(){return!0}))},e.prototype.toErrorObservable=function(e,t){return void 0===t&&(t=""),n.fromEvent(e,"error").pipe(o.mergeMap(function(r){return n.throwError(new Error("IndexedDB "+t+" issue : "+e.error.message+"."))}))},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[a]}]}]},e.ngInjectableDef=t.defineInjectable({factory:function(){return new e(t.inject(a,8))},token:e,providedIn:"root"}),e}(),s=function(){function e(e){void 0===e&&(e=null),this.userPrefix=e,this.prefix="",e&&(this.prefix=e+"_")}return e.prototype.getItem=function(e){var t=localStorage.getItem(""+this.prefix+e),r=null;if(null!=t)try{r=JSON.parse(t)}catch(e){return n.throwError(new Error("Invalid data in localStorage."))}return n.of(r)},e.prototype.setItem=function(e,t){return localStorage.setItem(""+this.prefix+e,JSON.stringify(t)),n.of(!0)},e.prototype.removeItem=function(e){return localStorage.removeItem(""+this.prefix+e),n.of(!0)},e.prototype.clear=function(){return localStorage.clear(),n.of(!0)},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[a]}]}]},e.ngInjectableDef=t.defineInjectable({factory:function(){return new e(t.inject(a,8))},token:e,providedIn:"root"}),e}(),c=function(){function e(){this.localStorage=new Map}return e.prototype.getItem=function(e){var t=this.localStorage.get(e);return n.of(void 0!==t?t:null)},e.prototype.setItem=function(e,t){return this.localStorage.set(e,t),n.of(!0)},e.prototype.removeItem=function(e){return this.localStorage.delete(e),n.of(!0)},e.prototype.clear=function(){return this.localStorage.clear(),n.of(!0)},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ngInjectableDef=t.defineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),p=function(){function e(){}return e.decorators=[{type:t.Injectable,args:[{providedIn:"root",useFactory:i,deps:[t.PLATFORM_ID,[new t.Optional,a]]}]}],e.ngInjectableDef=t.defineInjectable({factory:function(){return i(t.inject(t.PLATFORM_ID),t.inject(a,8))},token:e,providedIn:"root"}),e}(),l=function(){function e(){}return e.prototype.validate=function(e,t){if(!((t.hasOwnProperty("const")&&void 0!==t.const||t.hasOwnProperty("enum")&&null!=t.enum||t.hasOwnProperty("type")&&null!=t.type)&&"array"!==t.type&&"object"!==t.type||t.hasOwnProperty("properties")&&null!=t.properties||t.hasOwnProperty("items")&&null!=t.items))throw new Error("Each value must have a 'type' or 'properties' or 'items' or 'const' or 'enum', to enforce strict types.");return(!t.hasOwnProperty("const")||void 0===t.const||e===t.const)&&(!!this.validateEnum(e,t)&&(!!this.validateType(e,t)&&(!!this.validateItems(e,t)&&(!!this.validateProperties(e,t)&&!!this.validateRequired(e,t)))))},e.prototype.isObjectNotNull=function(e){return null!==e&&"object"==typeof e},e.prototype.validateProperties=function(e,t){if(!t.hasOwnProperty("properties")||null==t.properties)return!0;if(!this.isObjectNotNull(e))return!1;if(Object.keys(t.properties).length!==Object.keys(e).length)return!1;for(var r in t.properties)if(t.properties.hasOwnProperty(r)&&e.hasOwnProperty(r)&&!this.validate(e[r],t.properties[r]))return!1;return!0},e.prototype.validateRequired=function(e,t){if(!t.hasOwnProperty("required")||null==t.required)return!0;if(!this.isObjectNotNull(e))return!1;for(var r=0,n=t.required;r<n.length;r++){var o=n[r];if(!t.properties||!t.properties.hasOwnProperty(o))throw new Error("'required' properties must be described in 'properties' too.");if(!e.hasOwnProperty(o))return!1}return!0},e.prototype.validateEnum=function(e,t){return!t.hasOwnProperty("enum")||null==t.enum||-1!==t.enum.indexOf(e)},e.prototype.validateType=function(e,t){if(!t.hasOwnProperty("type")||null==t.type)return!0;switch(t.type){case"null":return null===e;case"string":return this.validateString(e,t);case"number":case"integer":return this.validateNumber(e,t);case"boolean":return"boolean"==typeof e;case"object":return"object"==typeof e;case"array":return Array.isArray(e)}},e.prototype.validateItems=function(e,t){if(!t.hasOwnProperty("items")||null==t.items)return!0;if(!Array.isArray(e))return!1;if(t.hasOwnProperty("maxItems")&&null!=t.maxItems){if(!Number.isInteger(t.maxItems)||t.maxItems<0)throw new Error("'maxItems' must be a non-negative integer.");if(e.length>t.maxItems)return!1}if(t.hasOwnProperty("minItems")&&null!=t.minItems){if(!Number.isInteger(t.minItems)||t.minItems<0)throw new Error("'minItems' must be a non-negative integer.");if(e.length<t.minItems)return!1}if(t.hasOwnProperty("uniqueItems")&&null!=t.uniqueItems&&t.uniqueItems){var r=new Set(e);if(e.length!==r.size)return!1}if(Array.isArray(t.items))return this.validateItemsList(e,t);for(var n=0,o=e;n<o.length;n++){var i=o[n];if(!this.validate(i,t.items))return!1}return!0},e.prototype.validateItemsList=function(e,t){var r=t.items;if(e.length!==r.length)return!1;for(var n=0;n<r.length;n+=1)if(!this.validate(e[n],r[n]))return!1;return!0},e.prototype.validateString=function(e,t){if("string"!=typeof e)return!1;if(t.hasOwnProperty("maxLength")&&null!=t.maxLength){if(!Number.isInteger(t.maxLength)||t.maxLength<0)throw new Error("'maxLength' must be a non-negative integer.");if(e.length>t.maxLength)return!1}if(t.hasOwnProperty("minLength")&&null!=t.minLength){if(!Number.isInteger(t.minLength)||t.minLength<0)throw new Error("'minLength' must be a non-negative integer.");if(e.length<t.minLength)return!1}if(t.hasOwnProperty("pattern")&&null!=t.pattern){if(!new RegExp(t.pattern).test(e))return!1}return!0},e.prototype.validateNumber=function(e,t){if("number"!=typeof e)return!1;if("integer"===t.type&&!Number.isInteger(e))return!1;if(t.hasOwnProperty("multipleOf")&&null!=t.multipleOf){if(t.multipleOf<=0)throw new Error("'multipleOf' must be a number strictly greater than 0.");if(!Number.isInteger(e/t.multipleOf))return!1}return!(t.hasOwnProperty("maximum")&&null!=t.maximum&&e>t.maximum)&&(!(t.hasOwnProperty("exclusiveMaximum")&&null!=t.exclusiveMaximum&&e>=t.exclusiveMaximum)&&(!(t.hasOwnProperty("minimum")&&null!=t.minimum&&e<t.minimum)&&!(t.hasOwnProperty("exclusiveMinimum")&&null!=t.exclusiveMinimum&&e<=t.exclusiveMinimum)))},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ngInjectableDef=t.defineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),f=function(){function e(e,t){this.database=e,this.jsonValidator=t,this.getItemOptionsDefault={schema:null}}return e.prototype.getItem=function(e,t){var r=this;return void 0===t&&(t=this.getItemOptionsDefault),this.database.getItem(e).pipe(o.mergeMap(function(e){if(t.schema&&null!==e){var o=!0;try{o=r.jsonValidator.validate(e,t.schema)}catch(e){return n.throwError(e)}if(!o)return n.throwError(new Error("JSON invalid"))}return n.of(e)}))},e.prototype.setItem=function(e,t){return this.database.setItem(e,t)},e.prototype.removeItem=function(e){return this.database.removeItem(e)},e.prototype.clear=function(){return this.database.clear()},e.prototype.setItemSubscribe=function(e,t){this.setItem(e,t).subscribe(function(){},function(){})},e.prototype.removeItemSubscribe=function(e){this.removeItem(e).subscribe(function(){},function(){})},e.prototype.clearSubscribe=function(){this.clear().subscribe(function(){},function(){})},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:p},{type:l}]},e.ngInjectableDef=t.defineInjectable({factory:function(){return new e(t.inject(p),t.inject(l))},token:e,providedIn:"root"}),e}();e.LocalDatabase=p,e.IndexedDBDatabase=u,e.LocalStorageDatabase=s,e.MockLocalDatabase=c,e.JSONValidator=l,e.LocalStorage=f,e.localStorageProviders=function(e){return[e.prefix?{provide:a,useValue:e.prefix}:[]]},e.LOCAL_STORAGE_PREFIX=a,e.ɵa=i,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=local-storage.umd.min.js.map

@@ -1,2 +0,2 @@

import { Injectable, PLATFORM_ID, defineInjectable, inject } from '@angular/core';
import { Inject, Injectable, InjectionToken, Optional, PLATFORM_ID, defineInjectable, inject } from '@angular/core';
import * as i0 from '@angular/core';

@@ -11,7 +11,28 @@ import { isPlatformBrowser } from '@angular/common';

*/
const LOCAL_STORAGE_PREFIX = new InjectionToken('localStoragePrefix', { providedIn: 'root', factory: () => '' });
/**
* @record
*/
/**
* @param {?} config
* @return {?}
*/
function localStorageProviders(config) {
return [
config.prefix ? { provide: LOCAL_STORAGE_PREFIX, useValue: config.prefix } : []
];
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
class IndexedDBDatabase {
/**
* Connects to IndexedDB
* @param {?=} prefix
*/
constructor() {
constructor(prefix = null) {
this.prefix = prefix;
/**

@@ -33,2 +54,8 @@ * IndexedDB database name for local storage

this.dataPath = 'value';
if (prefix) {
this.dbName = `${prefix}_${this.dbName}`;
}
if (prefix) {
this.dbName = `${prefix}_${this.dbName}`;
}
/* Creating the RxJS ReplaySubject */

@@ -193,4 +220,6 @@ this.database = new ReplaySubject();

/** @nocollapse */
IndexedDBDatabase.ctorParameters = () => [];
/** @nocollapse */ IndexedDBDatabase.ngInjectableDef = defineInjectable({ factory: function IndexedDBDatabase_Factory() { return new IndexedDBDatabase(); }, token: IndexedDBDatabase, providedIn: "root" });
IndexedDBDatabase.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [LOCAL_STORAGE_PREFIX,] },] },
];
/** @nocollapse */ IndexedDBDatabase.ngInjectableDef = defineInjectable({ factory: function IndexedDBDatabase_Factory() { return new IndexedDBDatabase(inject(LOCAL_STORAGE_PREFIX, 8)); }, token: IndexedDBDatabase, providedIn: "root" });

@@ -202,5 +231,12 @@ /**

class LocalStorageDatabase {
constructor() {
/**
* @param {?=} userPrefix
*/
constructor(userPrefix = null) {
this.userPrefix = userPrefix;
/* Initializing native localStorage right now to be able to check its support on class instanciation */
this.localStorage = localStorage;
this.prefix = '';
if (userPrefix) {
this.prefix = `${userPrefix}_`;
}
}

@@ -214,3 +250,3 @@ /**

getItem(key) {
const /** @type {?} */ unparsedData = this.localStorage.getItem(key);
const /** @type {?} */ unparsedData = localStorage.getItem(`${this.prefix}${key}`);
let /** @type {?} */ parsedData = null;

@@ -234,3 +270,3 @@ if (unparsedData != null) {

setItem(key, data) {
this.localStorage.setItem(key, JSON.stringify(data));
localStorage.setItem(`${this.prefix}${key}`, JSON.stringify(data));
return of(true);

@@ -244,3 +280,3 @@ }

removeItem(key) {
this.localStorage.removeItem(key);
localStorage.removeItem(`${this.prefix}${key}`);
return of(true);

@@ -253,3 +289,3 @@ }

clear() {
this.localStorage.clear();
localStorage.clear();
return of(true);

@@ -263,3 +299,7 @@ }

];
/** @nocollapse */ LocalStorageDatabase.ngInjectableDef = defineInjectable({ factory: function LocalStorageDatabase_Factory() { return new LocalStorageDatabase(); }, token: LocalStorageDatabase, providedIn: "root" });
/** @nocollapse */
LocalStorageDatabase.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [LOCAL_STORAGE_PREFIX,] },] },
];
/** @nocollapse */ LocalStorageDatabase.ngInjectableDef = defineInjectable({ factory: function LocalStorageDatabase_Factory() { return new LocalStorageDatabase(inject(LOCAL_STORAGE_PREFIX, 8)); }, token: LocalStorageDatabase, providedIn: "root" });

@@ -325,12 +365,13 @@ /**

* @param {?} platformId
* @param {?} prefix
* @return {?}
*/
function localDatabaseFactory(platformId) {
function localDatabaseFactory(platformId, prefix) {
if (isPlatformBrowser(platformId) && ('indexedDB' in window) && (indexedDB !== undefined) && (indexedDB !== null)) {
/* Try with IndexedDB in modern browsers */
return new IndexedDBDatabase();
return new IndexedDBDatabase(prefix);
}
else if (isPlatformBrowser(platformId) && ('localStorage' in window) && (localStorage !== undefined) && (localStorage !== null)) {
/* Try with localStorage in old browsers (IE9) */
return new LocalStorageDatabase();
return new LocalStorageDatabase(prefix);
}

@@ -352,6 +393,9 @@ else {

useFactory: localDatabaseFactory,
deps: [PLATFORM_ID]
deps: [
PLATFORM_ID,
[new Optional(), LOCAL_STORAGE_PREFIX]
]
},] },
];
/** @nocollapse */ LocalDatabase.ngInjectableDef = defineInjectable({ factory: function LocalDatabase_Factory() { return localDatabaseFactory(inject(PLATFORM_ID)); }, token: LocalDatabase, providedIn: "root" });
/** @nocollapse */ LocalDatabase.ngInjectableDef = defineInjectable({ factory: function LocalDatabase_Factory() { return localDatabaseFactory(inject(PLATFORM_ID), inject(LOCAL_STORAGE_PREFIX, 8)); }, token: LocalDatabase, providedIn: "root" });

@@ -369,34 +413,35 @@ /**

* @param {?} data JSON data to validate
* @param {?} schema Subset of JSON Schema
* @param {?} schema Subset of JSON Schema.
* Types are enforced to validate everything:
* each value MUST have 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* Not all validation features are supported: just follow the interface.
* @return {?} If data is valid : true, if it is invalid : false, and throws if the schema is invalid
*/
validate(data, schema) {
if (!this.isObjectNotNull(schema)) {
throw new Error(`A schema must be an object (unlike spec, booleans are not supported to enforce strict types).`);
}
if (((!schema.hasOwnProperty('const') && !schema.hasOwnProperty('enum') && !schema.hasOwnProperty('type'))
/** @todo When TS 2.8, explore if this is possible with conditional types */
if (((!(schema.hasOwnProperty('const') && schema.const !== undefined)
&& !(schema.hasOwnProperty('enum') && schema.enum != null) && !(schema.hasOwnProperty('type') && schema.type != null))
|| schema.type === 'array' || schema.type === 'object')
&& !schema.hasOwnProperty('properties') && !schema.hasOwnProperty('items')) {
&& !(schema.hasOwnProperty('properties') && schema.properties != null) && !(schema.hasOwnProperty('items') && schema.items != null)) {
throw new Error(`Each value must have a 'type' or 'properties' or 'items' or 'const' or 'enum', to enforce strict types.`);
}
if (schema.hasOwnProperty('const') && (data !== schema.const)) {
if (schema.hasOwnProperty('const') && schema.const !== undefined && (data !== schema.const)) {
return false;
}
if (schema.hasOwnProperty('enum') && !this.validateEnum(data, schema)) {
if (!this.validateEnum(data, schema)) {
return false;
}
if (schema.hasOwnProperty('type') && !this.validateType(data, schema)) {
if (!this.validateType(data, schema)) {
return false;
}
if (schema.hasOwnProperty('items') && !this.validateItems(data, schema)) {
if (!this.validateItems(data, schema)) {
return false;
}
if (schema.hasOwnProperty('properties')) {
if (schema.hasOwnProperty('required') && !this.validateRequired(data, schema)) {
return false;
}
if (!this.validateProperties(data, schema)) {
return false;
}
if (!this.validateProperties(data, schema)) {
return false;
}
if (!this.validateRequired(data, schema)) {
return false;
}
return true;

@@ -417,8 +462,8 @@ }

validateProperties(data, schema) {
if (!schema.hasOwnProperty('properties') || (schema.properties == null)) {
return true;
}
if (!this.isObjectNotNull(data)) {
return false;
}
if (!schema.properties || !this.isObjectNotNull(schema.properties)) {
throw new Error(`'properties' must be a schema object.`);
}
/**

@@ -447,12 +492,9 @@ * Check if the object doesn't have more properties than expected

validateRequired(data, schema) {
if (!schema.hasOwnProperty('required') || (schema.required == null)) {
return true;
}
if (!this.isObjectNotNull(data)) {
return false;
}
if (!Array.isArray(schema.required)) {
throw new Error(`'required' field must be an array. Note that since JSON Schema draft 6, booleans are not supported anymore.`);
}
for (let /** @type {?} */ requiredProp of schema.required) {
if (typeof requiredProp !== 'string') {
throw new Error(`'required' array must contain strings only.`);
}
/* Checks if the property is present in the schema 'properties' */

@@ -475,4 +517,4 @@ if (!schema.properties || !schema.properties.hasOwnProperty(requiredProp)) {

validateEnum(data, schema) {
if (!Array.isArray(schema.enum)) {
throw new Error(`'enum' must be an array.`);
if (!schema.hasOwnProperty('enum') || (schema.enum == null)) {
return true;
}

@@ -488,24 +530,20 @@ /** @todo Move to ES2016 .includes() ? */

validateType(data, schema) {
if (Array.isArray(schema.type)) {
return this.validateTypeList(data, schema);
if (!schema.hasOwnProperty('type') || (schema.type == null)) {
return true;
}
if (typeof schema.type !== 'string') {
throw new Error(`'type' must be a string (arrays of types are not supported yet).`);
switch (schema.type) {
case 'null':
return data === null;
case 'string':
return this.validateString(data, schema);
case 'number':
case 'integer':
return this.validateNumber(data, schema);
case 'boolean':
return typeof data === 'boolean';
case 'object':
return typeof data === 'object';
case 'array':
return Array.isArray(data);
}
if ((schema.type === 'null') && (data !== null)) {
return false;
}
if (schema.type === 'string') {
return this.validateString(data, schema);
}
if ((schema.type === 'number') || (schema.type === 'integer')) {
return this.validateNumber(data, schema);
}
if ((schema.type === 'boolean') && (typeof data !== 'boolean')) {
return false;
}
if ((schema.type === 'object') && (typeof data !== 'object')) {
return false;
}
return true;
}

@@ -517,21 +555,11 @@ /**

*/
validateTypeList(data, schema) {
const /** @type {?} */ types = /** @type {?} */ (schema.type);
const /** @type {?} */ typesTests = [];
for (let /** @type {?} */ type of types) {
typesTests.push(this.validateType(data, { type }));
validateItems(data, schema) {
if (!schema.hasOwnProperty('items') || (schema.items == null)) {
return true;
}
return (typesTests.indexOf(true) !== -1);
}
/**
* @param {?} data
* @param {?} schema
* @return {?}
*/
validateItems(data, schema) {
if (!Array.isArray(data)) {
return false;
}
if (schema.hasOwnProperty('maxItems')) {
if ((typeof schema.maxItems !== 'number') || !Number.isInteger(schema.maxItems) || schema.maxItems < 0) {
if (schema.hasOwnProperty('maxItems') && (schema.maxItems != null)) {
if (!Number.isInteger(schema.maxItems) || schema.maxItems < 0) {
throw new Error(`'maxItems' must be a non-negative integer.`);

@@ -543,4 +571,4 @@ }

}
if (schema.hasOwnProperty('minItems')) {
if ((typeof schema.minItems !== 'number') || !Number.isInteger(schema.minItems) || schema.minItems < 0) {
if (schema.hasOwnProperty('minItems') && (schema.minItems != null)) {
if (!Number.isInteger(schema.minItems) || schema.minItems < 0) {
throw new Error(`'minItems' must be a non-negative integer.`);

@@ -552,6 +580,3 @@ }

}
if (schema.hasOwnProperty('uniqueItems')) {
if (typeof schema.uniqueItems !== 'boolean') {
throw new Error(`'minItems' must be a boolean.`);
}
if (schema.hasOwnProperty('uniqueItems') && (schema.uniqueItems != null)) {
if (schema.uniqueItems) {

@@ -567,5 +592,2 @@ const /** @type {?} */ dataSet = new Set(data);

}
if (!schema.items || !this.isObjectNotNull(schema.items)) {
throw new Error(`'items' must be a schema object.`);
}
for (let /** @type {?} */ value of data) {

@@ -604,4 +626,4 @@ if (!this.validate(value, schema.items)) {

}
if (schema.hasOwnProperty('maxLength')) {
if ((typeof schema.maxLength !== 'number') || !Number.isInteger(schema.maxLength) || schema.maxLength < 0) {
if (schema.hasOwnProperty('maxLength') && (schema.maxLength != null)) {
if (!Number.isInteger(schema.maxLength) || schema.maxLength < 0) {
throw new Error(`'maxLength' must be a non-negative integer.`);

@@ -613,4 +635,4 @@ }

}
if (schema.hasOwnProperty('minLength')) {
if ((typeof schema.minLength !== 'number') || !Number.isInteger(schema.minLength) || schema.minLength < 0) {
if (schema.hasOwnProperty('minLength') && (schema.minLength != null)) {
if (!Number.isInteger(schema.minLength) || schema.minLength < 0) {
throw new Error(`'minLength' must be a non-negative integer.`);

@@ -622,6 +644,3 @@ }

}
if (schema.hasOwnProperty('pattern')) {
if (typeof schema.pattern !== 'string') {
throw new Error(`'pattern' must be a string with a valid RegExp.`);
}
if (schema.hasOwnProperty('pattern') && (schema.pattern != null)) {
const /** @type {?} */ regularExpression = new RegExp(schema.pattern);

@@ -646,4 +665,4 @@ if (!regularExpression.test(data)) {

}
if (schema.hasOwnProperty('multipleOf')) {
if ((typeof schema.multipleOf !== 'number') || schema.multipleOf <= 0) {
if (schema.hasOwnProperty('multipleOf') && (schema.multipleOf != null)) {
if (schema.multipleOf <= 0) {
throw new Error(`'multipleOf' must be a number strictly greater than 0.`);

@@ -655,6 +674,3 @@ }

}
if (schema.hasOwnProperty('maximum')) {
if (typeof schema.maximum !== 'number') {
throw new Error(`'maximum' must be a number.`);
}
if (schema.hasOwnProperty('maximum') && (schema.maximum != null)) {
if (data > schema.maximum) {

@@ -664,6 +680,3 @@ return false;

}
if (schema.hasOwnProperty('exclusiveMaximum')) {
if (typeof schema.exclusiveMaximum !== 'number') {
throw new Error(`'exclusiveMaximum' must be a number.`);
}
if (schema.hasOwnProperty('exclusiveMaximum') && (schema.exclusiveMaximum != null)) {
if (data >= schema.exclusiveMaximum) {

@@ -673,6 +686,3 @@ return false;

}
if (schema.hasOwnProperty('minimum')) {
if (typeof schema.minimum !== 'number') {
throw new Error(`'minimum' must be a number.`);
}
if (schema.hasOwnProperty('minimum') && (schema.minimum != null)) {
if (data < schema.minimum) {

@@ -682,6 +692,3 @@ return false;

}
if (schema.hasOwnProperty('exclusiveMinimum')) {
if (typeof schema.exclusiveMinimum !== 'number') {
throw new Error(`'exclusiveMinimum' must be a number.`);
}
if (schema.hasOwnProperty('exclusiveMinimum') && (schema.exclusiveMinimum != null)) {
if (data <= schema.exclusiveMinimum) {

@@ -820,3 +827,3 @@ return false;

export { LocalDatabase, IndexedDBDatabase, LocalStorageDatabase, MockLocalDatabase, JSONValidator, LocalStorage, localDatabaseFactory as ɵa };
export { LocalDatabase, IndexedDBDatabase, LocalStorageDatabase, MockLocalDatabase, JSONValidator, LocalStorage, localStorageProviders, LOCAL_STORAGE_PREFIX, localDatabaseFactory as ɵa };
//# sourceMappingURL=local-storage.js.map

@@ -1,2 +0,2 @@

import { Injectable, PLATFORM_ID, defineInjectable, inject } from '@angular/core';
import { Inject, Injectable, InjectionToken, Optional, PLATFORM_ID, defineInjectable, inject } from '@angular/core';
import * as i0 from '@angular/core';

@@ -11,2 +11,21 @@ import { isPlatformBrowser } from '@angular/common';

*/
var LOCAL_STORAGE_PREFIX = new InjectionToken('localStoragePrefix', { providedIn: 'root', factory: function () { return ''; } });
/**
* @record
*/
/**
* @param {?} config
* @return {?}
*/
function localStorageProviders(config) {
return [
config.prefix ? { provide: LOCAL_STORAGE_PREFIX, useValue: config.prefix } : []
];
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var IndexedDBDatabase = /** @class */ (function () {

@@ -16,3 +35,5 @@ /**

*/
function IndexedDBDatabase() {
function IndexedDBDatabase(prefix) {
if (prefix === void 0) { prefix = null; }
this.prefix = prefix;
/**

@@ -34,2 +55,8 @@ * IndexedDB database name for local storage

this.dataPath = 'value';
if (prefix) {
this.dbName = prefix + "_" + this.dbName;
}
if (prefix) {
this.dbName = prefix + "_" + this.dbName;
}
/* Creating the RxJS ReplaySubject */

@@ -283,4 +310,6 @@ this.database = new ReplaySubject();

/** @nocollapse */
IndexedDBDatabase.ctorParameters = function () { return []; };
/** @nocollapse */ IndexedDBDatabase.ngInjectableDef = defineInjectable({ factory: function IndexedDBDatabase_Factory() { return new IndexedDBDatabase(); }, token: IndexedDBDatabase, providedIn: "root" });
IndexedDBDatabase.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [LOCAL_STORAGE_PREFIX,] },] },
]; };
/** @nocollapse */ IndexedDBDatabase.ngInjectableDef = defineInjectable({ factory: function IndexedDBDatabase_Factory() { return new IndexedDBDatabase(inject(LOCAL_STORAGE_PREFIX, 8)); }, token: IndexedDBDatabase, providedIn: "root" });
return IndexedDBDatabase;

@@ -294,5 +323,10 @@ }());

var LocalStorageDatabase = /** @class */ (function () {
function LocalStorageDatabase() {
function LocalStorageDatabase(userPrefix) {
if (userPrefix === void 0) { userPrefix = null; }
this.userPrefix = userPrefix;
/* Initializing native localStorage right now to be able to check its support on class instanciation */
this.localStorage = localStorage;
this.prefix = '';
if (userPrefix) {
this.prefix = userPrefix + "_";
}
}

@@ -317,3 +351,3 @@ /**

function (key) {
var /** @type {?} */ unparsedData = this.localStorage.getItem(key);
var /** @type {?} */ unparsedData = localStorage.getItem("" + this.prefix + key);
var /** @type {?} */ parsedData = null;

@@ -349,3 +383,3 @@ if (unparsedData != null) {

function (key, data) {
this.localStorage.setItem(key, JSON.stringify(data));
localStorage.setItem("" + this.prefix + key, JSON.stringify(data));
return of(true);

@@ -369,3 +403,3 @@ };

function (key) {
this.localStorage.removeItem(key);
localStorage.removeItem("" + this.prefix + key);
return of(true);

@@ -386,3 +420,3 @@ };

function () {
this.localStorage.clear();
localStorage.clear();
return of(true);

@@ -395,3 +429,7 @@ };

];
/** @nocollapse */ LocalStorageDatabase.ngInjectableDef = defineInjectable({ factory: function LocalStorageDatabase_Factory() { return new LocalStorageDatabase(); }, token: LocalStorageDatabase, providedIn: "root" });
/** @nocollapse */
LocalStorageDatabase.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [LOCAL_STORAGE_PREFIX,] },] },
]; };
/** @nocollapse */ LocalStorageDatabase.ngInjectableDef = defineInjectable({ factory: function LocalStorageDatabase_Factory() { return new LocalStorageDatabase(inject(LOCAL_STORAGE_PREFIX, 8)); }, token: LocalStorageDatabase, providedIn: "root" });
return LocalStorageDatabase;

@@ -501,12 +539,13 @@ }());

* @param {?} platformId
* @param {?} prefix
* @return {?}
*/
function localDatabaseFactory(platformId) {
function localDatabaseFactory(platformId, prefix) {
if (isPlatformBrowser(platformId) && ('indexedDB' in window) && (indexedDB !== undefined) && (indexedDB !== null)) {
/* Try with IndexedDB in modern browsers */
return new IndexedDBDatabase();
return new IndexedDBDatabase(prefix);
}
else if (isPlatformBrowser(platformId) && ('localStorage' in window) && (localStorage !== undefined) && (localStorage !== null)) {
/* Try with localStorage in old browsers (IE9) */
return new LocalStorageDatabase();
return new LocalStorageDatabase(prefix);
}

@@ -529,6 +568,9 @@ else {

useFactory: localDatabaseFactory,
deps: [PLATFORM_ID]
deps: [
PLATFORM_ID,
[new Optional(), LOCAL_STORAGE_PREFIX]
]
},] },
];
/** @nocollapse */ LocalDatabase.ngInjectableDef = defineInjectable({ factory: function LocalDatabase_Factory() { return localDatabaseFactory(inject(PLATFORM_ID)); }, token: LocalDatabase, providedIn: "root" });
/** @nocollapse */ LocalDatabase.ngInjectableDef = defineInjectable({ factory: function LocalDatabase_Factory() { return localDatabaseFactory(inject(PLATFORM_ID), inject(LOCAL_STORAGE_PREFIX, 8)); }, token: LocalDatabase, providedIn: "root" });
return LocalDatabase;

@@ -550,3 +592,7 @@ }());

* @param data JSON data to validate
* @param schema Subset of JSON Schema
* @param schema Subset of JSON Schema.
* Types are enforced to validate everything:
* each value MUST have 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* Not all validation features are supported: just follow the interface.
* @returns If data is valid : true, if it is invalid : false, and throws if the schema is invalid

@@ -557,3 +603,7 @@ */

* @param {?} data JSON data to validate
* @param {?} schema Subset of JSON Schema
* @param {?} schema Subset of JSON Schema.
* Types are enforced to validate everything:
* each value MUST have 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* Not all validation features are supported: just follow the interface.
* @return {?} If data is valid : true, if it is invalid : false, and throws if the schema is invalid

@@ -564,34 +614,35 @@ */

* @param {?} data JSON data to validate
* @param {?} schema Subset of JSON Schema
* @param {?} schema Subset of JSON Schema.
* Types are enforced to validate everything:
* each value MUST have 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* Not all validation features are supported: just follow the interface.
* @return {?} If data is valid : true, if it is invalid : false, and throws if the schema is invalid
*/
function (data, schema) {
if (!this.isObjectNotNull(schema)) {
throw new Error("A schema must be an object (unlike spec, booleans are not supported to enforce strict types).");
}
if (((!schema.hasOwnProperty('const') && !schema.hasOwnProperty('enum') && !schema.hasOwnProperty('type'))
/** @todo When TS 2.8, explore if this is possible with conditional types */
if (((!(schema.hasOwnProperty('const') && schema.const !== undefined)
&& !(schema.hasOwnProperty('enum') && schema.enum != null) && !(schema.hasOwnProperty('type') && schema.type != null))
|| schema.type === 'array' || schema.type === 'object')
&& !schema.hasOwnProperty('properties') && !schema.hasOwnProperty('items')) {
&& !(schema.hasOwnProperty('properties') && schema.properties != null) && !(schema.hasOwnProperty('items') && schema.items != null)) {
throw new Error("Each value must have a 'type' or 'properties' or 'items' or 'const' or 'enum', to enforce strict types.");
}
if (schema.hasOwnProperty('const') && (data !== schema.const)) {
if (schema.hasOwnProperty('const') && schema.const !== undefined && (data !== schema.const)) {
return false;
}
if (schema.hasOwnProperty('enum') && !this.validateEnum(data, schema)) {
if (!this.validateEnum(data, schema)) {
return false;
}
if (schema.hasOwnProperty('type') && !this.validateType(data, schema)) {
if (!this.validateType(data, schema)) {
return false;
}
if (schema.hasOwnProperty('items') && !this.validateItems(data, schema)) {
if (!this.validateItems(data, schema)) {
return false;
}
if (schema.hasOwnProperty('properties')) {
if (schema.hasOwnProperty('required') && !this.validateRequired(data, schema)) {
return false;
}
if (!this.validateProperties(data, schema)) {
return false;
}
if (!this.validateProperties(data, schema)) {
return false;
}
if (!this.validateRequired(data, schema)) {
return false;
}
return true;

@@ -621,8 +672,8 @@ };

function (data, schema) {
if (!schema.hasOwnProperty('properties') || (schema.properties == null)) {
return true;
}
if (!this.isObjectNotNull(data)) {
return false;
}
if (!schema.properties || !this.isObjectNotNull(schema.properties)) {
throw new Error("'properties' must be a schema object.");
}
/**

@@ -656,13 +707,10 @@ * Check if the object doesn't have more properties than expected

function (data, schema) {
if (!schema.hasOwnProperty('required') || (schema.required == null)) {
return true;
}
if (!this.isObjectNotNull(data)) {
return false;
}
if (!Array.isArray(schema.required)) {
throw new Error("'required' field must be an array. Note that since JSON Schema draft 6, booleans are not supported anymore.");
}
for (var _i = 0, _a = schema.required; _i < _a.length; _i++) {
var requiredProp = _a[_i];
if (typeof requiredProp !== 'string') {
throw new Error("'required' array must contain strings only.");
}
/* Checks if the property is present in the schema 'properties' */

@@ -690,4 +738,4 @@ if (!schema.properties || !schema.properties.hasOwnProperty(requiredProp)) {

function (data, schema) {
if (!Array.isArray(schema.enum)) {
throw new Error("'enum' must be an array.");
if (!schema.hasOwnProperty('enum') || (schema.enum == null)) {
return true;
}

@@ -708,24 +756,20 @@ /** @todo Move to ES2016 .includes() ? */

function (data, schema) {
if (Array.isArray(schema.type)) {
return this.validateTypeList(data, schema);
if (!schema.hasOwnProperty('type') || (schema.type == null)) {
return true;
}
if (typeof schema.type !== 'string') {
throw new Error("'type' must be a string (arrays of types are not supported yet).");
switch (schema.type) {
case 'null':
return data === null;
case 'string':
return this.validateString(data, schema);
case 'number':
case 'integer':
return this.validateNumber(data, schema);
case 'boolean':
return typeof data === 'boolean';
case 'object':
return typeof data === 'object';
case 'array':
return Array.isArray(data);
}
if ((schema.type === 'null') && (data !== null)) {
return false;
}
if (schema.type === 'string') {
return this.validateString(data, schema);
}
if ((schema.type === 'number') || (schema.type === 'integer')) {
return this.validateNumber(data, schema);
}
if ((schema.type === 'boolean') && (typeof data !== 'boolean')) {
return false;
}
if ((schema.type === 'object') && (typeof data !== 'object')) {
return false;
}
return true;
};

@@ -737,3 +781,3 @@ /**

*/
JSONValidator.prototype.validateTypeList = /**
JSONValidator.prototype.validateItems = /**
* @param {?} data

@@ -744,26 +788,10 @@ * @param {?} schema

function (data, schema) {
var /** @type {?} */ types = /** @type {?} */ (schema.type);
var /** @type {?} */ typesTests = [];
for (var _i = 0, types_1 = types; _i < types_1.length; _i++) {
var type = types_1[_i];
typesTests.push(this.validateType(data, { type: type }));
if (!schema.hasOwnProperty('items') || (schema.items == null)) {
return true;
}
return (typesTests.indexOf(true) !== -1);
};
/**
* @param {?} data
* @param {?} schema
* @return {?}
*/
JSONValidator.prototype.validateItems = /**
* @param {?} data
* @param {?} schema
* @return {?}
*/
function (data, schema) {
if (!Array.isArray(data)) {
return false;
}
if (schema.hasOwnProperty('maxItems')) {
if ((typeof schema.maxItems !== 'number') || !Number.isInteger(schema.maxItems) || schema.maxItems < 0) {
if (schema.hasOwnProperty('maxItems') && (schema.maxItems != null)) {
if (!Number.isInteger(schema.maxItems) || schema.maxItems < 0) {
throw new Error("'maxItems' must be a non-negative integer.");

@@ -775,4 +803,4 @@ }

}
if (schema.hasOwnProperty('minItems')) {
if ((typeof schema.minItems !== 'number') || !Number.isInteger(schema.minItems) || schema.minItems < 0) {
if (schema.hasOwnProperty('minItems') && (schema.minItems != null)) {
if (!Number.isInteger(schema.minItems) || schema.minItems < 0) {
throw new Error("'minItems' must be a non-negative integer.");

@@ -784,6 +812,3 @@ }

}
if (schema.hasOwnProperty('uniqueItems')) {
if (typeof schema.uniqueItems !== 'boolean') {
throw new Error("'minItems' must be a boolean.");
}
if (schema.hasOwnProperty('uniqueItems') && (schema.uniqueItems != null)) {
if (schema.uniqueItems) {

@@ -799,5 +824,2 @@ var /** @type {?} */ dataSet = new Set(data);

}
if (!schema.items || !this.isObjectNotNull(schema.items)) {
throw new Error("'items' must be a schema object.");
}
for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {

@@ -847,4 +869,4 @@ var value = data_1[_i];

}
if (schema.hasOwnProperty('maxLength')) {
if ((typeof schema.maxLength !== 'number') || !Number.isInteger(schema.maxLength) || schema.maxLength < 0) {
if (schema.hasOwnProperty('maxLength') && (schema.maxLength != null)) {
if (!Number.isInteger(schema.maxLength) || schema.maxLength < 0) {
throw new Error("'maxLength' must be a non-negative integer.");

@@ -856,4 +878,4 @@ }

}
if (schema.hasOwnProperty('minLength')) {
if ((typeof schema.minLength !== 'number') || !Number.isInteger(schema.minLength) || schema.minLength < 0) {
if (schema.hasOwnProperty('minLength') && (schema.minLength != null)) {
if (!Number.isInteger(schema.minLength) || schema.minLength < 0) {
throw new Error("'minLength' must be a non-negative integer.");

@@ -865,6 +887,3 @@ }

}
if (schema.hasOwnProperty('pattern')) {
if (typeof schema.pattern !== 'string') {
throw new Error("'pattern' must be a string with a valid RegExp.");
}
if (schema.hasOwnProperty('pattern') && (schema.pattern != null)) {
var /** @type {?} */ regularExpression = new RegExp(schema.pattern);

@@ -894,4 +913,4 @@ if (!regularExpression.test(data)) {

}
if (schema.hasOwnProperty('multipleOf')) {
if ((typeof schema.multipleOf !== 'number') || schema.multipleOf <= 0) {
if (schema.hasOwnProperty('multipleOf') && (schema.multipleOf != null)) {
if (schema.multipleOf <= 0) {
throw new Error("'multipleOf' must be a number strictly greater than 0.");

@@ -903,6 +922,3 @@ }

}
if (schema.hasOwnProperty('maximum')) {
if (typeof schema.maximum !== 'number') {
throw new Error("'maximum' must be a number.");
}
if (schema.hasOwnProperty('maximum') && (schema.maximum != null)) {
if (data > schema.maximum) {

@@ -912,6 +928,3 @@ return false;

}
if (schema.hasOwnProperty('exclusiveMaximum')) {
if (typeof schema.exclusiveMaximum !== 'number') {
throw new Error("'exclusiveMaximum' must be a number.");
}
if (schema.hasOwnProperty('exclusiveMaximum') && (schema.exclusiveMaximum != null)) {
if (data >= schema.exclusiveMaximum) {

@@ -921,6 +934,3 @@ return false;

}
if (schema.hasOwnProperty('minimum')) {
if (typeof schema.minimum !== 'number') {
throw new Error("'minimum' must be a number.");
}
if (schema.hasOwnProperty('minimum') && (schema.minimum != null)) {
if (data < schema.minimum) {

@@ -930,6 +940,3 @@ return false;

}
if (schema.hasOwnProperty('exclusiveMinimum')) {
if (typeof schema.exclusiveMinimum !== 'number') {
throw new Error("'exclusiveMinimum' must be a number.");
}
if (schema.hasOwnProperty('exclusiveMinimum') && (schema.exclusiveMinimum != null)) {
if (data <= schema.exclusiveMinimum) {

@@ -1135,3 +1142,3 @@ return false;

export { LocalDatabase, IndexedDBDatabase, LocalStorageDatabase, MockLocalDatabase, JSONValidator, LocalStorage, localDatabaseFactory as ɵa };
export { LocalDatabase, IndexedDBDatabase, LocalStorageDatabase, MockLocalDatabase, JSONValidator, LocalStorage, localStorageProviders, LOCAL_STORAGE_PREFIX, localDatabaseFactory as ɵa };
//# sourceMappingURL=local-storage.js.map

@@ -1,2 +0,2 @@

export { JSONSchema, JSONSchemaType } from './src/service/validation/json-schema';
export { JSONSchema } from './src/service/validation/json-schema';
export { LocalDatabase } from './src/service/databases/local-database';

@@ -8,1 +8,2 @@ export { IndexedDBDatabase } from './src/service/databases/indexeddb-database';

export { LSGetItemOptions, LocalStorage } from './src/service/lib.service';
export { localStorageProviders, LocalStorageProvidersConfig, LOCAL_STORAGE_PREFIX } from './src/tokens';

@@ -1,1 +0,1 @@

{"__symbolic":"module","version":4,"metadata":{"JSONSchema":{"__symbolic":"interface"},"JSONSchemaType":{"__symbolic":"interface"},"ɵa":{"__symbolic":"function"},"LocalDatabase":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":29,"character":1},"arguments":[{"providedIn":"root","useFactory":{"__symbolic":"reference","name":"ɵa"},"deps":[{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":32,"character":9}]}]}],"members":{"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"IndexedDBDatabase":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor"}],"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"connect":[{"__symbolic":"method"}],"transaction":[{"__symbolic":"method"}],"toSuccessObservable":[{"__symbolic":"method"}],"toErrorObservable":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"LocalStorageDatabase":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"MockLocalDatabase":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"JSONValidator":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"validate":[{"__symbolic":"method"}],"isObjectNotNull":[{"__symbolic":"method"}],"validateProperties":[{"__symbolic":"method"}],"validateRequired":[{"__symbolic":"method"}],"validateEnum":[{"__symbolic":"method"}],"validateType":[{"__symbolic":"method"}],"validateTypeList":[{"__symbolic":"method"}],"validateItems":[{"__symbolic":"method"}],"validateItemsList":[{"__symbolic":"method"}],"validateString":[{"__symbolic":"method"}],"validateNumber":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"LSGetItemOptions":{"__symbolic":"interface"},"LocalStorage":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":12,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"LocalDatabase"},{"__symbolic":"reference","name":"JSONValidator"}]}],"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"setItemSubscribe":[{"__symbolic":"method"}],"removeItemSubscribe":[{"__symbolic":"method"}],"clearSubscribe":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}}},"origins":{"JSONSchema":"./src/service/validation/json-schema","JSONSchemaType":"./src/service/validation/json-schema","ɵa":"./src/service/databases/local-database","LocalDatabase":"./src/service/databases/local-database","IndexedDBDatabase":"./src/service/databases/indexeddb-database","LocalStorageDatabase":"./src/service/databases/localstorage-database","MockLocalDatabase":"./src/service/databases/mock-local-database","JSONValidator":"./src/service/validation/json-validator","LSGetItemOptions":"./src/service/lib.service","LocalStorage":"./src/service/lib.service"},"importAs":"@ngx-pwa/local-storage"}
{"__symbolic":"module","version":4,"metadata":{"JSONSchema":{"__symbolic":"interface"},"ɵa":{"__symbolic":"function"},"LocalDatabase":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":30,"character":1},"arguments":[{"providedIn":"root","useFactory":{"__symbolic":"reference","name":"ɵa"},"deps":[{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":34,"character":4},[{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":35,"character":9}},{"__symbolic":"reference","name":"LOCAL_STORAGE_PREFIX"}]]}]}],"members":{"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"IndexedDBDatabase":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":7,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":37,"character":15}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":37,"character":27},"arguments":[{"__symbolic":"reference","name":"LOCAL_STORAGE_PREFIX"}]}]],"parameters":[{"__symbolic":"reference","name":"string"}]}],"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"connect":[{"__symbolic":"method"}],"transaction":[{"__symbolic":"method"}],"toSuccessObservable":[{"__symbolic":"method"}],"toErrorObservable":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"LocalStorageDatabase":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":7,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":15,"character":15}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":15,"character":27},"arguments":[{"__symbolic":"reference","name":"LOCAL_STORAGE_PREFIX"}]}]],"parameters":[{"__symbolic":"reference","name":"string"}]}],"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"MockLocalDatabase":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"JSONValidator":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"validate":[{"__symbolic":"method"}],"isObjectNotNull":[{"__symbolic":"method"}],"validateProperties":[{"__symbolic":"method"}],"validateRequired":[{"__symbolic":"method"}],"validateEnum":[{"__symbolic":"method"}],"validateType":[{"__symbolic":"method"}],"validateItems":[{"__symbolic":"method"}],"validateItemsList":[{"__symbolic":"method"}],"validateString":[{"__symbolic":"method"}],"validateNumber":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"LSGetItemOptions":{"__symbolic":"interface"},"LocalStorage":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":12,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"LocalDatabase"},{"__symbolic":"reference","name":"JSONValidator"}]}],"getItem":[{"__symbolic":"method"}],"setItem":[{"__symbolic":"method"}],"removeItem":[{"__symbolic":"method"}],"clear":[{"__symbolic":"method"}],"setItemSubscribe":[{"__symbolic":"method"}],"removeItemSubscribe":[{"__symbolic":"method"}],"clearSubscribe":[{"__symbolic":"method"}]},"statics":{"ngInjectableDef":{}}},"localStorageProviders":{"__symbolic":"function","parameters":["config"],"value":[{"__symbolic":"if","condition":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"config"},"member":"prefix"},"thenExpression":{"provide":{"__symbolic":"reference","name":"LOCAL_STORAGE_PREFIX"},"useValue":{"__symbolic":"select","expression":{"__symbolic":"reference","name":"config"},"member":"prefix"}},"elseExpression":[]}]},"LocalStorageProvidersConfig":{"__symbolic":"interface"},"LOCAL_STORAGE_PREFIX":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":2,"character":40},"arguments":["localStoragePrefix",{"__symbolic":"error","message":"Lambda not supported","line":2,"character":116,"module":"./src/tokens"}]}},"origins":{"JSONSchema":"./src/service/validation/json-schema","ɵa":"./src/service/databases/local-database","LocalDatabase":"./src/service/databases/local-database","IndexedDBDatabase":"./src/service/databases/indexeddb-database","LocalStorageDatabase":"./src/service/databases/localstorage-database","MockLocalDatabase":"./src/service/databases/mock-local-database","JSONValidator":"./src/service/validation/json-validator","LSGetItemOptions":"./src/service/lib.service","LocalStorage":"./src/service/lib.service","localStorageProviders":"./src/tokens","LocalStorageProvidersConfig":"./src/tokens","LOCAL_STORAGE_PREFIX":"./src/tokens"},"importAs":"@ngx-pwa/local-storage"}
{
"name": "@ngx-pwa/local-storage",
"version": "6.0.0-beta.7",
"version": "6.0.0-rc.0",
"description": "Efficient local storage module for Angular apps and PWA: simple API based on native localStorage API, but internally stored via the asynchronous IndexedDB API for performance, and wrapped in RxJS observables to be homogeneous with other Angular modules.",

@@ -65,22 +65,22 @@ "main": "./bundles/local-storage.umd.js",

"reinstall": "rimraf node_modules && npm install",
"publish": "npm publish dist --tag next --access public"
"publish": "npm publish dist --tag rc --access public"
},
"dependencies": {},
"peerDependencies": {
"@angular/core": ">=6.0.0 <7.0.0 || >=6.0.0-rc <7.0.0",
"@angular/common": ">=6.0.0 <7.0.0 || >=6.0.0-rc <7.0.0",
"rxjs": ">=6.0.0 <7.0.0 || >=6.0.0-rc <7.0.0"
"@angular/core": ">=6.0.0 <7.0.0",
"@angular/common": ">=6.0.0 <7.0.0",
"rxjs": ">=6.0.0 <7.0.0"
},
"devDependencies": {
"@angular/common": "^6.0.0-rc.5",
"@angular/compiler": "^6.0.0-rc.5",
"@angular/compiler-cli": "^6.0.0-rc.5",
"@angular/core": "^6.0.0-rc.5",
"@angular/platform-browser": "^6.0.0-rc.5",
"@angular/platform-browser-dynamic": "^6.0.0-rc.5",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/compiler-cli": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@types/jasmine": "2.5.36",
"@types/node": "^6.0.46",
"@types/node": "^8.10.12",
"camelcase": "^4.0.0",
"concurrently": "3.4.0",
"core-js": "^2.4.1",
"core-js": "^2.5.5",
"glob": "^7.1.1",

@@ -107,3 +107,3 @@ "jasmine-core": "^2.5.2",

"rollup-plugin-uglify": "^2.0.1",
"rxjs": "^6.0.0-uncanny-rc.7",
"rxjs": "^6.1.0",
"standard-version": "^4.0.0",

@@ -113,4 +113,4 @@ "systemjs": "^0.19.40",

"typescript": "~2.7.2",
"zone.js": "~0.8.20"
"zone.js": "^0.8.26"
}
}

@@ -47,10 +47,10 @@ # Async local storage for Angular

```bash
# For Angular 5 (latest):
npm install @ngx-pwa/local-storage
# For Angular 6:
npm install @ngx-pwa/local-storage@6
# For Angular 5:
npm install @ngx-pwa/local-storage@5
# For Angular 4 (and TypeScript >= 2.3):
npm install @ngx-pwa/local-storage@4
# For Angular 6 (next):
npm install @ngx-pwa/local-storage@next
```

@@ -180,2 +180,18 @@

### Prefix
`localStorage` and `IndexedDB` are restricted to the same subdomain, so no risk of collision in most cases.
*Only* if you have multiple apps on the same *sub*domain *and* you don't want to share data between them, add a prefix:
```typescript
import { localStorageProviders } from '@ngx-pwa/local-storage';
@NgModule({
providers: [
localStorageProviders({ prefix: 'myapp' })
]
})
export class AppModule {}
```
### Other notes

@@ -182,0 +198,0 @@

import { Observable, ReplaySubject } from 'rxjs';
import { LocalDatabase } from './local-database';
export declare class IndexedDBDatabase implements LocalDatabase {
protected prefix: string | null;
/**
* IndexedDB database name for local storage
*/
protected readonly dbName: string;
protected dbName: string;
/**

@@ -28,3 +29,3 @@ * IndexedDB object store name for local storage

*/
constructor();
constructor(prefix?: string | null);
/**

@@ -31,0 +32,0 @@ * Gets an item value in local storage

@@ -5,3 +5,3 @@ import { Observable } from 'rxjs';

import { MockLocalDatabase } from './mock-local-database';
export declare function localDatabaseFactory(platformId: Object): IndexedDBDatabase | LocalStorageDatabase | MockLocalDatabase;
export declare function localDatabaseFactory(platformId: Object, prefix: string | null): IndexedDBDatabase | LocalStorageDatabase | MockLocalDatabase;
export declare abstract class LocalDatabase {

@@ -8,0 +8,0 @@ abstract getItem<T = any>(key: string): Observable<T | null>;

import { Observable } from 'rxjs';
import { LocalDatabase } from './local-database';
export declare class LocalStorageDatabase implements LocalDatabase {
protected localStorage: Storage;
protected userPrefix: string | null;
protected prefix: string;
constructor(userPrefix?: string | null);
/**

@@ -6,0 +8,0 @@ * Gets an item value in local storage

@@ -11,5 +11,3 @@ import { Observable } from 'rxjs';

protected jsonValidator: JSONValidator;
protected readonly getItemOptionsDefault: {
schema: null;
};
protected readonly getItemOptionsDefault: LSGetItemOptions;
constructor(database: LocalDatabase, jsonValidator: JSONValidator);

@@ -16,0 +14,0 @@ /**

/**
* Types allowed in a JSON Schema
*/
export declare type JSONSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'null';
/**
* Subset of the JSON Schema.
* Types are enforced to validate everything : each value MUST have either 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Types are enforced to validate everything: each value MUST have either 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* @see http://json-schema.org/latest/json-schema-validation.html
* @todo Not all validation features are supported yet : just follow the interface.
* Not all validation features are supported: just follow the interface.
* @todo When TS 2.8, explore if this schemas can be split for object and arrays with conditional types.
*/

@@ -17,4 +14,5 @@ export interface JSONSchema {

* Not required for arrays, just set 'items'.
* Not required for const and enum.
*/
type?: JSONSchemaType | JSONSchemaType[];
type?: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'null';
/**

@@ -21,0 +19,0 @@ * List of properties schemas for an object.

@@ -9,3 +9,7 @@ import { JSONSchema } from './json-schema';

* @param data JSON data to validate
* @param schema Subset of JSON Schema
* @param schema Subset of JSON Schema.
* Types are enforced to validate everything:
* each value MUST have 'type' or 'properties' or 'items' or 'const' or 'enum'.
* Therefore, unlike the spec, booleans are not allowed as schemas.
* Not all validation features are supported: just follow the interface.
* @returns If data is valid : true, if it is invalid : false, and throws if the schema is invalid

@@ -19,3 +23,2 @@ */

protected validateType(data: any, schema: JSONSchema): boolean;
protected validateTypeList(data: any, schema: JSONSchema): boolean;
protected validateItems(data: any[], schema: JSONSchema): boolean;

@@ -22,0 +25,0 @@ protected validateItemsList(data: any, schema: JSONSchema): boolean;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc