Skip to content

Commit

Permalink
feat: initial stuff for @core/router
Browse files Browse the repository at this point in the history
Nothing to see here
  • Loading branch information
itschip committed Jan 27, 2024
1 parent 9045195 commit c99a94d
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 14 deletions.
10 changes: 5 additions & 5 deletions build-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ on('onResourceStart', async (resName) => {
} catch {
console.log(
'^1==============================================\n\n' +
'!!! NPWD WAS UNABLE TO LOCATE BUILT FILES AND WAS UNABLE TO START !!!\n\n' +
'This error is most likely caused by downloading the source code instead of the release\n\n' +
'Find the latest NPWD release here: \n\n' +
'https://github.com/project-error/npwd/releases/latest/download/npwd.zip\n\n' +
'==============================================^0',
'!!! NPWD WAS UNABLE TO LOCATE BUILT FILES AND WAS UNABLE TO START !!!\n\n' +
'This error is most likely caused by downloading the source code instead of the release\n\n' +
'Find the latest NPWD release here: \n\n' +
'https://github.com/project-error/npwd/releases/latest/download/npwd.zip\n\n' +
'==============================================^0',
);
}
});
12 changes: 12 additions & 0 deletions core/query/package.json
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"
}
20 changes: 20 additions & 0 deletions core/router/.eslintrc
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
}
}
22 changes: 22 additions & 0 deletions core/router/package.json
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"
}
}
19 changes: 19 additions & 0 deletions core/router/src/example.ts
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;
9 changes: 9 additions & 0 deletions core/router/src/example_client.ts
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,
});
49 changes: 49 additions & 0 deletions core/router/src/index.ts
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;
}
24 changes: 24 additions & 0 deletions core/router/tsconfig.json
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"]
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"database": "pnpm --filter @npwd/database",
"logger": "pnpm --filter @npwd/logger",
"npwd-config": "pnpm --filter @npwd/config",
"ui": "pnpm --filter @npwd/keyos"
"ui": "pnpm --filter @npwd/keyos",
"query": "pnpm --filter @core/query",
"router": "pnpm --filter @core/router"
},
"husky": {
"hooks": {
Expand Down
60 changes: 52 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- 'apps/**'
- 'packages/**'
- 'core/**'

0 comments on commit c99a94d

Please sign in to comment.