diff --git a/src/ainize.ts b/src/ainize.ts index 3aaf92f..1570f84 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -7,6 +7,7 @@ import Model from "./model"; import { deployConfig } from "./types/type"; import AinModule from "./ain"; import Internal from "./internal"; +import { Account } from "@ainblockchain/ain-util"; export default class Ainize { private cache: NodeCache; @@ -23,16 +24,27 @@ export default class Ainize { this.internal = new Internal(); } - static createAinAccount () { + /** + * Create a new AI Network account. + * @returns {Account} created account. + */ + static createAinAccount (): Account { return AinModule.getInstance().createAccount(); } + /** + * Login to ainize using AI Network account private key. + * @param {string} privateKey + */ async login(privateKey: string) { this.ain.setDefaultAccount(privateKey); await this.handler.connect(); console.log('login success! address:', this.ain.getAddress()); } + /** + * Logout from ainize. + */ async logout() { this.ain.removeDefaultAccount(); await this.handler.disconnect(); @@ -48,11 +60,17 @@ export default class Ainize { } // FIXME(yoojin): add config type and change param type. + /** + * Deploy AI model container. + * @param {deployConfig} deployConfig Set configuration for setting container. modelName, billingConfig, etc. + * @returns {Model} Deployed model object. + */ // TODO(yoojin, woojae): Deploy container, advanced. async deploy({modelName, billingConfig, serviceUrl}: deployConfig): Promise { if(!this.ain.isDefaultAccountExist()) { throw new Error('you should login first'); } + // TODO(yoojin, woojae): Add container deploy logic. const result = await new Promise(async (resolve, reject) => { const deployer = this.ain.getAddress(); if (!billingConfig) { @@ -73,6 +91,11 @@ export default class Ainize { return this.model(modelName); } + /** + * Get deployed model. + * @param modelName + * @returns {Model} Deployed model object. + */ async model(modelName: string): Promise { const modelPath = Path.app(modelName).root(); const modelData = await this.ain.getValue(modelPath); diff --git a/src/controllers/appController.ts b/src/controllers/appController.ts index 2007a0e..193cbbb 100644 --- a/src/controllers/appController.ts +++ b/src/controllers/appController.ts @@ -15,13 +15,6 @@ export default class AppController { return AppController.instance; } - /** - * Create App for your AI Service on AI Network. - * @param {string} appName - The name of app you will create. - * @param {TriggerFunctionUrlMap} functioniUrls - The urls of trigger function you set. - * @param {setDefaultFlag} setDefaultFlag - Set true which you wan to set config as default. - * @returns Result of transaction. - */ async createApp({ appName, serviceUrl, billingConfig }: createAppConfig) { const setRuleOps: SetOperation[] = []; const setFunctionOps: SetOperation[] = []; @@ -74,33 +67,16 @@ export default class AppController { return await this.ain.sendTransaction(txBody); } - /** - * Set billing config to app. - * @param {string} appName - * @param {appBillingConfig} config - The configuration of your app's billing. - * @returns Result of transaction. - */ async setAppBillingConfig(appName: string, config: appBillingConfig) { const setConfigOp = this.buildSetAppBillingConfigOp(appName, config); const txBody = buildTxBody(setConfigOp); return await this.ain.sendTransaction(txBody); } - /** - * Get billing config of app - * @param {string} appName - * @returns {Promise} - */ async getBillingConfig(appName: string): Promise { return await this.ain.getValue(Path.app(appName).billingConfig()); } - /** - * Set trigger function to app. - * @param {string} appName - * @param {setTriggerFunctionParam[]} functions - * @returns Result of transaction. - */ async setTriggerFunctions(appName: string, functions: setTriggerFunctionParm[]) { const setFunctionOps: SetOperation[] = []; for (const param of Object.values(functions)) { @@ -117,12 +93,6 @@ export default class AppController { return await this.ain.sendTransaction(txBody); } - /** - * Set rules to app. - * @param {string} appName - * @param {setRuleParam} rules - * @returns Result of transaction. - */ async setRules(appName: string, rules: setRuleParam[]) { const setRuleOps: SetOperation[] = []; for (const rule of Object.values(rules)) { @@ -153,26 +123,12 @@ export default class AppController { return await this.ain.sendTransaction(txBody); } - /** - * Remove admin on app. - * @param {string} appName - * @param {string} userAddress - * @returns Result of transaction. - */ async deleteAdmin(appName: string, userAddress: string) { const op = this.buildSetAdminOp(appName, userAddress, true); const txBody = buildTxBody(op); return await this.ain.sendTransaction(txBody); } - /** - * Check cost of request and check if account can pay. You should use this function before send or handle request. - * If you don't set address, it will use default account's address. - * @param {string} appName - App name you want to request service to. - * @param {string} prompt - Data you want to request to service . - * @param {string=} userAddress - Address of account you want to check balance. You should set default account if you don't provide address. - * @returns Result cost of service. It throws error when user can't pay. - */ async checkCostAndBalance(appName: string, value: string) { const requesterAddress = this.ain.getAddress(); const billingConfig = (await this.getBillingConfig(appName));