Typescript does not let me type 'export' in bts_assert.ts for no discernable reason.
This commit is contained in:
1 parent
9f624d54b3
commit
49d16a3e03
4 files changed
+34
-12
No files matched your search
@@ -1,13 +1,17 @@
|
||||
|
||||
import {root} from 'proto'
|
||||
import { connect, ServiceContext } from '../src/ServiceContext'
|
||||
import WebSocket from 'ws'
|
||||
import { HelloService } from '../src/HelloService'
|
||||
|
||||
// Fix websocket for running in js
|
||||
import WebSocket from 'ws'
|
||||
global["WebSocket"] = WebSocket
|
||||
|
||||
test('promise works', async () => {
|
||||
let result = await connect("bts", "b");
|
||||
expect(result instanceof ServiceContext).toBe(true)
|
||||
test('log in and say hi', async () => {
|
||||
let ctx = await connect("bts", "password");
|
||||
expect(ctx instanceof ServiceContext).toBe(true)
|
||||
const hello = new HelloService(<ServiceContext>ctx)
|
||||
const reply = await hello.say_hello({ name: "name" })
|
||||
});
|
||||
|
||||
|
||||
@@ -18,7 +22,7 @@ test('api_errors_updated', () => {
|
||||
code: 3
|
||||
}).finish()
|
||||
const round = ResponseHeader.decode(rh)
|
||||
console.log(round.code)
|
||||
expect(round).toBeDefined()
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Future generated code
|
||||
import root from 'proto'
|
||||
import { ServiceContext } from 'ServiceContext'
|
||||
// import { assertValid } from 'bts_assert';
|
||||
|
||||
const HelloRequestProto = root.lookupType("bts.api.test.HelloRequest")
|
||||
const HelloResponseProto = root.lookupType("bts.api.test.HelloResponse")
|
||||
@@ -16,17 +17,21 @@ export class HelloService {
|
||||
private context : ServiceContext
|
||||
private service_id : string
|
||||
|
||||
constructor(sc : ServiceContext, qualifier: string) {
|
||||
constructor(sc : ServiceContext, qualifier?: string) {
|
||||
this.context = sc
|
||||
this.qualifier = qualifier.replace(/[+_]/g,"");
|
||||
this.service_id = (qualifier||"").replace(/[+_]/g,"");
|
||||
}
|
||||
|
||||
async say_hello(request : HelloRequest) : Promise<HelloResponse> {
|
||||
const r = HelloRequestProto.create(request)
|
||||
console.log(JSON.stringify(r))
|
||||
// assertValid(HelloRequestProto, r)
|
||||
const buffer = HelloRequestProto.encode(r).finish()
|
||||
// result = Uint8Array
|
||||
const result = await this.context.call("HelloService", this.qualifier, 0, buffer)
|
||||
const result = await this.context.call(this.service_id, 0, buffer)
|
||||
|
||||
// decode HelloResponse type
|
||||
const v = HelloResponseProto.decode(result);
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {root} from 'proto'
|
||||
import { assertValid } from 'bts_assert'
|
||||
// import { assertValid } from 'bts_assert'
|
||||
|
||||
const debug=true
|
||||
|
||||
@@ -15,6 +15,18 @@ function default_ws_uri() {
|
||||
return ws_uri;
|
||||
}
|
||||
|
||||
function assert(condition:boolean, message?:string) : void {
|
||||
if (!condition) {
|
||||
message = message || "Assertion failed"
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
function assertValid(mtype, message) : void {
|
||||
const r = mtype.verify(message)
|
||||
assert(r != null, r)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Message types
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
export function assert(condition:boolean, message?:string) {
|
||||
if (!condition) {
|
||||
message = message || "Assertion failed"
|
||||
throw new Error(message)
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
export function assertValid(mtype, message) {
|
||||
const r = mtype.verify(message)
|
||||
assert(r != null, r)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user