Skip to content
Open
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
76 changes: 17 additions & 59 deletions package-lock.json

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

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
},
"dependencies": {
"@types/pg": "^7.14.11",
"@types/ws": "^6.0.4",
"coderitter-api-remote-method-api": "^6.0.0",
"coderitter-api-remote-method-call": "^4.0.1",
"knight-change": "^1.0.0",
"knight-change": "^2.0.0",
"knight-criteria": "^2.0.7",
"knight-json": "^1.0.1",
"knight-log": "^1.0.6",
"knight-orm": "^0.3.1",
"knight-orm": "^0.4.0",
"knight-pg-migration": "^1.0.0",
"knight-pg-transaction": "^1.0.3",
"knight-validation": "^1.0.0",
"pg": "^8.5.1",
"ws": "^7.4.5"
"pg": "^8.5.1"
},
"devDependencies": {
"@types/chai": "^4.2.14",
Expand Down
2 changes: 0 additions & 2 deletions src/Instantiator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Result } from 'coderitter-api-remote-method-call'
import { Changes } from 'knight-change'
import { CountResult, CreateOrGetResult, EntitiesResult, EntitiesVersionResult, EntityResult } from './domain/api'
import Change from './domain/change/Change'
import Knight from './domain/knight/Knight'

export default {
// change
'Changes': () => new Changes,
'Change': () => new Change,

//knight
'Knight': () => new Knight,
Expand Down
27 changes: 0 additions & 27 deletions src/Services.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import http from 'http'
import { Pool } from 'pg'
import { Log } from 'knight-log'
import WebSocket from 'ws'
import ApiV1 from './api/ApiV1'
import HttpApi from './api/HttpApi'
import WebSocketApi from './api/WebSocketApi'
import { getConfigByArgvOrEnvOrDefault, test } from './config'
import ChangeLogic from './domain/change/ChangeLogic'
import DbMigration from './domain/DbMigration'
import DemoData from './domain/DemoData'
import instantiator from './Instantiator'
Expand All @@ -32,15 +29,12 @@ export default class Services {
pool!: Pool

httpServer!: http.Server
webSocketServer!: WebSocket.Server

apiV1 = new ApiV1
httpApi!: HttpApi
webSocketApi!: WebSocketApi

orm = new Orm(schema, 'postgres')

changeLogic = new ChangeLogic()
knightLogic = new KnightLogic()

async start() {
Expand All @@ -55,7 +49,6 @@ export default class Services {

inject() {
this.knightLogic.orm = this.orm
this.changeLogic.orm = this.orm

}

Expand All @@ -67,31 +60,16 @@ export default class Services {
async startServer() {
// HTTP Server
this.httpServer = http.createServer()

// WebSocket Server
this.webSocketServer = new WebSocket.Server({
server: this.httpServer
}, () => {
let address = this.webSocketServer.address() as any
log.admin('WebSocket server running at ' + address.address + ':' + address.port + ' - ' + address.family)
})
}

startApis() {
this.httpApi = new HttpApi(this.apiV1, instantiator, this.config.httpApi)
this.httpApi.server = this.httpServer

this.webSocketApi = new WebSocketApi
this.webSocketApi.webSocketServer = this.webSocketServer
this.webSocketApi.pool = this.pool
this.webSocketApi.changeLogic = this.changeLogic

this.apiV1.pool = this.pool
this.apiV1.webSocketApi = this.webSocketApi

this.httpApi.start()
log.admin('Started HTTP API (POSTonly)')
this.webSocketApi.start()
log.admin('Started WebSocket API')

log.admin('Initialized HTTP API with remote methods', this.apiV1.methodNames)
Expand All @@ -110,11 +88,6 @@ export default class Services {
log.admin('Stopped HTTP server')
}

if (this.webSocketServer) {
this.webSocketServer.close()
log.admin('Stopped WebSocket server')
}

Log.watcher?.close()
}

Expand Down
8 changes: 0 additions & 8 deletions src/api/ApiV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ import { PgTransaction } from 'knight-pg-transaction'
import { Pool } from 'pg'
import { Log } from 'knight-log'

import { ChangeSendingTransaction } from '../domain/ChangeSendingTransaction'
import Services from '../Services'
import WebSocketApi from './WebSocketApi'

let log = new Log('ApiV1.ts')

export default class Api extends RemoteMethodApi {

pool!: Pool
webSocketApi!: WebSocketApi

start() {
this.methods = {
Expand All @@ -22,9 +19,4 @@ export default class Api extends RemoteMethodApi {
tx(): PgTransaction {
return new PgTransaction(this.pool)
}

chgTx(): ChangeSendingTransaction {
log.mt('chgTx')
return new ChangeSendingTransaction(this.pool, Services.get().changeLogic, this.webSocketApi)
}
}
Loading