From 47b8e160486a8dfb4c3b6da6ed02ea44114ee2b7 Mon Sep 17 00:00:00 2001 From: Leonty Chudinov Date: Fri, 7 May 2021 08:33:47 +0500 Subject: [PATCH] Use DataServiceContext type Signed-off-by: Leonty Chudinov --- nodeServer/package-lock.json | 6 +++--- nodeServer/package.json | 2 +- nodeServer/ts/helloWorld.ts | 19 ++++++++----------- nodeServer/ts/storage.ts | 20 ++++++++++---------- nodeServer/tsconfig.json | 9 +++++++++ 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/nodeServer/package-lock.json b/nodeServer/package-lock.json index a56471c..473d0fd 100644 --- a/nodeServer/package-lock.json +++ b/nodeServer/package-lock.json @@ -73,9 +73,9 @@ } }, "typescript": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", - "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==", + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.8.tgz", + "integrity": "sha512-R97qglMfoKjfKD0N24o7W6bS+SwjN/eaQNIaxR8S5HdLRnt7rCk6LCmE3tve1KN8gXKgbJU51aZHRRMAQcIbMA==", "dev": true } } diff --git a/nodeServer/package.json b/nodeServer/package.json index b48c830..62f6ef1 100644 --- a/nodeServer/package.json +++ b/nodeServer/package.json @@ -10,6 +10,6 @@ "devDependencies": { "@types/express": "~4.16.0", "@types/node": "~8.10.23", - "typescript": "~2.9.0" + "typescript": "~3.1.0" } } diff --git a/nodeServer/ts/helloWorld.ts b/nodeServer/ts/helloWorld.ts index fb54185..9c7d2c0 100644 --- a/nodeServer/ts/helloWorld.ts +++ b/nodeServer/ts/helloWorld.ts @@ -1,7 +1,3 @@ -import { Response, Request } from "express"; -import { Router } from "express-serve-static-core"; - - /* This program and the accompanying materials are @@ -13,15 +9,16 @@ import { Router } from "express-serve-static-core"; Copyright Contributors to the Zowe Project. */ +import { Response, Request, Router } from 'express'; const express = require('express'); -const Promise = require('bluebird'); const obfuscator = require ('zlux-shared/src/obfuscator/htmlObfuscator.js'); +import { ZLUXServerFramework } from 'zlux-platform/server-framework'; class HelloWorldDataservice{ - private context: any; + private context: ZLUXServerFramework.DataServiceContext; private router: Router; - - constructor(context: any){ + + constructor(context: ZLUXServerFramework.DataServiceContext){ let htmlObfuscator = new obfuscator.HtmlObfuscator(); this.context = context; let router = express.Router(); @@ -55,7 +52,7 @@ class HelloWorldDataservice{ } -exports.helloWorldRouter = function(context): Router { +export function helloWorldRouter(context: ZLUXServerFramework.DataServiceContext): Promise { return new Promise(function(resolve, reject) { let dataservice = new HelloWorldDataservice(context); resolve(dataservice.getRouter()); @@ -67,9 +64,9 @@ exports.helloWorldRouter = function(context): Router { This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html - + SPDX-License-Identifier: EPL-2.0 - + Copyright Contributors to the Zowe Project. */ diff --git a/nodeServer/ts/storage.ts b/nodeServer/ts/storage.ts index 3e08d43..8d5a0b2 100644 --- a/nodeServer/ts/storage.ts +++ b/nodeServer/ts/storage.ts @@ -8,21 +8,21 @@ Copyright Contributors to the Zowe Project. */ -import { Response, Request } from 'express'; -import { Router } from 'express-serve-static-core'; +import { Response, Request, Router } from 'express'; import express = require('express'); +import { ZLUXServerFramework } from 'zlux-platform/server-framework'; class StorageDataService { private router: Router; - constructor(private context: any) { + constructor(private context: ZLUXServerFramework.DataServiceContext) { const storage = this.context.storage; const router = express.Router(); this.router = router; context.addBodyParseMiddleware(router); router.post('/', (req: Request, res: Response) => { - const storageType = req.query.storageType; + const storageType = req.query.storageType as ZLUXServerFramework.StorageLocationType; const dict = req.body; storage.setAll(dict, storageType).then(() => { res.sendStatus(204); @@ -34,7 +34,7 @@ class StorageDataService { }); router.get('/', (req: Request, res: Response) => { - const storageType = req.query.storageType; + const storageType = req.query.storageType as ZLUXServerFramework.StorageLocationType; storage.getAll(storageType).then(dict => { res.status(200).json(dict); }).catch(e => { @@ -45,7 +45,7 @@ class StorageDataService { }); router.delete('/', (req: Request, res: Response) => { - const storageType = req.query.storageType; + const storageType = req.query.storageType as ZLUXServerFramework.StorageLocationType; storage.deleteAll(storageType).then(() => { res.sendStatus(204); }).catch(e => { @@ -57,7 +57,7 @@ class StorageDataService { router.post('/:key', (req: Request, res: Response) => { const key = req.params.key; - const storageType = req.query.storageType; + const storageType = req.query.storageType as ZLUXServerFramework.StorageLocationType; const { value } = req.body; storage.set(key, value, storageType).then(() => { res.sendStatus(204); @@ -70,7 +70,7 @@ class StorageDataService { router.get('/:key', (req: Request, res: Response) => { const key = req.params.key; - const storageType = req.query.storageType; + const storageType = req.query.storageType as ZLUXServerFramework.StorageLocationType; storage.get(key, storageType).then(value => { res.status(200).json({ key, value }); }).catch(e => { @@ -82,7 +82,7 @@ class StorageDataService { router.delete('/:key', (req: Request, res: Response) => { const key = req.params.key; - const storageType = req.query.storageType; + const storageType = req.query.storageType as ZLUXServerFramework.StorageLocationType; storage.delete(key, storageType).then(() => { res.sendStatus(204); }).catch(e => { @@ -99,7 +99,7 @@ class StorageDataService { } } -export function storageRouter(context: any): Promise { +export function storageRouter(context: ZLUXServerFramework.DataServiceContext): Promise { const dataService = new StorageDataService(context); return Promise.resolve(dataService.getRouter()); } diff --git a/nodeServer/tsconfig.json b/nodeServer/tsconfig.json index 44366cd..286db08 100644 --- a/nodeServer/tsconfig.json +++ b/nodeServer/tsconfig.json @@ -3,7 +3,12 @@ "include": [ "ts/*.ts" ], + "files": [ + "../../zlux-platform/interface/src/index.d.ts", + "../../zlux-platform/interface/src/server-framework.d.ts" + ], "compilerOptions": { + "baseUrl": "", "outDir": "../lib", "sourceMap": true, "allowJs": true, @@ -12,6 +17,10 @@ "node", "express" ], + "paths": { + "zlux-platform/*": ["../../zlux-platform/interface/src/*"] + }, + "skipLibCheck": true, "lib": ["es5", "es6"] } }