mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
prep for live mocks
This commit is contained in:
committed by
Aiden McClelland
parent
21dd8fa618
commit
c5f2379c6e
@@ -16,11 +16,8 @@ export module RR {
|
||||
|
||||
// auth
|
||||
|
||||
export type SubmitPinReq = { pin: string } // auth.pin - unauthed
|
||||
export type SubmitPinRes = null
|
||||
|
||||
export type SubmitPasswordReq = { password: string } // auth.password - unauthed
|
||||
export type SubmitPasswordRes = null
|
||||
export type LoginReq = { password: string } // auth.login - unauthed
|
||||
export type loginRes = null
|
||||
|
||||
export type LogoutReq = { } // auth.logout
|
||||
export type LogoutRes = null
|
||||
|
||||
@@ -4,9 +4,9 @@ import { LiveApiService } from './live-api.service'
|
||||
import { ConfigService } from '../config.service'
|
||||
|
||||
export function ApiServiceFactory (config: ConfigService, http: HttpService) {
|
||||
if (config.api.mocks) {
|
||||
return new MockApiService(config)
|
||||
if (config.mocks.enabled) {
|
||||
return new MockApiService(http)
|
||||
} else {
|
||||
return new LiveApiService(http, config)
|
||||
return new LiveApiService(http)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
|
||||
}
|
||||
|
||||
// used for determining internet connectivity
|
||||
abstract ping (): Promise<void>
|
||||
abstract echo (): Promise<string>
|
||||
|
||||
// for getting static files: ex icons, instructions, licenses
|
||||
abstract getStatic (url: string): Promise<string>
|
||||
@@ -34,9 +34,7 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
|
||||
|
||||
// auth
|
||||
|
||||
abstract submitPin (params: RR.SubmitPinReq): Promise<RR.SubmitPinRes>
|
||||
|
||||
abstract submitPassword (params: RR.SubmitPasswordReq): Promise<RR.SubmitPasswordReq>
|
||||
abstract login (params: RR.LoginReq): Promise<RR.loginRes>
|
||||
|
||||
abstract logout (params: RR.LogoutReq): Promise<RR.LogoutRes>
|
||||
|
||||
|
||||
@@ -3,17 +3,15 @@ import { HttpService, Method } from '../http.service'
|
||||
import { ApiService } from './api.service'
|
||||
import { RR } from './api-types'
|
||||
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
|
||||
import { ConfigService } from '../config.service'
|
||||
|
||||
@Injectable()
|
||||
export class LiveApiService extends ApiService {
|
||||
constructor (
|
||||
private readonly http: HttpService,
|
||||
private readonly config: ConfigService,
|
||||
) { super() }
|
||||
|
||||
async ping (): Promise<void> {
|
||||
return this.http.rpcRequest({ method: 'ping', params: { } })
|
||||
async echo (): Promise<string> {
|
||||
return this.http.rpcRequest({ method: 'echo', params: { } })
|
||||
}
|
||||
|
||||
async getStatic (url: string): Promise<string> {
|
||||
@@ -36,12 +34,8 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// auth
|
||||
|
||||
async submitPin (params: RR.SubmitPinReq): Promise<RR.SubmitPinRes> {
|
||||
return this.http.rpcRequest({ method: 'auth.pin', params })
|
||||
}
|
||||
|
||||
async submitPassword (params: RR.SubmitPasswordReq): Promise<RR.SubmitPasswordRes> {
|
||||
return this.http.rpcRequest({ method: 'auth.password', params })
|
||||
async login (params: RR.LoginReq): Promise<RR.loginRes> {
|
||||
return this.http.rpcRequest({ method: 'auth.login', params })
|
||||
}
|
||||
|
||||
async logout (params: RR.LogoutReq): Promise<RR.LogoutRes> {
|
||||
|
||||
@@ -4,10 +4,10 @@ import { ApiService } from './api.service'
|
||||
import { Observable } from 'rxjs'
|
||||
import { PatchOp, Update } from 'patch-db-client'
|
||||
import { DataModel, PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/models/patch-db/data-model'
|
||||
import { ConfigService } from '../config.service'
|
||||
import { RR } from './api-types'
|
||||
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
|
||||
import { Mock } from './mock-app-fixures'
|
||||
import { HttpService } from '../http.service'
|
||||
|
||||
@Injectable()
|
||||
export class MockApiService extends ApiService {
|
||||
@@ -15,7 +15,7 @@ export class MockApiService extends ApiService {
|
||||
welcomeAck = false
|
||||
|
||||
constructor (
|
||||
private readonly config: ConfigService,
|
||||
private readonly http: HttpService,
|
||||
) { super() }
|
||||
|
||||
// every time a patch is returned from the mock, we override its sequence to be 1 more than the last sequence in the patch-db as provided by `o`.
|
||||
@@ -24,9 +24,9 @@ export class MockApiService extends ApiService {
|
||||
return super.watch$()
|
||||
}
|
||||
|
||||
async ping (): Promise<void> {
|
||||
console.log('pinging server')
|
||||
return
|
||||
async echo (): Promise<string> {
|
||||
console.log('echo...echo')
|
||||
return ''
|
||||
}
|
||||
|
||||
async getStatic (url: string): Promise<string> {
|
||||
@@ -36,47 +36,20 @@ export class MockApiService extends ApiService {
|
||||
// db
|
||||
|
||||
async getRevisions (since: number): Promise<RR.GetRevisionsRes> {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
...Mock.DbDump,
|
||||
id: this.nextSequence(),
|
||||
}
|
||||
return this.http.rpcRequest({ method: 'db.revisions', params: { since } })
|
||||
}
|
||||
|
||||
async getDump (): Promise<RR.GetDumpRes> {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
...Mock.DbDump,
|
||||
id: this.nextSequence(),
|
||||
}
|
||||
return this.http.rpcRequest({ method: 'db.dump' })
|
||||
}
|
||||
|
||||
async setDbValueRaw (params: RR.SetDBValueReq): Promise<RR.SetDBValueRes> {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: params.pointer,
|
||||
value: params.value,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
}
|
||||
return this.http.rpcRequest({ method: 'db.put.ui', params })
|
||||
}
|
||||
|
||||
// auth
|
||||
|
||||
async submitPin (params: RR.SubmitPinReq): Promise<RR.SubmitPinRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async submitPassword (params: RR.SubmitPasswordReq): Promise<RR.SubmitPasswordRes> {
|
||||
async login (params: RR.LoginReq): Promise<RR.loginRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user