How to use the hyperswitch.utils function in hyperswitch

To help you get started, we’ve selected a few hyperswitch 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 wikimedia / restbase / v1 / trending.js View on Github external
// TODO: not used any more due to T180384, remove in the near future

'use strict';

const HyperSwitch = require('hyperswitch');
const mwUtil = require('../lib/mwUtil');
const uuid = require('cassandra-uuid').TimeUuid;

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/trending.yaml`);

const CONTENT_TYPE = 'application/json; charset=utf-8; ' +
    'profile="https://www.mediawiki.org/wiki/Specs/trending-feed/0.5.0"';

class TrendingEdits {
    constructor(options) {
        this.options = options;
    }

    _assembleResult(result) {
        // assemble the final response to be returned
        return {
            status: 200,
            headers: {
                'cache-control': this.options.cache_control,
                // mimic ETag value
github wikimedia / restbase / sys / pageviews.js View on Github external
'use strict';

/**
 * Pageviews API module
 *
 * This API serves pre-aggregated pageview statistics from Cassandra
 */

var HyperSwitch = require('hyperswitch');
var HTTPError = HyperSwitch.HTTPError;
var URI = HyperSwitch.URI;

var spec = HyperSwitch.utils.loadSpec(__dirname + '/pageviews.yaml');

// Pageviews Service
function PJVS(options) {
    this.options = options;
}


var tables = {
    articleFlat: 'pageviews.per.article.flat',
    project: 'pageviews.per.project',
    tops: 'top.pageviews',
};
var tableURI = function(domain, tableName) {
    return new URI([domain, 'sys', 'table', tableName, '']);
};
var tableSchemas = {
github wikimedia / restbase / sys / page_revisions.js View on Github external
*
 * Main tasks:
 * - keep track of titles, and provide listings for them
 * - keep track of MediaWiki revisions and their metadata
 * - translate MediaWiki revisions into timeuuid ranges for property queries
 * - detect edit conflicts
 */

const HyperSwitch = require('hyperswitch');
const HTTPError = HyperSwitch.HTTPError;
const URI = HyperSwitch.URI;
const uuidv1 = require('uuid/v1');
const mwUtil = require('../lib/mwUtil');
const stringify = require('fast-json-stable-stringify');

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/page_revisions.yaml`);

const tableName = 'title_revisions-ng';

// Title Revision Service
class PRS {
    constructor(options) {
        this.options = options;
    }

    tableURI(domain) {
        return new URI([domain, 'sys', 'table', tableName, '']);
    }

    // Get the schema for the revision table
    getTableSchema() {
        return {
github wikimedia / restbase / v1 / onthisday.js View on Github external
});
                    // Just ignore individual portions errors
                    return undefined;
                });
            });
            return P.props(requests);
        } else {
            return hyper.get(REQUEST_TEMPLATE.expand({
                options: this.options,
                request: req
            }));
        }
    }
}

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/onthisday.yaml`);

module.exports = (options) => {
    options.name = 'feed.onthisday';
    // TODO: need a way to dynamically derive this
    options.content_type = 'application/json; charset=utf-8; ' +
        'profile="https://www.mediawiki.org/wiki/Specs/onthisday-feed/0.5.0"';
    options.spec = spec;
    options.storeHistory = false;

    return new Feed(options).getModuleDeclaration();
};
github wikimedia / restbase / v1 / feed.js View on Github external
const body = {};
        Object.keys(result).forEach((key) => {
            if (result[key].body && Object.keys(result[key].body).length) {
                // TODO: temp code to support transition to new MCS response format
                if (key === 'onthisday' && result.onthisday.body.selected) {
                    body[key] = result.onthisday.body.selected;
                } else {
                    body[key] = result[key].body;
                }
            }
        });
        return body;
    }
}

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/feed.yaml`);

module.exports = (options) => {
    options.name = 'feed.aggregated';
    // TODO: need a way to dynamically derive this
    options.content_type = 'application/json; charset=utf-8; ' +
        'profile="https://www.mediawiki.org/wiki/Specs/aggregated-feed/0.5.0"';
    options.spec = spec;
    options.storeHistory = false;

    return new Feed(options).getModuleDeclaration();
};
github wikimedia / restbase / sys / parsoid_old.js View on Github external
'use strict';

/*
 * Simple wrapper for Parsoid
 */

const P = require('bluebird');
const HyperSwitch = require('hyperswitch');
const URI = HyperSwitch.URI;
const HTTPError = HyperSwitch.HTTPError;

const uuid   = require('cassandra-uuid').TimeUuid;
const mwUtil = require('../lib/mwUtil');

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/parsoid.yaml`);

// Temporary work-around for Parsoid issue
// https://phabricator.wikimedia.org/T93715
function normalizeHtml(html) {
    return html && html.toString
        && html.toString()
        .replace(/ about="[^"]+"(?=[/> ])|]+>/g, '');
}
function sameHtml(a, b) {
    return normalizeHtml(a) === normalizeHtml(b);
}

/**
 * Cheap body.innerHTML extraction.
 *
 * This is safe as we know that the HTML we are receiving from Parsoid is
github wikimedia / restbase / v1 / pcs / stored_endpoint.js View on Github external
module.exports = (options) => {
    if (!options || !options.name) {
        throw new Error('name not specified for PCS endpoint configuration');
    }
    const pcs = new PCSEndpoint(options);
    const spec = HyperSwitch.utils.loadSpec(`${__dirname}/${options.name}.yaml`);
    return {
        spec,
        operations: {
            [`getContent-${options.name}`]: pcs.getContent.bind(pcs),
            [`getContentWithRevision-${options.name}`]: pcs.getContent.bind(pcs)
        },
        resources: [
            { uri: `/{domain}/sys/key_value/${options.name}` }
        ]
    };
};
github wikimedia / restbase / v1 / lists.js View on Github external
'use strict';

const P = require('bluebird');
const mwUtil = require('../lib/mwUtil');
const Title = require('mediawiki-title').Title;
const HyperSwitch = require('hyperswitch');
const URI = HyperSwitch.URI;
const spec = HyperSwitch.utils.loadSpec(`${__dirname}/lists.yaml`);

class ReadingLists {
    /**
     * @param {!Object} options RESTBase options object.
     */
    constructor(options) {
        this.options = options;
    }

    /**
     * Transform the continuation data into a string so it is easier for clients to deal with.
     * @param  {!Object|undefined} continuation Continuation object returned by the MediaWiki API.
     * @return {!string|undefined}              Continuation string.
     */
    flattenContinuation(continuation) {
        return JSON.stringify(continuation);
github wikimedia / restbase / sys / key_rev_large_value.js View on Github external
"use strict";

const P = require('bluebird');
const uuid = require('cassandra-uuid').TimeUuid;

const HyperSwitch = require('hyperswitch');
const HTTPError = HyperSwitch.HTTPError;
const URI = HyperSwitch.URI;

const mwUtil = require('../lib/mwUtil');

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/key_rev_value.yaml`);

/**
 * The chunk size to use for data slicing
 * @type {number}
 * @const
 */
const CHUNK_SIZE = 31000;

/**
 * The grace_ttl parameter for a revision policy
 * @type {number}
 * @const
 */
const GRACE_TTL = 86400;

function range(N) {
github wikimedia / restbase / sys / key_value.js View on Github external
'use strict';

/**
 * Key-value bucket handler
 */

const uuidv1 = require('uuid/v1');
const mwUtil = require('../lib/mwUtil');
const HyperSwitch = require('hyperswitch');
const stringify = require('fast-json-stable-stringify');
const HTTPError = HyperSwitch.HTTPError;
const URI = HyperSwitch.URI;

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/key_value.yaml`);

class KVBucket {
    createBucket(hyper, req) {
        const schema = this.makeSchema(req.body || {});
        schema.table = req.params.bucket;
        const rp = req.params;
        const storeRequest = {
            uri: new URI([rp.domain, 'sys', 'table', rp.bucket]),
            body: schema
        };
        return hyper.put(storeRequest);
    }

    makeSchema(opts) {
        const schemaVersionMajor = 5;

hyperswitch

REST API creation framework

Apache-2.0
Latest version published 4 years ago

Package Health Score

46 / 100
Full package analysis