How to use the assert function from hoek

Find comprehensive JavaScript hoek.assert code examples handpicked from public code repositorys.

52
53
54
55
56
57
58
59
60
61

internals.Alternatives.prototype.try = function (/* schemas */) {


    var schemas = Hoek.flatten(Array.prototype.slice.call(arguments));
    Hoek.assert(schemas.length, 'Cannot add other alternatives without at least one schema');

    var obj = this.clone();

    for (var i = 0, il = schemas.length; i < il; ++i) {
fork icon813
star icon0
watch icon2

+ 53 other calls in file

40
41
42
43
44
45
46
47
48
49
const collector = rootState.collector;
const defaults = options.defaults || {};

Object.keys(defaults).forEach((key) => {

    Hoek.assert(!collector.defaults[key], `Default for "${key}" has already been set.`);
    collector.defaults[key] = defaults[key];
});

// Decide whether server stop should teardown
fork icon14
star icon102
watch icon9

+ 9 other calls in file

48
49
50
51
52
53
54
55
56
57
if (Array.isArray(opt)) {
    type = opt[0];
    values = opt.slice(1);
}

Hoek.assert(type, 'unknown key ' + key);
Hoek.assert(typeof options[key] === type, key + ' should be of type ' + type);
if (values) {
    Hoek.assert(values.indexOf(options[key]) >= 0, key + ' should be one of ' + values.join(', '));
}
fork icon0
star icon2
watch icon0

+ 13 other calls in file

131
132
133
134
135
136
137
138
139
// If the supply a path or module node, try to load it
if (typeof item.reporter === 'string') {
    item.reporter = require(item.reporter);
}

Hoek.assert(typeof item.reporter === 'function', 'reporter key must be a constructor function');
Hoek.assert(typeof item.events === 'object', 'reporter must specify events to filter on');

var Reporter = item.reporter;
fork icon165
star icon1
watch icon2

+ 9 other calls in file

11
12
13
14
15
16
17
18
19
20
};


exports = module.exports = internals.Policy = function (options, cache, segment) {

    Hoek.assert(this.constructor === internals.Policy, 'Cache Policy must be instantiated using new');

    this._cache = cache;
    this._pendings = {};                                        // id -> [callbacks]
    this.rules(options);
fork icon74
star icon0
watch icon2

+ 3 other calls in file

11
12
13
14
15
16
17
18
19
  }
}

class Connection {
  constructor (options) {
    Hoek.assert(
      this.constructor === Connection,
      'Redis cache client must be instantiated using new'
    )
fork icon62
star icon49
watch icon28

113
114
115
116
117
118
119
120
121
    viewContext
  );
},

async sendInviteEmail(user, client, hoursTilExpiration, templateOverride, query, saveOptions) {
  Hoek.assert(Hoek.contain(
    Object.keys(query),
    ['client_id', 'redirect_uri', 'scope', 'response_type'],
  ), new Error('query must contain client_id, redirect_uri, response_type, and scope'));
fork icon5
star icon18
watch icon29

11
12
13
14
15
16
17
18
19
    name: 'hapi-auth-cookie-jwt'
};

internals.implementation = (server, options) => {

    Hoek.assert(options, 'Missing jwt auth strategy options');
    Hoek.assert(options.key, 'Missing required private key in configuration');

    const settings = Hoek.clone(options);
fork icon2
star icon6
watch icon1

+ 3 other calls in file

33
34
35
36
37
38
39
40
41
42
module.exports = internals.Monitor = function (plugin, options) {

    options = options || {};

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

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

    // Force them to be arrays
fork icon165
star icon1
watch icon2

+ 7 other calls in file

82
83
84
85
86
87
88
89
90
91

// Determine the submission status
const submission = await Submission.getSubmissionForEaIdAndYear(userContext.eaId.id, userContext.year);
const submissionStatus = submission ? submission.status : Submission.submissionStatusCodes.INCOMPLETE;

Hoek.assert(Object.values(Submission.submissionStatusCodes).includes(submissionStatus),
    `Unknown submission status: ${submissionStatus}`);

if (editSubmission.includes(request.path)) {
    if (submissionStatus === Submission.submissionStatusCodes.INCOMPLETE) {
fork icon1
star icon1
watch icon6

98
99
100
101
102
103
104
105
106
107
    continue;
}

const securityDefinition = api.securityDefinitions[securityDefinitionName];

Hoek.assert(securityDefinition, 'Security scheme not defined.');

options.auth = options.auth || { access: {}, mode: 'required' };
options.auth.access.scope = options.auth.access.scope || [];
options.auth.access.scope.push(...secdef[securityDefinitionName]);
fork icon75
star icon0
watch icon1

45
46
47
48
49
50
51
52
53
54
    return request;
}

decorate(property, method, options) {

    Hoek.assert(internals.properties.indexOf(property) === -1, 'Cannot override built-in request interface decoration:', property);

    this._decorations = this._decorations || {};
    this._decorations[property] = { method, apply: options.apply };
}
fork icon0
star icon1
watch icon2

+ 15 other calls in file

13
14
15
16
17
18
19
20
21
22
 *
 * @api public
 */
module.exports.Monitor = internals.OSMonitor = function () {

    Hoek.assert(this.constructor === internals.OSMonitor, 'OSMonitor must be instantiated using new');

    this.builtins = ['loadavg', 'uptime', 'freemem', 'totalmem', 'cpus'];

    // Expose Node os functions as async fns
fork icon165
star icon0
watch icon1

13
14
15
16
17
18
19
20
21
 *
 * @api public
 */
module.exports.Monitor = internals.ProcessMonitor = function (options) {

    Hoek.assert(this.constructor === internals.ProcessMonitor, 'ProcessMonitor must be instantiated using new');
    options = options || {};

    this.builtins = ['uptime', 'memoryUsage'];
fork icon165
star icon0
watch icon1

211
212
213
214
215
216
217
218
219
});


internals.Listener.subscription = function (path, options) {

    Hoek.assert(path, 'Subscription missing path');
    Joi.assert(options, internals.subSchema, 'Invalid subscription options: ' + path);

    const settings = Hoek.clone(options || {});
fork icon86
star icon0
watch icon2

+ 3 other calls in file

56
57
58
59
60
61
62
63
64
65
};


exports = module.exports = internals.Policy = function (options, cache, segment) {

    Hoek.assert(this instanceof internals.Policy, 'Cache Policy must be instantiated using new');

    this._cache = cache;
    this._pendings = Object.create(null);                       // id -> PendingResponse
    this._pendingGenerateCall = Object.create(null);            // id -> boolean
fork icon74
star icon0
watch icon3

+ 3 other calls in file

98
99
100
101
102
103
104
105
106
107
    settings.name = settings.provider;
    settings.provider = Providers[settings.provider].call(null, settings.config);
}

const results = Joi.validate(settings, internals.schema);
Hoek.assert(!results.error, results.error);

// Passed validation, use Joi converted settings

settings = results.value;
fork icon210
star icon0
watch icon2

76
77
78
79
80
81
82
83
84
85
    'options.agent cannot be set to an Agent at the same time as options.rejectUnauthorized is set');

Hoek.assert(options.beforeRedirect === undefined || options.beforeRedirect === null || typeof options.beforeRedirect === 'function',
    'options.beforeRedirect must be a function');

Hoek.assert(options.redirected === undefined || options.redirected === null || typeof options.redirected === 'function',
    'options.redirected must be a function');

if (options.baseUrl) {
    url = internals.resolveUrl(options.baseUrl, url);
fork icon107
star icon0
watch icon2

+ 7 other calls in file

6
7
8
9
10
11
12
13
14
15
var internals = {};

exports = module.exports = internals.Graph = function (definition) {

    var validated = Joi.validate(definition, Schema.definition);
    Hoek.assert(!validated.error, validated.error);

    definition = internals.normalizeDefinition(validated.value);

    this.directed = definition.directed;
fork icon3
star icon19
watch icon6

+ 11 other calls in file

47
48
49
50
51
52
53
54
55

const test = ([name, initFn, testFn]) => {

    const [schema, valid, invalid] = initFn();

    Hoek.assert(valid === undefined || testFn(schema, valid).error === null, 'validation must not fail for: ' + name);
    Hoek.assert(invalid === undefined || testFn(schema, invalid).error !== null, 'validation must fail for: ' + name);

    Suite.add(name + (valid !== undefined ? ' (valid)' : ''), () => {
fork icon0
star icon1
watch icon2