This commit is contained in:
Oleksandr Honcharov 2024-06-10 03:53:42 +03:00
parent 835c84261c
commit 8a42309956
26 changed files with 4275 additions and 613 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.idea
node_modules
dist

9
client/build.js Normal file
View File

@ -0,0 +1,9 @@
import { build } from 'esbuild'
build({
entryPoints: ['./src/index.ts'],
format: 'esm',
platform: 'node',
target: 'node10.4',
outdir: './dist',
}).then(r => console.log('Successfully build.'))

15
client/dts.config.json Normal file
View File

@ -0,0 +1,15 @@
{
"compilationOptions": {
"followSymlinks": true,
"preferredConfigPath": "../tsconfig.json"
},
"entries": [
{
"filePath": "./src/index.ts",
"outFile": "./dist/index.d.ts",
"libraries": {
"inlinedLibraries": ["@ragempcommunity/types-client"]
}
}
]
}

View File

@ -5,7 +5,11 @@
"type": "module",
"files": ["dist/**/*"],
"scripts": {
"build": "tsup"
"build": "node --es-module-specifier-resolution=node build.js",
"types": "dts-bundle-generator --config dts.config.json"
},
"peerDependencies": {
"rage-fw-shared-types": "workspace:shared-types:*"
},
"keywords": [],
"author": "SashaGoncharov19",

View File

@ -1,23 +1,19 @@
/// <reference types="../../shared/client/index.d.ts" />
import rpc from 'rage-rpc'
import {
RageFW_ClientEventReturn,
RageFW_ClientEvent,
RageFW_ClientEventArguments,
} from './types'
class Player implements RageFW_Player {
public triggerClient<EventName extends RageFW_ClientEvent>(
player: PlayerMp,
class Player {
public triggerServer<EventName extends RageFW_ClientEvent>(
eventName: EventName,
...args: RageFW_ClientEventArguments<EventName>
): Promise<RageFW_ClientEventReturn<EventName>> {
return rpc.callClient(player, eventName, ...args)
return rpc.callServer(eventName, ...args)
}
}
export const rage = {
player: new Player(),
}
const bool = rage.player.triggerClient(
{} as PlayerMp,
'customClientEvent',
'arg1',
2,
)

17
client/src/types.ts Normal file
View File

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

View File

@ -1,13 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"lib": ["ESNext", "ES5"],
"module": "ESNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"types": ["../node_modules/@ragempcommunity/types-server", "../../shared/client"]
"typeRoots": [
"@ragempcommunity/types-client"
],
"baseUrl": "./src"
}
}

5
lerna.json Normal file
View File

@ -0,0 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "0.0.1",
"npmClient": "pnpm"
}

View File

@ -1,16 +1,15 @@
{
"private": true,
"workspaces": [
"server"
],
"dependencies": {
"@ragempcommunity/types-cef": "^2.1.8",
"@ragempcommunity/types-client": "^2.1.8",
"@ragempcommunity/types-server": "^2.1.8",
"@ragempcommunity/types-cef": "^2.1.8",
"rage-rpc": "^0.4.0",
"tsup": "^8.1.0",
"dts-bundle-generator": "^9.5.1",
"esbuild": "^0.21.5",
"prettier": "^3.3.1",
"typescript": "^5.4.5"
"rage-rpc": "^0.4.0",
"typescript": "^5.4.5",
"lerna": "^8.1.3"
},
"type": "module"
}

4557
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

5
pnpm-workspace.yaml Normal file
View File

@ -0,0 +1,5 @@
packages:
- "server/*"
- "client/*"
- "shared/*"
- "shared-types/*"

9
server/build.js Normal file
View File

@ -0,0 +1,9 @@
import { build } from 'esbuild'
build({
entryPoints: ['./src/index.ts'],
format: 'esm',
platform: 'node',
target: 'node10.4',
outdir: './dist',
}).then(r => console.log('Successfully build.'))

15
server/dts.config.json Normal file
View File

@ -0,0 +1,15 @@
{
"compilationOptions": {
"followSymlinks": true,
"preferredConfigPath": "../tsconfig.json"
},
"entries": [
{
"filePath": "./src/index.ts",
"outFile": "./dist/index.d.ts",
"libraries": {
"inlinedLibraries": ["@ragempcommunity/types-server"]
}
}
]
}

View File

@ -2,10 +2,15 @@
"name": "rage-fw-server",
"version": "0.0.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"files": ["dist/**/*"],
"scripts": {
"build": "tsup"
"build": "node --es-module-specifier-resolution=node build.js",
"types": "dts-bundle-generator --config dts.config.json"
},
"peerDependencies": {
"rage-fw-shared-types": "workspace:shared-types:*"
},
"keywords": [],
"author": "SashaGoncharov19",

View File

@ -1,7 +1,7 @@
/// <reference types="../../shared/server/index.d.ts" />
import rpc from 'rage-rpc'
import { RageFW_ServerEvent, RageFW_ServerEventCallback } from './types.js'
class Server implements RageFW_Server {
class Server {
public register<EventName extends RageFW_ServerEvent>(
eventName: EventName,
callback: RageFW_ServerEventCallback<EventName>,
@ -19,34 +19,9 @@ class Server implements RageFW_Server {
: (callback as (arg: typeof args) => void)(args)
}),
)
// Object.keys(events).forEach(eventName =>
// // unknown[] ?
// // rpc.register(eventName, (args: unknown[]) =>
// // Array.isArray(args) ? events[eventName as keyof typeof events](...args) : callback(args),
// // ),
// rpc.register(eventName, (...args: unknown[]) =>
// events[eventName as EventName](args),
// ),
// )
}
}
export const rage = {
event: new Server(),
}
rage.event.register('customServerEvent', (player, arg1, arg2) => {
console.log(player, arg1, arg2)
return true
})
rage.event.registerMany({
customServerEvent: (player, arg1, arg2) => {
console.log(player, arg1, arg2)
return true
},
playerDeath: (player, reason, killer) => {
console.log(player, reason, killer)
return undefined
},
})

18
server/src/types.ts Normal file
View File

@ -0,0 +1,18 @@
/// <reference types="@ragempcommunity/types-server" />
import { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
export type RageFW_ServerEvent =
| keyof RageFW_ICustomServerEvent
| keyof IServerEvents
export type RageFW_ServerEventCallback<
K extends keyof RageFW_ICustomServerEvent | keyof IServerEvents,
> = K extends keyof RageFW_ICustomServerEvent
? (
player: PlayerMp,
...args: Parameters<RageFW_ICustomServerEvent[K]>
) => ReturnType<RageFW_ICustomServerEvent[K]>
: K extends keyof IServerEvents
? ThisifyServerEvents[K]
: never

View File

@ -1,17 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"lib": [
"ESNext",
"ES5",
"dom"
"typeRoots": [
"@ragempcommunity/types-server"
],
"module": "ESNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"types": ["../node_modules/@ragempcommunity/types-server", "../../shared/server"]
"baseUrl": "./src"
}
}

11
shared-types/package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "rage-fw-shared-types",
"version": "0.0.1",
"types": "types/types/index.d.ts",
"files": [
"types/**/*"
],
"author": "SashaGoncharov19",
"license": "MIT",
"type": "module"
}

5
shared-types/types/types/index.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
declare module 'rage-fw-shared-types' {
export interface RageFW_ICustomServerEvent {}
export interface RageFW_ICustomClientEvent {}
}

View File

@ -1,25 +0,0 @@
/// <reference types="@ragempcommunity/types-client" />
interface RageFW_ICustomClientEvent {
customClientEvent(arg1: string, arg2: number): boolean
}
type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent | keyof IClientEvents
type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
K extends keyof RageFW_ICustomClientEvent
? Parameters<RageFW_ICustomClientEvent[K]>
: (K extends keyof IClientEvents ? ThisifyClientEvents[K] : never)[]
type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
K extends keyof RageFW_ICustomClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]>
: never
declare class RageFW_Player {
declare triggerClient<EventName extends RageFW_ClientEvent>(
player: PlayerMp,
eventName: EventName,
...args: RageFW_ClientEventArguments<EventName>
): Promise<RageFW_ClientEventReturn<EventName>>
}

View File

@ -1,10 +0,0 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}

View File

@ -1,5 +1,5 @@
{
"name": "rage-fw-shared-client",
"name": "rage-fw-shared",
"version": "0.0.1",
"type": "module",
"main": "index.d.ts",

View File

@ -1,30 +0,0 @@
/// <reference types="@ragempcommunity/types-server" />
declare interface RageFW_ICustomServerEvent {
customServerEvent(arg1: string, arg2: number): boolean
}
type RageFW_ServerEvent =
| keyof RageFW_ICustomServerEvent
| keyof IServerEvents
type RageFW_ServerEventCallback<
K extends keyof RageFW_ICustomServerEvent | keyof IServerEvents,
> = K extends keyof RageFW_ICustomServerEvent
? (
player: PlayerMp,
...args: Parameters<RageFW_ICustomServerEvent[K]>
) => ReturnType<RageFW_ICustomServerEvent[K]>
: K extends keyof IServerEvents
? ThisifyServerEvents[K]
: never
declare class RageFW_Server {
declare register<EventName extends RageFW_ServerEvent>(
eventName: EventName,
callback: RageFW_ServerEventCallback<EventName>,
): void
declare registerMany<EventName extends RageFW_ServerEvent>(events: {
[key: EventName]: RageFW_ServerEventCallback<EventName>
}): void
}

View File

@ -1,16 +0,0 @@
{
"name": "rage-fw-shared-server",
"version": "0.0.1",
"type": "module",
"main": "index.d.ts",
"files": [
"index.d.ts"
],
"scripts": {
"test": "tsup"
},
"keywords": [],
"author": "SashaGoncharov19",
"license": "MIT",
"description": "Shared server types for rage-fw"
}

View File

@ -1,10 +0,0 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}

View File

@ -1,10 +1,20 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"target": "ESNext",
"module": "ESNext",
"strict": true,
"skipLibCheck": true
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"useUnknownInCatchVariables": false,
"exactOptionalPropertyTypes": true,
"typeRoots": [
"./shared-types/types"
]
}
}