From 3a4fe19df056f2be85728b79aae7ed0fc78cacae Mon Sep 17 00:00:00 2001 From: Danya H Date: Mon, 28 Oct 2024 15:14:41 +0000 Subject: [PATCH 1/7] upd readme bump --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 484be8a..ccb70b2 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ You can find out more about our CLI [here](https://git.entityseven.com/entitysev At the moment automation we have only works via [pnpm](https://pnpm.io/). To scaffold a basic project with minor settings you can use our CLI: -``pnpm create rage-fw`` +``pnpm create @entityseven/rage-fw`` This will give you a few options, among them, you can find ``Initialize new project``. Use that option to scaffold a new project for yourself using the preferred frontend framework -- 2.45.2 From 588bb42d04659c34f3b1b08c9b756a6c959e9c1c Mon Sep 17 00:00:00 2001 From: Danya H Date: Mon, 28 Oct 2024 15:20:43 +0000 Subject: [PATCH 2/7] upd core - types now use namespace to avoid bloating - moved items for further usage into data folder --- cef/src/index.ts | 45 +++++++------------ cef/src/types/cef.ts | 4 +- client/src/core/client.ts | 14 +++--- client/src/core/player.ts | 36 +++++---------- client/src/{ => data}/keys.ts | 0 server/src/core/player.ts | 27 ++++------- server/src/core/server.ts | 44 ++++++++---------- .../nativeEvents.ts} | 0 8 files changed, 61 insertions(+), 109 deletions(-) rename client/src/{ => data}/keys.ts (100%) rename server/src/{native.events.ts => data/nativeEvents.ts} (100%) diff --git a/cef/src/index.ts b/cef/src/index.ts index 0ee8496..f3c7aad 100644 --- a/cef/src/index.ts +++ b/cef/src/index.ts @@ -1,20 +1,5 @@ import { Rpc } from '@entityseven/rage-fw-rpc' - -import type { - _CefEventHasArgs, - _ClientEventHasArgs, - _ServerEventHasArgs, - RageFW_CefArgs, - RageFW_CefCallback, - RageFW_CefReturn, - RageFW_ClientArgs, - RageFW_ClientReturn, - RageFW_ICustomCefEvent, - RageFW_ICustomClientEvent, - RageFW_ICustomServerEvent, - RageFW_ServerArgs, - RageFW_ServerReturn, -} from './types' +import type * as T from './types' class Cef { private _debugMode: boolean = false @@ -30,9 +15,9 @@ class Cef { return this._rpc } - public register( + public register( eventName: EventName, - callback: RageFW_CefCallback, + callback: T.RageFW_CefCallback, ): void { if (this._debugMode) { console.log('[RPC](register):', eventName, callback) @@ -43,12 +28,12 @@ class Cef { } } - public async trigger( + public async trigger( eventName: EventName, - ...args: _CefEventHasArgs extends true - ? [RageFW_CefArgs] + ...args: T._CefEventHasArgs extends true + ? [T.RageFW_CefArgs] : [] - ): Promise> { + ): Promise> { if (this._debugMode) { console.log('[RPC](trigger):', eventName, ...args) } @@ -63,13 +48,13 @@ class Cef { } public async triggerServer< - EventName extends keyof RageFW_ICustomServerEvent, + EventName extends keyof T.RageFW_ICustomServerEvent, >( eventName: EventName, - ...args: _ServerEventHasArgs extends true - ? [RageFW_ServerArgs] + ...args: T._ServerEventHasArgs extends true + ? [T.RageFW_ServerArgs] : [] - ): Promise> { + ): Promise> { if (this._debugMode) { console.log('[RPC](triggerServer):', eventName, ...args) } @@ -84,13 +69,13 @@ class Cef { } public async triggerClient< - EventName extends keyof RageFW_ICustomClientEvent, + EventName extends keyof T.RageFW_ICustomClientEvent, >( eventName: EventName, - ...args: _ClientEventHasArgs extends true - ? [RageFW_ClientArgs] + ...args: T._ClientEventHasArgs extends true + ? [T.RageFW_ClientArgs] : [] - ): Promise> { + ): Promise> { if (this._debugMode) { console.log('[RPC](triggerClient):', eventName, ...args) } diff --git a/cef/src/types/cef.ts b/cef/src/types/cef.ts index 501b63a..130bf48 100644 --- a/cef/src/types/cef.ts +++ b/cef/src/types/cef.ts @@ -1,6 +1,6 @@ -import { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types' +import type { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types' -export { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types' +export type { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types' /** * Union of all available cef event names diff --git a/client/src/core/client.ts b/client/src/core/client.ts index 365cda7..0f40886 100644 --- a/client/src/core/client.ts +++ b/client/src/core/client.ts @@ -1,10 +1,6 @@ import { Rpc } from '@entityseven/rage-fw-rpc' -import type { - RageFW_ClientArgs, - RageFW_ClientCallback, - RageFW_ClientEvent, -} from '../types' +import type * as T from '../types' export class Client { private _rpc: Rpc = new Rpc() @@ -13,19 +9,19 @@ export class Client { return this._rpc } - public register( + public register( eventName: EventName, - callback: RageFW_ClientCallback, + callback: T.RageFW_ClientCallback, ): void { this._rpc.register( eventName, - async (data: RageFW_ClientArgs) => { + async (data: T.RageFW_ClientArgs) => { return await callback(data) }, ) } - public unregister( + public unregister( eventName: EventName, ): void { this._rpc.unregister(eventName) diff --git a/client/src/core/player.ts b/client/src/core/player.ts index 1af6056..6a31096 100644 --- a/client/src/core/player.ts +++ b/client/src/core/player.ts @@ -1,19 +1,7 @@ import { Rpc } from '@entityseven/rage-fw-rpc' import type { RageFW_ICustomClientEvent } from '@entityseven/rage-fw-shared-types' -import { - _CefEventHasArgs, - _ClientEventHasArgs, - _ServerEventHasArgs, - RageFW_CefArgs, - RageFW_CefEvent, - RageFW_CefReturn, - RageFW_ClientArgs, - RageFW_ClientReturn, - RageFW_ClientServerEvent, - RageFW_ClientServerArgs, - RageFW_ClientServerReturn, -} from '../types' +import type * as T from '../types' export class Player { private _rpc: Rpc = new Rpc() @@ -24,28 +12,28 @@ export class Player { } public trigger( eventName: EventName, - ...args: _ClientEventHasArgs extends true - ? [RageFW_ClientArgs] + ...args: T._ClientEventHasArgs extends true + ? [T.RageFW_ClientArgs] : [] - ): Promise> { + ): Promise> { return this._rpc.call(eventName, args) } - public triggerServer( + public triggerServer( eventName: EventName, - ...args: _ServerEventHasArgs extends true - ? [RageFW_ClientServerArgs] + ...args: T._ServerEventHasArgs extends true + ? [T.RageFW_ClientServerArgs] : [] - ): Promise> { + ): Promise> { return this._rpc.callServer(eventName, args) } - public triggerBrowser( + public triggerBrowser( eventName: EventName, - ...args: _CefEventHasArgs extends true - ? [RageFW_CefArgs] + ...args: T._CefEventHasArgs extends true + ? [T.RageFW_CefArgs] : [] - ): Promise> { + ): Promise> { if (!this.browser) throw new Error('You need to initialize browser first') return this._rpc.callBrowser(this.browser, eventName, args) diff --git a/client/src/keys.ts b/client/src/data/keys.ts similarity index 100% rename from client/src/keys.ts rename to client/src/data/keys.ts diff --git a/server/src/core/player.ts b/server/src/core/player.ts index 32e80eb..4ab4330 100644 --- a/server/src/core/player.ts +++ b/server/src/core/player.ts @@ -1,15 +1,6 @@ import { Rpc } from '@entityseven/rage-fw-rpc' -import type { - _CefEventHasArgs, - _ClientEventHasArgs, - RageFW_CefArgs, - RageFW_CefEvent, - RageFW_CefReturn, - RageFW_ClientEvent, - RageFW_ServerClientArgs, - RageFW_ServerClientReturn, -} from '../types' +import type * as T from '../types' export class Player { private _rpc: Rpc = new Rpc() @@ -18,23 +9,23 @@ export class Player { return this._rpc } - public triggerClient( + public triggerClient( player: PlayerMp, eventName: EventName, - ...args: _ClientEventHasArgs extends true - ? [RageFW_ServerClientArgs] + ...args: T._ClientEventHasArgs extends true + ? [T.RageFW_ServerClientArgs] : [] - ): Promise> { + ): Promise> { return this._rpc.callClient(player, eventName, args) } - public triggerBrowser( + public triggerBrowser( player: PlayerMp, eventName: EventName, - ...args: _CefEventHasArgs extends true - ? [RageFW_CefArgs] + ...args: T._CefEventHasArgs extends true + ? [T.RageFW_CefArgs] : [] - ): Promise> { + ): Promise> { return this._rpc.callBrowser(player, eventName, args) } } diff --git a/server/src/core/server.ts b/server/src/core/server.ts index 8515511..15fc60b 100644 --- a/server/src/core/server.ts +++ b/server/src/core/server.ts @@ -1,16 +1,8 @@ import { Rpc } from '@entityseven/rage-fw-rpc' import { RageFW_ICustomServerEvent } from '@entityseven/rage-fw-shared-types' -import { nativeEvents } from '../native.events' -import type { - _ServerEventHasArgs, - RageFW_ServerArgs, - RageFW_ServerCallback, - RageFW_ServerCallbackCustom, - RageFW_ServerCallbackNative, - RageFW_ServerEvent, - RageFW_ServerReturn, -} from '../types' +import { nativeEvents } from '../data/nativeEvents' +import type * as T from '../types' export class Server { private _rpc: Rpc = new Rpc() @@ -25,12 +17,12 @@ export class Server { private registerCustom( eventName: EventName, - callback: RageFW_ServerCallbackCustom, + callback: T.RageFW_ServerCallbackCustom, ): void { this._rpc.register( eventName, // fixme - async (args: RageFW_ServerArgs, info) => { + async (args: T.RageFW_ServerArgs, info) => { await callback([info.player as PlayerMp, ...args]) }, ) @@ -38,7 +30,7 @@ export class Server { private registerNative( eventName: EventName, - callback: RageFW_ServerCallbackNative, + callback: T.RageFW_ServerCallbackNative, ): void { mp.events.add( eventName, @@ -47,37 +39,37 @@ export class Server { ) } - public register( + public register( eventName: EventName, - callback: RageFW_ServerCallback, + callback: T.RageFW_ServerCallback, ): void { if (this.isNativeEvent(eventName)) { this.registerNative( eventName, - callback as RageFW_ServerCallbackNative, + callback as T.RageFW_ServerCallbackNative, ) } else { this.registerCustom( eventName, - callback as unknown as RageFW_ServerCallbackCustom, + callback as unknown as T.RageFW_ServerCallbackCustom, ) } } - public registerMany(events: { - [event in EventName]: RageFW_ServerCallback + public registerMany(events: { + [event in EventName]: T.RageFW_ServerCallback }): void { - Object.entries>(events).map( + Object.entries>(events).map( ([eventName, callback]) => { if (this.isNativeEvent(eventName)) { this.registerNative( eventName, - callback as RageFW_ServerCallbackNative, + callback as T.RageFW_ServerCallbackNative, ) } else { this.registerCustom( eventName as keyof RageFW_ICustomServerEvent, - callback as unknown as RageFW_ServerCallbackCustom, + callback as unknown as T.RageFW_ServerCallbackCustom, ) } }, @@ -96,7 +88,7 @@ export class Server { mp.events.remove(eventName) } - public unregister( + public unregister( eventName: EventName, ): void { if (this.isNativeEvent(eventName)) { @@ -108,10 +100,10 @@ export class Server { public trigger( eventName: EventName, - ...args: _ServerEventHasArgs extends true - ? [RageFW_ServerArgs] + ...args: T._ServerEventHasArgs extends true + ? [T.RageFW_ServerArgs] : [] - ): Promise> { + ): Promise> { return this._rpc.call(eventName, args) } } diff --git a/server/src/native.events.ts b/server/src/data/nativeEvents.ts similarity index 100% rename from server/src/native.events.ts rename to server/src/data/nativeEvents.ts -- 2.45.2 From 9fe9bad840c84c3a3b87000a05c01dc8cabbbced Mon Sep 17 00:00:00 2001 From: Danya H Date: Mon, 28 Oct 2024 16:05:18 +0000 Subject: [PATCH 3/7] upd core - renamed cef -> browser - added browser logger + custom logger option --- {cef => browser}/package.json | 2 +- {cef => browser}/readme.md | 0 browser/src/core/browser.ts | 96 +++++++++++++++++++++++++++ browser/src/core/helper.ts | 21 ++++++ browser/src/core/index.ts | 3 + browser/src/core/rpc.ts | 7 ++ browser/src/index.ts | 9 +++ browser/src/types/browser.ts | 40 ++++++++++++ {cef => browser}/src/types/client.ts | 0 {cef => browser}/src/types/index.ts | 2 +- {cef => browser}/src/types/server.ts | 0 {cef => browser}/tsconfig.json | 0 {cef => browser}/tsup.config.ts | 0 cef/src/index.ts | 98 ---------------------------- cef/src/types/cef.ts | 40 ------------ client/src/types/browser.ts | 21 +++--- pnpm-workspace.yaml | 2 +- server/src/types/browser.ts | 21 +++--- shared-types/types/types/index.d.ts | 9 ++- 19 files changed, 208 insertions(+), 163 deletions(-) rename {cef => browser}/package.json (93%) rename {cef => browser}/readme.md (100%) create mode 100644 browser/src/core/browser.ts create mode 100644 browser/src/core/helper.ts create mode 100644 browser/src/core/index.ts create mode 100644 browser/src/core/rpc.ts create mode 100644 browser/src/index.ts create mode 100644 browser/src/types/browser.ts rename {cef => browser}/src/types/client.ts (100%) rename {cef => browser}/src/types/index.ts (65%) rename {cef => browser}/src/types/server.ts (100%) rename {cef => browser}/tsconfig.json (100%) rename {cef => browser}/tsup.config.ts (100%) delete mode 100644 cef/src/index.ts delete mode 100644 cef/src/types/cef.ts diff --git a/cef/package.json b/browser/package.json similarity index 93% rename from cef/package.json rename to browser/package.json index 42d4af5..6c41277 100644 --- a/cef/package.json +++ b/browser/package.json @@ -1,5 +1,5 @@ { - "name": "@entityseven/rage-fw-cef", + "name": "@entityseven/rage-fw-browser", "version": "0.1.0", "main": "dist/index.js", "types": "dist/src/index.d.ts", diff --git a/cef/readme.md b/browser/readme.md similarity index 100% rename from cef/readme.md rename to browser/readme.md diff --git a/browser/src/core/browser.ts b/browser/src/core/browser.ts new file mode 100644 index 0000000..95e2b59 --- /dev/null +++ b/browser/src/core/browser.ts @@ -0,0 +1,96 @@ +import { Helper } from './helper' +import { rpc } from './rpc' +import type * as T from '../types' +import { + RageFW_BrowserEvent, + RageFW_ClientEvent, + RageFW_ServerEvent, +} from '../types' + +export class Browser extends Helper { + constructor() { + super() + } + + set debugLogs(debug: boolean) { + this.debugLogs_ = debug + } + + set customLogger( + fn: (method: string, eventName: string, ...args: unknown[]) => unknown, + ) { + this.customLogger_ = fn + } + + public register( + eventName: EventName, + callback: T.RageFW_BrowserCallback, + ): Browser { + this.log_('register', eventName, callback) + + rpc.register< + Parameters, + ReturnType, + EventName + >(eventName, async (...data) => await callback(...data)) + + return this + } + + public unregister( + eventName: EventName, + ): Browser { + rpc.unregister(eventName) + + return this + } + + public async trigger( + eventName: EventName, + ...args: T._BrowserEventHasArgs extends true + ? [T.RageFW_BrowserArgs] + : [] + ): Promise> { + this.log_('[RPC](trigger):', eventName, ...args) + + return await rpc.call< + typeof args, + EventName, + T.RageFW_BrowserReturn + >(eventName, args) + } + + public async triggerServer( + eventName: EventName, + ...args: T._ServerEventHasArgs extends true + ? [T.RageFW_ServerArgs] + : [] + ): Promise> { + this.log_('[RPC](triggerServer):', eventName, ...args) + + return await rpc.callServer< + typeof args, + EventName, + T.RageFW_ServerReturn + >(eventName, args) + } + + public async triggerClient( + eventName: EventName, + ...args: T._ClientEventHasArgs extends true + ? [T.RageFW_ClientArgs] + : [] + ): Promise> { + this.log_('[RPC](triggerClient):', eventName, ...args) + + return await rpc.callClient< + typeof args, + EventName, + T.RageFW_ClientReturn + >(eventName, args) + } +} + +// new Browser() +// .register('customCefEvent', async (a, b) => true) +// .triggerServer('customServerEvent', ['', 1]) diff --git a/browser/src/core/helper.ts b/browser/src/core/helper.ts new file mode 100644 index 0000000..d861710 --- /dev/null +++ b/browser/src/core/helper.ts @@ -0,0 +1,21 @@ +export class Helper { + protected debugLogs_: boolean = false + protected customLogger_: + | undefined + | ((method: string, eventName: string, ...args: unknown[]) => unknown) = + undefined + + constructor() {} + + protected log_( + method: string, + eventName: string, + ...args: unknown[] + ): void { + if (this.customLogger_) { + this.customLogger_(method, eventName, ...args) + } else if (this.debugLogs_) { + console.log('[RPC](' + method + ')', eventName + ':', ...args) + } + } +} diff --git a/browser/src/core/index.ts b/browser/src/core/index.ts new file mode 100644 index 0000000..1408bd0 --- /dev/null +++ b/browser/src/core/index.ts @@ -0,0 +1,3 @@ +export * from './browser' +export * from './helper' +export * from './rpc' diff --git a/browser/src/core/rpc.ts b/browser/src/core/rpc.ts new file mode 100644 index 0000000..1b31ed2 --- /dev/null +++ b/browser/src/core/rpc.ts @@ -0,0 +1,7 @@ +import { Rpc } from '@entityseven/rage-fw-rpc' + +export const rpc = new Rpc({ + forceBrowserDevMode: + process.env.RageFW_forceBrowserDevMode === 'true' ?? false, + debugLogs: false, +}) diff --git a/browser/src/index.ts b/browser/src/index.ts new file mode 100644 index 0000000..ad01249 --- /dev/null +++ b/browser/src/index.ts @@ -0,0 +1,9 @@ +import { Browser, rpc } from './core' + +export const fw = { + event: new Browser(), + rpc, +} +;(async () => { + await fw.event.triggerClient('cefReady') +})() diff --git a/browser/src/types/browser.ts b/browser/src/types/browser.ts new file mode 100644 index 0000000..ea66151 --- /dev/null +++ b/browser/src/types/browser.ts @@ -0,0 +1,40 @@ +import type { RageFW_ICustomBrowserEvent } from '@entityseven/rage-fw-shared-types' + +export type { RageFW_ICustomBrowserEvent } from '@entityseven/rage-fw-shared-types' + +/** + * Union of all available browser event names + * These only include custom events + */ +export type RageFW_BrowserEvent = keyof RageFW_ICustomBrowserEvent + +/** + * Array of arguments of an event you pass as a generic + * These only include custom browser events + */ +export type RageFW_BrowserArgs = Parameters< + RageFW_ICustomBrowserEvent[K] +> + +/** + * Return type of event you pass as a generic + * These only include custom browser events + */ +export type RageFW_BrowserReturn = ReturnType< + RageFW_ICustomBrowserEvent[K] +> + +/** + * Callback (function) of event you pass as a generic + * These only include custom browser events + */ +export type RageFW_BrowserCallback = + (...args: RageFW_BrowserArgs) => Promise> + +export type _BrowserEventHasArgs< + EventName extends keyof RageFW_ICustomBrowserEvent, +> = keyof RageFW_ICustomBrowserEvent extends never + ? false + : Parameters[0] extends undefined + ? false + : true diff --git a/cef/src/types/client.ts b/browser/src/types/client.ts similarity index 100% rename from cef/src/types/client.ts rename to browser/src/types/client.ts diff --git a/cef/src/types/index.ts b/browser/src/types/index.ts similarity index 65% rename from cef/src/types/index.ts rename to browser/src/types/index.ts index ef9b6be..1b288ef 100644 --- a/cef/src/types/index.ts +++ b/browser/src/types/index.ts @@ -1,3 +1,3 @@ -export * from './cef' +export * from './browser' export * from './client' export * from './server' diff --git a/cef/src/types/server.ts b/browser/src/types/server.ts similarity index 100% rename from cef/src/types/server.ts rename to browser/src/types/server.ts diff --git a/cef/tsconfig.json b/browser/tsconfig.json similarity index 100% rename from cef/tsconfig.json rename to browser/tsconfig.json diff --git a/cef/tsup.config.ts b/browser/tsup.config.ts similarity index 100% rename from cef/tsup.config.ts rename to browser/tsup.config.ts diff --git a/cef/src/index.ts b/cef/src/index.ts deleted file mode 100644 index f3c7aad..0000000 --- a/cef/src/index.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { Rpc } from '@entityseven/rage-fw-rpc' -import type * as T from './types' - -class Cef { - private _debugMode: boolean = false - private _rpc: Rpc = new Rpc() - - constructor() {} - - set debug(debug: boolean) { - this._debugMode = debug - } - - get rpc(): Rpc { - return this._rpc - } - - public register( - eventName: EventName, - callback: T.RageFW_CefCallback, - ): void { - if (this._debugMode) { - console.log('[RPC](register):', eventName, callback) - } - - if ('mp' in window) { - this._rpc.register(eventName, callback) - } - } - - public async trigger( - eventName: EventName, - ...args: T._CefEventHasArgs extends true - ? [T.RageFW_CefArgs] - : [] - ): Promise> { - if (this._debugMode) { - console.log('[RPC](trigger):', eventName, ...args) - } - - if ('mp' in window) { - return await this._rpc.call(eventName, args) - } - - return Promise.reject( - 'RageFW was started in window which does not contain MP', - ) - } - - public async triggerServer< - EventName extends keyof T.RageFW_ICustomServerEvent, - >( - eventName: EventName, - ...args: T._ServerEventHasArgs extends true - ? [T.RageFW_ServerArgs] - : [] - ): Promise> { - if (this._debugMode) { - console.log('[RPC](triggerServer):', eventName, ...args) - } - - if ('mp' in window) { - return await this._rpc.callServer(eventName, args) - } - - return Promise.reject( - 'RageFW was started in window which does not contain MP', - ) - } - - public async triggerClient< - EventName extends keyof T.RageFW_ICustomClientEvent, - >( - eventName: EventName, - ...args: T._ClientEventHasArgs extends true - ? [T.RageFW_ClientArgs] - : [] - ): Promise> { - if (this._debugMode) { - console.log('[RPC](triggerClient):', eventName, ...args) - } - - if ('mp' in window) { - return await this._rpc.callClient(eventName, args) - } - - return Promise.reject( - 'RageFW was started in window which does not contain MP', - ) - } -} - -export const fw = { - event: new Cef(), -} -;(async () => { - await fw.event.triggerClient('cefReady') -})() diff --git a/cef/src/types/cef.ts b/cef/src/types/cef.ts deleted file mode 100644 index 130bf48..0000000 --- a/cef/src/types/cef.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types' - -export type { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types' - -/** - * Union of all available cef event names - * These only include custom events - */ -export type RageFW_CefEvent = keyof RageFW_ICustomCefEvent - -/** - * Array of arguments of an event you pass as a generic - * These only include custom cef events - */ -export type RageFW_CefArgs = Parameters< - RageFW_ICustomCefEvent[K] -> - -/** - * Return type of event you pass as a generic - * These only include custom cef events - */ -export type RageFW_CefReturn = ReturnType< - RageFW_ICustomCefEvent[K] -> - -/** - * Callback (function) of event you pass as a generic - * These only include custom cef events - */ -export type RageFW_CefCallback = ( - args: RageFW_CefArgs, -) => Promise> - -export type _CefEventHasArgs = - keyof RageFW_ICustomCefEvent extends never - ? false - : Parameters[0] extends undefined - ? false - : true diff --git a/client/src/types/browser.ts b/client/src/types/browser.ts index 9b266ac..bcb0321 100644 --- a/client/src/types/browser.ts +++ b/client/src/types/browser.ts @@ -1,20 +1,21 @@ /// -import type { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types' +import type { RageFW_ICustomBrowserEvent } from '@entityseven/rage-fw-shared-types' -export type RageFW_CefEvent = keyof RageFW_ICustomCefEvent +export type RageFW_CefEvent = keyof RageFW_ICustomBrowserEvent export type RageFW_CefArgs = Parameters< - RageFW_ICustomCefEvent[K] + RageFW_ICustomBrowserEvent[K] > export type RageFW_CefReturn = ReturnType< - RageFW_ICustomCefEvent[K] + RageFW_ICustomBrowserEvent[K] > -export type _CefEventHasArgs = - keyof RageFW_ICustomCefEvent extends never - ? false - : Parameters[0] extends undefined - ? false - : true +export type _CefEventHasArgs< + EventName extends keyof RageFW_ICustomBrowserEvent, +> = keyof RageFW_ICustomBrowserEvent extends never + ? false + : Parameters[0] extends undefined + ? false + : true diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 4dda521..c7bce69 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,5 +1,5 @@ packages: - "server" - "client" - - "cef" + - "browser" - "shared-types" \ No newline at end of file diff --git a/server/src/types/browser.ts b/server/src/types/browser.ts index 4a40c56..c3ac629 100644 --- a/server/src/types/browser.ts +++ b/server/src/types/browser.ts @@ -1,18 +1,19 @@ -import type { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types' +import type { RageFW_ICustomBrowserEvent } from '@entityseven/rage-fw-shared-types' -export type RageFW_CefEvent = keyof RageFW_ICustomCefEvent +export type RageFW_CefEvent = keyof RageFW_ICustomBrowserEvent export type RageFW_CefArgs = Parameters< - RageFW_ICustomCefEvent[K] + RageFW_ICustomBrowserEvent[K] > export type RageFW_CefReturn = ReturnType< - RageFW_ICustomCefEvent[K] + RageFW_ICustomBrowserEvent[K] > -export type _CefEventHasArgs = - keyof RageFW_ICustomCefEvent extends never - ? false - : Parameters[0] extends undefined - ? false - : true +export type _CefEventHasArgs< + EventName extends keyof RageFW_ICustomBrowserEvent, +> = keyof RageFW_ICustomBrowserEvent extends never + ? false + : Parameters[0] extends undefined + ? false + : true diff --git a/shared-types/types/types/index.d.ts b/shared-types/types/types/index.d.ts index 4d7acb4..bf18c34 100644 --- a/shared-types/types/types/index.d.ts +++ b/shared-types/types/types/index.d.ts @@ -1,9 +1,14 @@ declare module '@entityseven/rage-fw-shared-types' { - export interface RageFW_ICustomServerEvent {} + export interface RageFW_ICustomServerEvent { + customServerEvent(arg1: string, arg2: number): boolean + } export interface RageFW_ICustomClientEvent { cefReady(): void + customClientEvent(arg1: string, arg2: number): boolean } - export interface RageFW_ICustomCefEvent {} + export interface RageFW_ICustomBrowserEvent { + customCefEvent(arg1: string, arg2: number): boolean + } } -- 2.45.2 From 3bbf1e220925c0deb1da4d26cd3d5e62bccb5d7b Mon Sep 17 00:00:00 2001 From: Danya H Date: Mon, 28 Oct 2024 16:53:42 +0000 Subject: [PATCH 4/7] upd core - typed client inner rpc - better type organization --- client/src/core/client.ts | 34 +++++++++++++++++----------------- client/src/core/index.ts | 3 ++- client/src/core/player.ts | 36 +++++++++++++++++++++++------------- client/src/core/rpc.ts | 5 +++++ client/src/index.ts | 3 ++- client/src/types/browser.ts | 8 ++++++++ client/src/types/client.ts | 25 ++++++++++++++++--------- client/src/types/server.ts | 6 +++--- 8 files changed, 76 insertions(+), 44 deletions(-) create mode 100644 client/src/core/rpc.ts diff --git a/client/src/core/client.ts b/client/src/core/client.ts index 0f40886..7b75cf8 100644 --- a/client/src/core/client.ts +++ b/client/src/core/client.ts @@ -1,29 +1,29 @@ -import { Rpc } from '@entityseven/rage-fw-rpc' - +import { rpc } from './rpc' import type * as T from '../types' export class Client { - private _rpc: Rpc = new Rpc() - - get rpc(): Rpc { - return this._rpc - } - public register( eventName: EventName, callback: T.RageFW_ClientCallback, - ): void { - this._rpc.register( - eventName, - async (data: T.RageFW_ClientArgs) => { - return await callback(data) - }, - ) + ): Client { + rpc.register< + Parameters, + ReturnType, + EventName + >(eventName, async (...data) => await callback(...data)) + + return this } public unregister( eventName: EventName, - ): void { - this._rpc.unregister(eventName) + ): Client { + rpc.unregister(eventName) + + return this } } + +// new Client() +// .register('customClientEvent', async (a, b) => true) +// .unregister('customClientEvent') diff --git a/client/src/core/index.ts b/client/src/core/index.ts index cde62c3..375ef93 100644 --- a/client/src/core/index.ts +++ b/client/src/core/index.ts @@ -1,3 +1,4 @@ export * from './client' -export * from './player' export * from './logger' +export * from './player' +export * from './rpc' diff --git a/client/src/core/player.ts b/client/src/core/player.ts index 6a31096..0e7a511 100644 --- a/client/src/core/player.ts +++ b/client/src/core/player.ts @@ -1,31 +1,33 @@ -import { Rpc } from '@entityseven/rage-fw-rpc' -import type { RageFW_ICustomClientEvent } from '@entityseven/rage-fw-shared-types' - +import { rpc } from './rpc' import type * as T from '../types' export class Player { - private _rpc: Rpc = new Rpc() public browser: BrowserMp | undefined - get rpc(): Rpc { - return this._rpc - } - public trigger( + public trigger( eventName: EventName, ...args: T._ClientEventHasArgs extends true ? [T.RageFW_ClientArgs] : [] ): Promise> { - return this._rpc.call(eventName, args) + return rpc.call< + typeof args, + EventName, + T.RageFW_ClientReturn + >(eventName, args) } - public triggerServer( + public triggerServer( eventName: EventName, ...args: T._ServerEventHasArgs extends true - ? [T.RageFW_ClientServerArgs] + ? [T.RageFW_ServerArgs] : [] ): Promise> { - return this._rpc.callServer(eventName, args) + return rpc.callServer< + typeof args, + EventName, + T.RageFW_ClientServerReturn + >(eventName, args) } public triggerBrowser( @@ -36,6 +38,14 @@ export class Player { ): Promise> { if (!this.browser) throw new Error('You need to initialize browser first') - return this._rpc.callBrowser(this.browser, eventName, args) + return rpc.callBrowser< + typeof args, + EventName, + T.RageFW_CefReturn + >(this.browser, eventName, args) } } + +// new Player().trigger('customClientEvent', ['', 1]) +// new Player().triggerServer('customServerEvent', ['', 1]) +// new Player().triggerBrowser('customCefEvent', ['', 1]) diff --git a/client/src/core/rpc.ts b/client/src/core/rpc.ts new file mode 100644 index 0000000..4972ca0 --- /dev/null +++ b/client/src/core/rpc.ts @@ -0,0 +1,5 @@ +import { Rpc } from '@entityseven/rage-fw-rpc' + +export const rpc = new Rpc({ + debugLogs: false, +}) diff --git a/client/src/index.ts b/client/src/index.ts index d6c1455..f653742 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -1,4 +1,4 @@ -import { Client, Logger, Player } from './core' +import { Client, Logger, Player, rpc } from './core' export const fw = { event: new Client(), @@ -6,4 +6,5 @@ export const fw = { system: { log: new Logger(), }, + rpc, } diff --git a/client/src/types/browser.ts b/client/src/types/browser.ts index bcb0321..a4b343d 100644 --- a/client/src/types/browser.ts +++ b/client/src/types/browser.ts @@ -2,8 +2,16 @@ import type { RageFW_ICustomBrowserEvent } from '@entityseven/rage-fw-shared-types' +/** + * Union of all available browser event names callable from client + * These only include custom events + */ export type RageFW_CefEvent = keyof RageFW_ICustomBrowserEvent +/** + * Array of arguments for an event, name of which you pass as a generic + * These only include custom events + */ export type RageFW_CefArgs = Parameters< RageFW_ICustomBrowserEvent[K] > diff --git a/client/src/types/client.ts b/client/src/types/client.ts index a94eea9..08e0719 100644 --- a/client/src/types/client.ts +++ b/client/src/types/client.ts @@ -2,6 +2,8 @@ import type { RageFW_ICustomClientEvent } from '@entityseven/rage-fw-shared-types' +export type { RageFW_ICustomClientEvent } from '@entityseven/rage-fw-shared-types' + /** * Union of all available client event names * These include custom and system events @@ -21,14 +23,6 @@ export type RageFW_ClientArgs = ? Parameters : never -/** - * Callback (function) for an event, name of which you pass as a generic - * These only include custom events - */ -export type RageFW_ClientCallback = ( - args: RageFW_ClientArgs, -) => Promise> - /** * Return type for an event, name of which you pass as a generic * These only include custom events @@ -36,8 +30,21 @@ export type RageFW_ClientCallback = ( export type RageFW_ClientReturn = K extends keyof RageFW_ICustomClientEvent ? ReturnType - : void + : K extends keyof IClientEvents + ? ReturnType + : void +/** + * Callback (function) for an event, name of which you pass as a generic + * These only include custom events + */ +export type RageFW_ClientCallback = ( + ...args: RageFW_ClientArgs +) => Promise> + +/** + * + */ export type _ClientEventHasArgs< EventName extends keyof RageFW_ICustomClientEvent, > = keyof RageFW_ICustomClientEvent extends never diff --git a/client/src/types/server.ts b/client/src/types/server.ts index 23ce9df..3cc520e 100644 --- a/client/src/types/server.ts +++ b/client/src/types/server.ts @@ -9,13 +9,13 @@ import type { * Union of all available server event names callable from client * These only include custom events */ -export type RageFW_ClientServerEvent = keyof RageFW_ICustomServerEvent +export type RageFW_ServerEvent = keyof RageFW_ICustomServerEvent /** * Array of arguments for an event, name of which you pass as a generic * These only include custom events */ -export type RageFW_ClientServerArgs = +export type RageFW_ServerArgs = K extends keyof RageFW_ICustomServerEvent ? Parameters : never @@ -24,7 +24,7 @@ export type RageFW_ClientServerArgs = * Return type for an event, name of which you pass as a generic * These only include custom events */ -export type RageFW_ClientServerReturn = +export type RageFW_ClientServerReturn = K extends keyof RageFW_ICustomServerEvent ? ReturnType : never -- 2.45.2 From cbbf4f38e66fd123f9ed0efc85679a707beb8927 Mon Sep 17 00:00:00 2001 From: Danya H Date: Mon, 28 Oct 2024 17:30:28 +0000 Subject: [PATCH 5/7] upd core - typed server inner rpc - client minor fixes - sharing browser with rpc on client --- browser/src/core/browser.ts | 2 +- client/src/core/client.ts | 2 +- client/src/core/player.ts | 24 +++++--- client/src/types/client.ts | 4 +- server/src/core/index.ts | 5 +- server/src/core/player.ts | 28 ++++----- server/src/core/rpc.ts | 5 ++ server/src/core/server.ts | 120 ++++++++---------------------------- server/src/index.ts | 3 +- server/src/types/browser.ts | 21 ++++++- server/src/types/client.ts | 7 ++- server/src/types/server.ts | 37 +++-------- 12 files changed, 98 insertions(+), 160 deletions(-) create mode 100644 server/src/core/rpc.ts diff --git a/browser/src/core/browser.ts b/browser/src/core/browser.ts index 95e2b59..de7efdc 100644 --- a/browser/src/core/browser.ts +++ b/browser/src/core/browser.ts @@ -40,7 +40,7 @@ export class Browser extends Helper { public unregister( eventName: EventName, ): Browser { - rpc.unregister(eventName) + rpc.unregister(eventName) return this } diff --git a/client/src/core/client.ts b/client/src/core/client.ts index 7b75cf8..27e0f64 100644 --- a/client/src/core/client.ts +++ b/client/src/core/client.ts @@ -18,7 +18,7 @@ export class Client { public unregister( eventName: EventName, ): Client { - rpc.unregister(eventName) + rpc.unregister(eventName) return this } diff --git a/client/src/core/player.ts b/client/src/core/player.ts index 0e7a511..3572715 100644 --- a/client/src/core/player.ts +++ b/client/src/core/player.ts @@ -2,47 +2,53 @@ import { rpc } from './rpc' import type * as T from '../types' export class Player { - public browser: BrowserMp | undefined + private _browser: BrowserMp | undefined = undefined - public trigger( + set browser(browser: BrowserMp) { + this._browser = browser + rpc.browser = browser + } + + public async trigger( eventName: EventName, ...args: T._ClientEventHasArgs extends true ? [T.RageFW_ClientArgs] : [] ): Promise> { - return rpc.call< + return await rpc.call< typeof args, EventName, T.RageFW_ClientReturn >(eventName, args) } - public triggerServer( + public async triggerServer( eventName: EventName, ...args: T._ServerEventHasArgs extends true ? [T.RageFW_ServerArgs] : [] ): Promise> { - return rpc.callServer< + return await rpc.callServer< typeof args, EventName, T.RageFW_ClientServerReturn >(eventName, args) } - public triggerBrowser( + public async triggerBrowser( eventName: EventName, ...args: T._CefEventHasArgs extends true ? [T.RageFW_CefArgs] : [] ): Promise> { - if (!this.browser) + if (!this._browser) throw new Error('You need to initialize browser first') - return rpc.callBrowser< + + return await rpc.callBrowser< typeof args, EventName, T.RageFW_CefReturn - >(this.browser, eventName, args) + >(eventName, args) } } diff --git a/client/src/types/client.ts b/client/src/types/client.ts index 08e0719..dca0f87 100644 --- a/client/src/types/client.ts +++ b/client/src/types/client.ts @@ -25,7 +25,7 @@ export type RageFW_ClientArgs = /** * Return type for an event, name of which you pass as a generic - * These only include custom events + * These include custom and system events */ export type RageFW_ClientReturn = K extends keyof RageFW_ICustomClientEvent @@ -36,7 +36,7 @@ export type RageFW_ClientReturn = /** * Callback (function) for an event, name of which you pass as a generic - * These only include custom events + * These include custom and system events */ export type RageFW_ClientCallback = ( ...args: RageFW_ClientArgs diff --git a/server/src/core/index.ts b/server/src/core/index.ts index 48fa963..b6900db 100644 --- a/server/src/core/index.ts +++ b/server/src/core/index.ts @@ -1,3 +1,4 @@ -export * from './player' -export * from './server' export * from './logger' +export * from './player' +export * from './rpc' +export * from './server' diff --git a/server/src/core/player.ts b/server/src/core/player.ts index 4ab4330..2838221 100644 --- a/server/src/core/player.ts +++ b/server/src/core/player.ts @@ -1,31 +1,27 @@ -import { Rpc } from '@entityseven/rage-fw-rpc' - +import { rpc } from './rpc' import type * as T from '../types' export class Player { - private _rpc: Rpc = new Rpc() - - get rpc(): Rpc { - return this._rpc - } - - public triggerClient( + public async triggerClient( player: PlayerMp, eventName: EventName, ...args: T._ClientEventHasArgs extends true - ? [T.RageFW_ServerClientArgs] + ? [T.RageFW_ClientArgs] : [] - ): Promise> { - return this._rpc.callClient(player, eventName, args) + ): Promise> { + return await rpc.callClient(player, eventName, args) } - public triggerBrowser( + public async triggerBrowser( player: PlayerMp, eventName: EventName, ...args: T._CefEventHasArgs extends true - ? [T.RageFW_CefArgs] + ? [T.RageFW_BrowserArgs] : [] - ): Promise> { - return this._rpc.callBrowser(player, eventName, args) + ): Promise> { + return await rpc.callBrowser(player, eventName, args) } } + +// new Player().triggerBrowser({} as PlayerMp, 'customCefEvent', ['', 1]) +// new Player().triggerClient({} as PlayerMp, 'customClientEvent', ['', 1]) diff --git a/server/src/core/rpc.ts b/server/src/core/rpc.ts new file mode 100644 index 0000000..4972ca0 --- /dev/null +++ b/server/src/core/rpc.ts @@ -0,0 +1,5 @@ +import { Rpc } from '@entityseven/rage-fw-rpc' + +export const rpc = new Rpc({ + debugLogs: false, +}) diff --git a/server/src/core/server.ts b/server/src/core/server.ts index 15fc60b..c3cea7e 100644 --- a/server/src/core/server.ts +++ b/server/src/core/server.ts @@ -1,109 +1,39 @@ -import { Rpc } from '@entityseven/rage-fw-rpc' -import { RageFW_ICustomServerEvent } from '@entityseven/rage-fw-shared-types' - -import { nativeEvents } from '../data/nativeEvents' +import { rpc } from './rpc' import type * as T from '../types' export class Server { - private _rpc: Rpc = new Rpc() - - get rpc(): Rpc { - return this._rpc - } - - private isNativeEvent(eventName: string): eventName is keyof IServerEvents { - return nativeEvents.includes(eventName) - } - - private registerCustom( - eventName: EventName, - callback: T.RageFW_ServerCallbackCustom, - ): void { - this._rpc.register( - eventName, - // fixme - async (args: T.RageFW_ServerArgs, info) => { - await callback([info.player as PlayerMp, ...args]) - }, - ) - } - - private registerNative( - eventName: EventName, - callback: T.RageFW_ServerCallbackNative, - ): void { - mp.events.add( - eventName, - (...args: Parameters) => - callback([...args]), - ) - } - public register( eventName: EventName, callback: T.RageFW_ServerCallback, - ): void { - if (this.isNativeEvent(eventName)) { - this.registerNative( - eventName, - callback as T.RageFW_ServerCallbackNative, - ) - } else { - this.registerCustom( - eventName, - callback as unknown as T.RageFW_ServerCallbackCustom, - ) - } - } + ): Server { + rpc.register< + Parameters, + ReturnType, + EventName + >(eventName, async (...data) => await callback(...data)) - public registerMany(events: { - [event in EventName]: T.RageFW_ServerCallback - }): void { - Object.entries>(events).map( - ([eventName, callback]) => { - if (this.isNativeEvent(eventName)) { - this.registerNative( - eventName, - callback as T.RageFW_ServerCallbackNative, - ) - } else { - this.registerCustom( - eventName as keyof RageFW_ICustomServerEvent, - callback as unknown as T.RageFW_ServerCallbackCustom, - ) - } - }, - ) - } - - private unregisterCustom( - eventName: EventName, - ): void { - this._rpc.unregister(eventName) - } - - private unregisterNative( - eventName: EventName, - ): void { - mp.events.remove(eventName) + return this } public unregister( eventName: EventName, - ): void { - if (this.isNativeEvent(eventName)) { - this.unregisterNative(eventName) - } else { - this.unregisterCustom(eventName) - } + ): Server { + rpc.unregister(eventName) + + return this } - public trigger( - eventName: EventName, - ...args: T._ServerEventHasArgs extends true - ? [T.RageFW_ServerArgs] - : [] - ): Promise> { - return this._rpc.call(eventName, args) - } + // fixme + // public trigger( + // eventName: EventName, + // ...args: T._ServerEventHasArgs extends true + // ? [T.RageFW_ServerArgs] + // : [] + // ): Promise> { + // return rpc.call(eventName, args) + // } } + +// new Server() +// .register('customServerEvent', async (a, b, c) => true) +// .unregister('customServerEvent') diff --git a/server/src/index.ts b/server/src/index.ts index 0bbda5a..555ca74 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,4 +1,4 @@ -import { Logger, Player, Server } from './core' +import { Logger, Player, Server, rpc } from './core' export const fw = { event: new Server(), @@ -6,6 +6,7 @@ export const fw = { system: { log: new Logger(), }, + rpc, } fw.system.log.info( diff --git a/server/src/types/browser.ts b/server/src/types/browser.ts index c3ac629..eb410a0 100644 --- a/server/src/types/browser.ts +++ b/server/src/types/browser.ts @@ -1,15 +1,30 @@ import type { RageFW_ICustomBrowserEvent } from '@entityseven/rage-fw-shared-types' -export type RageFW_CefEvent = keyof RageFW_ICustomBrowserEvent +/** + * Union of all available browser event names + * These only include custom events + */ +export type RageFW_BrowserEvent = keyof RageFW_ICustomBrowserEvent -export type RageFW_CefArgs = Parameters< +/** + * Array of arguments of an event you pass as a generic + * These only include custom events + */ +export type RageFW_BrowserArgs = Parameters< RageFW_ICustomBrowserEvent[K] > -export type RageFW_CefReturn = ReturnType< +/** + * Return type of event you pass as a generic + * These only include custom events + */ +export type RageFW_BrowserReturn = ReturnType< RageFW_ICustomBrowserEvent[K] > +/** + * + */ export type _CefEventHasArgs< EventName extends keyof RageFW_ICustomBrowserEvent, > = keyof RageFW_ICustomBrowserEvent extends never diff --git a/server/src/types/client.ts b/server/src/types/client.ts index 0416299..44fc16f 100644 --- a/server/src/types/client.ts +++ b/server/src/types/client.ts @@ -12,7 +12,7 @@ export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent * Array of arguments of an event you pass as a generic * These only include custom events */ -export type RageFW_ServerClientArgs = +export type RageFW_ClientArgs = K extends RageFW_ClientEvent ? Parameters : never @@ -21,11 +21,14 @@ export type RageFW_ServerClientArgs = * Return type of event you pass as a generic * These only include custom events */ -export type RageFW_ServerClientReturn = +export type RageFW_ClientReturn = K extends RageFW_ClientEvent ? ReturnType : never +/** + * + */ export type _ClientEventHasArgs< EventName extends keyof RageFW_ICustomClientEvent, > = keyof RageFW_ICustomClientEvent extends never diff --git a/server/src/types/server.ts b/server/src/types/server.ts index 244f9b7..8cfd2dc 100644 --- a/server/src/types/server.ts +++ b/server/src/types/server.ts @@ -4,6 +4,7 @@ import type { RageFW_ICustomClientEvent, RageFW_ICustomServerEvent, } from '@entityseven/rage-fw-shared-types' + export type { RageFW_ICustomServerEvent } from '@entityseven/rage-fw-shared-types' /** @@ -20,20 +21,9 @@ export type RageFW_ServerEvent = */ export type RageFW_ServerArgs = K extends keyof RageFW_ICustomServerEvent - ? Parameters + ? [PlayerMp, ...Parameters] : K extends keyof IServerEvents - ? Parameters - : never - -/** - * Callback (function) for an event, name of which you pass as a generic - * These include system and custom events - */ -export type RageFW_ServerCallback = - K extends keyof RageFW_ICustomServerEvent - ? RageFW_ServerCallbackCustom - : K extends keyof IServerEvents - ? RageFW_ServerCallbackNative + ? [PlayerMp, Parameters] : never /** @@ -45,28 +35,19 @@ export type RageFW_ServerReturn = ? ReturnType : K extends keyof IServerEvents ? ReturnType - : never + : void /** - * Array of arguments for an event, name of which you pass as a generic - * These only include custom events + * Callback (function) for an event, name of which you pass as a generic + * These include system and custom events */ -export type RageFW_ServerCallbackCustom< - K extends keyof RageFW_ICustomServerEvent = keyof RageFW_ICustomServerEvent, -> = ( - payload: [player: PlayerMp, ...args: RageFW_ServerArgs], +export type RageFW_ServerCallback = ( + ...args: RageFW_ServerArgs ) => Promise> /** - * Array of arguments for an event, name of which you pass as a generic - * These only include system events + * */ -export type RageFW_ServerCallbackNative< - K extends keyof IServerEvents = keyof IServerEvents, -> = ( - payload: Parameters, -) => Promise> - export type _ServerEventHasArgs = EventName extends keyof RageFW_ICustomServerEvent ? keyof RageFW_ICustomClientEvent extends never -- 2.45.2 From d9b917c02464237dae7b9ca09182ff916e39c887 Mon Sep 17 00:00:00 2001 From: Danya H Date: Mon, 28 Oct 2024 17:37:17 +0000 Subject: [PATCH 6/7] core version bump --- browser/package.json | 2 +- client/package.json | 2 +- server/package.json | 2 +- shared-types/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/browser/package.json b/browser/package.json index 6c41277..4dbb75b 100644 --- a/browser/package.json +++ b/browser/package.json @@ -1,6 +1,6 @@ { "name": "@entityseven/rage-fw-browser", - "version": "0.1.0", + "version": "0.1.2", "main": "dist/index.js", "types": "dist/src/index.d.ts", "files": [ diff --git a/client/package.json b/client/package.json index 4092690..da68719 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "@entityseven/rage-fw-client", - "version": "0.1.0", + "version": "0.1.2", "main": "dist/index.js", "types": "dist/src/index.d.ts", "files": [ diff --git a/server/package.json b/server/package.json index df3c0fe..1aa9796 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "@entityseven/rage-fw-server", - "version": "0.1.0", + "version": "0.1.2", "main": "dist/index.js", "types": "dist/src/index.d.ts", "files": [ diff --git a/shared-types/package.json b/shared-types/package.json index ad693a7..9ece53d 100644 --- a/shared-types/package.json +++ b/shared-types/package.json @@ -1,6 +1,6 @@ { "name": "@entityseven/rage-fw-shared-types", - "version": "0.1.0", + "version": "0.1.2", "types": "types/types/index.d.ts", "files": [ "types/**/*" -- 2.45.2 From d8df9fa7ef0594895b7be28392ca7ce6281d91b2 Mon Sep 17 00:00:00 2001 From: Danya H Date: Mon, 28 Oct 2024 17:40:25 +0000 Subject: [PATCH 7/7] fix core - renaming done --- client/src/core/player.ts | 10 +++++----- client/src/types/browser.ts | 8 ++++---- server/src/core/player.ts | 2 +- server/src/types/browser.ts | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/src/core/player.ts b/client/src/core/player.ts index 3572715..e4949f0 100644 --- a/client/src/core/player.ts +++ b/client/src/core/player.ts @@ -35,19 +35,19 @@ export class Player { >(eventName, args) } - public async triggerBrowser( + public async triggerBrowser( eventName: EventName, - ...args: T._CefEventHasArgs extends true - ? [T.RageFW_CefArgs] + ...args: T._BrowserEventHasArgs extends true + ? [T.RageFW_BrowserArgs] : [] - ): Promise> { + ): Promise> { if (!this._browser) throw new Error('You need to initialize browser first') return await rpc.callBrowser< typeof args, EventName, - T.RageFW_CefReturn + T.RageFW_BrowserReturn >(eventName, args) } } diff --git a/client/src/types/browser.ts b/client/src/types/browser.ts index a4b343d..27292f7 100644 --- a/client/src/types/browser.ts +++ b/client/src/types/browser.ts @@ -6,21 +6,21 @@ import type { RageFW_ICustomBrowserEvent } from '@entityseven/rage-fw-shared-typ * Union of all available browser event names callable from client * These only include custom events */ -export type RageFW_CefEvent = keyof RageFW_ICustomBrowserEvent +export type RageFW_BrowserEvent = keyof RageFW_ICustomBrowserEvent /** * Array of arguments for an event, name of which you pass as a generic * These only include custom events */ -export type RageFW_CefArgs = Parameters< +export type RageFW_BrowserArgs = Parameters< RageFW_ICustomBrowserEvent[K] > -export type RageFW_CefReturn = ReturnType< +export type RageFW_BrowserReturn = ReturnType< RageFW_ICustomBrowserEvent[K] > -export type _CefEventHasArgs< +export type _BrowserEventHasArgs< EventName extends keyof RageFW_ICustomBrowserEvent, > = keyof RageFW_ICustomBrowserEvent extends never ? false diff --git a/server/src/core/player.ts b/server/src/core/player.ts index 2838221..571fd1f 100644 --- a/server/src/core/player.ts +++ b/server/src/core/player.ts @@ -15,7 +15,7 @@ export class Player { public async triggerBrowser( player: PlayerMp, eventName: EventName, - ...args: T._CefEventHasArgs extends true + ...args: T._BrowserEventHasArgs extends true ? [T.RageFW_BrowserArgs] : [] ): Promise> { diff --git a/server/src/types/browser.ts b/server/src/types/browser.ts index eb410a0..41c4f29 100644 --- a/server/src/types/browser.ts +++ b/server/src/types/browser.ts @@ -25,7 +25,7 @@ export type RageFW_BrowserReturn = ReturnType< /** * */ -export type _CefEventHasArgs< +export type _BrowserEventHasArgs< EventName extends keyof RageFW_ICustomBrowserEvent, > = keyof RageFW_ICustomBrowserEvent extends never ? false -- 2.45.2