diff --git a/generator/generatedClasses/Linode/compute/linode-computeInstance.js b/generator/generatedClasses/Linode/compute/linode-computeInstance.js new file mode 100644 index 00000000..11073154 --- /dev/null +++ b/generator/generatedClasses/Linode/compute/linode-computeInstance.js @@ -0,0 +1,75 @@ +/*This is an auto generated class, please do not change.*/ +/** + * Class to create a ComputeInstanceLinodeClass object + * @category Linode + */ +class Linode_ComputeInstance { + /** + * + * @param {module} do Linode SDK + * @param {object} options SDK options + */ + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } + /** + * Trigers the getLinodes function of ComputeInstanceLinodeClass + * @param {Params} params - Data required for getLinodes + * @param {Filter} filter - Data required for getLinodes + * @returns {Promise} + */ + list(params = undefined, filter = undefined) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getLinodes(params, filter) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the createLinode function of ComputeInstanceLinodeClass + * @param {CreateLinodeRequest} data - Data required for createLinode + * @returns {Promise} + */ + create(data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .createLinode(data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the updateLinode function of ComputeInstanceLinodeClass + * @param {NumberKeyword} linodeId - Data required for updateLinode + * @param {DeepPartial} values - Data required for updateLinode + * @returns {Promise} + */ + update(linodeId, values) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .updateLinode(linodeId, values) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the deleteLinode function of ComputeInstanceLinodeClass + * @param {NumberKeyword} linodeId - Data required for deleteLinode + * @returns {Promise} + */ + delete(linodeId) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .deleteLinode(linodeId) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } +} +module.exports = Linode_ComputeInstance; diff --git a/generator/generatedClasses/Linode/compute/linode-kubernetes.js b/generator/generatedClasses/Linode/compute/linode-kubernetes.js new file mode 100644 index 00000000..34e3ef4c --- /dev/null +++ b/generator/generatedClasses/Linode/compute/linode-kubernetes.js @@ -0,0 +1,106 @@ +/*This is an auto generated class, please do not change.*/ +/** + * Class to create a KubernetesLinodeClass object + * @category Linode + */ +class Linode_Kubernetes { + /** + * + * @param {module} do Linode SDK + * @param {object} options SDK options + */ + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } + /** + * Trigers the createKubernetesCluster function of KubernetesLinodeClass + * @param {CreateKubeClusterPayload} data - Data required for createKubernetesCluster + * @returns {Promise} + */ + create(data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .createKubernetesCluster(data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the deleteKubernetesCluster function of KubernetesLinodeClass + * @param {NumberKeyword} clusterID - Data required for deleteKubernetesCluster + * @returns {Promise} + */ + delete(clusterID) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .deleteKubernetesCluster(clusterID) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the getNodePool function of KubernetesLinodeClass + * @param {NumberKeyword} clusterID - Data required for getNodePool + * @param {NumberKeyword} nodePoolID - Data required for getNodePool + * @returns {Promise} + */ + getNodePool(clusterID, nodePoolID) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getNodePool(clusterID, nodePoolID) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the createNodePool function of KubernetesLinodeClass + * @param {NumberKeyword} clusterID - Data required for createNodePool + * @param {CreateNodePoolData} data - Data required for createNodePool + * @returns {Promise} + */ + createNodePool(clusterID, data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .createNodePool(clusterID, data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the updateNodePool function of KubernetesLinodeClass + * @param {NumberKeyword} clusterID - Data required for updateNodePool + * @param {NumberKeyword} nodePoolID - Data required for updateNodePool + * @param {Partial} data - Data required for updateNodePool + * @returns {Promise} + */ + updateNodePool(clusterID, nodePoolID, data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .updateNodePool(clusterID, nodePoolID, data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the deleteNodePool function of KubernetesLinodeClass + * @param {NumberKeyword} clusterID - Data required for deleteNodePool + * @param {NumberKeyword} nodePoolID - Data required for deleteNodePool + * @returns {Promise} + */ + deleteNodePool(clusterID, nodePoolID) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .deleteNodePool(clusterID, nodePoolID) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } +} +module.exports = Linode_Kubernetes; diff --git a/generator/generatedClasses/Linode/database/linode-noSql.js b/generator/generatedClasses/Linode/database/linode-noSql.js new file mode 100644 index 00000000..fe19e6e0 --- /dev/null +++ b/generator/generatedClasses/Linode/database/linode-noSql.js @@ -0,0 +1,108 @@ +/*This is an auto generated class, please do not change.*/ +/** + * Class to create a NoSqlLinodeClass object + * @category Linode + */ +class Linode_NoSql { + /** + * + * @param {module} do Linode SDK + * @param {object} options SDK options + */ + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } + /** + * Trigers the getDatabases function of NoSqlLinodeClass + * @param {Params} params - Data required for getDatabases + * @param {Filter} filter - Data required for getDatabases + * @returns {Promise} + */ + getDatabases(params = undefined, filter = undefined) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getDatabases(params, filter) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the getDatabaseEngines function of NoSqlLinodeClass + * @param {Params} params - Data required for getDatabaseEngines + * @param {Filter} filter - Data required for getDatabaseEngines + * @returns {Promise} + */ + getDatabaseEngines(params = undefined, filter = undefined) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getDatabaseEngines(params, filter) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the createDatabase function of NoSqlLinodeClass + * @param {UnionType} engine - Data required for createDatabase + * @param {CreateDatabasePayload} data - Data required for createDatabase + * @returns {Promise} + */ + createDatabase(engine, data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .createDatabase(engine, data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the getEngineDatabase function of NoSqlLinodeClass + * @param {Engine} engine - Data required for getEngineDatabase + * @param {NumberKeyword} databaseID - Data required for getEngineDatabase + * @returns {Promise} + */ + getEngineDatabase(engine, databaseID) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getEngineDatabase(engine, databaseID) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the updateDatabase function of NoSqlLinodeClass + * @param {Engine} engine - Data required for updateDatabase + * @param {NumberKeyword} databaseID - Data required for updateDatabase + * @param {UpdateDatabasePayload} data - Data required for updateDatabase + * @returns {Promise} + */ + updateDatabase(engine, databaseID, data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .updateDatabase(engine, databaseID, data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the deleteDatabase function of NoSqlLinodeClass + * @param {Engine} engine - Data required for deleteDatabase + * @param {NumberKeyword} databaseID - Data required for deleteDatabase + * @returns {Promise} + */ + deleteDatabase(engine, databaseID) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .deleteDatabase(engine, databaseID) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } +} +module.exports = Linode_NoSql; diff --git a/generator/generatedClasses/Linode/network/linode-DNS.js b/generator/generatedClasses/Linode/network/linode-DNS.js new file mode 100644 index 00000000..215b4427 --- /dev/null +++ b/generator/generatedClasses/Linode/network/linode-DNS.js @@ -0,0 +1,104 @@ +/*This is an auto generated class, please do not change.*/ +/** + * Class to create a DNSLinodeClass object + * @category Linode + */ +class Linode_DNS { + /** + * + * @param {module} do Linode SDK + * @param {object} options SDK options + */ + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } + /** + * Trigers the getDomains function of DNSLinodeClass + * @param {Params} params - Data required for getDomains + * @param {Filter} filter - Data required for getDomains + * @returns {Promise} + */ + getDomains(params = undefined, filter = undefined) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getDomains(params, filter) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the getDomain function of DNSLinodeClass + * @param {NumberKeyword} domainId - Data required for getDomain + * @returns {Promise} + */ + getDomain(domainId) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getDomain(domainId) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the createDomain function of DNSLinodeClass + * @param {CreateDomainPayload} data - Data required for createDomain + * @returns {Promise} + */ + createDomain(data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .createDomain(data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the updateDomain function of DNSLinodeClass + * @param {NumberKeyword} domainId - Data required for updateDomain + * @param {UpdateDomainPayload} data - Data required for updateDomain + * @returns {Promise} + */ + updateDomain(domainId, data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .updateDomain(domainId, data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the deleteDomain function of DNSLinodeClass + * @param {NumberKeyword} domainId - Data required for deleteDomain + * @returns {Promise} + */ + deleteDomain(domainId) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .deleteDomain(domainId) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the cloneDomain function of DNSLinodeClass + * @param {NumberKeyword} domainId - Data required for cloneDomain + * @param {CloneDomainPayload} data - Data required for cloneDomain + * @returns {Promise} + */ + cloneDomain(domainId, data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .cloneDomain(domainId, data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } +} +module.exports = Linode_DNS; diff --git a/generator/generatedClasses/Linode/network/linode-loadBalancer.js b/generator/generatedClasses/Linode/network/linode-loadBalancer.js new file mode 100644 index 00000000..bdcce93e --- /dev/null +++ b/generator/generatedClasses/Linode/network/linode-loadBalancer.js @@ -0,0 +1,75 @@ +/*This is an auto generated class, please do not change.*/ +/** + * Class to create a LoadBalancerLinodeClass object + * @category Linode + */ +class Linode_LoadBalancer { + /** + * + * @param {module} do Linode SDK + * @param {object} options SDK options + */ + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } + /** + * Trigers the getNodeBalancers function of LoadBalancerLinodeClass + * @param {Params} params - Data required for getNodeBalancers + * @param {Filter} filters - Data required for getNodeBalancers + * @returns {Promise} + */ + list(params = undefined, filters = undefined) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getNodeBalancers(params, filters) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the updateNodeBalancer function of LoadBalancerLinodeClass + * @param {NumberKeyword} nodeBalancerId - Data required for updateNodeBalancer + * @param {Partial} data - Data required for updateNodeBalancer + * @returns {Promise} + */ + update(nodeBalancerId, data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .updateNodeBalancer(nodeBalancerId, data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the createNodeBalancer function of LoadBalancerLinodeClass + * @param {CreateNodeBalancerPayload} data - Data required for createNodeBalancer + * @returns {Promise} + */ + create(data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .createNodeBalancer(data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the deleteNodeBalancer function of LoadBalancerLinodeClass + * @param {NumberKeyword} nodeBalancerId - Data required for deleteNodeBalancer + * @returns {Promise} + */ + delete(nodeBalancerId) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .deleteNodeBalancer(nodeBalancerId) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } +} +module.exports = Linode_LoadBalancer; diff --git a/generator/generatedClasses/Linode/storage/linode-blockStorage.js b/generator/generatedClasses/Linode/storage/linode-blockStorage.js new file mode 100644 index 00000000..a4d93e6d --- /dev/null +++ b/generator/generatedClasses/Linode/storage/linode-blockStorage.js @@ -0,0 +1,75 @@ +/*This is an auto generated class, please do not change.*/ +/** + * Class to create a BlockStorageLinodeClass object + * @category Linode + */ +class Linode_BlockStorage { + /** + * + * @param {module} do Linode SDK + * @param {object} options SDK options + */ + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } + /** + * Trigers the getVolumes function of BlockStorageLinodeClass + * @param {Params} params - Data required for getVolumes + * @param {Filter} filters - Data required for getVolumes + * @returns {Promise} + */ + list(params = undefined, filters = undefined) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .getVolumes(params, filters) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the deleteVolume function of BlockStorageLinodeClass + * @param {NumberKeyword} volumeId - Data required for deleteVolume + * @returns {Promise} + */ + delete(volumeId) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .deleteVolume(volumeId) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the updateVolume function of BlockStorageLinodeClass + * @param {NumberKeyword} volumeId - Data required for updateVolume + * @param {UpdateVolumeRequest} data - Data required for updateVolume + * @returns {Promise} + */ + update(volumeId, data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .updateVolume(volumeId, data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } + /** + * Trigers the createVolume function of BlockStorageLinodeClass + * @param {VolumeRequestPayload} data - Data required for createVolume + * @returns {Promise} + */ + create(data) { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .createVolume(data) + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } +} +module.exports = Linode_BlockStorage; diff --git a/generator/generators/linode/generator.js b/generator/generators/linode/generator.js index 90f2271b..87629c4d 100644 --- a/generator/generators/linode/generator.js +++ b/generator/generators/linode/generator.js @@ -185,7 +185,7 @@ function extractSDKData(sdkAst, serviceClass) { parameters_1.push(parameter); } }); - // console.log(parameters); + methods.push({ functionName: name_1.toString(), SDKFunctionName: methodName, @@ -198,12 +198,14 @@ function extractSDKData(sdkAst, serviceClass) { exports.extractSDKData = extractSDKData; function getFunctions(sdkFiles, serviceClass) { return __awaiter(this, void 0, void 0, function() { - var functionsArray; + var functionsArray, classData; + var _this = this; return __generator(this, function(_a) { switch (_a.label) { case 0: functionsArray = []; + return [ 4 /*yield*/, sdkFiles.map(function(file) { @@ -258,7 +260,13 @@ function getFunctions(sdkFiles, serviceClass) { ]; case 1: _a.sent(); - return [2 /*return*/, functionsArray]; + classData = { + className: '', + functions: functionsArray, + serviceName: null, + }; + // console.log(classData); + return [2 /*return*/, classData]; } }); }); @@ -266,6 +274,7 @@ function getFunctions(sdkFiles, serviceClass) { exports.getFunctions = getFunctions; function generateLinodeClass(serviceClass, serviceName) { return __awaiter(this, void 0, void 0, function() { + var methods_1, files, sdkFiles, @@ -316,20 +325,19 @@ function generateLinodeClass(serviceClass, serviceName) { }); return [4 /*yield*/, getFunctions(sdkFiles, serviceClass)]; case 1: - functionsArray = _a.sent(); - classData = { - className: serviceName + 'LinodeClass', - functions: functionsArray, - serviceName: serviceName, - }; + classData = _a.sent(); + classData.className = serviceName + 'LinodeClass'; + classData.serviceName = serviceName; + return [ 4 /*yield*/, transformer_1.transform(dummyAst, classData), ]; case 2: output = _a.sent(); - filePath = void 0; dir = helper_1.getDir(serviceName); + filePath = void 0; + if ( !fs.existsSync( process.cwd() + '/generatedClasses/Linode/' + dir diff --git a/generator/generators/linode/generator.ts b/generator/generators/linode/generator.ts index b6d95a43..f1af53e7 100644 --- a/generator/generators/linode/generator.ts +++ b/generator/generators/linode/generator.ts @@ -79,8 +79,6 @@ export function extractSDKData(sdkAst, serviceClass) { parameters.push(parameter); } }); - // console.log(parameters); - methods.push({ functionName: name.toString(), SDKFunctionName: methodName, @@ -94,6 +92,8 @@ export function extractSDKData(sdkAst, serviceClass) { export async function getFunctions(sdkFiles, serviceClass) { const functionsArray: FunctionData[] = []; + // console.log(sdkFiles); + await sdkFiles.map(async file => { getAST(file).then(async result => { const sdkAst = result; @@ -111,7 +111,14 @@ export async function getFunctions(sdkFiles, serviceClass) { } }); }); - return functionsArray; + const classData: ClassData = { + className: '', + functions: functionsArray, + serviceName: null, + }; + // console.log(classData); + + return classData; } export async function generateLinodeClass(serviceClass, serviceName) { @@ -145,20 +152,13 @@ export async function generateLinodeClass(serviceClass, serviceName) { .map(method => method.SDKFunctionName), }; }); - const functionsArray: FunctionData[] = await getFunctions( - sdkFiles, - serviceClass - ); + const classData: ClassData = await getFunctions(sdkFiles, serviceClass); + classData.className = serviceName + 'LinodeClass'; + classData.serviceName = serviceName; - const classData: ClassData = { - className: serviceName + 'LinodeClass', - functions: functionsArray, - serviceName: serviceName, - }; const output = await transform(dummyAst, classData); - let filePath; const dir = getDir(serviceName); - + let filePath; if (!fs.existsSync(process.cwd() + '/generatedClasses/Linode/' + dir)) { fs.mkdirSync(process.cwd() + '/generatedClasses/Linode/' + dir); } diff --git a/generator/main.js b/generator/main.js index 5c5205a5..b5d229c1 100644 --- a/generator/main.js +++ b/generator/main.js @@ -2,6 +2,7 @@ exports.__esModule = true; var fs = require('fs'); var yaml = require('js-yaml'); + var generator_6 = require('./generators/linode/generator'); var generator_5 = require('./generators/oracle/generator'); var generator_1 = require('./generators/aws/generator'); diff --git a/generator/node-cloud.yml b/generator/node-cloud.yml index 36db0bc0..684b2a30 100644 --- a/generator/node-cloud.yml +++ b/generator/node-cloud.yml @@ -22,8 +22,14 @@ ComputeInstance: list: droplets.d.ts getAll destroy: droplets.d.ts deleteById start: droplets.d.ts requestAction - stop: droplets.d.ts requestAction - + stop: droplets.d.ts requestActio + Linode: + create: linodes linodes.d.ts createLinode + list: linodes linodes.d.ts getLinodes + update: linodes linodes.d.ts updateLinode + delete: linodes linodes.d.ts deleteLinode + clone: linodes linodes.d.ts cloneLinode + StorageBucket: AWS: create: s3.d.ts createBucket @@ -43,13 +49,20 @@ StorageBucket: list: storage storage.d.ts getBuckets upload: storage bucket.d.ts upload makePublic: storage file.d.ts makePublic +# Linode: +# create: object-storage buckets.d.ts createBucket +# get: object-storage buckets.d.ts getBucket +# list: object-storage buckets.d.ts getBuckets +# delete: object-storage buckets.d.ts deleteBucket +# getBucketAccess: object-storage buckets.d.ts getBucketAccess +# updateBucketAccess: object-storage buckets.d.ts updateBucketAccess Oracle: create: objectstorage createBucket delete: objectstorage deleteBucket get: objectstorage getBucket list: objectstorage listBuckets reencrypt: objectstorage reencryptBucket - + PaaS: AWS: create: elasticbeanstalk.d.ts createApplication @@ -124,6 +137,13 @@ Kubernetes: deleteNodegroup: kubernetes.d.ts deleteNodePool describeNodeGroup: kubernetes.d.ts getNodePoolById listNodegroups: kubernetes.d.ts getNodePools + Linode: + create: kubernetes kubernetes.d.ts createKubernetesCluster + delete: kubernetes kubernetes.d.ts deleteKubernetesCluster + getNodePool: kubernetes nodePools.d.ts getNodePool + createNodePool: kubernetes nodePools.d.ts createNodePool + updateNodePool: kubernetes nodePools.d.ts updateNodePool + deleteNodePool: kubernetes nodePools.d.ts deleteNodePool Oracle: create: containerengine createCluster delete: containerengine deleteCluster @@ -248,6 +268,13 @@ NoSql: deleteTable: nosql deleteTable list: nosql listTables updateTable: nosql updateTable + Linode: + createDatabase: databases databases.d.ts createDatabase + updateDatabase: databases databases.d.ts updateDatabase + deleteDatabase: databases databases.d.ts deleteDatabase + getDatabases: databases databases.d.ts getDatabases + getDatabaseEngines: databases databases.d.ts getDatabaseEngines + getEngineDatabase: databases databases.d.ts getEngineDatabase DNS: AWS: @@ -277,7 +304,14 @@ DNS: createZone: dns createZone deleteZone: dns deleteZone listZones: dns listZones - changeRecordSets: dns updateDomainRecords + changeRecordSets: dns updateDomainRecords + Linode: + createDomain: domains domains.d.ts createDomain + updateDomain: domains domains.d.ts updateDomain + deleteDomain: domains domains.d.ts deleteDomain + cloneDomain: domains domains.d.ts cloneDomain + getDomain: domains domains.d.ts getDomain + getDomains: domains domains.d.ts getDomains LoadBalancer: AWS: @@ -303,6 +337,11 @@ LoadBalancer: list: loadbalancer listLoadBalancers update: loadbalancer updateLoadBalancer get: loadbalancer getLoadBalancer + Linode: + create: nodebalancers nodebalancers.d.ts createNodeBalancer + delete: nodebalancers nodebalancers.d.ts deleteNodeBalancer + list: nodebalancers nodebalancers.d.ts getNodeBalancers + update: nodebalancers nodebalancers.d.ts updateNodeBalancer IAM: AWS: createGroup: iam.d.ts createGroup @@ -416,4 +455,9 @@ BlockStorage: create: volumes.d.ts create delete: volumes.d.ts deleteById list: volumes.d.ts getAll - describe: volumes.d.ts getById \ No newline at end of file + describe: volumes.d.ts getById + Linode: + create: volumes volumes.d.ts createVolume + delete: volumes volumes.d.ts deleteVolume + update: volumes volumes.d.ts updateVolume + list: volumes volumes.d.ts getVolumes diff --git a/generator/parsers/linode/parser.js b/generator/parsers/linode/parser.js index e98e1784..82965942 100644 --- a/generator/parsers/linode/parser.js +++ b/generator/parsers/linode/parser.js @@ -175,8 +175,7 @@ function getAST(sdkFileInfo) { typescript_1.SyntaxKind[child.kind] === 'FirstStatement' ) { - // console.log("child",child); - // resolve(false) + tmp_1 = Object.assign({}, child); cloned_1.push( tmp_1.declarationList.declarations[0] diff --git a/generator/test/generators/linode/dummyData/invalidDataset_1/sdkFile.txt b/generator/test/generators/linode/dummyData/invalidDataset_1/sdkFile.txt new file mode 100644 index 00000000..d2a6e413 --- /dev/null +++ b/generator/test/generators/linode/dummyData/invalidDataset_1/sdkFile.txt @@ -0,0 +1,82 @@ +import { ResourcePage as Page } from '../types'; +import { CreateKubeClusterPayload, KubeConfigResponse, KubernetesCluster, KubernetesEndpointResponse, KubernetesDashboardResponse, KubernetesVersion } from './types'; +/** + * getKubernetesClusters + * + * Gets a list of a uinterface ClassData { + className: string; + functions: FunctionData[]; + serviceName: string; +}ser's Kubernetes clusters + */ +export declare const getKubernetesClusters: (params?: any, filters?: any) => Promise>; +/** + * getKubernetesCluster + * + * Return details about a single Kubernetes cluster + */ +export declare const getKubernetesCluster: (clusterID: number) => Promise; +/** + * createKubernetesClusters + * + * Create a new cluster. + */ +export declare const createKubernetesCluster: (data: CreateKubeClusterPayload) => Promise; +/** + * updateKubernetesCluster + * + * Update an existing cluster. + */ +export declare const updateKubernetesCluster: (clusterID: number, data: Partial) => Promise; +/** + * deleteKubernetesCluster + * + * Delete the specified Cluster. + */ +export declare const deleteKubernetesCluster: (clusterID: number) => Promise<{}>; +/** + * getKubeConfig + * + * Returns a base64 encoded string of a cluster's kubeconfig.yaml + * + * @param clusterId + */ +export declare const getKubeConfig: (clusterId: number) => Promise; +/** + * resetKubeConfig + * + * Regenerates the cluster's kubeconfig.yaml + * + * @param clusterId + */ +export declare const resetKubeConfig: (clusterId: number) => Promise<{}>; +/** getKubernetesVersions + * + * Returns a paginated list of available Kubernetes versions. + * + */ +export declare const getKubernetesVersions: (params?: any, filters?: any) => Promise>; +/** getKubernetesVersion + * + * Returns a single Kubernetes version by ID. + * + */ +export declare const getKubernetesVersion: (versionID: string) => Promise; +/** getKubernetesClusterEndpoint + * + * Returns the endpoint URL for a single Kubernetes cluster by ID. + * + */ +export declare const getKubernetesClusterEndpoints: (clusterID: number, params?: any, filters?: any) => Promise>; +/** getKubernetesClusterDashboard + * Returns the URL for a single Kubernetes Dashboard for a single Kubernetes Cluster by ID. + * + */ +export declare const getKubernetesClusterDashboard: (clusterID: number) => Promise; +/** recycleClusterNodes + * + * Recycle all nodes in the target cluster (across all node pools) + * + */ +export declare const recycleClusterNodes: (clusterID: number) => Promise<{}>; +//# sourceMappingURL=kubernetes.d.ts.map \ No newline at end of file diff --git a/generator/test/generators/linode/dummyData/invalidDataset_1/serviceClass.json b/generator/test/generators/linode/dummyData/invalidDataset_1/serviceClass.json new file mode 100644 index 00000000..70062b56 --- /dev/null +++ b/generator/test/generators/linode/dummyData/invalidDataset_1/serviceClass.json @@ -0,0 +1,8 @@ +{ + "create": "kubernetes kubernetes.d.ts createKubernetesCluster", + "delete": "kubernetes kubernetes.d.ts", + "getNodePool": "kubernetes nodePools.d.ts getNodePool", + "createNodePool": "kubernetes nodePools.d.ts createNodePool", + "updateNodePool": "kubernetes nodePools.d.ts updateNodePool", + "deleteNodePool": "kubernetes nodePools.d.ts deleteNodePool" +} diff --git a/generator/test/generators/linode/dummyData/invalidDataset_2/sdkFile.txt b/generator/test/generators/linode/dummyData/invalidDataset_2/sdkFile.txt new file mode 100644 index 00000000..579a6b39 --- /dev/null +++ b/generator/test/generators/linode/dummyData/invalidDataset_2/sdkFile.txt @@ -0,0 +1,2 @@ +import { ResourcePage as Page } from '../types'; +import { CreateKubeClusterPayload, KubeConfigResponse, KubernetesCluster, KubernetesEndpointResponse, KubernetesDashboardResponse, KubernetesVersion } from './types'; \ No newline at end of file diff --git a/generator/test/generators/linode/dummyData/invalidDataset_2/serviceClass.json b/generator/test/generators/linode/dummyData/invalidDataset_2/serviceClass.json new file mode 100644 index 00000000..3d7c929a --- /dev/null +++ b/generator/test/generators/linode/dummyData/invalidDataset_2/serviceClass.json @@ -0,0 +1,7 @@ +{ + "create": "kubernetes kubernetes.d.ts createKubernetesCluster", + "getNodePool": "kubernetes nodePools.d.ts getNodePool", + "createNodePool": "kubernetes nodePools.d.ts createNodePool", + "updateNodePool": "kubernetes nodePools.d.ts updateNodePool", + "deleteNodePool": "kubernetes nodePools.d.ts deleteNodePool" +} diff --git a/generator/test/generators/linode/dummyData/validDataset/sdkFile.txt b/generator/test/generators/linode/dummyData/validDataset/sdkFile.txt new file mode 100644 index 00000000..d2a6e413 --- /dev/null +++ b/generator/test/generators/linode/dummyData/validDataset/sdkFile.txt @@ -0,0 +1,82 @@ +import { ResourcePage as Page } from '../types'; +import { CreateKubeClusterPayload, KubeConfigResponse, KubernetesCluster, KubernetesEndpointResponse, KubernetesDashboardResponse, KubernetesVersion } from './types'; +/** + * getKubernetesClusters + * + * Gets a list of a uinterface ClassData { + className: string; + functions: FunctionData[]; + serviceName: string; +}ser's Kubernetes clusters + */ +export declare const getKubernetesClusters: (params?: any, filters?: any) => Promise>; +/** + * getKubernetesCluster + * + * Return details about a single Kubernetes cluster + */ +export declare const getKubernetesCluster: (clusterID: number) => Promise; +/** + * createKubernetesClusters + * + * Create a new cluster. + */ +export declare const createKubernetesCluster: (data: CreateKubeClusterPayload) => Promise; +/** + * updateKubernetesCluster + * + * Update an existing cluster. + */ +export declare const updateKubernetesCluster: (clusterID: number, data: Partial) => Promise; +/** + * deleteKubernetesCluster + * + * Delete the specified Cluster. + */ +export declare const deleteKubernetesCluster: (clusterID: number) => Promise<{}>; +/** + * getKubeConfig + * + * Returns a base64 encoded string of a cluster's kubeconfig.yaml + * + * @param clusterId + */ +export declare const getKubeConfig: (clusterId: number) => Promise; +/** + * resetKubeConfig + * + * Regenerates the cluster's kubeconfig.yaml + * + * @param clusterId + */ +export declare const resetKubeConfig: (clusterId: number) => Promise<{}>; +/** getKubernetesVersions + * + * Returns a paginated list of available Kubernetes versions. + * + */ +export declare const getKubernetesVersions: (params?: any, filters?: any) => Promise>; +/** getKubernetesVersion + * + * Returns a single Kubernetes version by ID. + * + */ +export declare const getKubernetesVersion: (versionID: string) => Promise; +/** getKubernetesClusterEndpoint + * + * Returns the endpoint URL for a single Kubernetes cluster by ID. + * + */ +export declare const getKubernetesClusterEndpoints: (clusterID: number, params?: any, filters?: any) => Promise>; +/** getKubernetesClusterDashboard + * Returns the URL for a single Kubernetes Dashboard for a single Kubernetes Cluster by ID. + * + */ +export declare const getKubernetesClusterDashboard: (clusterID: number) => Promise; +/** recycleClusterNodes + * + * Recycle all nodes in the target cluster (across all node pools) + * + */ +export declare const recycleClusterNodes: (clusterID: number) => Promise<{}>; +//# sourceMappingURL=kubernetes.d.ts.map \ No newline at end of file diff --git a/generator/test/generators/linode/dummyData/validDataset/serviceClass.json b/generator/test/generators/linode/dummyData/validDataset/serviceClass.json new file mode 100644 index 00000000..8c0cefa3 --- /dev/null +++ b/generator/test/generators/linode/dummyData/validDataset/serviceClass.json @@ -0,0 +1,8 @@ +{ + "create": "kubernetes kubernetes.d.ts createKubernetesCluster", + "delete": "kubernetes kubernetes.d.ts deleteKubernetesCluster", + "getNodePool": "kubernetes nodePools.d.ts getNodePool", + "createNodePool": "kubernetes nodePools.d.ts createNodePool", + "updateNodePool": "kubernetes nodePools.d.ts updateNodePool", + "deleteNodePool": "kubernetes nodePools.d.ts deleteNodePool" +} diff --git a/generator/test/generators/linode/generator.test.ts b/generator/test/generators/linode/generator.test.ts new file mode 100644 index 00000000..d4ebbe72 --- /dev/null +++ b/generator/test/generators/linode/generator.test.ts @@ -0,0 +1,91 @@ +import { expect } from 'chai'; +import { SyntaxKind } from 'typescript'; + +import { extractSDKData } from '../../../generators/linode/generator'; +import { readJsonData, readSourceFile } from '../lib/helper'; + +describe('Linode generator extractSDKData', () => { + context('with valid methods and valid AST', () => { + it('should return extracted functions array', async () => { + const sdkFile: any = await readSourceFile('validDataset', 'linode'); + const data: any = await readJsonData( + 'validDataset', + 'linode', + 'serviceClass' + ); + const cloned = []; + let tmp = null; + sdkFile.forEachChild(child => { + if (SyntaxKind[child.kind] === 'FirstStatement') { + tmp = Object.assign({}, child); + cloned.push(tmp.declarationList.declarations[0]); + } + }); + if (cloned) { + const result = extractSDKData(cloned, data); + expect(result).to.be.an('array'); + } else { + console.error('Error in cloning class'); + } + }); + }); + + context('with invalid method data:missing method name', () => { + it('should drop invalid method', async () => { + const sdkFile: any = await readSourceFile( + 'invalidDataset_1', + 'linode' + ); + const data: any = await readJsonData( + 'invalidDataset_1', + 'linode', + 'serviceClass' + ); + const cloned = []; + let tmp = null; + sdkFile.forEachChild(child => { + if (SyntaxKind[child.kind] === 'FirstStatement') { + tmp = Object.assign({}, child); + cloned.push(tmp.declarationList.declarations[0]); + } + }); + + if (cloned) { + const result = extractSDKData(cloned, data); + expect(result.length < Object.keys(data).length).to.be.true; + } else { + console.error('Error in cloning class'); + } + }); + }); + + context('Linode with no functions', () => { + it('should return empty array of methods', async () => { + const sdkFile: any = await readSourceFile( + 'invalidDataset_2', + 'linode' + ); + const data: any = await readJsonData( + 'invalidDataset_2', + 'linode', + 'serviceClass' + ); + const cloned = []; + let tmp = null; + sdkFile.forEachChild(child => { + if (SyntaxKind[child.kind] === 'FirstStatement') { + tmp = Object.assign({}, child); + cloned.push(tmp.declarationList.declarations[0]); + } + }); + + if (cloned) { + const result = extractSDKData(cloned, data); + expect(result).to.be.an('array'); + expect(result.length).to.eql(0); + } else { + console.error('Error in cloning class'); + } + }); + }); +}); diff --git a/generator/test/parsers/linode/parser.test.ts b/generator/test/parsers/linode/parser.test.ts new file mode 100644 index 00000000..e866aa4e --- /dev/null +++ b/generator/test/parsers/linode/parser.test.ts @@ -0,0 +1,39 @@ +import { expect } from 'chai'; +import { SyntaxKind } from 'typescript'; + +import { getAST } from '../../../parsers/linode/parser'; + +describe('Linode parser getAST', () => { + context('With existing file', () => { + it('Should return Abstract syntax tree of the class', async () => { + const ast: any = await getAST({ + pkgName: 'kubernetes', + fileName: 'kubernetes.d.ts', + }); + expect(ast).to.be.an('array'); + }); + }); + + context('With non-existing file', () => { + it('should return File not found Error', async () => { + try { + await getAST({ + pkgName: 'kubernetes', + fileName: 'unknown.d.ts', + }); + } catch (error) { + expect(error.message).to.eql('File not found!'); + } + }); + }); + + context('With wrong format file', () => { + it('Should return class not found Error', async () => { + try { + await getAST({ pkgName: 'kubernetes', fileName: 'types.d.ts' }); + } catch (error) { + expect(error.message).to.eql('Class not found!'); + } + }); + }); +}); diff --git a/generator/test/transformers/linode/dummyData/invalidDataset_1/data.json b/generator/test/transformers/linode/dummyData/invalidDataset_1/data.json new file mode 100644 index 00000000..5a3e3bff --- /dev/null +++ b/generator/test/transformers/linode/dummyData/invalidDataset_1/data.json @@ -0,0 +1,66 @@ +{ + "className": "BlockStorageLinodeClass", + "functions": [ + { + "functionName": "list", + "SDKFunctionName": "getVolumes", + "params": [ + { + "name": "params", + "optional": true, + "type": "AnyKeyword", + "typeName": null + }, + { + "name": "filters", + "optional": true, + "type": "AnyKeyword", + "typeName": null + } + ] + }, + { + "functionName": "delete", + "SDKFunctionName": "deleteVolume", + "params": [ + { + "name": "volumeId", + "optional": false, + "type": "NumberKeyword", + "typeName": null + } + ] + }, + { + "functionName": "update", + "SDKFunctionName": "updateVolume", + "params": [ + { + "name": "volumeId", + "optional": false, + "type": "NumberKeyword", + "typeName": null + }, + { + "name": "data", + "optional": false, + "type": "TypeReference", + "typeName": "UpdateVolumeRequest" + } + ] + }, + { + "functionName": "create", + "SDKFunctionName": "createVolume", + "params": [ + { + "name": "data", + "optional": false, + "type": "TypeReference", + "typeName": "VolumeRequestPayload" + } + ] + } + ], + "serviceName": "BlockStorage" +} diff --git a/generator/test/transformers/linode/dummyData/invalidDataset_1/sourceFile.js b/generator/test/transformers/linode/dummyData/invalidDataset_1/sourceFile.js new file mode 100644 index 00000000..f7c98732 --- /dev/null +++ b/generator/test/transformers/linode/dummyData/invalidDataset_1/sourceFile.js @@ -0,0 +1,8 @@ +class ClassName { + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } +} + +module.exports = ClassName; diff --git a/generator/test/transformers/linode/dummyData/invalidDataset_2/data.json b/generator/test/transformers/linode/dummyData/invalidDataset_2/data.json new file mode 100644 index 00000000..0e792ed5 --- /dev/null +++ b/generator/test/transformers/linode/dummyData/invalidDataset_2/data.json @@ -0,0 +1,21 @@ +{ + "functions": [ + { + "SDKFunctionName": "getVolumes", + "params": [ + { + "name": "params", + "optional": true, + "type": "AnyKeyword", + "typeName": null + }, + { + "name": "filters", + "optional": true, + "type": "AnyKeyword", + "typeName": null + } + ] + } + ] +} diff --git a/generator/test/transformers/linode/dummyData/invalidDataset_2/sourceFile.js b/generator/test/transformers/linode/dummyData/invalidDataset_2/sourceFile.js new file mode 100644 index 00000000..1e3401bf --- /dev/null +++ b/generator/test/transformers/linode/dummyData/invalidDataset_2/sourceFile.js @@ -0,0 +1,18 @@ +class ClassName { + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } + + function() { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .SDKFunctionName() + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } +} + +module.exports = ClassName; diff --git a/generator/test/transformers/linode/dummyData/validDataset/data.json b/generator/test/transformers/linode/dummyData/validDataset/data.json new file mode 100644 index 00000000..5a3e3bff --- /dev/null +++ b/generator/test/transformers/linode/dummyData/validDataset/data.json @@ -0,0 +1,66 @@ +{ + "className": "BlockStorageLinodeClass", + "functions": [ + { + "functionName": "list", + "SDKFunctionName": "getVolumes", + "params": [ + { + "name": "params", + "optional": true, + "type": "AnyKeyword", + "typeName": null + }, + { + "name": "filters", + "optional": true, + "type": "AnyKeyword", + "typeName": null + } + ] + }, + { + "functionName": "delete", + "SDKFunctionName": "deleteVolume", + "params": [ + { + "name": "volumeId", + "optional": false, + "type": "NumberKeyword", + "typeName": null + } + ] + }, + { + "functionName": "update", + "SDKFunctionName": "updateVolume", + "params": [ + { + "name": "volumeId", + "optional": false, + "type": "NumberKeyword", + "typeName": null + }, + { + "name": "data", + "optional": false, + "type": "TypeReference", + "typeName": "UpdateVolumeRequest" + } + ] + }, + { + "functionName": "create", + "SDKFunctionName": "createVolume", + "params": [ + { + "name": "data", + "optional": false, + "type": "TypeReference", + "typeName": "VolumeRequestPayload" + } + ] + } + ], + "serviceName": "BlockStorage" +} diff --git a/generator/test/transformers/linode/dummyData/validDataset/sourceFile.js b/generator/test/transformers/linode/dummyData/validDataset/sourceFile.js new file mode 100644 index 00000000..02304d27 --- /dev/null +++ b/generator/test/transformers/linode/dummyData/validDataset/sourceFile.js @@ -0,0 +1,23 @@ +class ClassName { + /** + * + * @param {module} do Linode SDK + * @param {object} options SDK options + */ + constructor(linodeSdk, linodeToken) { + this._linode = linodeSdk; + this._linodeToken = linodeToken; + } + + function() { + this._linode.setToken(this._linodeToken); + return new Promise((resolve, reject) => { + this._linode + .SDKFunctionName() + .then(data => resolve(data)) + .catch(err => reject(err)); + }); + } +} + +module.exports = ClassName; diff --git a/generator/test/transformers/linode/transformer.test.ts b/generator/test/transformers/linode/transformer.test.ts new file mode 100644 index 00000000..2aacc497 --- /dev/null +++ b/generator/test/transformers/linode/transformer.test.ts @@ -0,0 +1,71 @@ +import { expect } from 'chai'; +import { createSourceFile, isSourceFile, ScriptTarget } from 'typescript'; + +import { transform } from '../../../transformers/linode/transformer'; +import { readJsonData, readSourceFile } from '../lib/helper'; + +interface TestData { + AST: any; + data: any; +} + +describe('Linode transformer transform', () => { + context('Valid source code and valid data', () => { + const testData: TestData = { AST: null, data: null }; + before(async () => { + testData.AST = await readSourceFile('validDataset', 'linode'); + testData.data = await readJsonData('validDataset', 'linode'); + }); + + it('Should return a String', async () => { + const result = await transform(testData.AST, testData.data); + expect(result).to.be.string; + }); + + it('Should return a Javascript code in String format', async () => { + const result = await transform(testData.AST, testData.data); + try { + const sourceCode = createSourceFile( + 'someClass.js', + result, + ScriptTarget.Latest + ); + expect(isSourceFile(sourceCode)).to.be.true; + } catch (error) { + console.log(error); + } + }); + }); + + context('Invalid source code and valid data', () => { + const testData: TestData = { AST: null, data: null }; + before(async () => { + testData.AST = await readSourceFile('invalidDataset_1', 'linode'); + testData.data = await readJsonData('invalidDataset_1', 'linode'); + }); + + it('Should return a validation Error', async () => { + try { + await transform(testData.AST, testData.data); + } catch (error) { + expect(error.message).to.eql('Code is invalid'); + } + }); + }); + + context('Valid source code and invalid data', () => { + const testData: TestData = { AST: null, data: null }; + before(async () => { + testData.AST = await readSourceFile('invalidDataset_2', 'linode'); + testData.data = await readJsonData('invalidDataset_2', 'linode'); + }); + + it('Should return a validation Error', async () => { + try { + await transform(testData.AST, testData.data); + } catch (error) { + expect(error.message).to.eql('Input is invalid'); + } + }); + }); +}); diff --git a/generator/transformers/linode/transformer.js b/generator/transformers/linode/transformer.js index 8f76a586..3bec62f2 100644 --- a/generator/transformers/linode/transformer.js +++ b/generator/transformers/linode/transformer.js @@ -283,10 +283,7 @@ function transform(code, classData) { ts.isIdentifier(childNode) && childNode.text === 'SDKFunctionName' ) { - console.log( - classData.functions[count] - .params - ); + var args = classData.functions[ count ].params.map(function(param) { @@ -366,7 +363,7 @@ function transform(code, classData) { } return statment; }); - console.log('parameters', parameters); + var comment = void 0; if (parameters.length > 0) { var paramStatments_1 = ''; diff --git a/generator/transformers/linode/transformer.ts b/generator/transformers/linode/transformer.ts index 3630b0ba..45d8c8b3 100644 --- a/generator/transformers/linode/transformer.ts +++ b/generator/transformers/linode/transformer.ts @@ -138,8 +138,6 @@ export async function transform( ts.isIdentifier(childNode) && childNode.text === 'SDKFunctionName' ) { - console.log(classData.functions[count].params); - const args = classData.functions[count].params.map( param => ts.createIdentifier(param.name) ); @@ -189,7 +187,6 @@ export async function transform( return statment; } ); - console.log('parameters', parameters); let comment; if (parameters.length > 0) { diff --git a/package-lock.json b/package-lock.json index 58d0d766..b341bc32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31350,4 +31350,4 @@ "dev": true } } -} +} \ No newline at end of file