How to use the hoek.applyToDefaultsWithShallow function in hoek

To help you get started, we’ve selected a few hoek 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 DefinitelyTyped / DefinitelyTyped / hoek / hoek-tests.ts View on Github external
config = Hoek.applyToDefaults(defaults, options1, true); // results in { host: null, port: 8080 }

// applyToDefaultsWithShallow(defaults, options, keys)

let defaults1 = {
    server: {
        host: "localhost",
        port: 8000
    },
    name: 'example'
};

let options2 = { server: { port: 8080 } };

let config1 = Hoek.applyToDefaultsWithShallow(defaults1, options2, ['server']); // results in { server: { port: 8080 }, name: 'example' }

// deepEqual(b, a, [options])

Hoek.deepEqual({ a: [1, 2], b: 'string', c: { d: true } }, { a: [1, 2], b: 'string', c: { d: true } }); //results in true
Hoek.deepEqual(Object.create(null), {}, { prototype: false }); //results in true
Hoek.deepEqual(Object.create(null), {}); //results in false

// unique(array, key)

let array = [1, 2, 2, 3, 3, 4, 5, 6];

let newArray = Hoek.unique(array);    // results in [1,2,3,4,5,6]

let array1 = [{ id: 1 }, { id: 1 }, { id: 2 }];

let newArray1 = Hoek.unique(array1, "id");  // results in [{id: 1}, {id: 2}]
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / hapi / lib / route.js View on Github external
Hoek.assert(options.path, 'Route missing path');
    Hoek.assert(options.handler || (options.config && options.config.handler), 'Missing or undefined handler:', options.method, options.path);
    Hoek.assert(!!options.handler ^ !!(options.config && options.config.handler), 'Handler must only appear once:', options.method, options.path);            // XOR
    Hoek.assert(options.path === '/' || options.path[options.path.length - 1] !== '/' || !connection.settings.router.stripTrailingSlash, 'Path cannot end with a trailing slash when connection configured to strip:', options.method, options.path);
    Hoek.assert(/^[a-zA-Z0-9!#\$%&'\*\+\-\.^_`\|~]+$/.test(options.method), 'Invalid method name:', options.method, options.path);

    options = Schema.apply('route', options, options.path);

    var handler = options.handler || options.config.handler;
    var method = options.method.toLowerCase();
    Hoek.assert(method !== 'head', 'Method name not allowed:', options.method, options.path);

    // Apply settings in order: {connection} <- {handler} <- {realm} <- {route}

    var handlerDefaults = Handler.defaults(method, handler, connection.server);
    var base = Hoek.applyToDefaultsWithShallow(connection.settings.routes, handlerDefaults, ['bind']);
    base = Hoek.applyToDefaultsWithShallow(base, realm.settings, ['bind']);
    this.settings = Hoek.applyToDefaultsWithShallow(base, options.config || {}, ['bind']);
    this.settings.handler = handler;
    this.settings = Schema.apply('routeConfig', this.settings, options.path);

    var socketTimeout = (this.settings.timeout.socket === undefined ? 2 * 60 * 1000 : this.settings.timeout.socket);
    Hoek.assert(!this.settings.timeout.server || !socketTimeout || this.settings.timeout.server < socketTimeout, 'Server timeout must be shorter than socket timeout:', options.path);
    Hoek.assert(!this.settings.payload.timeout || !socketTimeout || this.settings.payload.timeout < socketTimeout, 'Payload timeout must be shorter than socket timeout:', options.path);

    this.connection = connection;
    this.server = connection.server;
    this.path = options.path;
    this.method = method;
    this.plugin = plugin;

    this.public = {
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / hapi / lib / route.js View on Github external
Hoek.assert(options.handler || (options.config && options.config.handler), 'Missing or undefined handler:', options.method, options.path);
    Hoek.assert(!!options.handler ^ !!(options.config && options.config.handler), 'Handler must only appear once:', options.method, options.path);            // XOR
    Hoek.assert(options.path === '/' || options.path[options.path.length - 1] !== '/' || !connection.settings.router.stripTrailingSlash, 'Path cannot end with a trailing slash when connection configured to strip:', options.method, options.path);
    Hoek.assert(/^[a-zA-Z0-9!#\$%&'\*\+\-\.^_`\|~]+$/.test(options.method), 'Invalid method name:', options.method, options.path);

    options = Schema.apply('route', options, options.path);

    var handler = options.handler || options.config.handler;
    var method = options.method.toLowerCase();
    Hoek.assert(method !== 'head', 'Method name not allowed:', options.method, options.path);

    // Apply settings in order: {connection} <- {handler} <- {realm} <- {route}

    var handlerDefaults = Handler.defaults(method, handler, connection.server);
    var base = Hoek.applyToDefaultsWithShallow(connection.settings.routes, handlerDefaults, ['bind']);
    base = Hoek.applyToDefaultsWithShallow(base, realm.settings, ['bind']);
    this.settings = Hoek.applyToDefaultsWithShallow(base, options.config || {}, ['bind']);
    this.settings.handler = handler;
    this.settings = Schema.apply('routeConfig', this.settings, options.path);

    var socketTimeout = (this.settings.timeout.socket === undefined ? 2 * 60 * 1000 : this.settings.timeout.socket);
    Hoek.assert(!this.settings.timeout.server || !socketTimeout || this.settings.timeout.server < socketTimeout, 'Server timeout must be shorter than socket timeout:', options.path);
    Hoek.assert(!this.settings.payload.timeout || !socketTimeout || this.settings.payload.timeout < socketTimeout, 'Payload timeout must be shorter than socket timeout:', options.path);

    this.connection = connection;
    this.server = connection.server;
    this.path = options.path;
    this.method = method;
    this.plugin = plugin;

    this.public = {
        method: this.method,
github muzzley / good-bunyan / lib / index.js View on Github external
constructor (events, config) {
    // Validates inputs and throws errors
    validate(events, config);

    super({ objectMode: true });

    this.settings = Hoek.applyToDefaultsWithShallow(defaults, config, ['logger']);
    this.logger = this.settings.logger; // Alias for consistency
    this._subscription = Squeeze.subscription(events);
  }
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / hapi / lib / server.js View on Github external
internals.Server.prototype.connection = function (options) {

    var root = this.root;                                   // Explicitly use the root reference (for plugin invocation)

    var settings = Hoek.applyToDefaultsWithShallow(root._settings.connections, options || {}, ['listener', 'routes.bind']);
    settings.routes.cors = Hoek.applyToDefaults(root._settings.connections.routes.cors || Defaults.cors, settings.routes.cors) || false;
    settings.routes.security = Hoek.applyToDefaults(root._settings.connections.routes.security || Defaults.security, settings.routes.security);

    settings = Schema.apply('connection', settings);       // Applies validation changes (type cast)

    var connection = new Connection(root, settings);
    root.connections.push(connection);
    root.addEmitter(connection);
    root._single();

    var registrations = Object.keys(root._registrations);
    for (var i = 0, il = registrations.length; i < il; ++i) {
        var name = registrations[i];
        connection.registrations[name] = root._registrations[name];
    }
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / good / lib / monitor.js View on Github external
module.exports = internals.Monitor = function (server, options) {

    options = options || {};

    Hoek.assert(this instanceof internals.Monitor, 'Monitor must be instantiated using new');
    Hoek.assert(server, 'server required to create monitor');

    options = Hoek.applyToDefaultsWithShallow(internals.defaults, options, ['reporters', 'httpAgents', 'httpsAgents']);

    // Force them to be arrays
    options.httpAgents = [].concat(options.httpAgents || Http.globalAgent);
    options.httpsAgents = [].concat(options.httpsAgents || Https.globalAgent);


    this.settings = options;
    this._state = {
        handlers: {},
        extensions: {}
    };
    this._server = server;
    this._dataStream = new Stream.Readable({ objectMode: true });
    this._dataStream._read = Hoek.ignore;

    // Options used to create Great Response
github hapijs / hapi / lib / realm.js View on Github external
internals.configure = function (options) {

    var settings = Hoek.applyToDefaultsWithShallow(internals.defaults.connection, options || {}, ['listener', 'app', 'plugins']);
    settings = Schema.assert('connection', settings);

    settings.labels = Hoek.unique([].concat(settings.labels));       // Convert string to array and removes duplicates

    // Set basic configuration

    Hoek.assert(settings.autoListen || !settings.port, 'Cannot specify port when autoListen is false');

    var socketTimeout = (settings.timeout.socket === undefined ? 2 * 60 * 1000 : settings.timeout.socket);
    Hoek.assert(!settings.timeout.server || !socketTimeout || settings.timeout.server < socketTimeout, 'Server timeout must be shorter than socket timeout');
    Hoek.assert(!settings.timeout.client || !socketTimeout || settings.timeout.client < socketTimeout, 'Client timeout must be shorter than socket timeout');

    // Generate CORS headers

    settings.cors = Hoek.applyToDefaults(internals.defaults.cors, settings.cors);
    if (settings.cors) {
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / h2o2 / lib / index.js View on Github external
internals.handler = function (route, handlerOptions) {

    Joi.assert(handlerOptions, internals.schema, 'Invalid proxy handler options (' + route.path + ')');
    Hoek.assert(!route.settings.payload || ((route.settings.payload.output === 'data' || route.settings.payload.output === 'stream') && !route.settings.payload.parse), 'Cannot proxy if payload is parsed or if output is not stream or data');
    var settings = Hoek.applyToDefaultsWithShallow(internals.defaults, handlerOptions, ['agent']);
    settings.mapUri = handlerOptions.mapUri || internals.mapUri(handlerOptions.protocol, handlerOptions.host, handlerOptions.port, handlerOptions.uri);

    if (settings.ttl === 'upstream') {
        settings._upstreamTtl = true;
    }

    return function (request, reply) {

        settings.mapUri(request, function (err, uri, headers) {

            if (err) {
                return reply(err);
            }

            var protocol = uri.split(':', 1)[0];
github ozum / joi18n / node_modules / hapi / lib / route.js View on Github external
internals.config = function (chain) {

    if (!chain.length) {
        return {};
    }

    let config = chain[0];
    for (const item of chain) {
        config = Hoek.applyToDefaultsWithShallow(config, item, ['bind', 'validate.headers', 'validate.payload', 'validate.params', 'validate.query']);
    }

    return config;
};
github g-div / crudy / index.js View on Github external
internals.after = function (server, next) {
	for (const entity in server.plugins.dogwater) {
		if (server.plugins.dogwater.hasOwnProperty(entity)) {
			let current;
			if (internals[entity]) {
				current = Hoek.applyToDefaultsWithShallow(internals.defaults, internals[entity], ['actions']);
			} else {
				current = internals.defaults;
			}
			const path = `${current.config.handler.bedwetter.prefix || ''}/${entity}`;

			if (current.actions.find) {
				current.config.description = `Find all ${entity} entries`;
				server.route({
					method: 'GET',
					path,
					config: current.config
				});
			}
			if (current.actions.findOne) {
				current.config.description = `Find one ${entity} by id`;
				server.route({