Rpc integration + type fixes #3

Merged
rilaxik merged 26 commits from dev into master 2024-10-28 12:13:19 +00:00
5 changed files with 9 additions and 7 deletions
Showing only changes of commit b1adb809f8 - Show all commits

View File

@ -30,7 +30,7 @@ export type RageFW_CefReturn<K extends RageFW_CefEvent> = ReturnType<
*/ */
export type RageFW_CefCallback<K extends keyof RageFW_ICustomCefEvent> = ( export type RageFW_CefCallback<K extends keyof RageFW_ICustomCefEvent> = (
args: RageFW_CefArgs<K>, args: RageFW_CefArgs<K>,
) => RageFW_CefReturn<K> ) => Promise<RageFW_CefReturn<K>>
export type _CefEventHasArgs<EventName extends keyof RageFW_ICustomCefEvent> = export type _CefEventHasArgs<EventName extends keyof RageFW_ICustomCefEvent> =
keyof RageFW_ICustomCefEvent extends never keyof RageFW_ICustomCefEvent extends never

View File

@ -7,8 +7,8 @@ export class Client {
eventName: EventName, eventName: EventName,
callback: RageFW_ClientCallback<EventName>, callback: RageFW_ClientCallback<EventName>,
): void { ): void {
rpc.register(eventName, data => { rpc.register(eventName, async data => {
return callback(data) return await callback(data)
}) })
} }

View File

@ -27,7 +27,7 @@ export type RageFW_ClientArgs<K extends RageFW_ClientEvent> =
*/ */
export type RageFW_ClientCallback<K extends RageFW_ClientEvent> = ( export type RageFW_ClientCallback<K extends RageFW_ClientEvent> = (
args: RageFW_ClientArgs<K>, args: RageFW_ClientArgs<K>,
) => RageFW_ClientReturn<K> ) => Promise<RageFW_ClientReturn<K>>
/** /**
* Return type for an event, name of which you pass as a generic * Return type for an event, name of which you pass as a generic

View File

@ -24,7 +24,7 @@ export class Server {
rpc.register( rpc.register(
eventName, eventName,
async (args: RageFW_ServerArgs<EventName>, info) => { async (args: RageFW_ServerArgs<EventName>, info) => {
callback([info.player as PlayerMp, ...args]) await callback([info.player as PlayerMp, ...args])
}, },
) )
} }

View File

@ -55,7 +55,7 @@ export type RageFW_ServerCallbackCustom<
K extends keyof RageFW_ICustomServerEvent = keyof RageFW_ICustomServerEvent, K extends keyof RageFW_ICustomServerEvent = keyof RageFW_ICustomServerEvent,
> = ( > = (
payload: [player: PlayerMp, ...args: RageFW_ServerArgs<K>], payload: [player: PlayerMp, ...args: RageFW_ServerArgs<K>],
) => RageFW_ServerReturn<K> ) => Promise<RageFW_ServerReturn<K>>
/** /**
* Array of arguments for an event, name of which you pass as a generic * Array of arguments for an event, name of which you pass as a generic
@ -63,7 +63,9 @@ export type RageFW_ServerCallbackCustom<
*/ */
export type RageFW_ServerCallbackNative< export type RageFW_ServerCallbackNative<
K extends keyof IServerEvents = keyof IServerEvents, K extends keyof IServerEvents = keyof IServerEvents,
> = (payload: Parameters<IServerEvents[K]>) => ReturnType<IServerEvents[K]> > = (
payload: Parameters<IServerEvents[K]>,
) => Promise<ReturnType<IServerEvents[K]>>
export type _ServerEventHasArgs<EventName extends RageFW_ServerEvent> = export type _ServerEventHasArgs<EventName extends RageFW_ServerEvent> =
EventName extends keyof RageFW_ICustomServerEvent EventName extends keyof RageFW_ICustomServerEvent