@ionic/storage
Advanced tools
Comparing version 1.1.6 to 1.1.7
@@ -0,1 +1,2 @@ | ||
/// <reference types="localforage" /> | ||
/** | ||
@@ -29,20 +30,20 @@ * Storage is an easy way to store key/value pairs and JSON objects. | ||
* ```typescript | ||
import { Storage } from '@ionic/storage'; | ||
@NgModule({ | ||
declarations: [ | ||
// ... | ||
], | ||
imports: [ | ||
IonicModule.forRoot(MyApp) | ||
], | ||
bootstrap: [IonicApp], | ||
entryComponents: [ | ||
// ... | ||
], | ||
providers: [ | ||
Storage | ||
] | ||
}) | ||
export class AppModule {} | ||
* import { Storage } from '@ionic/storage'; | ||
* | ||
* @NgModule({ | ||
* declarations: [ | ||
* // ... | ||
* ], | ||
* imports: [ | ||
* IonicModule.forRoot(MyApp) | ||
* ], | ||
* bootstrap: [IonicApp], | ||
* entryComponents: [ | ||
* // ... | ||
* ], | ||
* providers: [ | ||
* Storage | ||
* ] | ||
* }) | ||
* export class AppModule {} | ||
*``` | ||
@@ -56,3 +57,7 @@ * | ||
* constructor(storage: Storage) { | ||
* | ||
* // set a key/value | ||
* storage.set('name', 'Max'); | ||
* | ||
* // Or to get a key/value pair | ||
* storage.get('name').then((val) => { | ||
@@ -64,7 +69,41 @@ * console.log('Your name is', val); | ||
* ``` | ||
* | ||
* ### Configuring Storage | ||
* | ||
* The Storage engine can be configured both with specific storage engine priorities, or custom configuration | ||
* options to pass to localForage. See the localForage config docs for possible options: https://github.com/localForage/localForage#configuration | ||
* | ||
* | ||
* ```typescript | ||
* import { Storage } from '@ionic/storage'; | ||
* | ||
* export function provideStorage() { | ||
* return new Storage(['sqlite', 'websql', 'indexeddb'], { name: '__mydb' }// optional config); | ||
* } | ||
* | ||
* @NgModule({ | ||
* declarations: ..., | ||
* imports: ..., | ||
* bootstrap: ..., | ||
* entryComponents: ..., | ||
* providers: [ | ||
* { provide: Storage, useFactory: provideStorage } | ||
* ] | ||
* }) | ||
* export class AppModule {} | ||
* ``` | ||
*/ | ||
export declare class Storage { | ||
_db: any; | ||
constructor(); | ||
private _dbPromise; | ||
/** | ||
* Create a new Storage instance using the order of drivers and any additional config | ||
* options to pass to LocalForage. | ||
* | ||
* Possible driver options are: ['sqlite', 'indexeddb', 'websql', 'localstorage'] and the | ||
* default is that exact ordering. | ||
*/ | ||
constructor(driverOrder?: [string], config?: any); | ||
ready(): Promise<LocalForage>; | ||
_getDriverOrder(driverOrder: any): any; | ||
/** | ||
* Get the value assocated with the given key. | ||
@@ -80,3 +119,3 @@ * @return Promise that resolves with the value | ||
*/ | ||
set(key: string, value: any): any; | ||
set(key: string, value: any): Promise<any>; | ||
/** | ||
@@ -87,3 +126,3 @@ * Remove any value associated with this key. | ||
*/ | ||
remove(key: string): any; | ||
remove(key: string): Promise<any>; | ||
/** | ||
@@ -93,11 +132,11 @@ * Clear the entire key value store. WARNING: HOT! | ||
*/ | ||
clear(): any; | ||
clear(): Promise<null>; | ||
/** | ||
* @return the number of keys stored. | ||
*/ | ||
length(): any; | ||
length(): Promise<number>; | ||
/** | ||
* @return the keys in the store. | ||
*/ | ||
keys(): any; | ||
keys(): Promise<string[]>; | ||
/** | ||
@@ -107,3 +146,3 @@ * Iterate through each key,value pair. | ||
*/ | ||
forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): any; | ||
forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): Promise<null>; | ||
} |
@@ -38,20 +38,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
* ```typescript | ||
import { Storage } from '@ionic/storage'; | ||
@NgModule({ | ||
declarations: [ | ||
// ... | ||
], | ||
imports: [ | ||
IonicModule.forRoot(MyApp) | ||
], | ||
bootstrap: [IonicApp], | ||
entryComponents: [ | ||
// ... | ||
], | ||
providers: [ | ||
Storage | ||
] | ||
}) | ||
export class AppModule {} | ||
* import { Storage } from '@ionic/storage'; | ||
* | ||
* @NgModule({ | ||
* declarations: [ | ||
* // ... | ||
* ], | ||
* imports: [ | ||
* IonicModule.forRoot(MyApp) | ||
* ], | ||
* bootstrap: [IonicApp], | ||
* entryComponents: [ | ||
* // ... | ||
* ], | ||
* providers: [ | ||
* Storage | ||
* ] | ||
* }) | ||
* export class AppModule {} | ||
*``` | ||
@@ -65,3 +65,7 @@ * | ||
* constructor(storage: Storage) { | ||
* | ||
* // set a key/value | ||
* storage.set('name', 'Max'); | ||
* | ||
* // Or to get a key/value pair | ||
* storage.get('name').then((val) => { | ||
@@ -73,20 +77,79 @@ * console.log('Your name is', val); | ||
* ``` | ||
* | ||
* ### Configuring Storage | ||
* | ||
* The Storage engine can be configured both with specific storage engine priorities, or custom configuration | ||
* options to pass to localForage. See the localForage config docs for possible options: https://github.com/localForage/localForage#configuration | ||
* | ||
* | ||
* ```typescript | ||
* import { Storage } from '@ionic/storage'; | ||
* | ||
* export function provideStorage() { | ||
* return new Storage(['sqlite', 'websql', 'indexeddb'], { name: '__mydb' }// optional config); | ||
* } | ||
* | ||
* @NgModule({ | ||
* declarations: ..., | ||
* imports: ..., | ||
* bootstrap: ..., | ||
* entryComponents: ..., | ||
* providers: [ | ||
* { provide: Storage, useFactory: provideStorage } | ||
* ] | ||
* }) | ||
* export class AppModule {} | ||
* ``` | ||
*/ | ||
export var Storage = (function () { | ||
function Storage() { | ||
var Storage = (function () { | ||
/** | ||
* Create a new Storage instance using the order of drivers and any additional config | ||
* options to pass to LocalForage. | ||
* | ||
* Possible driver options are: ['sqlite', 'indexeddb', 'websql', 'localstorage'] and the | ||
* default is that exact ordering. | ||
*/ | ||
function Storage(driverOrder, config) { | ||
if (driverOrder === void 0) { driverOrder = ['sqlite', 'indexeddb', 'websql', 'localstorage']; } | ||
var _this = this; | ||
this._db = LocalForage; | ||
this._db.config({ | ||
name: '_ionicstorage', | ||
storeName: '_ionickv' | ||
this._dbPromise = new Promise(function (resolve, reject) { | ||
var db; | ||
var dbConfig = { | ||
name: '_ionicstorage', | ||
storeName: '_ionickv' | ||
}; | ||
// Merge any custom config options they have | ||
if (config) { | ||
for (var k in config) { | ||
dbConfig[k] = config[k]; | ||
} | ||
} | ||
LocalForage.defineDriver(CordovaSQLiteDriver).then(function () { | ||
db = LocalForage.createInstance(dbConfig); | ||
}) | ||
.then(function () { return db.setDriver(_this._getDriverOrder(driverOrder)); }) | ||
.then(function () { | ||
console.info('Ionic Storage driver:', db.driver()); | ||
resolve(db); | ||
}) | ||
.catch(function (reason) { return reject(reason); }); | ||
}); | ||
this._db.defineDriver(CordovaSQLiteDriver).then(function () { return _this._db.setDriver([ | ||
CordovaSQLiteDriver._driver, | ||
_this._db.INDEXEDDB, | ||
_this._db.WEBSQL, | ||
_this._db.LOCALSTORAGE | ||
]); }).then(function () { | ||
console.info('Ionic Storage driver:', _this._db.driver()); | ||
} | ||
Storage.prototype.ready = function () { | ||
return this._dbPromise; | ||
}; | ||
Storage.prototype._getDriverOrder = function (driverOrder) { | ||
return driverOrder.map(function (driver) { | ||
switch (driver) { | ||
case 'sqlite': | ||
return CordovaSQLiteDriver._driver; | ||
case 'indexeddb': | ||
return LocalForage.INDEXEDDB; | ||
case 'websql': | ||
return LocalForage.WEBSQL; | ||
case 'localstorage': | ||
return LocalForage.LOCALSTORAGE; | ||
} | ||
}); | ||
} | ||
}; | ||
/** | ||
@@ -97,3 +160,3 @@ * Get the value assocated with the given key. | ||
Storage.prototype.get = function (key) { | ||
return this._db.getItem(key); | ||
return this._dbPromise.then(function (db) { return db.getItem(key); }); | ||
}; | ||
@@ -107,3 +170,3 @@ /** | ||
Storage.prototype.set = function (key, value) { | ||
return this._db.setItem(key, value); | ||
return this._dbPromise.then(function (db) { return db.setItem(key, value); }); | ||
}; | ||
@@ -116,3 +179,3 @@ /** | ||
Storage.prototype.remove = function (key) { | ||
return this._db.removeItem(key); | ||
return this._dbPromise.then(function (db) { return db.removeItem(key); }); | ||
}; | ||
@@ -124,3 +187,3 @@ /** | ||
Storage.prototype.clear = function () { | ||
return this._db.clear(); | ||
return this._dbPromise.then(function (db) { return db.clear(); }); | ||
}; | ||
@@ -131,3 +194,3 @@ /** | ||
Storage.prototype.length = function () { | ||
return this._db.length(); | ||
return this._dbPromise.then(function (db) { return db.length(); }); | ||
}; | ||
@@ -138,3 +201,3 @@ /** | ||
Storage.prototype.keys = function () { | ||
return this._db.keys(); | ||
return this._dbPromise.then(function (db) { return db.keys(); }); | ||
}; | ||
@@ -146,8 +209,9 @@ /** | ||
Storage.prototype.forEach = function (iteratorCallback) { | ||
return this._db.iterate(iteratorCallback); | ||
return this._dbPromise.then(function (db) { return db.iterate(iteratorCallback); }); | ||
}; | ||
Storage = __decorate([ | ||
Injectable() | ||
], Storage); | ||
return Storage; | ||
}()); | ||
Storage = __decorate([ | ||
Injectable() | ||
], Storage); | ||
export { Storage }; |
"use strict"; | ||
var storage_1 = require('./storage'); | ||
var storage_1 = require("./storage"); | ||
exports.Storage = storage_1.Storage; |
@@ -0,1 +1,2 @@ | ||
/// <reference types="localforage" /> | ||
/** | ||
@@ -29,20 +30,20 @@ * Storage is an easy way to store key/value pairs and JSON objects. | ||
* ```typescript | ||
import { Storage } from '@ionic/storage'; | ||
@NgModule({ | ||
declarations: [ | ||
// ... | ||
], | ||
imports: [ | ||
IonicModule.forRoot(MyApp) | ||
], | ||
bootstrap: [IonicApp], | ||
entryComponents: [ | ||
// ... | ||
], | ||
providers: [ | ||
Storage | ||
] | ||
}) | ||
export class AppModule {} | ||
* import { Storage } from '@ionic/storage'; | ||
* | ||
* @NgModule({ | ||
* declarations: [ | ||
* // ... | ||
* ], | ||
* imports: [ | ||
* IonicModule.forRoot(MyApp) | ||
* ], | ||
* bootstrap: [IonicApp], | ||
* entryComponents: [ | ||
* // ... | ||
* ], | ||
* providers: [ | ||
* Storage | ||
* ] | ||
* }) | ||
* export class AppModule {} | ||
*``` | ||
@@ -56,3 +57,7 @@ * | ||
* constructor(storage: Storage) { | ||
* | ||
* // set a key/value | ||
* storage.set('name', 'Max'); | ||
* | ||
* // Or to get a key/value pair | ||
* storage.get('name').then((val) => { | ||
@@ -64,7 +69,41 @@ * console.log('Your name is', val); | ||
* ``` | ||
* | ||
* ### Configuring Storage | ||
* | ||
* The Storage engine can be configured both with specific storage engine priorities, or custom configuration | ||
* options to pass to localForage. See the localForage config docs for possible options: https://github.com/localForage/localForage#configuration | ||
* | ||
* | ||
* ```typescript | ||
* import { Storage } from '@ionic/storage'; | ||
* | ||
* export function provideStorage() { | ||
* return new Storage(['sqlite', 'websql', 'indexeddb'], { name: '__mydb' }// optional config); | ||
* } | ||
* | ||
* @NgModule({ | ||
* declarations: ..., | ||
* imports: ..., | ||
* bootstrap: ..., | ||
* entryComponents: ..., | ||
* providers: [ | ||
* { provide: Storage, useFactory: provideStorage } | ||
* ] | ||
* }) | ||
* export class AppModule {} | ||
* ``` | ||
*/ | ||
export declare class Storage { | ||
_db: any; | ||
constructor(); | ||
private _dbPromise; | ||
/** | ||
* Create a new Storage instance using the order of drivers and any additional config | ||
* options to pass to LocalForage. | ||
* | ||
* Possible driver options are: ['sqlite', 'indexeddb', 'websql', 'localstorage'] and the | ||
* default is that exact ordering. | ||
*/ | ||
constructor(driverOrder?: [string], config?: any); | ||
ready(): Promise<LocalForage>; | ||
_getDriverOrder(driverOrder: any): any; | ||
/** | ||
* Get the value assocated with the given key. | ||
@@ -80,3 +119,3 @@ * @return Promise that resolves with the value | ||
*/ | ||
set(key: string, value: any): any; | ||
set(key: string, value: any): Promise<any>; | ||
/** | ||
@@ -87,3 +126,3 @@ * Remove any value associated with this key. | ||
*/ | ||
remove(key: string): any; | ||
remove(key: string): Promise<any>; | ||
/** | ||
@@ -93,11 +132,11 @@ * Clear the entire key value store. WARNING: HOT! | ||
*/ | ||
clear(): any; | ||
clear(): Promise<null>; | ||
/** | ||
* @return the number of keys stored. | ||
*/ | ||
length(): any; | ||
length(): Promise<number>; | ||
/** | ||
* @return the keys in the store. | ||
*/ | ||
keys(): any; | ||
keys(): Promise<string[]>; | ||
/** | ||
@@ -107,3 +146,3 @@ * Iterate through each key,value pair. | ||
*/ | ||
forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): any; | ||
forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): Promise<null>; | ||
} |
@@ -8,5 +8,5 @@ "use strict"; | ||
}; | ||
var core_1 = require('@angular/core'); | ||
var localforage_1 = require('localforage'); | ||
var localforage_cordovasqlitedriver_1 = require('localforage-cordovasqlitedriver'); | ||
var core_1 = require("@angular/core"); | ||
var localforage_1 = require("localforage"); | ||
var localforage_cordovasqlitedriver_1 = require("localforage-cordovasqlitedriver"); | ||
/** | ||
@@ -40,20 +40,20 @@ * Storage is an easy way to store key/value pairs and JSON objects. | ||
* ```typescript | ||
import { Storage } from '@ionic/storage'; | ||
@NgModule({ | ||
declarations: [ | ||
// ... | ||
], | ||
imports: [ | ||
IonicModule.forRoot(MyApp) | ||
], | ||
bootstrap: [IonicApp], | ||
entryComponents: [ | ||
// ... | ||
], | ||
providers: [ | ||
Storage | ||
] | ||
}) | ||
export class AppModule {} | ||
* import { Storage } from '@ionic/storage'; | ||
* | ||
* @NgModule({ | ||
* declarations: [ | ||
* // ... | ||
* ], | ||
* imports: [ | ||
* IonicModule.forRoot(MyApp) | ||
* ], | ||
* bootstrap: [IonicApp], | ||
* entryComponents: [ | ||
* // ... | ||
* ], | ||
* providers: [ | ||
* Storage | ||
* ] | ||
* }) | ||
* export class AppModule {} | ||
*``` | ||
@@ -67,3 +67,7 @@ * | ||
* constructor(storage: Storage) { | ||
* | ||
* // set a key/value | ||
* storage.set('name', 'Max'); | ||
* | ||
* // Or to get a key/value pair | ||
* storage.get('name').then((val) => { | ||
@@ -75,20 +79,79 @@ * console.log('Your name is', val); | ||
* ``` | ||
* | ||
* ### Configuring Storage | ||
* | ||
* The Storage engine can be configured both with specific storage engine priorities, or custom configuration | ||
* options to pass to localForage. See the localForage config docs for possible options: https://github.com/localForage/localForage#configuration | ||
* | ||
* | ||
* ```typescript | ||
* import { Storage } from '@ionic/storage'; | ||
* | ||
* export function provideStorage() { | ||
* return new Storage(['sqlite', 'websql', 'indexeddb'], { name: '__mydb' }// optional config); | ||
* } | ||
* | ||
* @NgModule({ | ||
* declarations: ..., | ||
* imports: ..., | ||
* bootstrap: ..., | ||
* entryComponents: ..., | ||
* providers: [ | ||
* { provide: Storage, useFactory: provideStorage } | ||
* ] | ||
* }) | ||
* export class AppModule {} | ||
* ``` | ||
*/ | ||
var Storage = (function () { | ||
function Storage() { | ||
/** | ||
* Create a new Storage instance using the order of drivers and any additional config | ||
* options to pass to LocalForage. | ||
* | ||
* Possible driver options are: ['sqlite', 'indexeddb', 'websql', 'localstorage'] and the | ||
* default is that exact ordering. | ||
*/ | ||
function Storage(driverOrder, config) { | ||
if (driverOrder === void 0) { driverOrder = ['sqlite', 'indexeddb', 'websql', 'localstorage']; } | ||
var _this = this; | ||
this._db = localforage_1.default; | ||
this._db.config({ | ||
name: '_ionicstorage', | ||
storeName: '_ionickv' | ||
this._dbPromise = new Promise(function (resolve, reject) { | ||
var db; | ||
var dbConfig = { | ||
name: '_ionicstorage', | ||
storeName: '_ionickv' | ||
}; | ||
// Merge any custom config options they have | ||
if (config) { | ||
for (var k in config) { | ||
dbConfig[k] = config[k]; | ||
} | ||
} | ||
localforage_1.default.defineDriver(localforage_cordovasqlitedriver_1.default).then(function () { | ||
db = localforage_1.default.createInstance(dbConfig); | ||
}) | ||
.then(function () { return db.setDriver(_this._getDriverOrder(driverOrder)); }) | ||
.then(function () { | ||
console.info('Ionic Storage driver:', db.driver()); | ||
resolve(db); | ||
}) | ||
.catch(function (reason) { return reject(reason); }); | ||
}); | ||
this._db.defineDriver(localforage_cordovasqlitedriver_1.default).then(function () { return _this._db.setDriver([ | ||
localforage_cordovasqlitedriver_1.default._driver, | ||
_this._db.INDEXEDDB, | ||
_this._db.WEBSQL, | ||
_this._db.LOCALSTORAGE | ||
]); }).then(function () { | ||
console.info('Ionic Storage driver:', _this._db.driver()); | ||
} | ||
Storage.prototype.ready = function () { | ||
return this._dbPromise; | ||
}; | ||
Storage.prototype._getDriverOrder = function (driverOrder) { | ||
return driverOrder.map(function (driver) { | ||
switch (driver) { | ||
case 'sqlite': | ||
return localforage_cordovasqlitedriver_1.default._driver; | ||
case 'indexeddb': | ||
return localforage_1.default.INDEXEDDB; | ||
case 'websql': | ||
return localforage_1.default.WEBSQL; | ||
case 'localstorage': | ||
return localforage_1.default.LOCALSTORAGE; | ||
} | ||
}); | ||
} | ||
}; | ||
/** | ||
@@ -99,3 +162,3 @@ * Get the value assocated with the given key. | ||
Storage.prototype.get = function (key) { | ||
return this._db.getItem(key); | ||
return this._dbPromise.then(function (db) { return db.getItem(key); }); | ||
}; | ||
@@ -109,3 +172,3 @@ /** | ||
Storage.prototype.set = function (key, value) { | ||
return this._db.setItem(key, value); | ||
return this._dbPromise.then(function (db) { return db.setItem(key, value); }); | ||
}; | ||
@@ -118,3 +181,3 @@ /** | ||
Storage.prototype.remove = function (key) { | ||
return this._db.removeItem(key); | ||
return this._dbPromise.then(function (db) { return db.removeItem(key); }); | ||
}; | ||
@@ -126,3 +189,3 @@ /** | ||
Storage.prototype.clear = function () { | ||
return this._db.clear(); | ||
return this._dbPromise.then(function (db) { return db.clear(); }); | ||
}; | ||
@@ -133,3 +196,3 @@ /** | ||
Storage.prototype.length = function () { | ||
return this._db.length(); | ||
return this._dbPromise.then(function (db) { return db.length(); }); | ||
}; | ||
@@ -140,3 +203,3 @@ /** | ||
Storage.prototype.keys = function () { | ||
return this._db.keys(); | ||
return this._dbPromise.then(function (db) { return db.keys(); }); | ||
}; | ||
@@ -148,9 +211,9 @@ /** | ||
Storage.prototype.forEach = function (iteratorCallback) { | ||
return this._db.iterate(iteratorCallback); | ||
return this._dbPromise.then(function (db) { return db.iterate(iteratorCallback); }); | ||
}; | ||
Storage = __decorate([ | ||
core_1.Injectable() | ||
], Storage); | ||
return Storage; | ||
}()); | ||
Storage = __decorate([ | ||
core_1.Injectable() | ||
], Storage); | ||
exports.Storage = Storage; |
{ | ||
"name": "@ionic/storage", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"description": "Ionic Storage utility", | ||
@@ -5,0 +5,0 @@ "main": "es2015/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
24491
702
0