How to use the krl-stdlib/types.typeOf function in krl-stdlib

To help you get started, we’ve selected a few krl-stdlib 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 Picolab / pico-engine / packages / pico-engine-core / src / migrations / 20171031T182007_pvar_index.js View on Github external
var onKV = function (data) {
      var keyPrefix = data.key
      var val = data.value

      // NOTE: not sharing code with DB.js b/c migrations should be immutable
      // i.e. produce the same result regardless of previous codebase states
      var indexType = ktypes.typeOf(val)
      var rootValue = { type: indexType }
      switch (indexType) {
        case 'Null':
          rootValue.value = null
          break
        case 'Function':
        case 'Action':
          rootValue.type = 'String'
          rootValue.value = ktypes.toString(val)
          break
        case 'Map':
        case 'Array':
          _.each(val, function (v, k) {
            dbOps.push({
              type: 'put',
              key: keyPrefix.concat(['value', k]),
github Picolab / pico-engine / packages / pico-engine-core / src / DB.js View on Github external
}, function(err){
            if(err) return callback(err);
            var root = {
                type: ktypes.typeOf(val)
            };
            switch(root.type){
            case "Null":
                root.value = null;
                break;
            case "Function":
            case "Action":
                root.type = "String";
                root.value = ktypes.toString(val);
                break;
            case "Map":
            case "Array":
                _.each(val, function(v, k){
                    ops.push({
                        type: "put",
                        key: key_prefix.concat(["value", k]),
github Picolab / pico-engine / packages / pico-engine-core / src / modules / engine.js View on Github external
let assertArg = function (fnName, args, key, type) {
  if (!_.has(args, key)) {
    throw new Error('engine:' + fnName + ' argument `' + key + '` ' + type + ' is required')
  }
  if (ktypes.typeOf(args[key]) !== type) {
    throw new TypeError('engine:' + fnName + ' argument `' + key + '` should be ' + type + ' but was ' + ktypes.typeOf(args[key]))
  }
  return args[key]
}
github Picolab / pico-engine / packages / pico-engine-core / src / ChannelPolicy.js View on Github external
var clean = function(policy){
    if( ! ktypes.isMap(policy)){
        throw new TypeError("Policy definition should be a Map, but was " + ktypes.typeOf(policy));
    }

    if(isBlank(policy.name)){
        throw new Error("missing `policy.name`");
    }

    assertOnlyAllowedProperties("Policy", policy, ["name", "event", "query"]);

    if(policy.event){
        assertOnlyAllowedProperties("Policy.event", policy.event, ["deny", "allow"]);
    }
    if(policy.query){
        assertOnlyAllowedProperties("Policy.query", policy.query, ["deny", "allow"]);
    }

    return {
github Picolab / pico-engine / packages / pico-engine-core / src / modules / engine.js View on Github external
let assertArg = function (fnName, args, key, type) {
  if (!_.has(args, key)) {
    throw new Error('engine:' + fnName + ' argument `' + key + '` ' + type + ' is required')
  }
  if (ktypes.typeOf(args[key]) !== type) {
    throw new TypeError('engine:' + fnName + ' argument `' + key + '` should be ' + type + ' but was ' + ktypes.typeOf(args[key]))
  }
  return args[key]
}
github Picolab / pico-engine / packages / pico-engine-core / src / modules / engine.js View on Github external
], async function (ctx, args) {
      let picoId = picoArgOrCtxPico('newChannel', ctx, args)
      let policyId = ADMIN_POLICY_ID

      if (_.has(args, 'policy_id')) {
        if (!ktypes.isString(args.policy_id)) {
          throw new TypeError('engine:newChannel argument `policy_id` should be String but was ' + ktypes.typeOf(args.policy_id))
        }
        policyId = args.policy_id
      }

      if (!_.has(args, 'name')) {
        throw new Error('engine:newChannel needs a name string')
      }
      if (!_.has(args, 'type')) {
        throw new Error('engine:newChannel needs a type string')
      }

      picoId = await core.db.assertPicoID(picoId)

      policyId = await core.db.assertPolicyID(policyId)

      return core.db.newChannel({
github Picolab / pico-engine / packages / pico-engine-core / src / ChannelPolicy.js View on Github external
return _.map(rules, function(rule_orig){
        if( ! ktypes.isMap(rule_orig)){
            throw new Error("Policy rules must be Maps, not " + ktypes.typeOf(rule_orig));
        }
        assertOnlyAllowedProperties("Policy.event rule", rule_orig, ["domain", "type"]);

        var rule = {};
        if(!isBlank(rule_orig.domain)){
            rule.domain = rule_orig.domain.trim();
        }
        if(!isBlank(rule_orig.type)){
            rule.type = rule_orig.type.trim();
        }
        return rule;
    });
};