-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial stuff for @core/router
Nothing to see here
- Loading branch information
Showing
11 changed files
with
216 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@core/query", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], | ||
"rules": { | ||
"no-undef": 0, | ||
"@typescript-eslint/ban-types": [ | ||
"error", | ||
{ | ||
"types": { | ||
"Function": false | ||
} | ||
} | ||
], | ||
"@typescript-eslint/no-var-requires": 0, | ||
"@typescript-eslint/no-explicit-any": 0, | ||
"@typescript-eslint/explicit-module-boundary-types": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@core/router", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "tsup src/index.ts --format cjs,esm --dts --minify --clean --sourcemap" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@citizenfx/client": "^2.0.4170-1", | ||
"@citizenfx/server": "2.0.7359-1", | ||
"@types/node": "^20.11.7", | ||
"@typescript-eslint/eslint-plugin": "^4.33.0", | ||
"@typescript-eslint/parser": "^4.33.0", | ||
"eslint": "^7.32.0", | ||
"tsup": "^6.6.3", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { initRouter } from '.'; | ||
|
||
const t = initRouter.create(); | ||
const router = t.router; | ||
|
||
const eventProcedure = t.eventProcedure; | ||
|
||
type PlayerData = { | ||
playerId: number; | ||
amount: number; | ||
}; | ||
|
||
const appRouter = router({ | ||
giveMoney: eventProcedure('giveMoney', async (data: PlayerData) => { | ||
console.log('Giving money to player: ', data.playerId, data.amount); | ||
}), | ||
}); | ||
|
||
export type AppRouter = typeof appRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createClient } from '.'; | ||
import { AppRouter } from './example'; | ||
|
||
const client = createClient<AppRouter>(); | ||
|
||
client.giveMoney.emitNet({ | ||
amount: 100, | ||
playerId: 1, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
type RouterFunction = (...args: any[]) => Promise<any>; | ||
type FunctionWithEmit<T extends RouterFunction> = { | ||
emit: T; | ||
emitNet: T; | ||
}; | ||
|
||
function createdFunctionWithEmit<T extends RouterFunction>(fn: T): FunctionWithEmit<T> { | ||
return { | ||
emit: ((...args: Parameters<T>): Promise<ReturnType<T>> => { | ||
console.log('emit', args); | ||
return fn(...args); | ||
}) as T, | ||
emitNet: ((...args: Parameters<T>): Promise<ReturnType<T>> => { | ||
console.log('emitNet', args); | ||
return fn(...args); | ||
}) as T, | ||
}; | ||
} | ||
|
||
function eventProcedure<T extends RouterFunction>(event: string, callback: T): FunctionWithEmit<T> { | ||
// uhh what to do here | ||
onNet(event, callback); | ||
return createdFunctionWithEmit(callback); | ||
} | ||
|
||
type RouterFunctions = Record<string, FunctionWithEmit<RouterFunction>>; | ||
|
||
function createRouter() { | ||
return function <T extends RouterFunctions>(routes: T): T { | ||
return routes; | ||
}; | ||
} | ||
|
||
class RouterBuilder { | ||
create() { | ||
return { | ||
router: createRouter(), | ||
eventProcedure: eventProcedure, | ||
}; | ||
} | ||
} | ||
|
||
export const initRouter = new RouterBuilder(); | ||
|
||
export function createClient< | ||
T extends Record<string, FunctionWithEmit<(...args: any[]) => Promise<any>>>, | ||
>(): T { | ||
return {} as T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
"*": ["./types/*"], | ||
"@shared/*": ["../../../shared/*"], | ||
"@typings/*": ["../../../typings/*"] | ||
}, | ||
"outDir": "./", | ||
"noImplicitAny": true, | ||
"module": "commonjs", | ||
"target": "ES2018", | ||
"allowJs": false, | ||
"lib": ["es2018"], | ||
"types": ["@citizenfx/server", "@citizenfx/client", "@types/node"], | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true | ||
}, | ||
"include": ["./**/*", "../../shared/*"], | ||
"exclude": ["**/node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
packages: | ||
- 'apps/**' | ||
- 'packages/**' | ||
- 'core/**' |