tsc
Typescript consumer of public API
Installation
$ npm install --save @deepcode/tsc
Usage
Creates and initializes an instance
import { ServiceAI } from '@deepcode/tsc';
const baseURL = 'https://www.deepcode.ai';
const AI = new ServiceAI();
Requests the creation of a new login session
const { sessionToken, loginURL } = await AI.startSession({
baseURL,
source: 'atom',
});
Checks status of the login process
const { isLoggedIn } = await AI.checkSession({ baseURL, sessionToken });
const { extensions, configFiles } = await AI.getFilters({ baseURL, sessionToken });
Create and upload bundle for Analysis
public async analyse(options: AnalyseRequestDto): Promise<void> {}
Needs to subscribe for the following events:
AI.on('buildBundleProgress', (processed: number, total: number) = {
console.log(processed, total);
});
AI.on('buildBundleFinish', () => {
console.log('bundle is built');
});
AI.on('uploadBundleProgress', (processed: number, total: number) => {
console.log(processed, total);
});
AI.on('uploadBundleFinish', () => {
console.log('upload is finished');
});
AI.on('analysisResults', (analysisResults, analysisURL) => {
conosle.log(analysisResults, analysisURL);
});
AI.on('analyseFinish', analysisResults => {
console.log(analysisResults);
});
AI.on('sendError', error => {
console.log(error);
});
Manual processing
If you prefer to configure ServiceAI instance manually and take the full control of the process - use the following methods
Creates a new bundle
const result = await AI.createBundle({
sessionToken,
files: {
'/home/user/repo/main.js': '3e297985...',
'/home/user/repo/app.js': 'c8bc6452...',
},
});
const { bundleId, missingFiles, uploadURL } = result;
Checks the status of a bundle
const result = await AI.checkBundle({ baseURL, sessionToken, bundleId });
const { bundleId, missingFiles, uploadURL } = result;
Creates a new bundle based on a previously uploaded one
const result = await AI.extendBundle({
sessionToken,
bundleId,
files: {
'/home/user/repo/main.js': '3e297985...',
'/home/user/repo/app.js': 'c8bc6452...',
},
removedFiles: [],
});
const { bundleId, missingFiles, uploadURL } = result;
Uploads missing files to a bundle
const { success } = await AI.uploadFiles({
sessionToken,
bundleId,
content: [
{
'3e297985...': 'import React from "react"...',
},
],
});
Starts a new bundle analysis or checks its current status and available results
const result = await AI.getAnalysis({
sessionToken,
bundleId,
useLinters: false,
});
const { status, progress, analysisURL, analysisResults } = result;
Errors
If there are any errors the result of every call will contain the following:
const { error, statusCode, statusText } = result;