Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DataServiceContext type #55

Draft
wants to merge 2 commits into
base: v1.x/staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions nodeServer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nodeServer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"devDependencies": {
"@types/express": "~4.16.0",
"@types/node": "~8.10.23",
"typescript": "~2.9.0"
"typescript": "~3.1.0"
}
}
19 changes: 8 additions & 11 deletions nodeServer/ts/helloWorld.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { Response, Request } from "express";
import { Router } from "express-serve-static-core";



/*
This program and the accompanying materials are
Expand All @@ -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();
Expand Down Expand Up @@ -55,7 +52,7 @@ class HelloWorldDataservice{
}


exports.helloWorldRouter = function(context): Router {
export function helloWorldRouter(context: ZLUXServerFramework.DataServiceContext): Promise<Router> {
return new Promise(function(resolve, reject) {
let dataservice = new HelloWorldDataservice(context);
resolve(dataservice.getRouter());
Expand All @@ -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.
*/

20 changes: 10 additions & 10 deletions nodeServer/ts/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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);
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -99,7 +99,7 @@ class StorageDataService {
}
}

export function storageRouter(context: any): Promise<Router> {
export function storageRouter(context: ZLUXServerFramework.DataServiceContext): Promise<Router> {
const dataService = new StorageDataService(context);
return Promise.resolve(dataService.getRouter());
}
Expand Down
9 changes: 9 additions & 0 deletions nodeServer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -12,6 +17,10 @@
"node",
"express"
],
"paths": {
"zlux-platform/*": ["../../zlux-platform/interface/src/*"]
},
"skipLibCheck": true,
"lib": ["es5", "es6"]
}
}