split types in server/client files

This commit is contained in:
Danya H 2024-06-11 16:02:53 +01:00
parent 3f48215eb1
commit e1450397ab
9 changed files with 59 additions and 61 deletions

View File

@ -1,8 +1,8 @@
import rpc from 'rage-rpc'
import {
RageFW_ClientCallback,
import type {
RageFW_ClientEventCallback,
RageFW_ClientEvent,
RageFW_ClientEventReturn,
RageFW_ClientServerEvent,
RageFW_ClientServerEventArguments,
RageFW_ClientServerEventReturn,
@ -11,7 +11,7 @@ import {
class Client {
public register<EventName extends RageFW_ClientEvent>(
eventName: EventName,
callback: RageFW_ClientCallback<EventName>,
callback: RageFW_ClientEventCallback<EventName>,
): void {
rpc.register(eventName, data => {
return callback(data)

View File

@ -1,34 +0,0 @@
/// <reference types="@ragempcommunity/types-client" />
import type {
RageFW_ICustomClientEvent,
RageFW_ICustomServerEvent,
} from 'rage-fw-shared-types'
// CLIENT
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
export type RageFW_ClientCallback<K extends RageFW_ClientEvent> = (
args: Parameters<RageFW_ICustomClientEvent[K]>,
) => RageFW_ClientEventReturn<K>
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
K extends keyof RageFW_ICustomClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]>
: never
// SERVER
export type RageFW_ClientServerEvent = keyof RageFW_ICustomServerEvent
export type RageFW_ClientServerEventArguments<
K extends RageFW_ClientServerEvent,
> = K extends keyof RageFW_ICustomServerEvent
? Parameters<RageFW_ICustomServerEvent[K]>
: never
export type RageFW_ClientServerEventReturn<K extends RageFW_ClientServerEvent> =
K extends keyof RageFW_ICustomServerEvent
? ReturnType<RageFW_ICustomServerEvent[K]>
: never

View File

@ -0,0 +1,14 @@
/// <reference types="@ragempcommunity/types-client" />
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
export type RageFW_ClientEventCallback<K extends RageFW_ClientEvent> = (
args: Parameters<RageFW_ICustomClientEvent[K]>,
) => RageFW_ClientEventReturn<K>
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
K extends keyof RageFW_ICustomClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]>
: never

View File

@ -0,0 +1,2 @@
export * from './client'
export * from './server'

View File

@ -0,0 +1,16 @@
/// <reference types="@ragempcommunity/types-client" />
import type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
export type RageFW_ClientServerEvent = keyof RageFW_ICustomServerEvent
export type RageFW_ClientServerEventArguments<
K extends RageFW_ClientServerEvent,
> = K extends keyof RageFW_ICustomServerEvent
? Parameters<RageFW_ICustomServerEvent[K]>
: never
export type RageFW_ClientServerEventReturn<K extends RageFW_ClientServerEvent> =
K extends keyof RageFW_ICustomServerEvent
? ReturnType<RageFW_ICustomServerEvent[K]>
: never

View File

@ -1,15 +1,16 @@
import rpc from 'rage-rpc'
import {
import type {
RageFW_ClientEvent,
RageFW_ClientEventArguments,
RageFW_ClientEventReturn,
RageFW_ICustomServerEvent,
RageFW_ServerEvent,
RageFW_ServerEventCallback,
RageFW_ServerEventCallbackCustom,
RageFW_ServerEventCallbackNative,
} from './types.js'
} from './types'
import { nativeEvents } from './native.events'
import type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
class Server {
private isNativeEvent(eventName: string): eventName is keyof IServerEvents {

View File

@ -0,0 +1,15 @@
/// <reference types="@ragempcommunity/types-server" />
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
export type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
K extends RageFW_ClientEvent
? Parameters<RageFW_ICustomClientEvent[K]>
: never
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
K extends RageFW_ClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]>
: never

View File

@ -0,0 +1,2 @@
export * from './client'
export * from './server'

View File

@ -1,11 +1,7 @@
/// <reference types="@ragempcommunity/types-server" />
import type {
RageFW_ICustomServerEvent,
RageFW_ICustomClientEvent,
} from 'rage-fw-shared-types'
// SERVER
import type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
export type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
export type RageFW_ServerEvent =
| keyof RageFW_ICustomServerEvent
@ -28,17 +24,3 @@ export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
: K extends keyof IServerEvents
? RageFW_ServerEventCallbackNative<K>
: never
// CLIENT
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
export type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
K extends RageFW_ClientEvent
? Parameters<RageFW_ICustomClientEvent[K]>
: never
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
K extends RageFW_ClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]>
: never