Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
// Load modules
const EventEmitter = require('events');
const Stream = require('stream');
const Lab = require('@hapi/lab');
const Code = require('@hapi/code');
const Somever = require('@hapi/somever');
const Boom = require('@hapi/boom');
const Hoek = require('@hapi/hoek');
const Toys = require('..');
const Hapi = Somever.match(process.version, '>=12') ? require('@hapi/hapi-19') : require('@hapi/hapi');
// Test shortcuts
const lab = exports.lab = Lab.script();
const describe = lab.describe;
const it = lab.it;
const expect = Code.expect;
describe('Toys', () => {
describe('withRouteDefaults()', () => {
const defaults = {
a: 1,
b: 2,
c: {
}
item = Config.apply('plugin', item);
const name = item.plugin.name || item.plugin.pkg.name;
const clone = this._clone(name);
clone.realm.modifiers.route.prefix = item.routes.prefix || options.routes.prefix;
clone.realm.modifiers.route.vhost = item.routes.vhost || options.routes.vhost;
clone.realm.pluginOptions = item.options || {};
// Validate requirements
const requirements = item.plugin.requirements;
Hoek.assert(!requirements.node || Somever.match(process.version, requirements.node), 'Plugin', name, 'requires node version', requirements.node, 'but found', process.version);
Hoek.assert(!requirements.hapi || Somever.match(this.version, requirements.hapi), 'Plugin', name, 'requires hapi version', requirements.hapi, 'but found', this.version);
// Protect against multiple registrations
if (this._core.registrations[name]) {
if (item.plugin.once ||
item.once ||
options.once) {
continue;
}
Hoek.assert(item.plugin.multiple, 'Plugin', name, 'already registered');
}
else {
this._core.registrations[name] = {
version: item.plugin.version || item.plugin.pkg.version,
item = Object.assign({}, item); // Shallow cloned
}
item = Config.apply('plugin', item);
const name = item.plugin.name || item.plugin.pkg.name;
const clone = this._clone(name);
clone.realm.modifiers.route.prefix = item.routes.prefix || options.routes.prefix;
clone.realm.modifiers.route.vhost = item.routes.vhost || options.routes.vhost;
clone.realm.pluginOptions = item.options || {};
// Validate requirements
const requirements = item.plugin.requirements;
Hoek.assert(!requirements.node || Somever.match(process.version, requirements.node), 'Plugin', name, 'requires node version', requirements.node, 'but found', process.version);
Hoek.assert(!requirements.hapi || Somever.match(this.version, requirements.hapi), 'Plugin', name, 'requires hapi version', requirements.hapi, 'but found', this.version);
// Protect against multiple registrations
if (this._core.registrations[name]) {
if (item.plugin.once ||
item.once ||
options.once) {
continue;
}
Hoek.assert(item.plugin.multiple, 'Plugin', name, 'already registered');
}
else {
this._core.registrations[name] = {
_validateDeps() {
for (const { deps, plugin } of this.dependencies) {
for (const dep in deps) {
const version = deps[dep];
Hoek.assert(this.registrations[dep], 'Plugin', plugin, 'missing dependency', dep);
Hoek.assert(version === '*' || Somever.match(this.registrations[dep].version, version), 'Plugin', plugin, 'requires', dep, 'version', version, 'but found', this.registrations[dep].version);
}
}
}
const fnConfig = sls.service.getFunction(id);
Hoek.assert(!fnConfig.handler, `Lambda "${id}" already has a handler configured in the serverless config.`);
const { settings } = lambdas.get(id);
Hoek.merge(fnConfig, {
...settings,
handler: Path.posix.join(BUILD_FOLDER, `${id}.handler`)
});
const runtime = fnConfig.runtime || sls.service.provider.runtime;
Hoek.assert(runtime && runtime.startsWith('nodejs'), `Lambda "${id}" must be configured with a nodejs runtime.`);
Hoek.assert(Somever.match(runtime.slice(6), '>=8.10'), `Lambda "${id}" must be configured with a nodejs runtime >=8.10.`);
}
}