Skip to content

Change guide

1. Node.js 18 Version update

1.1. Firstly, check current version of Node.js

  • Windows: Press (Win+R) to open the Run dialog, type cmd and then enter the command node -vin the Command Prompt.

    Alt text

  • macOS: Open the Terminal App and type node -v

    Alt text

1.2. If the version check result does not start with v18.xx.x, proceed to step 3.

1.3. Update to Node.js 18 (for each OS, installation method, update method is different)

→After installation, apply Node.js 18 using the command `nvm use 18` (Windows)`nvm use 18` (Windows)

Alt text

2. Update VSCode CALS Extension version (based on written date, latest version is v1.0.10)

2.1. Launch the previously installed Visual Studio. (If it is not installed, please refer to the “installation guide ”

Alt text

2.2. Move to extension menu. ( Windows: Ctrl + Shift + X / macOS: Cmd+Shift+X)

Alt text

2.3. Depending on whether or not cals-vscode-extension is installed, proceed with a new installation or version update.
a. If the extension is installed, click the version update button and proceed with the update.

Alt text

b. If the extension is not installed, search for cals-vscode-extension in the marketplace and proceed with the installation.

Alt text

2.4. Please run the cals-vscode-extension extension program to verify its latest version and the installed Node.js version. a. In case that extension latest version and Node.js 18 or higher version are used, run properly.

Alt text

b. When using the latest version and node version lower than Node.js 18. Error occurs

Alt text

3. Create new Application Lambda

3.1. Click on the New button in Remote Explorer and create Lambda Project.

Alt text

3.2. After creating the Lambda project name, click on the Enter button.

Alt text

3.3. Upon cloning the default Lambda template source, a folder corresponding to the project name you specified will be created in the Local Explorer.

Alt text

3.4. When conducting local testing, the database information to be used can be configured in the/config/projectBaseConfigDev.js file.

Alt text

3.5. Except for this, the source code structure is the same as before.
(※ Refer to “2.5 Framework Context” for changing loading method of Util, Exception module.)

4. Create new Long-Term Service

5. Modify existing application Lambda

5.1. Modify the database information in the /config/projectBaseConfigDev.js file to replace the configuration previously defined in the development.json file.

※ File /config/projectBaseConfigDev.js is created after Migration task.

(Refer to the "3.7 Application Lambda & Long-Term Service deployment section")

// As-is (development.json)
{
 "NODE_ENV" : "development",
 "Logger" : {
   "LEVEL" : "all",
   "ParamEnabled" : true,
   "ResultEnabled" : true
 },
 "DB" : {
   "ENGINE": "mysql",
   "CONNECTION_TYPE": "config",
   "HOST": "{{dbHost}}",
   "USER": "{{dbUser}}",
   "PASSWORD": "{{dbPassword}}",
   "SCHEMA": "{{dbSchema}}",
   "PORT": "{{dbPort}}"
 }
}






// To-be (projectBaseConfigDev.js)
'use strict'


const { LambdaBaseConfig, DB_CONNECTION_TYPE, LogLevel, NODE_ENV_TYPE } = require('@cals-framework/lambda')
const { resolve } = require('path')


/**
* ProjectBaseConstant class
*
* @class
*/
class ProjectBaseConfigDev extends LambdaBaseConfig {
 /**
  * Create constant variable by constructor 
  *
  * @constructor
  */


 // Can edit from this part 
 constructor() {
   super()


   this.NODE_ENV = NODE_ENV_TYPE.DEVELOPMENT


   this.OBJ_MAPPER.path.push(resolve(__dirname, '../query/mysql/mysql.xml'))
   this.OBJ_MAPPER.namespace.mysql = 'mysql'


   this.Logger.LEVEL = LogLevel.DEBUG
   this.Logger.ParamEnabled = false
   this.Logger.ResultEnabled = false
   this.Logger.RdkLogEnabled = false
   this.Logger.DBLogEnabled = true


   this._DB.ENGINE = 'mysql'
   this._DB.CONNECTION_TYPE = DB_CONNECTION_TYPE.CONFIG
   this._DB.HOST = '{{dbHost}}'
   this._DB.USER = '{{dbUser}}'
   this._DB.PASSWORD = '{{dbPassword}}'
   this._DB.SCHEMA = '{{dbSchema}}'
 }
}
module.exports.ProjectBaseConfigDev = ProjectBaseConfigDev

5.2. Change the module import name of /constant/projectBaseConstant.js file, change member variable to static variable.


// As-is
const AppLambdaBaseConstant = require('@rdk/lambda').AppLambdaBaseConstant


module.exports = class ProjectBaseConstant extends AppLambdaBaseConstant {
 /**
  * Create constant variable by constructor 
  * @constructor
  */


 // can edit from this part 
 constructor () {
   super()


   this.ERROR_MESSAGE = {
     NO_AFFECTED_QEURY: 'NO AFFECTED QUERY'
   }
 }
}




// To-be (use destructuring assignment or variable assignment method.)
const { AppLambdaBaseConstant } = require('@cals-framework/lambda')
// const AppLambdaBaseConstant = require('@cals-framework/lambda').AppLambdaBaseConstant


module.exports = class ProjectBaseConstant extends AppLambdaBaseConstant {
 /**
  * create constant variable by constructor
  * @constructor
  */


 // can edit from this part
 constructor () {
   super()
 }


 static ERROR_MESSAGE = {
   NO_AFFECTED_QUERY: 'NO AFFECTED QUERY'
 }
}

5.3. It is required to change the import module name in the /exception/lambdaException.js file

// As-is
const LambdaBaseException = require('@rdk/lambda').LambdaBaseException
class NoAffectedDataException extends LambdaBaseException {  ….  }


// To-be (use destructuring assignment or variable assignment method. )
const { ApplicationLambdaException} = require('@cals-framework/lambda')
class NoAffectedDataException extends ApplicationLambdaException {  ….  }

5.4. It is required to change import module name on file /lib/lambdaLib.js

// As-is
const LambdaBaseLib = require('@rdk/core').RdkCoreBase


// To-be Use destructuring assignment or variable assignment method. 
const { LambdaBaseLib } = require('@cals-framework/lambda')
// const LambdaBaseLib = require('@cals-framework/lambda').LambdaBaseLib

5.5. It is required to change import module name on file /model/lambdaModel.js

// As-is
const AppLambdaBaseModel = require('@rdk/lambda/model/applicationLambdaBaseModel')


// To-be (Use destructuring assignment or variable assignment method)
const { ApplicationLambdaBaseModel } = require('@cals-framework/lambda')
// const AppLambdaBaseModel = require('@cals-framework/lambda').ApplicationLambdaBaseModel

5.6. It is required to change the import module name on file /src/controller.js, and then change the method name of Framework Context (Util, Exception)


// As-is
'use strict'
const Service = require('./service')
const clsService = new Service()


module.exports = class Controller extends require('@rdk/lambda').BaseController {
 constructor (event, context) {
   super({ event, context, clsService })
   this.event = event
   this.context = context
 }


 async execute () {
   global.rdkLogger.param(this.event, this.context)


   // Todo : Parameter validation check, session check
   this.objRequestParams.sampleName = 'test1'
   this.objRequestParams.sampleDesc = 'test1'
   if (global.clsBaseUtil.CompareUtility.isEmpty(this.objRequestParams.sampleName)) {
     throw new global.ParameterNonExistException('sampleName')
   }
   if (global.clsBaseUtil.CompareUtility.isEmpty(this.objRequestParams.sampleDesc)) {
     throw new global.ParameterNonExistException('sampleDesc')
   }
   this.objReturn = await clsService.runMethod({ objRequestParams: this.objRequestParams, objReturn: this.objReturn })
   global.rdkLogger.result(this.objReturn)
   return this.objReturn
 }
}


// To-be
'use strict'


const { BaseController, CompareUtility, ParameterNonExistException, calsLogger } = require('@cals-framework/lambda')
const Service = require('./service')


module.exports = class Controller extends BaseController {
 constructor ({ event, context }) {
   super({ event, context })
   this.event = event
   this.context = context


   this.calsContext.serviceContext === undefined
     ? this.clsService = new Service()
     : typeof this.calsContext.serviceContext !== 'undefined'
     ? this.calsContext.serviceContext = new Service()
     : this.clsService = this.calsContext.serviceContext
 }


 async process () {
   calsLogger.param(this.event, this.context)


   // Todo : Parameter validation check, session check
   this.objRequestParams.sampleName = 'test1'
   this.objRequestParams.sampleDesc = 'test1'
   if (CompareUtility.isEmpty(this.objRequestParams.sampleName)) {
     throw new ParameterNonExistException('sampleName')
   }
   if (CompareUtility.isEmpty(this.objRequestParams.sampleDesc)) {
     throw new ParameterNonExistException('sampleDesc')
   }


   this.objReturn = await this.clsService.runMethod({ objRequestParams: this.objRequestParams, objReturn: this.objReturn })


   calsLogger.result(this.objReturn)
   return this.objReturn
 }
}

5.7. It is required to change the import module name on /src/service.js file and Framework Context (Util, Exception)

// As-is
'use strict'


const NoAffectedDataException = require('../exception/lambdaException').NoAffectedDataException
const DAO = require('./dao')
const clsDAO = new DAO()


module.exports = class Service extends require('@rdk/lambda').BaseService {
 constructor () {
   super(clsDAO)
 }


 async runMethod ({ objRequestParams, objReturn }) {
   global.rdkLogger.param(objRequestParams)
   // 1. Create model registering data. 
   const SampleAddDataModel = require('../model/lambdaModel').SampleAddDataModel
   var objSampleAddDataModel = new SampleAddDataModel()
   // 2. Register data in data registering model. 
   objSampleAddDataModel.sampleName = objRequestParams.sampleName
   objSampleAddDataModel.sampleDesc = objRequestParams.sampleDesc
   // 3. Input data
   const objAddReturn = await clsDAO.addData({ objDAOParams: objSampleAddDataModel, objReturn })
   if (objAddReturn.affectedRows === 0) {
     throw new NoAffectedDataException(global.clsBaseConstant.ERROR_MESSAGE.NO_AFFECTED_QEURY)
   }
   global.rdkLogger.result(objReturn)
   return objReturn
 }
 // Can edit up to here 
}
// To-be
'use strict'


const { BaseService, calsLogger } = require('@cals-framework/lambda')
const { NoAffectedDataException } = require('../exception/lambdaException')
const ProjectBaseConstant = require('../constant/projectBaseConstant')
const DAO = require('./dao')


module.exports = class Service extends BaseService {
 constructor () {
   super()


   this.calsContext.daoContext === undefined
      ? this.clsDAO = new DAO()
      : typeof this.calsContext.daoContext !== 'undefined'
      ? this.calsContext.daoContext = new DAO()
      : this.clsDAO = this.calsContext.daoContext
 }


 async runMethod ({ objRequestParams, objReturn }) {
   calsLogger.param(objRequestParams)
   // 1. Create data register model 
   const SampleAddDataModel = require('../model/lambdaModel').SampleAddDataModel
   const objSampleAddDataModel = new SampleAddDataModel()


   // 2. Register data in data register model
   objSampleAddDataModel.sampleName = objRequestParams.sampleName
   objSampleAddDataModel.sampleDesc = objRequestParams.sampleDesc


   // 3. Input data
   const objAddReturn = await this.clsDAO.addData({ objDAOParams: objSampleAddDataModel, objReturn })
   if (objAddReturn.affectedRows === 0) {
     throw new NoAffectedDataException(ProjectBaseConstant.ERROR_MESSAGE.NO_AFFECTED_QUERY)
   }
   calsLogger.result(objReturn)
   return objReturn
 }
 // can edit up to here
}

5.8. It is required to change the “import module name” on /src/dao.js file and Framework Context.

// As-is
'use strict'


module.exports = class DAO extends require('@rdk/lambda').AppDAO {
 // can edit from this part 
 async addData ({ objDAOParams, objReturn }) {
   global.rdkLogger.param(objDAOParams)
   // Todo : create query information object 
   const objQueryInfo = {
     sQueryId: 'insertData',
     objParam: objDAOParams,
     objReturn: objReturn
   }
   const objDAOReturn = await this.insert(objQueryInfo)
   global.rdkLogger.result(objDAOReturn)
   return objDAOReturn
 }
 // can edit up to here
}




// To-be
'use strict'


const { ApplicationDAO, calsLogger } = require('@cals-framework/lambda')
const ProjectBaseConstant = require('../constant/projectBaseConstant')


module.exports = class DAO extends ApplicationDAO {
 // can edit from this part
 async addData ({ objDAOParams, objReturn }) {
   calsLogger.param(objDAOParams)
  
   const objDAOReturn = await this.insert({
     sQueryId: 'insertData',
     objParam: objDAOParams,
     objReturn
   })
  
   calsLogger.result(objDAOReturn)
   return objDAOReturn
 }
 // can edit up to here
}

6. Modify existing Long-Term Service

7. Deploy Application Lambda & Long-Term Service

※ Explain the method to deploy Application Lambda and Long-Term Service created before.

7.1. Implement 3.5 Modify existing Application Lambda or “3.6 Modify existing Long-Term Service ".

7.2. Click the Migration button in the context menu of the project to be deployed. (The icon will be changed in the future)

Alt text

※ For specific rules related to the Migration button, please refer to section Migration Button Display Rules.

  • After completing the Migration, verify the following 2 files are created in the project to be deployed.

  • projectBaseConfigDev.js file should replace the development.json file

  • File app.js - This file should replace the index.js file.

    Alt text

7.3. Before deployment, run the Local Debug to test whether the application executes correctly. If the following written source code operates correctly as indicated by the "Handle Finish" functionality, proceed to prepare for the deployment stage.

Alt text