From 8233ac7f9fb6f81dff764d90eb787fe3db0bb6ae Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 17 Dec 2024 15:56:25 +0900 Subject: [PATCH 1/2] fix: lib --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index dc9b10c..e13d1a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,7 @@ "sourceMap": true, "strict": true, "strictNullChecks": true, - "target": "es2016", + "target": "ES2021", }, "include": [ "src/**/*" From b7745fa3616fc38c76791628b55c3266d7b538d0 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Tue, 17 Dec 2024 15:56:32 +0900 Subject: [PATCH 2/2] feat: add name parser --- src/ainize.ts | 19 +++++++++++-------- src/utils/appName.ts | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/utils/appName.ts diff --git a/src/ainize.ts b/src/ainize.ts index 0fc0c5e..0dd631e 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -10,6 +10,7 @@ import Internal from "./internal"; import { Account } from "@ainblockchain/ain-util"; import { AinWalletSigner } from "@ainblockchain/ain-js/lib/signer/ain-wallet-signer"; import { ConnectionCallback, DisconnectionCallback } from "@ainblockchain/ain-js/lib/types"; +import { nameParser } from "./utils/appName"; export default class Ainize { private cache: NodeCache; @@ -86,7 +87,8 @@ export default class Ainize { // TODO(yoojin, woojae): Deploy container, advanced. async deploy({modelName, billingConfig, modelUrl}: deployConfig): Promise { // TODO(yoojin, woojae): Add container deploy logic. - const result = await new Promise(async (resolve, reject) => { + const pasredName = nameParser(modelName); + await new Promise(async (resolve, reject) => { const deployer = await this.ain.getAddress(); if (!billingConfig) { billingConfig = { @@ -96,15 +98,15 @@ export default class Ainize { } // NOTE(yoojin): For test. We make fixed url on model. if (!modelUrl) { - modelUrl = `https://${modelName}.ainetwork.xyz`; + modelUrl = `https://${pasredName}.ainetwork.xyz`; } modelUrl = modelUrl.replace(/\/$/, ''); - const modelPath = Path.app(modelName).status(); + const modelPath = Path.app(pasredName).status(); await this.handler.subscribe(modelPath, resolve); - await this.appController.createApp({ appName: modelName, modelUrl, billingConfig }); + await this.appController.createApp({ appName: pasredName, modelUrl, billingConfig }); }); - console.log(`${modelName} deploy success!`); - return this.getModel(modelName); + console.log(`${pasredName} deploy success!`); + return this.getModel(pasredName); } /** @@ -113,12 +115,13 @@ export default class Ainize { * @returns {Model} Deployed model object. */ async getModel(modelName: string): Promise { - const modelPath = Path.app(modelName).root(); + const parsedName = nameParser(modelName); + const modelPath = Path.app(parsedName).root(); const modelData = await this.ain.getValue(modelPath, { is_shallow: true }); if(!modelData) { throw new Error("Model not found"); } - return new Model(modelName); + return new Model(parsedName); } test() { diff --git a/src/utils/appName.ts b/src/utils/appName.ts new file mode 100644 index 0000000..69e5c2e --- /dev/null +++ b/src/utils/appName.ts @@ -0,0 +1,3 @@ +export const nameParser = (name: string) => { + return name.replaceAll(/[./-]/g, "_").toLowerCase(); +} \ No newline at end of file