fix(core): serialize longs from port to worker

This commit is contained in:
alina 🌸 2024-07-17 19:22:10 +03:00
parent 03c2d453e4
commit 69eda9decb
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
3 changed files with 10 additions and 6 deletions

View file

@ -1,6 +1,6 @@
import { ControllablePromise, createControllablePromise } from '../../utils/controllable-promise.js' import { ControllablePromise, createControllablePromise } from '../../utils/controllable-promise.js'
import { deserializeError } from './errors.js' import { deserializeError } from './errors.js'
import { deserializeResult, SendFn, WorkerInboundMessage, WorkerOutboundMessage } from './protocol.js' import { deserializeResult, SendFn, serializeResult, WorkerInboundMessage, WorkerOutboundMessage } from './protocol.js'
export type InvokeTarget = Extract<WorkerInboundMessage, { type: 'invoke' }>['target'] export type InvokeTarget = Extract<WorkerInboundMessage, { type: 'invoke' }>['target']
@ -18,7 +18,7 @@ export class WorkerInvoker {
id, id,
target, target,
method, method,
args, args: serializeResult(args),
void: isVoid, void: isVoid,
withAbort: Boolean(abortSignal), withAbort: Boolean(abortSignal),
}) })

View file

@ -12,7 +12,7 @@ export type WorkerInboundMessage =
id: number id: number
target: 'custom' | 'client' | 'storage' | 'storage-self' | 'storage-peers' | 'app-config' target: 'custom' | 'client' | 'storage' | 'storage-self' | 'storage-peers' | 'app-config'
method: string method: string
args: unknown[] args: SerializedResult<unknown[]>
void: boolean void: boolean
withAbort: boolean withAbort: boolean
} }

View file

@ -1,7 +1,9 @@
import { BaseTelegramClient } from '../base.js' import { BaseTelegramClient } from '../base.js'
import { serializeError } from './errors.js' import { serializeError } from './errors.js'
import { import {
deserializeResult,
RespondFn, RespondFn,
SerializedResult,
serializeResult, serializeResult,
WorkerCustomMethods, WorkerCustomMethods,
WorkerInboundMessage, WorkerInboundMessage,
@ -132,19 +134,21 @@ export abstract class TelegramWorker<T extends WorkerCustomMethods> {
return return
} }
let args = msg.args let args: unknown[]
if (msg.target === 'client' && msg.method === 'call' && msg.withAbort) { if (msg.target === 'client' && msg.method === 'call' && msg.withAbort) {
const abort = new AbortController() const abort = new AbortController()
this.pendingAborts.set(msg.id, abort) this.pendingAborts.set(msg.id, abort)
args = [ args = [
args[0], deserializeResult((msg.args as unknown as unknown[])[0] as SerializedResult<unknown>),
{ {
...(args[1] as object), ...((msg.args as unknown as unknown[])[1] as object),
abortSignal: abort.signal, abortSignal: abort.signal,
}, },
] ]
} else {
args = deserializeResult(msg.args)
} }
// eslint-disable-next-line @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-call