How to use the krl-stdlib/types.decode 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 / processQuery.js View on Github external
ctx = core.mkCTX({
    query: ctx.query,
    pico_id: ctx.pico_id,
    rid: rs.rid,
    scope: rs.scope
  })
  var val = ctx.scope.get(ctx.query.name)
  if (_.isFunction(val)) {
    val = await runKRL(function (ctx, args) {
      // use ctx.applyFn so it behaves like any other fn call
      // i.e. errors on trying defaction like a function
      return ctx.applyFn(val, ctx, args)
    }, ctx, ctx.query.args)
  }
  // To ensure we don't leak out functions etc.
  return ktypes.decode(ktypes.encode(val))
}
github Picolab / pico-engine / packages / pico-engine-core / src / cleanEvent.js View on Github external
}
    if(isBlank(event_orig.domain)){
        throw new Error("missing event.domain");
    }
    if(isBlank(event_orig.type)){
        throw new Error("missing event.type");
    }

    var attrs = {};
    if(_.has(event_orig, "attrs")){
        //we want to make sure only json-able values are in the attrs
        //also want to clone it as to not mutate the original copy
        var attrs_json = ktypes.encode(event_orig.attrs);
        //only if it's a map or array do we consider it valid
        if(attrs_json[0] === "{" || attrs_json[0] === "["){
            attrs = ktypes.decode(attrs_json);
        }
    }

    var eid = ktypes.toString(event_orig.eid).trim();
    if(eid.length === 0 || eid === "null"){
        eid = "none";
    }

    return {

        eci: event_orig.eci.trim(),

        eid: eid,

        domain: event_orig.domain.trim(),
        type: event_orig.type.trim(),
github Picolab / pico-engine / packages / pico-engine-core / src / cleanQuery.js View on Github external
}
    if(isBlank(query_orig.rid)){
        throw new Error("missing query.rid");
    }
    if(isBlank(query_orig.name)){
        throw new Error("missing query.name");
    }

    var args = {};
    if(_.has(query_orig, "args")){
        //we want to make sure only json-able values are in the args
        //also want to clone it as to not mutate the original copy
        var attrs_json = ktypes.encode(query_orig.args);
        //only if it's a map or array do we consider it valid
        if(attrs_json[0] === "{" || attrs_json[0] === "["){
            args = ktypes.decode(attrs_json);
        }
    }

    return {
        eci: query_orig.eci.trim(),

        rid: query_orig.rid.trim(),

        name: query_orig.name.trim(),

        args: args,
    };
};