serialize messages for dev client

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-09-09 15:24:15 +02:00
parent e9d2f4c4b9
commit 5455507e1f
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
3 changed files with 27 additions and 6 deletions

View File

@ -18,16 +18,19 @@ import { DOMAIN_TX } from '@anticrm/core'
import { createInMemoryAdapter, createInMemoryTxAdapter } from '@anticrm/dev-storage'
import { createServerStorage, FullTextAdapter, IndexedDoc } from '@anticrm/server-core'
import type { DbConfiguration } from '@anticrm/server-core'
import { protoSerialize, protoDeserialize } from '@anticrm/platform'
class ServerStorageWrapper implements Storage {
constructor (private readonly storage: ServerStorage, private readonly handler: TxHander) {}
findAll <T extends Doc>(_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindResult<T>> {
return this.storage.findAll(_class, query, options)
const [c, q, o] = protoDeserialize(protoSerialize([_class, query, options]))
return this.storage.findAll(c, q, o)
}
async tx (tx: Tx): Promise<void> {
const derived = await this.storage.tx(tx)
const _tx = protoDeserialize(protoSerialize(tx))
const derived = await this.storage.tx(_tx)
for (const tx of derived) { this.handler(tx) }
}
}

View File

@ -42,13 +42,31 @@ export interface Response<R> {
error?: Status
}
/**
* @public
* @param object -
* @returns
*/
export function protoSerialize (object: object): string {
return JSON.stringify(object, (key, value) => { return value ?? null })
}
/**
* @public
* @param data -
* @returns
*/
export function protoDeserialize (data: string): any {
return JSON.parse(data)
}
/**
* @public
* @param object -
* @returns
*/
export function serialize (object: Request<any> | Response<any>): string {
return JSON.stringify(object)
return protoSerialize(object)
}
/**
@ -57,7 +75,7 @@ export function serialize (object: Request<any> | Response<any>): string {
* @returns
*/
export function readResponse<D> (response: string): Response<D> {
return JSON.parse(response)
return protoDeserialize(response)
}
/**
@ -66,7 +84,7 @@ export function readResponse<D> (response: string): Response<D> {
* @returns
*/
export function readRequest<P extends any[]> (request: string): Request<P> {
const result: Request<P> = JSON.parse(request)
const result: Request<P> = protoDeserialize(request)
if (typeof result.method !== 'string') {
throw new PlatformError(
new Status(Severity.ERROR, platform.status.BadRequest, {})

View File

@ -24,7 +24,7 @@ const dist = resolve(__dirname, 'dist')
console.log('serving static files from', dist)
app.use(express.static(dist, { maxAge: '10m' }))
app.use(express.static(dist, { /* maxAge: '10m' */ }))
app.get('*', function (request, response) {
response.sendFile(join(dist, 'index.html'))