Skip to content

Commit

Permalink
chore: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj authored and tkurki committed Jan 29, 2022
1 parent 521b172 commit abcbfbd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 60 deletions.
5 changes: 3 additions & 2 deletions packages/streams/nmea0183-signalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ function Nmea0183ToSignalK(options) {
Transform.call(this, {
objectMode: true,
})
this.debug = (options.createDebug || require('debug'))('signalk:streams:nmea0183-signalk')

this.debug = (options.createDebug || require('debug'))(
'signalk:streams:nmea0183-signalk'
)

this.parser = new Parser(options)
this.n2kParser = new FromPgn(options)
Expand Down
9 changes: 4 additions & 5 deletions src/api/course/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Debug from 'debug'
const debug = Debug('signalk:courseApi')
// import { createDebug } from './debug'
// const debug = createDebug('signalk:courseApi')
import { createDebug } from '../../debug'
const debug = createDebug('signalk:courseApi')

import { FullSignalK } from '@signalk/signalk-schema'
import { Application, Request, Response } from 'express'
import _ from 'lodash'
Expand All @@ -10,9 +9,9 @@ import { WithConfig } from '../../app'
import { WithSecurityStrategy } from '../../security'
import { Position } from '../../types'

import { Responses } from '../'
import { Store } from '../../serverstate/store'
import { Route } from '../resources/types'
import { Responses } from '../'

const SIGNALK_API_PATH = `/signalk/v1/api`
const COURSE_API_PATH = `${SIGNALK_API_PATH}/vessels/self/navigation/course`
Expand Down
72 changes: 36 additions & 36 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
export interface ApiResponse {
state: 'FAILED' | 'COMPLETED' | 'PENDING'
statusCode: number
message: string
requestId?: string
href?: string
token?: string
state: 'FAILED' | 'COMPLETED' | 'PENDING'
statusCode: number
message: string
requestId?: string
href?: string
token?: string
}

export const Responses = {
ok: {
state: 'COMPLETED',
statusCode: 200,
message: 'OK'
},
invalid: {
state: 'FAILED',
statusCode: 406,
message: `Invalid Data supplied.`
},
unauthorised: {
state: 'FAILED',
statusCode: 403,
message: 'Unauthorised'
},
notFound: {
state: 'FAILED',
statusCode: 404,
message: 'Resource not found.'
}
ok: {
state: 'COMPLETED',
statusCode: 200,
message: 'OK'
},
invalid: {
state: 'FAILED',
statusCode: 406,
message: `Invalid Data supplied.`
},
unauthorised: {
state: 'FAILED',
statusCode: 403,
message: 'Unauthorised'
},
notFound: {
state: 'FAILED',
statusCode: 404,
message: 'Resource not found.'
}
}

// returns true if target path is an API request
export function isApiRequest(path:string): boolean {
if (
path.split('/')[4] === 'resources' || // resources API
path.indexOf('/navigation/course/') !== -1 // course API
) {
return true
} else {
return false
}
}
export function isApiRequest(path: string): boolean {
if (
path.split('/')[4] === 'resources' || // resources API
path.indexOf('/navigation/course/') !== -1 // course API
) {
return true
} else {
return false
}
}
18 changes: 7 additions & 11 deletions src/api/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Debug from 'debug'
const debug = Debug('signalk:resourcesApi')
// import { createDebug } from './debug'
// const debug = createDebug('signalk:resourcesApi')
import { createDebug } from '../../debug'
const debug = createDebug('signalk:resourcesApi')

import {
ResourceProvider,
Expand All @@ -11,7 +9,7 @@ import {

import { Application, NextFunction, Request, Response } from 'express'
import { v4 as uuidv4 } from 'uuid'
//import { SignalKMessageHub } from '../../app'
// import { SignalKMessageHub } from '../../app'
import { WithSecurityStrategy } from '../../security'

import { Responses } from '../'
Expand All @@ -21,13 +19,11 @@ import { validate } from './validate'
const SIGNALK_API_PATH = `/signalk/v1/api`
const UUID_PREFIX = 'urn:mrn:signalk:uuid:'

interface ResourceApplication
extends Application,
WithSecurityStrategy {
handleMessage: (id: string, data: any) => void
}
interface ResourceApplication extends Application, WithSecurityStrategy {
handleMessage: (id: string, data: any) => void
}

export class Resources {
export class ResourcesApi {
private resProvider: { [key: string]: ResourceProviderMethods | null } = {}
private server: ResourceApplication

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import SubscriptionManager from './subscriptionmanager'
import { Delta } from './types'

import { CourseApi } from './api/course'
import { Resources } from './api/resources'
import { ResourcesApi } from './api/resources'

const debug = createDebug('signalk-server')

Expand Down Expand Up @@ -80,7 +80,7 @@ class Server {
require('./serverroutes')(app, saveSecurityConfig, getSecurityConfig)
require('./put').start(app)

app.resourcesApi = new Resources(app)
app.resourcesApi = new ResourcesApi(app)
const courseApi = new CourseApi(app)

app.signalk = new FullSignalK(app.selfId, app.selfType)
Expand Down
5 changes: 2 additions & 3 deletions src/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { v4: uuidv4 } = require('uuid')
const { createRequest, updateRequest } = require('./requestResponse')
const skConfig = require('./config/config')

const {isApiRequest} = require('./api')
const { isApiRequest } = require('./api')

const pathPrefix = '/signalk'
const versionPrefix = '/v1'
Expand Down Expand Up @@ -33,13 +33,12 @@ module.exports = {
app.deRegisterActionHandler = deRegisterActionHandler

app.put(apiPathPrefix + '*', function(req, res, next) {

// check for resources API, course API, etc request
if (isApiRequest(req.path)) {
next()
return
}

let path = String(req.path).replace(apiPathPrefix, '')

const value = req.body
Expand Down
2 changes: 1 addition & 1 deletion src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { Request } from 'express'
import {
chmodSync,
existsSync,
Expand All @@ -30,7 +31,6 @@ import { Mode } from 'stat-mode'
import { WithConfig } from './app'
import { createDebug } from './debug'
import dummysecurity from './dummysecurity'
import { Request } from 'express'
const debug = createDebug('signalk-server:security')

export interface WithSecurityStrategy {
Expand Down

0 comments on commit abcbfbd

Please sign in to comment.