How to use simperium - 8 common examples

To help you get started, we’ve selected a few simperium 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 Automattic / simplenote-electron / lib / simperium / indexeddb / index.js View on Github external
var results = [];
			openRequest.onsuccess = function(e) {
				var cursor = e.target.result;
				if (cursor) {
					results.push(cursor.value);
					cursor.continue();
				} else {
					resolve(results);
				}
			};
			openRequest.onerror = (e) => reject(e.targer.error);
		});
	}

	// monkey-patch the query interface to rely setup being ready
	Client.Bucket.prototype.query = function(fn) {
		const store = this.store,
					bucket = this;

		var query = new Query(function(query) {
			return store.setup.then(
					(db) => performQuery(db, query, bucket),
					(e) => console.error("Failed to query %s", bucket.name, e)
				);
		});

		if (fn) {
			query.exec(fn);
		}
		return query;
	}
github Automattic / simplenote-electron / lib / simperium / memorydb / index.js View on Github external
export default function(database, version, config) {

	// TODO: sorting, filtering, etc
	Client.Bucket.prototype.query = function(fn) {
		var bucket = this,
				query = new Query(function(query) {
					return (new Promise(function(resolve, reject) {
						var objects = [];
						for (var id in bucket.store.objects) {
							objects.push(bucket.store.objects[id]);
						}
						resolve(objects);
					})).catch((e) => { console.error("Failed to query", e)})
				});

		if (fn) {
			query.exec(fn);
		}

		return query;
github Automattic / simplenote-electron / lib / boot.js View on Github external
import { Provider } from 'react-redux';
import { get, some } from 'lodash';

import '../scss/style.scss';

import { content as welcomeMessage } from './welcome-message';

import appState from './flux/app-state';
import isDevConfig from './utils/is-dev-config';
import { normalizeForSorting } from './utils/note-utils';
const { newNote } = appState.actionCreators;

const config = getConfig();

const cookie = parse(document.cookie);
const auth = new Auth(config.app_id, config.app_key);
const appProvider = 'simplenote.com';

const appID = config.app_id;
let token = cookie.token || localStorage.access_token;

// Signs out the user from app engine and redirects to signin page
const redirectToWebSigninIfNecessary = () => {
  if (!config.is_app_engine) {
    return;
  }

  if (window.webConfig && window.webConfig.signout) {
    window.webConfig.signout(function() {
      window.location = `${config.app_engine_url}/`;
    });
  }
github Automattic / simplenote-electron / lib / boot.js View on Github external
import { Provider } from 'react-redux';
import { get, some } from 'lodash';

import '../scss/style.scss';

import { content as welcomeMessage } from './welcome-message';

import appState from './flux/app-state';
import isDevConfig from './utils/is-dev-config';
import { normalizeForSorting } from './utils/note-utils';
const { newNote } = appState.actionCreators;

const config = getConfig();

const cookie = parse(document.cookie);
const auth = new Auth(config.app_id, config.app_key);
const appProvider = 'simplenote.com';

const appID = config.app_id;
let token = cookie.token || localStorage.access_token;

// Redirect to web sign in if running on App Engine
if (!token && config.is_app_engine) {
  window.location = `${config.app_engine_url}/login/`;
}

const client = initClient({
  appID,
  token,
  bucketConfig: {
    note: {
      beforeIndex: function(note) {
github Automattic / simplenote-electron / lib / simperium / websql / index.js View on Github external
export default function configure(database, version, config) {

	Client.Bucket.prototype.query = function(fn) {
		return this.store.query(fn);
	};

	var setup = setupObjectStore(database, version, config)
			.catch((e) => console.error("Failed to setup", e))

	var ghostSetup = setupGhostStore()
		.catch((e) => console.error("Failed to setup ghosts", e));

	return {
		ghostStoreProvider: function(bucket) {
			return new GhostStore(ghostSetup, bucket);
		},
		objectStoreProvider: function(bucket) {
			return new BucketStore(setup, bucket, config[bucket.name]);
		},
github Automattic / simplenote-electron / lib / simperium / index.js View on Github external
import util from 'util';
import events from 'events';

export const Auth = simperium.Auth;

export default function(settings) {
  const browserClient = new BrowserClient(settings);

  window.addEventListener('beforeunload', () => {
    Object.values(browserClient.buckets).forEach(localQueueStore.persist);
  });

  return browserClient;
}

Client.Bucket.prototype.query = function(fn) {
  this.store.setup.then(fn);
};

function BrowserClient({ appID, token, bucketConfig, database, version }) {
  this.databaseName = database || 'simperium-objects';
  this.databaseVersion = version || 1;
  let config = (this.bucketConfig = bucketConfig);
  this.bucketDB = store_provider(this.configureDb.bind(this));
  this.buckets = {};

  let objectStoreProvider = this.bucketDB.provider();
  this.ghostStore = ghost_store;

  this.client = simperium(appID, token, {
    ghostStoreProvider: ghost_store,
    objectStoreProvider: function(bucket) {
github Automattic / simplenote-electron / lib / simperium / index.js View on Github external
import simperium, { Client } from 'simperium';
import store_provider from './store-provider';
import ghost_store from './ghost-store';
import localQueueStore from './local-queue-store';
import util from 'util';
import events from 'events';

export const Auth = simperium.Auth;

export default function(settings) {
  const browserClient = new BrowserClient(settings);

  window.addEventListener('beforeunload', () => {
    Object.values(browserClient.buckets).forEach(localQueueStore.persist);
  });

  return browserClient;
}

Client.Bucket.prototype.query = function(fn) {
  this.store.setup.then(fn);
};

function BrowserClient({ appID, token, bucketConfig, database, version }) {
github Automattic / simplenote-electron / lib / simperium / index.js View on Github external
function BrowserClient({ appID, token, bucketConfig, database, version }) {
  this.databaseName = database || 'simperium-objects';
  this.databaseVersion = version || 1;
  let config = (this.bucketConfig = bucketConfig);
  this.bucketDB = store_provider(this.configureDb.bind(this));
  this.buckets = {};

  let objectStoreProvider = this.bucketDB.provider();
  this.ghostStore = ghost_store;

  this.client = simperium(appID, token, {
    ghostStoreProvider: ghost_store,
    objectStoreProvider: function(bucket) {
      var store = objectStoreProvider.apply(null, arguments);
      if (config[bucket.name].beforeIndex) {
        store.beforeIndex = config[bucket.name].beforeIndex;
      }
      return store;
    },
  });

  [
    'send',
    'message',
    'connect',
    'reconnect',
    'disconnect',

simperium

A simperium client for node.js

BSD-2-Clause
Latest version published 3 years ago

Package Health Score

52 / 100
Full package analysis