How to use the idb-keyval.Store function in idb-keyval

To help you get started, we’ve selected a few idb-keyval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datavized / twotone / src / engine / speech-voices.js View on Github external
/* global SPEECH_API_KEY */
import * as idbKeyval from 'idb-keyval';
import { genders } from '../constants';
import capitalize from '../util/capitalize';
import reportError from '../util/reportError';

const VOICES_URL = `https://texttospeech.googleapis.com/v1beta1/voices?key=${SPEECH_API_KEY || ''}`;

const voicesByLanguage = new Map();
const voicesCacheDB = new idbKeyval.Store('voices-cache-db', 'voices-cache');

let loadVoicesPromise = null;

function fetchVoices() {
	return fetch(VOICES_URL, {
		headers: {
			'Content-Type': 'application/json; charset=utf-8'
		},
		method: 'GET'
	})
		.then(response => response.json())
		.then(response => {
			if (response.error) {
				throw new Error(response.error.message);
			}
github LulumiProject / lulumi-browser / src / renderer / api / inject-to.ts View on Github external
// Finds the correct signature for the given arguments, then validates the
// arguments against that signature. Returns a 'normalized' arguments list
// where nulls are inserted where optional parameters were omitted.
// |args| is expected to be an array.
function normalizeArgumentsAndValidate(namespace, name, args) {
  const newArgs = Array.prototype.slice.call(args);
  if (!resolveSignature(namespace, name, newArgs)) {
    throw new Error(
      `Invocation of form ${namespace}.${getArgumentSignatureString(name, newArgs)} doesn't match definition ${namespace}.${getParameterSignatureString(namespace, name)}`);
  }
}

let nextId = 0;
let nextPortId = 0;

const localStorage = new Store('local-store', 'local-storage');

ipcRenderer.setMaxListeners(0);
// tslint:disable-next-line:variable-name
export default function injectTo(guestInstanceId, thisExtensionId, scriptType, context: Lulumi.Preload.Context) {
  context.lulumi = context.lulumi || {};
  const lulumi = context.lulumi;

  const manifest = ipcRenderer.sendSync('get-manifest-map')[thisExtensionId];

  lulumi.env = {
    appName: (callback) => {
      wrapper((results) => {
        if (callback) {
          // we only need one window to tell us the result
          callback(results[0]);
        }
github TimvanScherpenzeel / spars / dist / lib / cache / PersistentCache.js View on Github external
function PersistentCache(databaseName, storeName) {
        if (databaseName === void 0) { databaseName = 'persistent-cache-db'; }
        if (storeName === void 0) { storeName = 'persistent-cache-store'; }
        // Back persistent cache with in-memory cache in order to maintain functionality
        // in case IndexedDB is not available (private browsing mode)
        this.memoryCache = new Map();
        this.store = new idb_keyval_1.Store(databaseName, storeName);
    }
    /**
github paperize / paperize / lib / services / sheet_cache.js View on Github external
import { Store, get, set } from 'idb-keyval'

const
  DATABASE_NAME = "Sheet Cache",
  STORE_NAME = "spreadsheetId-worksheetId-values",
  IMAGE_STORE = new Store(DATABASE_NAME, STORE_NAME)

export const
  getCachedWorksheet = function(key) {
    return get(key, IMAGE_STORE)
  },

  setCachedWorksheet = function(key, value) {
    return set(key, value, IMAGE_STORE)
  }
github paperize / paperize / lib / services / font_cache.js View on Github external
import { Store, get, set } from 'idb-keyval'

const
  DATABASE_NAME = "Font Cache",
  STORE_NAME = "url-base64",
  IMAGE_STORE = new Store(DATABASE_NAME, STORE_NAME)

export const
  getCachedFont = function(key) {
    return get(key, IMAGE_STORE)
  },

  setCachedFont = function(key, value) {
    return set(key, value, IMAGE_STORE)
  }
github ctf0 / Laravel-Media-Manager / src / resources / assets / js / webworkers / db.js View on Github external
const db = require('idb-keyval')
const store = new db.Store('ctf0-Media_Manager', 'media_manager')

self.addEventListener('message', async (e) => {
    let {type, key, val} = e.data

    switch (type) {
        case 'get':
            db.get(key, store)
                .then((res) => self.postMessage(res))
            break
        case 'set':
            db.set(key, val, store)
                .then(() => self.postMessage(true))
                .catch(() => self.postMessage(false))
            break
        case 'del':
            db.del(key, store)
github botim / botz / src / core / cache-service.ts View on Github external
import { Store, set, get, del } from 'idb-keyval';

import { CACHE_EXPIRE_MIN } from './consts';

export class CacheService {
  private _store = new Store('botim', 'statuses');

  /**
   * Store value in store, with last updated key.
   *
   * @param key Usually an id
   * @param value
   */
  public set(key: string, value: any): Promise {
    const entry = { value, lastUpdated: new Date() };

    return set(key, entry, this._store);
  }

  /**
   * Retrieve key from store, if not expired.
   *
github leonardochaia / timoneer / src / app / tim-cache / tim-indexeddb-cache-store.ts View on Github external
import { Injectable } from '@angular/core';
import { TimCacheStoreService, CacheContent } from './tim-cache-store.service';
import { Observable, from } from 'rxjs';
import { set, get, del, Store, clear } from 'idb-keyval';
import { map } from 'rxjs/operators';

@Injectable()
export class TimIndexedDBCacheStore extends TimCacheStoreService {

    protected readonly store = new Store('tim-cache', 'keyval');

    public get(key: string): Observable {
        return from(get(key, this.store));
    }

    public set(key: string, contets: CacheContent): Observable {
        return from(set(key, contets, this.store));
    }

    public has(key: string): Observable {
        return this.get(key)
            .pipe(map(value => typeof value !== 'undefined'));
    }

    public evict(key: string): Observable {
        return from(del(key, this.store));
github expo / snack-web / snack / workers / typings.worker.js View on Github external
* Credits to @CompuIves
 * https://github.com/CompuIves/codesandbox-client/blob/dcdb4169bcbe3e5aeaebae19ff1d45940c1af834/packages/app/src/app/components/CodeEditor/Monaco/workers/fetch-dependency-typings.js
 *
 * global ts
 * @flow
 */

import path from 'path';
import { Store, set as setItem, get as getItem } from 'idb-keyval';
import resources from '../../resources.json';

self.importScripts(resources.typescript);

const ROOT_URL = `https://cdn.jsdelivr.net/`;

const store = new Store('typescript-definitions-cache-v1');
const fetchCache = new Map();

const doFetch = url => {
  const cached = fetchCache.get(url);

  if (cached) {
    return cached;
  }

  const promise = fetch(url)
    .then(response => {
      if (response.status >= 200 && response.status < 300) {
        return Promise.resolve(response);
      }

      const error = new Error(response.statusText || response.status);

idb-keyval

A super-simple-small keyval store built on top of IndexedDB

Apache-2.0
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis