diff --git a/build-detector.js b/build-detector.js index 0e6422e72..e18170da3 100644 --- a/build-detector.js +++ b/build-detector.js @@ -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', ); } }); diff --git a/core/query/package.json b/core/query/package.json new file mode 100644 index 000000000..91c45b5e9 --- /dev/null +++ b/core/query/package.json @@ -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" +} diff --git a/core/router/.eslintrc b/core/router/.eslintrc new file mode 100644 index 000000000..1303a451a --- /dev/null +++ b/core/router/.eslintrc @@ -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 + } +} diff --git a/core/router/package.json b/core/router/package.json new file mode 100644 index 000000000..0a1da1284 --- /dev/null +++ b/core/router/package.json @@ -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" + } +} diff --git a/core/router/src/example.ts b/core/router/src/example.ts new file mode 100644 index 000000000..1d79b95d3 --- /dev/null +++ b/core/router/src/example.ts @@ -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; diff --git a/core/router/src/example_client.ts b/core/router/src/example_client.ts new file mode 100644 index 000000000..4aea6e7be --- /dev/null +++ b/core/router/src/example_client.ts @@ -0,0 +1,9 @@ +import { createClient } from '.'; +import { AppRouter } from './example'; + +const client = createClient(); + +client.giveMoney.emitNet({ + amount: 100, + playerId: 1, +}); diff --git a/core/router/src/index.ts b/core/router/src/index.ts new file mode 100644 index 000000000..af09e6a0d --- /dev/null +++ b/core/router/src/index.ts @@ -0,0 +1,49 @@ +type RouterFunction = (...args: any[]) => Promise; +type FunctionWithEmit = { + emit: T; + emitNet: T; +}; + +function createdFunctionWithEmit(fn: T): FunctionWithEmit { + return { + emit: ((...args: Parameters): Promise> => { + console.log('emit', args); + return fn(...args); + }) as T, + emitNet: ((...args: Parameters): Promise> => { + console.log('emitNet', args); + return fn(...args); + }) as T, + }; +} + +function eventProcedure(event: string, callback: T): FunctionWithEmit { + // uhh what to do here + onNet(event, callback); + return createdFunctionWithEmit(callback); +} + +type RouterFunctions = Record>; + +function createRouter() { + return function (routes: T): T { + return routes; + }; +} + +class RouterBuilder { + create() { + return { + router: createRouter(), + eventProcedure: eventProcedure, + }; + } +} + +export const initRouter = new RouterBuilder(); + +export function createClient< + T extends Record Promise>>, +>(): T { + return {} as T; +} diff --git a/core/router/tsconfig.json b/core/router/tsconfig.json new file mode 100644 index 000000000..e770f7fa9 --- /dev/null +++ b/core/router/tsconfig.json @@ -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"] +} diff --git a/package.json b/package.json index 763db15ff..1f5e9b32b 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 231a71c89..4ce6b1569 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,9 +1,5 @@ lockfileVersion: '6.0' -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false - importers: .: @@ -447,6 +443,35 @@ importers: specifier: ^4.7.4 version: 4.7.4(webpack-cli@4.10.0)(webpack@5.74.0) + core/query: {} + + core/router: + devDependencies: + '@citizenfx/client': + specifier: ^2.0.4170-1 + version: 2.0.4170-1 + '@citizenfx/server': + specifier: 2.0.7359-1 + version: 2.0.7359-1 + '@types/node': + specifier: ^20.11.7 + version: 20.11.7 + '@typescript-eslint/eslint-plugin': + specifier: ^4.33.0 + version: 4.33.0(@typescript-eslint/parser@4.33.0)(eslint@7.32.0)(typescript@4.9.5) + '@typescript-eslint/parser': + specifier: ^4.33.0 + version: 4.33.0(eslint@7.32.0)(typescript@4.9.5) + eslint: + specifier: ^7.32.0 + version: 7.32.0 + tsup: + specifier: ^6.6.3 + version: 6.6.3(postcss@8.4.31)(typescript@4.9.5) + typescript: + specifier: ^4.9.5 + version: 4.9.5 + packages/config: devDependencies: '@citizenfx/server': @@ -2809,7 +2834,7 @@ packages: babel-plugin-polyfill-corejs3: 0.4.0(@babel/core@7.23.2) babel-plugin-polyfill-regenerator: 0.3.1(@babel/core@7.23.2) core-js-compat: 3.30.2 - semver: 6.3.0 + semver: 6.3.1 transitivePeerDependencies: - supports-color dev: false @@ -2979,6 +3004,10 @@ packages: resolution: {integrity: sha512-djM+opelAVHyHELCcueYYDAUgsj/MU7XuM+gGdXGQP4332tCdY1Mi0W1NQpXEebNmQeasJfrWml1W/3RrQZZbQ==} dev: true + /@citizenfx/server@2.0.7359-1: + resolution: {integrity: sha512-ivqUDc+BDqpnaY8O9HmeXeVaaI/dx6ldMo4SmBT2nIiHcTi7Suj6+0t20emrWImVIsLiGiSH+XCvF9eAqowr5g==} + dev: true + /@cnakazawa/watch@1.0.4: resolution: {integrity: sha512-v9kIhKwjeZThiWrLmj0y17CWoyddASLj9O2yvbZkbvw/N3rWOYy9zkV66ursAoVr0mV15bL8g0c4QZUE6cdDoQ==} engines: {node: '>=0.1.95'} @@ -6082,6 +6111,12 @@ packages: /@types/node@18.15.0: resolution: {integrity: sha512-z6nr0TTEOBGkzLGmbypWOGnpSpSIBorEhC4L+4HeQ2iezKCi4f77kyslRwvHeNitymGQ+oFyIWGP96l/DPSV9w==} + /@types/node@20.11.7: + resolution: {integrity: sha512-GPmeN1C3XAyV5uybAf4cMLWT9fDWcmQhZVtMFu7OR32WjrqGG+Wnk2V1d0bmtUyE/Zy1QJ9BxyiTih9z8Oks8A==} + dependencies: + undici-types: 5.26.5 + dev: true + /@types/normalize-package-data@2.4.1: resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} dev: true @@ -10448,6 +10483,7 @@ packages: glob-parent: 5.1.2 merge2: 1.4.1 micromatch: 4.0.5 + dev: true /fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} @@ -11007,7 +11043,7 @@ packages: dependencies: array-union: 2.1.0 dir-glob: 3.0.1 - fast-glob: 3.2.12 + fast-glob: 3.3.2 ignore: 5.2.4 merge2: 1.4.1 slash: 3.0.0 @@ -11017,7 +11053,7 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: dir-glob: 3.0.1 - fast-glob: 3.2.12 + fast-glob: 3.3.2 ignore: 5.2.4 merge2: 1.4.1 slash: 4.0.0 @@ -13425,7 +13461,7 @@ packages: resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==} engines: {node: '>=8'} dependencies: - semver: 6.3.0 + semver: 6.3.1 /make-error@1.3.6: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} @@ -17953,6 +17989,10 @@ packages: resolution: {integrity: sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==} dev: true + /undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + dev: true + /unicode-canonical-property-names-ecmascript@2.0.0: resolution: {integrity: sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==} engines: {node: '>=4'} @@ -19085,3 +19125,7 @@ packages: name: lodash version: 4.17.21 dev: true + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 44665b756..ff8c1f39b 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,4 @@ packages: - 'apps/**' - 'packages/**' + - 'core/**'