The code imports necessary functions and sets the environment to 'STUDY_LOCAL'
, then conditionally executes a block of code and finally calls main functions to convert notebooks to OpenAPI, extract RPC information, and test permissions. The main functions are executed within a promise chain that handles success and error cases.
npm run import -- "test convert notebook api"
var importer = require('../Core');
var getRpcSpecFromCells = importer.import("convert notebook to open api");
var getRpcFromSpec = importer.import("get rpc from spec");
var getEnvironment = importer.import("get environment");
var groupPermissions = importer.import("test get permissions");
getEnvironment('STUDY_LOCAL')
if(typeof $ !== 'undefined') {
$.async()
var spec = getRpcSpecFromCells(['study sauce.ipynb', 'rpc.ipynb'])
// var spec = getRpcSpecFromCells('study sauce.ipynb');
console.log(spec)
var juypter_ops = getRpcFromSpec(spec)
console.log(juypter_ops)
// juypter_ops.marketing.studysauce.copyStudy({email: 'megamindbrian@gmail.com'})
juypter_ops.core.rpc.getPermissions({search: null})
.then(r => $.sendResult(r))
.catch(e => $.sendError(e))
}
// Import required modules
const { getEnvironment, getRpcSpecFromCells, getRpcFromSpec, groupPermissions } = require('../Core');
// Set environment
const environment = getEnvironment('STUDY_LOCAL');
// Function to execute RPC operations
async function executeRpcOps(cells = null) {
// Check if cells are provided
if (!cells) {
throw new Error('Cells are required to generate RPC spec');
}
// Generate RPC spec from cells
const spec = await getRpcSpecFromCells(cells);
console.log(spec);
// Extract RPC operations from spec
const rpcOps = await getRpcFromSpec(spec);
console.log(rpcOps);
// Initialize permissions group
const permissionsGroup = groupPermissions;
// Example usage: Get permissions
const getPermissionsResult = await rpcOps.core.rpc.getPermissions({ search: null });
console.log(getPermissionsResult);
// TODO: Implement sending results and error handling
// const result = await getPermissionsResult;
// $.sendResult(result);
// getPermissionsResult.catch(e => $.sendError(e));
}
// Check if $ is defined and execute RPC operations
if (typeof $!== 'undefined') {
$.async();
executeRpcOps(['study sauce.ipynb', 'rpc.ipynb']).catch((e) => {
console.error(e);
});
}
var importer = require('../Core');
var getRpcSpecFromCells = importer.import('convert notebook to open api');
var getRpcFromSpec = importer.import('get rpc from spec');
var getEnvironment = importer.import('get environment');
var groupPermissions = importer.import('test get permissions');
importer
from the ../Core
directory.importer
module:
getRpcSpecFromCells
: converts notebooks to OpenAPI.getRpcFromSpec
: extracts RPC information from a specification.getEnvironment
: gets the environment.groupPermissions
: tests getting permissions.getEnvironment('STUDY_LOCAL')
'STUDY_LOCAL'
using the getEnvironment
function.if (typeof $!== 'undefined') {
//...
}
$
is defined.if
statement is executed.$.$async()
var spec = getRpcSpecFromCells(['study sauce.ipynb', 'rpc.ipynb'])
console.log(spec)
var juypter_ops = getRpcFromSpec(spec)
console.log(juypter_ops)
juypter_ops.core.rpc.getPermissions({search: null})
.then(r => $.sendResult(r))
.catch(e => $.sendError(e))
$
is called with the method $async()
.getRpcSpecFromCells
function is called with the notebook paths ['study sauce.ipynb', 'rpc.ipynb']
and the result is logged to the console.getRpcFromSpec
function is called with the spec
and the result is logged to the console.getPermissions
method is called on the juypter_ops
object and handled with a then
block for success and a catch
block for errors.