simpler server API

This commit is contained in:
Sergey Chernov 2022-12-09 02:38:42 +01:00
parent d6d479f853
commit 69e4448749
3 changed files with 11 additions and 7 deletions

View File

@ -354,7 +354,7 @@ class SuperloginClient<D, S : WithAdapter>(
companion object {
inline operator fun <reified D, S : WithAdapter> invoke(
inline operator fun <reified D,S : WithAdapter> invoke(
t: Parsec3Transport<S>,
savedData: SuperloginData<D>? = null,
): SuperloginClient<D, S> {

View File

@ -10,7 +10,10 @@ import kotlin.random.Random
fun randomACOLike(): ByteArray {
return Random.nextBytes(117)
}
inline fun <reified D, T : SLServerSession<D>, H : CommandHost<T>> AdapterBuilder<T, H>.superloginServer() {
inline fun <reified D, T : SLServerSession<D>, H : CommandHost<T>> AdapterBuilder<T, H>.superloginServer(
crossinline sessionBuilder: suspend ()->T
) {
newSession { sessionBuilder() }
addErrors(SuperloginExceptionsRegistry)
val a2 = SuperloginServerApi<WithAdapter>()
on(a2.slGetNonce) { nonce }

View File

@ -154,15 +154,17 @@ internal class WsServerKtTest {
}
class S1: WithAdapter()
@Test
fun changePasswordTest() {
embeddedServer(Netty, port = 8081, module = Application::testServerModule).start(wait = false)
runBlocking {
val client = Parsec3WSClient("ws://localhost:8081/api/p3")
val client = Parsec3WSClient.withSession<S1>("ws://localhost:8081/api/p3")
val api = TestApiServer<WithAdapter>()
val slc = SuperloginClient<TestData, WithAdapter>(client)
val slc = SuperloginClient<TestData, S1>(client)
assertEquals(LoginState.LoggedOut, slc.state.value)
var rt = slc.register("foo", "passwd", TestData("bar!"))
assertIs<Registration.Result.Success>(rt)
@ -211,10 +213,9 @@ internal class WsServerKtTest {
}
fun Application.testServerModule() {
parsec3TransportServer(TestApiServer<SLServerSession<TestData>>()) {
parsec3TransportServer(TestApiServer<TestSession>()) {
// superloginServer(TestServerTraits,TestApiServer<SLServerSession<TestData>>()) {
newSession { TestSession() }
superloginServer()
superloginServer { TestSession() }
on(api.loginName) {
println("login name called. now we have $currentLoginName : $superloginData")
currentLoginName