fix: update core and apply stricter tslint rules

This commit is contained in:
Michel Jonathan Schmitz
2019-07-10 12:38:29 +02:00
parent 03c317430a
commit 911492d064
67 changed files with 1291 additions and 507 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 StApps
* Copyright (C) 2018, 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -12,16 +12,19 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { NgModule } from '@angular/core';
import { IonicStorageModule } from '@ionic/storage';
import { StorageProvider } from './storage.provider';
import {NgModule} from '@angular/core';
import {IonicStorageModule} from '@ionic/storage';
import {StorageProvider} from './storage.provider';
/**
* Angular storage provider module
*/
@NgModule({
imports: [
IonicStorageModule.forRoot()
IonicStorageModule.forRoot(),
],
providers: [
StorageProvider
]
StorageProvider,
],
})
export class StorageModule {}

View File

@@ -20,24 +20,29 @@ import {Storage} from '@ionic/storage';
*/
@Injectable()
export class StorageProvider {
constructor(private storage: Storage) {
}
/**
* Initializes the storage (waits until it's ready)
*
* @param storage TODO
*/
async init(): Promise<any> {
return this.storage.ready();
constructor(private readonly storage: Storage) {
}
/**
* Puts a value of type T into the storage using provided key
* Deletes storage entries using keys used to save them
*
* @param key Unique indentifier
* @param value Resource to store under the key
* @param keys Unique identifiers of the resources for deletion
*/
async put<T>(key: string, value: T): Promise<T> {
return this.storage.set(key, value);
async delete(...keys: string[]): Promise<void> {
keys.forEach(async (key) => {
await this.storage.remove(key);
});
}
/**
* Deletes all the entries in the storage (empty the storage)
*/
async deleteAll(): Promise<void> {
return this.storage.clear();
}
/**
@@ -50,68 +55,23 @@ export class StorageProvider {
if (!entry) {
throw new Error('Value not found.');
}
return entry;
}
// tslint:disable:no-any
/**
* Gets values from the storage using the provided pattern
*
* @param pattern Regular expression or text to test existing storage keys with
* Retrieves all the storage entries
*/
async search<T>(pattern: RegExp | string): Promise<Map<string, T>> {
async getAll(): Promise<Map<string, any>> {
const map: Map<string, any> = new Map();
const check = (input: RegExp | string) => {
if (input instanceof RegExp) {
return (p: any, k: string): boolean => {
return p.test(k);
};
} else {
return (p: any, k: string): boolean => {
return k.includes(p);
};
}
};
const checkIt = check(pattern);
await this.storage.forEach((value, key) => {
if (checkIt(pattern, key)) {
map.set(key, value);
}
map.set(key, value);
});
return map;
}
/**
* Deletes storage entries using keys used to save them
*
* @param keys Unique identifiers of the resources for deletion
*/
async delete(...keys: string[]): Promise<void> {
await keys.forEach((key) => {
this.storage.remove(key);
});
}
/**
* Deletes all the entries in the storage (empty the storage)
*/
async deleteAll(): Promise<void> {
return this.storage.clear();
}
/**
* Saves multiple entries into the storage
*
* @param entries Resources to be put into the storage
*/
async putMultiple(entries: Map<string, any>): Promise<Map<string, any>> {
const puts: Array<Promise<any>> = [];
entries.forEach(async (value, key) => {
puts.push(this.put(key, value));
});
await Promise.all(puts);
return entries;
}
/**
* Retrieves multiple entries from the storage using their keys
*
@@ -127,34 +87,10 @@ export class StorageProvider {
gets.push(getToMap(key));
});
await Promise.all(gets);
return map;
}
/**
* Retrieves all the storage entries
*/
async getAll(): Promise<Map<string, any>> {
const map: Map<string, any> = new Map();
await this.storage.forEach((value, key) => {
map.set(key, value);
});
return map;
}
/**
* Provides a number of entries in the storage (number of keys)
*/
async length(): Promise<number> {
return this.storage.length();
}
/**
* Provides information if storage is empty or not
*/
async isEmpty(): Promise<boolean> {
return (await this.storage.length()) === 0;
}
/**
* Provides information if storage has an entry with the given key
*
@@ -163,4 +99,78 @@ export class StorageProvider {
async has(key: string): Promise<boolean> {
return (await this.storage.keys()).includes(key);
}
/**
* Initializes the storage (waits until it's ready)
*/
async init(): Promise<any> {
return this.storage.ready();
}
/**
* Provides information if storage is empty or not
*/
async isEmpty(): Promise<boolean> {
return (await this.storage.length()) === 0;
}
/**
* Provides a number of entries in the storage (number of keys)
*/
async length(): Promise<number> {
return this.storage.length();
}
/**
* Puts a value of type T into the storage using provided key
*
* @param key Unique indentifier
* @param value Resource to store under the key
*/
async put<T>(key: string, value: T): Promise<T> {
return this.storage.set(key, value);
}
/**
* Saves multiple entries into the storage
*
* @param entries Resources to be put into the storage
*/
async putMultiple(entries: Map<string, any>): Promise<Map<string, any>> {
const puts: Array<Promise<any>> = [];
entries.forEach(async (value, key) => {
puts.push(this.put(key, value));
});
await Promise.all(puts);
return entries;
}
/**
* Gets values from the storage using the provided pattern
*
* @param pattern Regular expression or text to test existing storage keys with
*/
async search<T>(pattern: RegExp | string): Promise<Map<string, T>> {
const map: Map<string, any> = new Map();
const check = (input: RegExp | string) => {
if (input instanceof RegExp) {
return (p: any, k: string): boolean => {
return p.test(k);
};
}
return (p: any, k: string): boolean => {
return k.includes(p);
};
};
const checkIt = check(pattern);
await this.storage.forEach((value, key) => {
if (checkIt(pattern, key)) {
map.set(key, value);
}
});
return map;
}
}