How to use coinstac-common - 10 common examples

To help you get started, we’ve selected a few coinstac-common 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 trendscenter / coinstac / packages / coinstac-computation-registry-new / src / adapters / ui-adapter.js View on Github external
pullImageWrapper(payload) {  // eslint-disable-line class-methods-use-this
    common.services.dockerManager.pullImage(payload.img)
    .then((stream) => {
      return new Promise((res) => {
        stream.on('data', (data) => {
          let output = compact(data.toString().split('\r\n'));
          output = output.map(JSON.parse);
          payload.window.webContents.send('docker-out', output);
        });

        stream.on('close', (code) => {
          res(code);
        });
      });
    })
    .catch(console.log);
  }
}
github trendscenter / coinstac / packages / coinstac-computation-registry-new / src / adapters / cli-adapter.js View on Github external
pullImageWrapper(payload) { // eslint-disable-line class-methods-use-this
    common.services.dockerManager.pullImage(payload.img)
    .then((stream) => {
      return new Promise((res) => {
        stream.pipe(process.stdout);

        stream.on('close', (code) => {
          res(code);
        });
      });
    })
    .catch(console.log);
  }
}
github trendscenter / coinstac / packages / coinstac-server-core / src / services / db-registry.js View on Github external
init(opts) {
    // Unfortunately necessary for sinon spying
    const dbRegistryFactory = common.services.dbRegistry;

    const config = opts ? cloneDeep(opts) : {};
    const dbRegistryOptions = cloneDeep(DB_REGISTRY_DEFAULTS);
    if (config.dbUrl) {
      dbRegistryOptions.remote.db = url.parse(config.dbUrl);
    }

    if (config.inMemory) {
      dbRegistryFactory.DBRegistry.Pouchy.plugin(pouchDBAdapterMemory);
      dbRegistryOptions.pouchConfig.adapter = 'memory';
    } else {
      dbRegistryFactory.DBRegistry.Pouchy.plugin(pouchDbAdapterLevelDB);
      dbRegistryOptions.pouchConfig.adapter = 'leveldb';
    }

    dbRegistryOptions.path = this.getDBPath();
github trendscenter / coinstac / packages / coinstac-server-core / src / services / seed-consortia.js View on Github external
'use strict';

const Consortium = require('coinstac-common').models.Consortium;
const dbRegistryService = require('./db-registry');
const logger = require('./logger.js');

/**
 * @module service/seed-consortia
 */

/**
 * conditionally seeds consortia db
 * @param {object} config server config
 * @returns {Promise} resolves to boolean indicating whether seeding happened or not
 */
/* istanbul ignore next */
module.exports = function seedConsortia(config) {
  let seedDocs;
  if (config.seed && typeof config.seed === 'string') {
github trendscenter / coinstac / packages / coinstac-simulator / src / seed-central-db.js View on Github external
'use strict';

const Pouchy = require('pouchy');
const dbConf = require('./.pouchdb-server-config');
const url = require('url');
const common = require('coinstac-common');
const Consortium = common.models.Consortium;

/**
 * @private
 * @module seed-central-db
 * @description stubs a dummy consortium and a dummy computation into the
 * infrastructure DBs, which will be consumed by the server and client processes
 * @returns {Promise}
 */
module.exports = {

  seed(declPath) {
    const decl = require(declPath); // eslint-disable-line global-require
    return Promise.all([
      this._seedConsortia(decl),
      this._seedComputations(decl),
    ])
github trendscenter / coinstac / packages / coinstac-client-core / src / sub-api / consortia-service.js View on Github external
'use strict';

/**
 * @module consortia-service
 */
const common = require('coinstac-common');
const uuid = require('uuid');
const toArray = require('lodash/toArray');

const Consortium = common.models.Consortium;
const ModelService = require('../model-service');

class ConsortiaService extends ModelService {

  constructor(opts) {
    super(opts);
    this.auth = opts.client.auth;
    /* istanbul ignore next */
    if (!this.auth) {
      throw new ReferenceError('auth instance');
    }
  }

  modelServiceHooks() { // eslint-disable-line class-methods-use-this
    return {
      dbName: 'consortia',
github trendscenter / coinstac / packages / coinstac-simulator / src / utils / get-pool-config.js View on Github external
module.exports = function getPoolConfig(params) {
  const computationPath = params.computationPath;
  const isLocal = ('isLocal' in params && typeof params.isLocal === 'boolean') ?
    params.isLocal :
    true;
  const computationDir = path.dirname(computationPath);

  const dbRegistry = common.services.dbRegistry({
    isLocal,
    isRemote: !isLocal,
    local: {
      pouchConfig: {
        adapter: 'memory',
      },
    },
    noURLPrefix: true, // disable db pre-fixing (e.g. no `up/`, `down/`)
    path: path.join(__dirname, '..', '.tmp'),
    remote: {
      db: {
        hostname: 'localhost',
        port: pouchDBServerConfig.port,
        protocol: 'http',
      },
      pouchConfig: {
github trendscenter / coinstac / packages / coinstac-client-core / src / sub-api / computation-service.js View on Github external
'use strict';

/**
 * @module computation-service
 */
const common = require('coinstac-common');

const Computation = common.models.computation.Computation;
const crypto = require('crypto');
const deepEqual = require('deep-equal');

const getSyncedDatabase = common.utils.getSyncedDatabase;
const ModelService = require('../model-service');

const RemoteComputationResult = common.models.computation.RemoteComputationResult;

/**
 * @extends ModelService
 */
class ComputationService extends ModelService {
  modelServiceHooks() { // eslint-disable-line class-methods-use-this
    return {
      dbName: 'computations',
      ModelType: Computation,
    };
  }

  /**
github trendscenter / coinstac / packages / coinstac-client-core / src / sub-api / project-service.js View on Github external
getDBListener({ callback, consortiumId, projectId }) {
    if (!consortiumId) {
      throw new Error('Consortium ID required');
    } else if (!callback || !(callback instanceof Function)) {
      throw new Error('Callback function required');
    }

    // Deep props are unfortunately necessary for testing:
    const dbListener = new coinstacCommon.helpers.DBListener(
      this.dbRegistry.get(`remote-consortium-${consortiumId}`)
    );

    dbListener.on('change', ({ doc }) => {
      ProjectService.handleRemoteResultChange({
        callback,
        consortiumId,
        doc,
        projectId,
      });
    });
    dbListener.on('delete', ({ doc }) => {
      ProjectService.handleRemoteResultDelete({
        callback,
        consortiumId,
        doc,
github trendscenter / coinstac / packages / coinstac-server-core / src / services / remote-prp.js View on Github external
'use strict';

/**
 * @module service/remote-pipeline-runner-pool
 */

const coinstacCommon = require('coinstac-common');
const computationRegistryService = require('./computation-registry');
const dbRegistryService = require('./db-registry');
const logger = require('./logger');
const RemotePipelineRunnerPool =
  coinstacCommon.models.pipeline.runner.pool.RemotePipelineRunnerPool;

/**
 * @property pool RemotePipelineRunnerPool
 * {@link http://mrn-code.github.io/coinstac-common/PipelineRunnerPool.html RemotePipelineRunnerPool}
 */
module.exports = {

  pool: null,

  /**
   * initializes the server pipeline runner pool.
   * @returns {Promise}
   */
  init() {
    const dbRegistry = dbRegistryService.get();
    const computationRegistry = computationRegistryService.get();

coinstac-common

COINSTAC core functionality.

MIT
Latest version published 1 month ago

Package Health Score

73 / 100
Full package analysis

Similar packages