Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async componentDidMount() {
if (('indexedDB' in window)) {
try {
this.model = await tf.loadLayersModel('indexeddb://' + INDEXEDDB_KEY);
// Safe to assume tensorflowjs database and related object store exists.
// Get the date when the model was saved.
try {
const db = await openDB(INDEXEDDB_DB, 1, );
const item = await db.transaction(INDEXEDDB_STORE)
.objectStore(INDEXEDDB_STORE)
.get(INDEXEDDB_KEY);
const dateSaved = new Date(item.modelArtifactsInfo.dateSaved);
await this.getModelInfo();
console.log(this.modelLastUpdated);
if (!this.modelLastUpdated || dateSaved >= new Date(this.modelLastUpdated).getTime()) {
console.log('Using saved model');
}
else {
this.setState({
modelUpdateAvailable: true,
showModelUpdateAlert: true,
});
}
login.recent.when = Date.now();
settings.recent[sha1(settings.origin + sha1(login.store.id + sha1(login.login)))] =
login.recent;
// save to local storage
localStorage.setItem("recent", JSON.stringify(settings.recent));
// a new entry was added to the popup matching list, need to refresh the count
if (!login.inCurrentHost && login.recent.count === 1) {
updateMatchingPasswordsCount(settings.tab.id, true);
}
// save to usage log
try {
const DB_VERSION = 1;
const db = await idb.openDB("browserpass", DB_VERSION, {
upgrade(db) {
db.createObjectStore("log", { keyPath: "time" });
}
});
await db.add("log", { time: Date.now(), host: settings.origin, login: login.login });
} catch {
// ignore any errors and proceed without saving a log entry to Indexed DB
}
}
*/
uiTheme?: monaco.editor.BuiltinTheme;
description?: string;
/**
* Follow https://code.visualstudio.com/api/extension-guides/color-theme#create-a-new-color-theme to create a custom theme.
*/
json: any
/**
* Themes can include each other. It specifies how inclusions should be resolved.
*/
includes?: { [includePath: string]: any }
}
let monacoDB: Promise | undefined;
if ('indexedDB' in window) {
monacoDB = idb.openDB('theia-monaco', 1, {
upgrade: db => {
if (!db.objectStoreNames.contains('themes')) {
db.createObjectStore('themes', { keyPath: 'id' });
}
}
});
}
@injectable()
export class MonacoThemingService {
@inject(FileSystem)
protected readonly fileSystem: FileSystem;
// tslint:disable-next-line:no-any
register(theme: MonacoTheme, pending: { [uri: string]: Promise } = {}): Disposable {
export function createCache(name: string, predicate?: CachePredicate): Runtime.Cache {
const idbPromise = openDB(name, IDB_CACHE_VERSION, {
async upgrade(db, oldVersion, newVersion, tx) {
log('Upgrading cache from version %s to %s', oldVersion, newVersion);
switch (oldVersion) {
case 0:
db.createObjectStore(Runtime.CacheSegment.Registration);
db.createObjectStore(Runtime.CacheSegment.Resolution);
case 1:
await tx.objectStore(Runtime.CacheSegment.Registration).clear();
await tx.objectStore(Runtime.CacheSegment.Resolution).clear();
}
},
});
return {
clear(segment?: Runtime.CacheSegment) {
function open() {
return openDB(DB_NAME, 1, {
upgrade(db) {
db.createObjectStore(DB_STORE_DAPPS, {
keyPath: 'id',
})
},
})
}
static create(options: {
name?: string,
storeNames?: string[],
version?: number,
onUpgrade?: OnUpgrade
}): any[] {
const {
name = 'cache',
storeNames = ['persist'],
version = 1,
onUpgrade = (db, oldVersion, newVersion, transaction) => { }
} = options;
const dbPromise = openDB(name, version, {
upgrade(dbPromise, oldVersion, newVersion, transaction) {
if (newVersion === 1) {
storeNames.forEach(storeName => {
dbPromise.createObjectStore(storeName);
});
}
onUpgrade(dbPromise, oldVersion, newVersion, transaction);
}
})
const listItems = storeNames.map((value) => (
createIdbStorage(dbPromise, value)
));
return listItems;
import L from 'leaflet';
import { openDB } from 'idb';
const tileStoreName = 'tileStore';
const urlTemplateIndex = 'urlTemplate';
const dbPromise = openDB('leaflet.offline', 1, {
upgrade(db) {
const tileStore = db.createObjectStore(tileStoreName, {
keyPath: 'key',
});
tileStore.createIndex(urlTemplateIndex, 'urlTemplate');
tileStore.createIndex('z', 'z');
},
});
/**
*
* @typedef {Object} tileInfo
* @property {string} key storage key
* @property {string} url resolved url
* @property {string} urlTemplate orig url, used to find tiles per layer
* @property {string} x left point of tile