Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function loadFunction(modulepath, funcname) {
// Read and load the code. It's placed there securely by the fission runtime.
try {
let startTime = process.hrtime();
// support v1 codepath and v2 entrypoint like 'foo', '', 'index.hello'
let userFunction = funcname ? require(modulepath)[funcname] : require(modulepath);
let elapsed = process.hrtime(startTime);
console.log(`user code loaded in ${elapsed[0]}sec ${elapsed[1]/1000000}ms`);
return userFunction;
} catch(e) {
console.error(`user code load error: ${e}`);
return e;
}
}
function aggregate(dbConfig, pipeline, options, callback){
if(typeof(options) == 'function'){
callback = options
options = {}
}
let startTime = process.hrtime()
dbConfig = preprocessDbConfig(dbConfig)
pipeline = preprocessPipeline(dbConfig, pipeline)
let collection = initCollection(dbConfig)
callback = preprocessCallback(callback)
collection.aggregate(pipeline, options, function(err, docs){
let elapsedTime = process.hrtime(startTime)
if(dbConfig.verbose){
console.warn('[INFO] Execute "aggregate" in:' + chimera.getFormattedNanoSecond(elapsedTime) + ' NS');
}
// close the database connection
if(!dbConfig.persistence_connection){closeConnection(dbConfig.verbose);}
// deal with callback
if(err){
console.error('[ERROR] ' + err.stack)
callback(null, false, err.stack)
}
function permanentRemove(dbConfig, removeFilter, options, callback){
if(typeof(removeFilter) == 'function'){
callback = removeFilter
removeFilter = {}
options = {}
}
else if(typeof(options) == 'function'){
callback = options
options = {}
}
let startTime = process.hrtime()
dbConfig = preprocessDbConfig(dbConfig)
dbConfig.process_deleted = true
let collection = initCollection(dbConfig)
let [filter, multi] = preprocessFilter(dbConfig, removeFilter)
if(typeof(callback) != 'function'){
callback = function(result, success, errorMessage){
console.log(JSON.stringify({'result' : result, 'success' : success, 'errorMessage' : errorMessage}))
}
}
return collection.remove(filter, options, function(err, result){
let elapsedTime = process.hrtime(startTime)
if(dbConfig.verbose){
console.warn('[INFO] Execute "permanentRemove" in: ' + chimera.getFormattedNanoSecond(elapsedTime) + ' NS')
}
// close the database connection
if(!dbConfig.persistence_connection){closeConnection(dbConfig.verbose);}
sendFrame(frameRequest) {
const ii = frameRequest.index;
const last_index = frameRequest.end;
const {skip_images} = this.settings;
const frame_send_time = process.hrtime();
const frames = this.frames;
const frames_timing = this.frames_timing;
// get frame info
const frame_index = getFrameIndex(ii, frames.length);
const frame = getFrameData(frames[frame_index]);
// TODO images are not supported here, but glb data is
// old image had a binary header
const isBuffer = frame instanceof Buffer;
const skipSending = isBuffer && skip_images;
// End case
if (ii >= last_index) {
// When last_index reached send 'done' message
this.ws.send(JSON.stringify({type: 'done'}), {}, () => {
function spinWait(ms) {
const start = process.hrtime();
while(timeToMs(process.hrtime(start)) < ms) {
}
}
stoppable.stop(x => console.log(process.hrtime(startTime)))
res.status(200).send(body)
}
function fail(error) {
let elapsed = process.hrtime(startTime)
let body = {
"output": "Function invocation error",
"duration": elapsed[0],
"success": false,
"logs": ""
}
res.status(500).send(body)
}
var startTime = process.hrtime()
download(requestData).then(getHandler).then(run).then(succeed).catch(fail)
}
elapsed(task = "default") {
const started = this.start[task];
return this.acc[task] + (started
? getSeconds(process.hrtime(started))
: 0);
}
function createActionStartEntry(data) {
const logEntry =
typeof data === "string"
? {
action_name: data
}
: data;
const action_name = logEntry.action_name;
return createEntry(
_objectSpread({}, logEntry, {
action_name,
action_phase: "start",
log_entry_label: action_name,
start_timestamp: process.hrtime()
})
);
}
const script = new vm.Script(code);
const context = new vm.createContext({
console: {
log: (...args) => result += (util.format(...args) + '\n'),
},
require: (...args) => {
if (args[0] === 'one')
return requireFromString(stdlibCode, 'one.js');
else
return require(...args);
}
});
const startTime = process.hrtime();
script.runInContext(context);
const elapsedTime = process.hrtime(startTime);
const elapsedMs = elapsedTime[0] * 1000 + Math.round(elapsedTime[1] / 1e6);
resp({ result, elapsedMs });
} catch(e) {
resp({ exceptionText: `${e}\n\n${e.stack}` });
}
});