Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd9f1cab18 | ||
|
|
21ca123797 |
@@ -1,8 +0,0 @@
|
|||||||
# Changesets
|
|
||||||
|
|
||||||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
||||||
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
||||||
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
||||||
|
|
||||||
We have a quick list of common questions to get you started engaging with this project in
|
|
||||||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
|
|
||||||
"changelog": "@changesets/cli/changelog",
|
|
||||||
"commit": false,
|
|
||||||
"fixed": [
|
|
||||||
["@entityseven/rage-fw-browser","@entityseven/rage-fw-client","@entityseven/rage-fw-server"]
|
|
||||||
],
|
|
||||||
"linked": [],
|
|
||||||
"access": "public",
|
|
||||||
"baseBranch": "master",
|
|
||||||
"updateInternalDependencies": "patch",
|
|
||||||
"ignore": []
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
env:
|
||||||
|
node: true
|
||||||
|
es6: true
|
||||||
|
es2019: true
|
||||||
|
extends:
|
||||||
|
- 'eslint:recommended'
|
||||||
|
- 'plugin:@typescript-eslint/recommended'
|
||||||
|
# - 'prettier'
|
||||||
|
parser: '@typescript-eslint/parser'
|
||||||
|
parserOptions:
|
||||||
|
ecmaVersion: '2019'
|
||||||
|
sourceType: 'script'
|
||||||
|
plugins:
|
||||||
|
- '@typescript-eslint'
|
||||||
|
ignorePatterns:
|
||||||
|
- 'node_modules'
|
||||||
|
rules: {
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
'@typescript-eslint/no-unused-vars': [
|
||||||
|
'warn',
|
||||||
|
{
|
||||||
|
"argsIgnorePattern": '^_',
|
||||||
|
"varsIgnorePattern": '^_',
|
||||||
|
"caughtErrorsIgnorePattern": '^_'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'@typescript-eslint/ban-ts-comment': 'off',
|
||||||
|
'@typescript-eslint/ban-types': 'off',
|
||||||
|
'consistent-return': 'warn',
|
||||||
|
'no-empty': 'off',
|
||||||
|
}
|
||||||
@@ -2,4 +2,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
dist
|
dist
|
||||||
.nx/cache
|
|
||||||
|
|||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"dependencyTypes": ["prod", "peer", "dev"],
|
|
||||||
"versionGroups": [
|
|
||||||
{
|
|
||||||
"label": "Ensure @ragempcommunity/types-* always match",
|
|
||||||
"packages": ["**"],
|
|
||||||
"dependencies": ["@ragempcommunity/types-cef","@ragempcommunity/types-client", "@ragempcommunity/types-server"],
|
|
||||||
"pinVersion": "sameRange",
|
|
||||||
"range": "^"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Use workspace protocol when developing local packages",
|
|
||||||
"packages": ["**"],
|
|
||||||
"dependencies": ["@entityseven/rage-fw-shared-types", "@entityseven/rage-fw-rpc"]
|
|
||||||
"pinVersion": "workspace:*",
|
|
||||||
"range": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Ensure @types/node match same version (for tsup)",
|
|
||||||
"packages": ["**"],
|
|
||||||
"dependencies": ["@types/node"],
|
|
||||||
"pinVersion": "sameRange",
|
|
||||||
"range": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Ensure newest breaking Typescript version",
|
|
||||||
"packages": ["**"],
|
|
||||||
"dependencies": ["typescript"],
|
|
||||||
"pinVersion": "sameRange",
|
|
||||||
"range": "^"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# Custom Attribution-NoDerives Software License
|
# Custom Attribution-NoDerivs Software License
|
||||||
|
|
||||||
This license allows you to use, copy, and distribute the RageFW (the "Software"), including for commercial purposes, provided that the following conditions are met:
|
This license allows you to use, copy, and distribute the RageFW (the "Software"), including for commercial purposes, provided that the following conditions are met:
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Custom Attribution-NoDerives Software License
|
Custom Attribution-NoDerivs Software License
|
||||||
|
|
||||||
Copyright (c) 2024 Entity Seven Group
|
Copyright (c) 2024 Entity Seven Group
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
+8
-19
@@ -1,37 +1,26 @@
|
|||||||
{
|
{
|
||||||
"private": false,
|
|
||||||
"name": "@entityseven/rage-fw-browser",
|
"name": "@entityseven/rage-fw-browser",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"types": "dist/src/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"readme.md",
|
"readme.md",
|
||||||
"LICENSE",
|
"LICENSE"
|
||||||
"package.json"
|
|
||||||
],
|
],
|
||||||
"main": "src/index.ts",
|
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./dist/index.js"
|
||||||
},
|
|
||||||
"publishConfig": {
|
|
||||||
"main": "dist/index.js",
|
|
||||||
"types": "dist/index.d.ts",
|
|
||||||
"exports": {
|
|
||||||
".": "./dist/index.js"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@entityseven/rage-fw-rpc": "workspace:*"
|
"@entityseven/rage-fw-rpc": "0.2.5",
|
||||||
},
|
"zod": "^3.23.8"
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "22.12.0"
|
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@entityseven/rage-fw-shared-types": "workspace:*",
|
"@entityseven/rage-fw-shared-types": "0.2.0",
|
||||||
"@ragempcommunity/types-cef": "^2.1.8",
|
"@ragempcommunity/types-cef": "^2.1.8"
|
||||||
"typescript": "^5.7.3"
|
|
||||||
},
|
},
|
||||||
"description": "Package used on a browser-side of your Rage:MP Server",
|
"description": "Package used on a browser-side of your Rage:MP Server",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Helper } from './helper'
|
|
||||||
import { rpc } from './rpc'
|
import { rpc } from './rpc'
|
||||||
|
import { Helper } from './helper'
|
||||||
|
import { Validation } from './validation'
|
||||||
import type * as T from '../types'
|
import type * as T from '../types'
|
||||||
|
|
||||||
/** Browser-side interactions */
|
/** Browser-side interactions */
|
||||||
@@ -29,6 +30,8 @@ export class Browser extends Helper {
|
|||||||
*
|
*
|
||||||
* @param eventName - The name of the event to register
|
* @param eventName - The name of the event to register
|
||||||
* @param callback - The callback function to be executed when the event is triggered
|
* @param callback - The callback function to be executed when the event is triggered
|
||||||
|
* @param [options] - Optional settings for callback execution
|
||||||
|
* @param [options.validation] - Validation schema to be checked before the callback executes
|
||||||
* @returns {Browser} The current browser instance, enabling method chaining
|
* @returns {Browser} The current browser instance, enabling method chaining
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@@ -42,14 +45,27 @@ export class Browser extends Helper {
|
|||||||
public register<EventName extends T.RageFW_BrowserEvent>(
|
public register<EventName extends T.RageFW_BrowserEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: T.RageFW_BrowserCallback<EventName>,
|
callback: T.RageFW_BrowserCallback<EventName>,
|
||||||
|
options?: {
|
||||||
|
validation?: T.RageFW_ValidationOptions
|
||||||
|
},
|
||||||
): Browser {
|
): Browser {
|
||||||
this.log_('register', eventName, callback)
|
this.log_('register', eventName, callback)
|
||||||
|
|
||||||
rpc.register<
|
rpc.register<
|
||||||
Parameters<typeof callback>,
|
Parameters<typeof callback>,
|
||||||
ReturnType<typeof callback>,
|
ReturnType<typeof callback> | Promise<unknown>,
|
||||||
EventName
|
EventName
|
||||||
>(eventName, async (...data) => await callback(...data))
|
>(eventName, async (...data) => {
|
||||||
|
if (!options?.validation) return await callback(...data)
|
||||||
|
|
||||||
|
const validationSuccess = Validation.process(
|
||||||
|
data,
|
||||||
|
options?.validation,
|
||||||
|
)
|
||||||
|
if (!validationSuccess) return
|
||||||
|
|
||||||
|
return await callback(...data)
|
||||||
|
})
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import type * as T from '../types'
|
||||||
|
|
||||||
|
export class Validation {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
public static process<EventName extends T.RageFW_BrowserEvent>(
|
||||||
|
args: T.RageFW_BrowserArgs<EventName>,
|
||||||
|
validationOptions?: T.RageFW_ValidationOptions,
|
||||||
|
): boolean {
|
||||||
|
if (!validationOptions) return true
|
||||||
|
|
||||||
|
if ('schema' in validationOptions) {
|
||||||
|
const validationResponse = validationOptions.schema.safeParse(args)
|
||||||
|
|
||||||
|
if (validationResponse.success) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
validationOptions.onError(validationResponse.error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const validationResponse = validationOptions.safeParse(args)
|
||||||
|
return validationResponse.success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './browser'
|
export * from './browser'
|
||||||
export * from './client'
|
export * from './client'
|
||||||
export * from './server'
|
export * from './server'
|
||||||
|
export * from './validation'
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import type { z } from 'zod'
|
||||||
|
|
||||||
|
export type RageFW_ValidationSchema = z.ZodTuple<any, any> | z.ZodArray<any>
|
||||||
|
export type RageFW_ValidationSchemaExtended = {
|
||||||
|
schema: RageFW_ValidationSchema
|
||||||
|
onError: (error: z.ZodError) => unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RageFW_ValidationOptions =
|
||||||
|
| RageFW_ValidationSchema
|
||||||
|
| RageFW_ValidationSchemaExtended
|
||||||
+21
-4
@@ -1,8 +1,25 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json.schemastore.org/tsconfig",
|
"$schema": "https://json.schemastore.org/tsconfig",
|
||||||
"display": "Browser",
|
"display": "Base",
|
||||||
|
"exclude": [
|
||||||
|
"node_modules"
|
||||||
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": ["./node_modules/@ragempcommunity/types-cef/index.d.ts", "node"]
|
"incremental": false,
|
||||||
},
|
"composite": false,
|
||||||
"extends": ["../tsconfig.ragefw.json"]
|
"target": "ES2022",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"moduleDetection": "auto",
|
||||||
|
"module": "CommonJS",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"declaration": false,
|
||||||
|
"declarationMap": false,
|
||||||
|
"sourceMap": false,
|
||||||
|
"downlevelIteration": false,
|
||||||
|
"inlineSourceMap": false,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { defineConfig } from 'tsup'
|
import { defineConfig } from 'tsup'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
entry: ['src/**/*.ts'],
|
entry: ['src/index.ts'],
|
||||||
outDir: './dist',
|
outDir: './dist',
|
||||||
format: ['cjs'],
|
format: ['cjs'],
|
||||||
experimentalDts: true,
|
experimentalDts: true,
|
||||||
splitting: false,
|
splitting: false,
|
||||||
bundle: false,
|
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
clean: true,
|
clean: true,
|
||||||
})
|
})
|
||||||
|
|||||||
+4
-5
@@ -13,8 +13,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "tsc -w",
|
"watch": "tsc -w",
|
||||||
"build": "tsup",
|
"build": "tsup",
|
||||||
"start": "npx ./dist create",
|
"start": "npx ./dist create"
|
||||||
"install": "pnpm install --ignore-workspace"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@inquirer/prompts": "^5.0.5",
|
"@inquirer/prompts": "^5.0.5",
|
||||||
@@ -23,12 +22,12 @@
|
|||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.12.0",
|
"@types/node": "^20.14.2",
|
||||||
"@types/yargs": "^17.0.32",
|
"@types/yargs": "^17.0.32",
|
||||||
"prettier": "^3.3.2",
|
"prettier": "^3.3.2",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.4.5"
|
||||||
},
|
},
|
||||||
"description": "CLI to scaffold a preview for Rage FW",
|
"description": "CLI to scaffold a preview for Rage-FW",
|
||||||
"keywords": ["create-rage-fw","ragefw-cli", "ragefw", "rage-fw", "ragemp", "rage:mp", "rage", "gta5"],
|
"keywords": ["create-rage-fw","ragefw-cli", "ragefw", "rage-fw", "ragemp", "rage:mp", "rage", "gta5"],
|
||||||
"author": "Entity Seven Group",
|
"author": "Entity Seven Group",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
|||||||
Generated
-488
@@ -1,488 +0,0 @@
|
|||||||
lockfileVersion: '9.0'
|
|
||||||
|
|
||||||
settings:
|
|
||||||
autoInstallPeers: true
|
|
||||||
excludeLinksFromLockfile: false
|
|
||||||
|
|
||||||
importers:
|
|
||||||
|
|
||||||
.:
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/prompts':
|
|
||||||
specifier: ^5.0.5
|
|
||||||
version: 5.5.0
|
|
||||||
chalk:
|
|
||||||
specifier: 4.1.2
|
|
||||||
version: 4.1.2
|
|
||||||
ky:
|
|
||||||
specifier: ^1.7.2
|
|
||||||
version: 1.7.4
|
|
||||||
yargs:
|
|
||||||
specifier: ^17.7.2
|
|
||||||
version: 17.7.2
|
|
||||||
devDependencies:
|
|
||||||
'@types/node':
|
|
||||||
specifier: ^22.12.0
|
|
||||||
version: 22.12.0
|
|
||||||
'@types/yargs':
|
|
||||||
specifier: ^17.0.32
|
|
||||||
version: 17.0.33
|
|
||||||
prettier:
|
|
||||||
specifier: ^3.3.2
|
|
||||||
version: 3.4.2
|
|
||||||
typescript:
|
|
||||||
specifier: ^5.7.3
|
|
||||||
version: 5.7.3
|
|
||||||
|
|
||||||
packages:
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-sMgdETOfi2dUHT8r7TT1BTKOwNvdDGFDXYWtQ2J69SvlYNntk9I/gJe7r5yvMwwsuKnYbuRs3pNhx4tgNck5aA==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-oOIwPs0Dvq5220Z8lGL/6LHRTEr9TgLHmiI99Rj1PJ1p1czTys+olrgBqZk4E2qC0YTzeHprxSQmoHioVdJ7Lw==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-F2VBt7W/mwqEU4bL0RnHNZmC/OxzNx9cOYxHqnXX3MP6ruYvZUZAW9imgN9+h/uBT/oP8Gh888J2OZSbjSeWcg==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-9KHOpJ+dIL5SZli8lJ6xdaYLPPzB8xB9GZItg39MBybzhxA16vxmszmQFrRwbOA918WA2rvu8xhDEg/p6LXKbw==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-qnJsUcOGCSG1e5DTOErmv2BPQqrtT6uzqn1vI/aYGiPKq+FgslGZmtdnXbhuI7IlT7OByDoEEqdnhUnVR2hhLw==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-BXvGj0ehzrngHTPTDqUoDT3NXL8U0RxUk2zJm2A66RhCEIWdtU1v6GuUqNAgArW4PQ9CinqIWyHdQgdwOj06zQ==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-XfnpCStx2xgh1LIRqPXrTNEEByqQWoxsWYzNRSEUxJ5c6EQlhMogJ3vHKu8aXuTacebtaZzMAHwEL0kAflKOBw==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-ilUnia/GZUtfSZy3YEErXLJ2Sljo/mf9fiKc08n18DdwdmDbOzRcTv65H1jjDvlsAuvdFXf4Sa/aL7iw/NanVA==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-5otqIpgsPYIshqhgtEwSspBQE40etouR8VIxzpJkv9i0dVHIpyhiivbkH9/dGiMLdyamT54YRdGJLfl8TFnLHg==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-BHDeL0catgHdcHbSFFUddNzvx/imzJMft+tWDPwTm3hfu8/tApk1HrooNngB2Mb4qY+KaRWF+iZqoVUPeslEog==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-zzfNuINhFF7OLAtGHfhwOW2TlYJyli7lOUoJUXw/uyklcwalV6WRXBXtFIicN8rTRK1XTiPWB4UY+YuW8dsnLQ==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-h+/5LSj51dx7hp5xOn4QFnUaKeARwUCLs6mIhtkJ0JYPBLmEYjdHSYh7I6GrLg9LwpJ3xeX0FZgAG1q0QdCpVQ==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-YmDobTItPP3WcEI86GvPo+T2sRHkxxOq/kXmsBjHS5BVXUgvgZ5AfJjkvQvZr03T81NnI3KrrRuMzeuYUQRFOA==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-MzICLu4yS7V8AA61sANROZ9vT1H3ooca5dSmI1FjZkzq7o/koMsRfQSzRtFo+F3Ao4Sf1C0bpLKejpKB/+j6MA==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
resolution: {integrity: sha512-XvJRx+2KR3YXyYtPUUy+qd9i7p+GO9Ko6VIIpWlBrpWwXDv8WLFeHTxz35CfQFUiBMLXlGHhGzys7lqit9gWag==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
resolution: {integrity: sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==}
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
resolution: {integrity: sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==}
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
resolution: {integrity: sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==}
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==}
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
resolution: {integrity: sha512-WpxBCKWPLr4xSsHgz511rFJAM+wS28w2zEO1QDNY5zM/S8ok70NNfztH0xwhqKyaK0OHCbN98LDAZuy1ctxDkA==}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
|
||||||
engines: {node: '>=10'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==}
|
|
||||||
engines: {node: '>= 12'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==}
|
|
||||||
engines: {node: '>=7.0.0'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==}
|
|
||||||
engines: {node: '>=6'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==}
|
|
||||||
engines: {node: '>=4'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
|
|
||||||
engines: {node: 6.* || 8.* || >= 10.*}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
|
|
||||||
engines: {node: '>=0.10.0'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-zYEr/gh7uLW2l4su11bmQ2M9xLgQLjyvx58UyNM/6nuqyWFHPX5ktMjvpev3F8QWdjSsHUpnWew4PBCswBNuMQ==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==}
|
|
||||||
engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==}
|
|
||||||
engines: {node: '>=0.10.0'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==}
|
|
||||||
engines: {node: '>=14'}
|
|
||||||
hasBin: true
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==}
|
|
||||||
engines: {node: '>=0.10.0'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==}
|
|
||||||
engines: {node: '>=14'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==}
|
|
||||||
engines: {node: '>=0.6.0'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==}
|
|
||||||
engines: {node: '>=10'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==}
|
|
||||||
engines: {node: '>=14.17'}
|
|
||||||
hasBin: true
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==}
|
|
||||||
engines: {node: '>=10'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
|
|
||||||
engines: {node: '>=10'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
resolution: {integrity: sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA==}
|
|
||||||
engines: {node: '>=18'}
|
|
||||||
|
|
||||||
snapshots:
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/figures': 1.0.9
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
ansi-escapes: 4.3.2
|
|
||||||
yoctocolors-cjs: 2.1.2
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/figures': 1.0.9
|
|
||||||
'@inquirer/type': 2.0.0
|
|
||||||
'@types/mute-stream': 0.0.4
|
|
||||||
'@types/node': 22.12.0
|
|
||||||
'@types/wrap-ansi': 3.0.0
|
|
||||||
ansi-escapes: 4.3.2
|
|
||||||
cli-width: 4.1.0
|
|
||||||
mute-stream: 1.0.0
|
|
||||||
signal-exit: 4.1.0
|
|
||||||
strip-ansi: 6.0.1
|
|
||||||
wrap-ansi: 6.2.0
|
|
||||||
yoctocolors-cjs: 2.1.2
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
external-editor: 3.1.0
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
yoctocolors-cjs: 2.1.2
|
|
||||||
|
|
||||||
'@inquirer/[email protected]': {}
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
ansi-escapes: 4.3.2
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/checkbox': 2.5.0
|
|
||||||
'@inquirer/confirm': 3.2.0
|
|
||||||
'@inquirer/editor': 2.2.0
|
|
||||||
'@inquirer/expand': 2.3.0
|
|
||||||
'@inquirer/input': 2.3.0
|
|
||||||
'@inquirer/number': 1.1.0
|
|
||||||
'@inquirer/password': 2.2.0
|
|
||||||
'@inquirer/rawlist': 2.3.0
|
|
||||||
'@inquirer/search': 1.1.0
|
|
||||||
'@inquirer/select': 2.5.0
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
yoctocolors-cjs: 2.1.2
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/figures': 1.0.9
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
yoctocolors-cjs: 2.1.2
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@inquirer/core': 9.2.1
|
|
||||||
'@inquirer/figures': 1.0.9
|
|
||||||
'@inquirer/type': 1.5.5
|
|
||||||
ansi-escapes: 4.3.2
|
|
||||||
yoctocolors-cjs: 2.1.2
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
mute-stream: 1.0.0
|
|
||||||
|
|
||||||
'@inquirer/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
mute-stream: 1.0.0
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@types/node': 22.12.0
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
undici-types: 6.20.0
|
|
||||||
|
|
||||||
'@types/[email protected]': {}
|
|
||||||
|
|
||||||
'@types/[email protected]': {}
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
dependencies:
|
|
||||||
'@types/yargs-parser': 21.0.3
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
type-fest: 0.21.3
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
color-convert: 2.0.1
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
ansi-styles: 4.3.0
|
|
||||||
supports-color: 7.2.0
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
string-width: 4.2.3
|
|
||||||
strip-ansi: 6.0.1
|
|
||||||
wrap-ansi: 7.0.0
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
color-name: 1.1.4
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
chardet: 0.7.0
|
|
||||||
iconv-lite: 0.4.24
|
|
||||||
tmp: 0.0.33
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
safer-buffer: 2.1.2
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
emoji-regex: 8.0.0
|
|
||||||
is-fullwidth-code-point: 3.0.0
|
|
||||||
strip-ansi: 6.0.1
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
ansi-regex: 5.0.1
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
has-flag: 4.0.0
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
os-tmpdir: 1.0.2
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
ansi-styles: 4.3.0
|
|
||||||
string-width: 4.2.3
|
|
||||||
strip-ansi: 6.0.1
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
ansi-styles: 4.3.0
|
|
||||||
string-width: 4.2.3
|
|
||||||
strip-ansi: 6.0.1
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
|
|
||||||
[email protected]:
|
|
||||||
dependencies:
|
|
||||||
cliui: 8.0.1
|
|
||||||
escalade: 3.2.0
|
|
||||||
get-caller-file: 2.0.5
|
|
||||||
require-directory: 2.1.1
|
|
||||||
string-width: 4.2.3
|
|
||||||
y18n: 5.0.8
|
|
||||||
yargs-parser: 21.1.1
|
|
||||||
|
|
||||||
[email protected]: {}
|
|
||||||
+13
-20
@@ -3,22 +3,9 @@ import { input, select } from '@inquirer/prompts'
|
|||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { cloneBranch } from '../utils/cloner'
|
import { cloneBranch } from '../utils/cloner'
|
||||||
|
|
||||||
const choices = {
|
|
||||||
'react-18': {
|
|
||||||
name: 'React 18',
|
|
||||||
value: 'react-18',
|
|
||||||
description: 'React 18 + TypeScript (Vite) as a front-end',
|
|
||||||
},
|
|
||||||
'svelte-5': {
|
|
||||||
name: 'Svelte 5',
|
|
||||||
value: 'svelte-5',
|
|
||||||
description: 'Svelte 5 + TypeScript (Vite) as a front-end',
|
|
||||||
},
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export async function initProject() {
|
export async function initProject() {
|
||||||
let folder: string | undefined
|
let folder
|
||||||
let framework: keyof typeof choices | undefined
|
let framework
|
||||||
|
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
folder = await input({
|
folder = await input({
|
||||||
@@ -34,17 +21,23 @@ export async function initProject() {
|
|||||||
message: c.gray('Select front-end:'),
|
message: c.gray('Select front-end:'),
|
||||||
default: 'react-18',
|
default: 'react-18',
|
||||||
loop: true,
|
loop: true,
|
||||||
choices: Object.values(choices),
|
choices: [
|
||||||
|
{
|
||||||
|
name: 'React 18',
|
||||||
|
value: 'react-18',
|
||||||
|
description: 'React 18 + TypeScript (Vite) as a front-end',
|
||||||
|
},
|
||||||
|
],
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log(c.gray('Front-end:'), choices[framework].name)
|
console.log(c.gray('Front-end:'), framework)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
c.gray('\nScaffolding template project into'),
|
c.gray('\nScaffolding template project into'),
|
||||||
folder,
|
folder,
|
||||||
c.gray('with'),
|
c.gray('with'),
|
||||||
choices[framework].name,
|
framework,
|
||||||
c.gray('as a front-end..'),
|
c.gray('as a front-end..'),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,12 +50,12 @@ export async function initProject() {
|
|||||||
console.log(c.gray('Scaffolded project into'), folder)
|
console.log(c.gray('Scaffolded project into'), folder)
|
||||||
console.log(
|
console.log(
|
||||||
c.gray(
|
c.gray(
|
||||||
`Project was created in: ${path.join(process.cwd(), folder)}`,
|
`Project was created ar dir: ${path.join(process.cwd(), folder)}`,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(c.red('Error occurred: \n', e))
|
console.log(c.red('Error occured: \n', e))
|
||||||
console.log(c.red('Please open an issue if you see this'))
|
console.log(c.red('Please open an issue if you see this'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ const choices = {
|
|||||||
} as const
|
} as const
|
||||||
|
|
||||||
export async function testRpc() {
|
export async function testRpc() {
|
||||||
let folder: string | undefined
|
let folder
|
||||||
let framework: keyof typeof choices | undefined
|
let framework
|
||||||
|
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
folder = await input({
|
folder = await input({
|
||||||
@@ -37,7 +37,7 @@ export async function testRpc() {
|
|||||||
choices: Object.values(choices),
|
choices: Object.values(choices),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log(c.gray('Front-end:'), choices[framework].name)
|
console.log(c.gray('Front-end:'), framework)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
@@ -45,7 +45,7 @@ export async function testRpc() {
|
|||||||
folder,
|
folder,
|
||||||
c.gray('with'),
|
c.gray('with'),
|
||||||
choices[framework].name,
|
choices[framework].name,
|
||||||
c.gray('as a frontend'),
|
c.gray('as a frontend..'),
|
||||||
)
|
)
|
||||||
|
|
||||||
cloneBranch(
|
cloneBranch(
|
||||||
@@ -62,7 +62,7 @@ export async function testRpc() {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(c.red('Error occurred: \n', e))
|
console.log(c.red('Error occured: \n', e))
|
||||||
console.log(c.red('Please open an issue if you see this'))
|
console.log(c.red('Please open an issue if you see this'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"target": "es6",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"lib": ["DOM", "esnext"],
|
"lib": ["DOM", "ES6"],
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Custom Attribution-NoDerives Software License
|
Custom Attribution-NoDerivs Software License
|
||||||
|
|
||||||
Copyright (c) 2024 Entity Seven Group
|
Copyright (c) 2024 Entity Seven Group
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
+8
-20
@@ -1,38 +1,26 @@
|
|||||||
{
|
{
|
||||||
"private": false,
|
|
||||||
"name": "@entityseven/rage-fw-client",
|
"name": "@entityseven/rage-fw-client",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"types": "dist/src/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"readme.md",
|
"readme.md",
|
||||||
"LICENSE",
|
"LICENSE"
|
||||||
"package.json"
|
|
||||||
],
|
],
|
||||||
"main": "src/index.ts",
|
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./dist/index.js"
|
||||||
},
|
|
||||||
"publishConfig": {
|
|
||||||
"main": "dist/index.js",
|
|
||||||
"types": "dist/index.d.ts",
|
|
||||||
"exports": {
|
|
||||||
".": "./dist/index.js"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@entityseven/rage-fw-rpc": "workspace:*",
|
"@entityseven/rage-fw-rpc": "0.2.5",
|
||||||
"zod": "^3.24.1"
|
"zod": "^3.23.8"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "22.12.0"
|
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@entityseven/rage-fw-shared-types": "workspace:*",
|
"@entityseven/rage-fw-shared-types": "0.2.0",
|
||||||
"@ragempcommunity/types-client": "^2.1.8",
|
"@ragempcommunity/types-client": "^2.1.8"
|
||||||
"typescript": "^5.7.3"
|
|
||||||
},
|
},
|
||||||
"description": "Package used on a client-side of your Rage:MP Server",
|
"description": "Package used on a client-side of your Rage:MP Server",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { rpc } from './rpc'
|
import { rpc } from './rpc'
|
||||||
import { Middleware } from './middleware'
|
import { Middleware } from './middleware'
|
||||||
|
import { Validation } from './validation'
|
||||||
import type * as T from '../types'
|
import type * as T from '../types'
|
||||||
|
|
||||||
/** Client-side interactions */
|
/** Client-side interactions */
|
||||||
@@ -10,6 +11,7 @@ export class Client {
|
|||||||
* @param eventName - The name of the event to register
|
* @param eventName - The name of the event to register
|
||||||
* @param callback - The callback function to be executed when the event is triggered
|
* @param callback - The callback function to be executed when the event is triggered
|
||||||
* @param [options] - Optional settings for callback execution
|
* @param [options] - Optional settings for callback execution
|
||||||
|
* @param [options.validation] - Validation schema to be checked before the callback executes
|
||||||
* @param [options.middlewares] - Middleware functions to be checked before the callback executes
|
* @param [options.middlewares] - Middleware functions to be checked before the callback executes
|
||||||
* @returns {Client} The current client instance, enabling method chaining
|
* @returns {Client} The current client instance, enabling method chaining
|
||||||
*
|
*
|
||||||
@@ -44,6 +46,7 @@ export class Client {
|
|||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: T.RageFW_ClientCallback<EventName>,
|
callback: T.RageFW_ClientCallback<EventName>,
|
||||||
options?: {
|
options?: {
|
||||||
|
validation?: T.RageFW_ValidationOptions
|
||||||
middlewares?: T.RageFW_MiddlewareOptions<EventName>
|
middlewares?: T.RageFW_MiddlewareOptions<EventName>
|
||||||
},
|
},
|
||||||
): Client {
|
): Client {
|
||||||
@@ -52,9 +55,22 @@ export class Client {
|
|||||||
ReturnType<typeof callback> | Promise<unknown>,
|
ReturnType<typeof callback> | Promise<unknown>,
|
||||||
EventName
|
EventName
|
||||||
>(eventName, async (...data) => {
|
>(eventName, async (...data) => {
|
||||||
if (!options?.middlewares) return await callback(...data)
|
if (!options?.middlewares && !options?.validation)
|
||||||
|
return await callback(...data)
|
||||||
|
|
||||||
await Middleware.process(options.middlewares, callback, data)
|
const validationSuccess = Validation.process(
|
||||||
|
data,
|
||||||
|
options?.validation,
|
||||||
|
)
|
||||||
|
if (!validationSuccess) return
|
||||||
|
|
||||||
|
const middlewaresSuccess = await Middleware.process(
|
||||||
|
data,
|
||||||
|
options?.middlewares,
|
||||||
|
)
|
||||||
|
if (!middlewaresSuccess) return
|
||||||
|
|
||||||
|
return await callback(...data)
|
||||||
})
|
})
|
||||||
|
|
||||||
return this
|
return this
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
export * from './client'
|
export * from './client'
|
||||||
export * from './logger'
|
export * from './logger'
|
||||||
export * from './middleware'
|
|
||||||
export * from './player'
|
export * from './player'
|
||||||
export * from './rpc'
|
export * from './rpc'
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ export class Middleware {
|
|||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
private static async execute<EventName extends T.RageFW_ClientEvent>(
|
private static async execute<EventName extends T.RageFW_ClientEvent>(
|
||||||
middlewares: T.RageFW_MiddlewareFunction<EventName>[],
|
|
||||||
args: T.RageFW_ClientArgs<EventName>,
|
args: T.RageFW_ClientArgs<EventName>,
|
||||||
|
middlewares: T.RageFW_MiddlewareFunction<EventName>[],
|
||||||
): Promise<T.RageFW_MiddlewareResponseInternal> {
|
): Promise<T.RageFW_MiddlewareResponseInternal> {
|
||||||
for (let i = 0; i < middlewares.length; i++) {
|
for (let i = 0; i < middlewares.length; i++) {
|
||||||
const result = await middlewares[i](...args)
|
const result = await middlewares[i](...args)
|
||||||
@@ -22,25 +22,25 @@ export class Middleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async process<EventName extends T.RageFW_ClientEvent>(
|
public static async process<EventName extends T.RageFW_ClientEvent>(
|
||||||
middlewareOptions: T.RageFW_MiddlewareOptions<EventName>,
|
|
||||||
callback: T.RageFW_ClientCallback<EventName>,
|
|
||||||
args: T.RageFW_ClientArgs<EventName>,
|
args: T.RageFW_ClientArgs<EventName>,
|
||||||
) {
|
middlewareOptions?: T.RageFW_MiddlewareOptions<EventName>,
|
||||||
|
): Promise<boolean> {
|
||||||
|
if (!middlewareOptions) return true
|
||||||
|
|
||||||
if (Array.isArray(middlewareOptions)) {
|
if (Array.isArray(middlewareOptions)) {
|
||||||
const middlewaresResponse = await Middleware.execute(
|
const middlewaresResponse = await Middleware.execute(
|
||||||
middlewareOptions,
|
|
||||||
args,
|
args,
|
||||||
|
middlewareOptions,
|
||||||
)
|
)
|
||||||
|
return middlewaresResponse.success
|
||||||
if (middlewaresResponse.success) return await callback(...args)
|
|
||||||
} else {
|
} else {
|
||||||
const middlewaresResponse = await Middleware.execute(
|
const middlewaresResponse = await Middleware.execute(
|
||||||
middlewareOptions.executables,
|
|
||||||
args,
|
args,
|
||||||
|
middlewareOptions.executables,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (middlewaresResponse.success) {
|
if (middlewaresResponse.success) {
|
||||||
return await callback(...args)
|
return true
|
||||||
} else {
|
} else {
|
||||||
middlewareOptions.onError(
|
middlewareOptions.onError(
|
||||||
middlewaresResponse.message ??
|
middlewaresResponse.message ??
|
||||||
@@ -48,6 +48,7 @@ export class Middleware {
|
|||||||
middlewaresResponse.id +
|
middlewaresResponse.id +
|
||||||
' failed',
|
' failed',
|
||||||
)
|
)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import type * as T from '../types'
|
||||||
|
|
||||||
|
export class Validation {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
public static process<EventName extends T.RageFW_ClientEvent>(
|
||||||
|
args: T.RageFW_ClientArgs<EventName>,
|
||||||
|
validationOptions?: T.RageFW_ValidationOptions,
|
||||||
|
): boolean {
|
||||||
|
if (!validationOptions) return true
|
||||||
|
|
||||||
|
if ('schema' in validationOptions) {
|
||||||
|
const validationResponse = validationOptions.schema.safeParse(args)
|
||||||
|
|
||||||
|
if (validationResponse.success) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
validationOptions.onError(validationResponse.error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const validationResponse = validationOptions.safeParse(args)
|
||||||
|
return validationResponse.success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,3 +2,4 @@ export * from './browser'
|
|||||||
export * from './client'
|
export * from './client'
|
||||||
export * from './middleware'
|
export * from './middleware'
|
||||||
export * from './server'
|
export * from './server'
|
||||||
|
export * from './validation'
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import type { z } from 'zod'
|
||||||
|
|
||||||
|
export type RageFW_ValidationSchema = z.ZodTuple<any, any> | z.ZodArray<any>
|
||||||
|
export type RageFW_ValidationSchemaExtended = {
|
||||||
|
schema: RageFW_ValidationSchema
|
||||||
|
onError: (error: z.ZodError) => unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RageFW_ValidationOptions =
|
||||||
|
| RageFW_ValidationSchema
|
||||||
|
| RageFW_ValidationSchemaExtended
|
||||||
+21
-4
@@ -1,8 +1,25 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json.schemastore.org/tsconfig",
|
"$schema": "https://json.schemastore.org/tsconfig",
|
||||||
"display": "Client",
|
"display": "Base",
|
||||||
|
"exclude": [
|
||||||
|
"node_modules"
|
||||||
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": ["./node_modules/@ragempcommunity/types-client/index.d.ts"]
|
"incremental": false,
|
||||||
},
|
"composite": false,
|
||||||
"extends": ["../tsconfig.ragefw.json"]
|
"target": "ES2022",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"moduleDetection": "auto",
|
||||||
|
"module": "CommonJS",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"declaration": false,
|
||||||
|
"declarationMap": false,
|
||||||
|
"sourceMap": false,
|
||||||
|
"downlevelIteration": false,
|
||||||
|
"inlineSourceMap": false,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { defineConfig } from 'tsup'
|
import { defineConfig } from 'tsup'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
entry: ['src/**/*.ts'],
|
entry: ['src/index.ts'],
|
||||||
outDir: './dist',
|
outDir: './dist',
|
||||||
format: ['cjs'],
|
format: ['cjs'],
|
||||||
experimentalDts: true,
|
experimentalDts: true,
|
||||||
splitting: false,
|
splitting: false,
|
||||||
bundle: false,
|
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
clean: true,
|
clean: true,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
import globals from 'globals'
|
|
||||||
import pluginJs from '@eslint/js'
|
|
||||||
import tseslint from 'typescript-eslint'
|
|
||||||
|
|
||||||
import type { Linter } from 'eslint'
|
|
||||||
|
|
||||||
export default [
|
|
||||||
{
|
|
||||||
ignores: ['**/.*/*', '**/dist/*', '**/node_modules/*', '*.config.*'],
|
|
||||||
},
|
|
||||||
pluginJs.configs.recommended,
|
|
||||||
...(tseslint.configs.recommended as Linter.Config[]),
|
|
||||||
{
|
|
||||||
name: 'global',
|
|
||||||
rules: {
|
|
||||||
'@typescript-eslint/no-explicit-any': 'off',
|
|
||||||
'@typescript-eslint/no-unused-vars': [
|
|
||||||
'warn',
|
|
||||||
{
|
|
||||||
argsIgnorePattern: '^_',
|
|
||||||
varsIgnorePattern: '^_',
|
|
||||||
caughtErrorsIgnorePattern: '^_',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'@typescript-eslint/ban-ts-comment': 'off',
|
|
||||||
'@typescript-eslint/ban-types': 'off',
|
|
||||||
'consistent-return': 'off',
|
|
||||||
'no-empty': 'off',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'browser/rpc',
|
|
||||||
files: ['browser/src/*.{ts,js}', 'rpc/src/*.{ts,js}'],
|
|
||||||
languageOptions: {
|
|
||||||
globals: { ...globals.browser, ...globals.node, ...globals.es2022 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'cli',
|
|
||||||
files: ['cli/src/*.{ts,js}'],
|
|
||||||
languageOptions: {
|
|
||||||
globals: { ...globals.node, ...globals.es2024 },
|
|
||||||
ecmaVersion: 2024,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'client/server/shared',
|
|
||||||
files: [
|
|
||||||
'client/**/*.{ts,js}',
|
|
||||||
'server/**/*.{ts,js}',
|
|
||||||
'shared/**/*.{ts,js}',
|
|
||||||
],
|
|
||||||
languageOptions: {
|
|
||||||
globals: { ...globals.node, ...globals.es2022 },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
] satisfies Linter.Config[]
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||||
|
"version": "0.2.1-0.2.0-alpha.2.0",
|
||||||
|
"npmClient": "pnpm"
|
||||||
|
}
|
||||||
+20
-40
@@ -1,46 +1,29 @@
|
|||||||
{
|
{
|
||||||
"workspaces": [
|
|
||||||
"*",
|
|
||||||
"!cli"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint . --config eslint.config.ts",
|
"publish": "lerna publish --force-publish",
|
||||||
"_____build": "echo build",
|
"build": "lerna run build",
|
||||||
"build:browser": "cd browser && pnpm build",
|
"lint": "eslint --c .eslintrc.yaml --ext .ts client/ server/ shared-types/",
|
||||||
"build:client": "cd client && pnpm build",
|
|
||||||
"build:server": "cd server && pnpm build",
|
"rebuild:browser": "cd browser && pnpm build",
|
||||||
"build:rpc": "cd rpc && pnpm build",
|
"rebuild:client": "cd client && pnpm build",
|
||||||
"build": "pnpm build:browser && pnpm build:client && pnpm build:server && pnpm build:rpc",
|
"rebuild:server": "cd server && pnpm build",
|
||||||
"_____deps": "echo must be ran before lerna commands",
|
"rebuild": "pnpm rebuild:browser && pnpm rebuild:client && pnpm rebuild:server"
|
||||||
"deps:check": "syncpack list-mismatches",
|
|
||||||
"deps:fix": "syncpack fix-mismatches",
|
|
||||||
"_____publish": "echo publish",
|
|
||||||
"publish:check": "pnpm run deps:check && pnpm run lint",
|
|
||||||
"publish:changeset": "pnpm changeset add",
|
|
||||||
"publish:version": "pnpm changeset version"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@changesets/cli": "^2.27.12",
|
"@microsoft/api-extractor": "^7.47.0",
|
||||||
"@eslint/js": "^9.19.0",
|
|
||||||
"@microsoft/api-extractor": "^7.49.1",
|
|
||||||
"@ragempcommunity/types-cef": "^2.1.8",
|
"@ragempcommunity/types-cef": "^2.1.8",
|
||||||
"@ragempcommunity/types-client": "^2.1.8",
|
"@ragempcommunity/types-client": "^2.1.8",
|
||||||
"@ragempcommunity/types-server": "^2.1.8",
|
"@ragempcommunity/types-server": "^2.1.8",
|
||||||
"eslint": "^9.19.0",
|
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
||||||
"globals": "^15.14.0",
|
"@typescript-eslint/parser": "^7.13.0",
|
||||||
"jiti": "^2.4.2",
|
"@types/node": "^22.8.1",
|
||||||
"prettier": "^3.4.2",
|
"eslint": "^8.56.0",
|
||||||
"tsup": "^8.3.6",
|
"lerna": "^8.1.3",
|
||||||
"typescript": "^5.7.3",
|
"prettier": "^3.3.1",
|
||||||
"typescript-eslint": "^8.22.0",
|
"rage-rpc": "^0.4.0",
|
||||||
"winston": "^3.17.0"
|
"tsup": "^8.1.0",
|
||||||
},
|
"typescript": "^5.4.5",
|
||||||
"engines": {
|
"winston": "^3.13.0"
|
||||||
"node": ">=14",
|
|
||||||
"pnpm": ">=10"
|
|
||||||
},
|
|
||||||
"pnpm": {
|
|
||||||
"requiredScripts": []
|
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -57,8 +40,5 @@
|
|||||||
"email": "[email protected]",
|
"email": "[email protected]",
|
||||||
"url": "https://github.com/SashaGoncharov19/"
|
"url": "https://github.com/SashaGoncharov19/"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"devDependencies": {
|
|
||||||
"syncpack": "^13.0.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+4355
-1345
File diff suppressed because it is too large
Load Diff
+4
-2
@@ -1,3 +1,5 @@
|
|||||||
packages:
|
packages:
|
||||||
- "*"
|
- "server"
|
||||||
- "!cli"
|
- "client"
|
||||||
|
- "browser"
|
||||||
|
- "shared-types"
|
||||||
+4
-3
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"private": false,
|
|
||||||
"name": "@entityseven/rage-fw-rpc",
|
"name": "@entityseven/rage-fw-rpc",
|
||||||
"version": "0.2.5",
|
"version": "0.2.5",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@@ -14,10 +13,12 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "22.12.0"
|
"@microsoft/api-extractor": "^7.47.9",
|
||||||
|
"prettier": "^3.3.2",
|
||||||
|
"tsup": "^8.3.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5"
|
||||||
},
|
},
|
||||||
"description": "Rage-FW RPC (Remote procedure caller) for Rage:MP",
|
"description": "Rage-FW RPC (Remote procedure caller) for Rage:MP",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ export class Browser extends Wrapper {
|
|||||||
* NOT INTENDED FOR OUT-OF-CONTEXT USE
|
* NOT INTENDED FOR OUT-OF-CONTEXT USE
|
||||||
*/
|
*/
|
||||||
public _resolveEmitDestination(dataRaw: string) {
|
public _resolveEmitDestination(dataRaw: string) {
|
||||||
const state = Utils.prepareExecution(dataRaw)
|
let state = Utils.prepareExecution(dataRaw)
|
||||||
|
|
||||||
switch (state.calledTo) {
|
switch (state.calledTo) {
|
||||||
case Environment.BROWSER:
|
case Environment.BROWSER:
|
||||||
|
|||||||
+53
-53
@@ -91,7 +91,7 @@ class Rpc extends Wrapper {
|
|||||||
*/
|
*/
|
||||||
public register<
|
public register<
|
||||||
CallbackArguments extends unknown[] = unknown[],
|
CallbackArguments extends unknown[] = unknown[],
|
||||||
CallbackReturn = unknown,
|
CallbackReturn extends unknown = unknown,
|
||||||
EventName extends string = string,
|
EventName extends string = string,
|
||||||
>(
|
>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
@@ -155,7 +155,7 @@ class Rpc extends Wrapper {
|
|||||||
public async callClient<
|
public async callClient<
|
||||||
Arguments extends unknown[] = unknown[],
|
Arguments extends unknown[] = unknown[],
|
||||||
EventName extends string = string,
|
EventName extends string = string,
|
||||||
Return = unknown,
|
Return extends unknown = unknown,
|
||||||
>(eventName: EventName, args?: Arguments): Promise<Return>
|
>(eventName: EventName, args?: Arguments): Promise<Return>
|
||||||
/**
|
/**
|
||||||
* Calls a client-side event from server or browser
|
* Calls a client-side event from server or browser
|
||||||
@@ -178,28 +178,37 @@ class Rpc extends Wrapper {
|
|||||||
public async callClient<
|
public async callClient<
|
||||||
Arguments extends unknown[] = unknown[],
|
Arguments extends unknown[] = unknown[],
|
||||||
EventName extends string = string,
|
EventName extends string = string,
|
||||||
Return = unknown,
|
Return extends unknown = unknown,
|
||||||
>(player: PlayerMp, eventName: EventName, args?: Arguments): Promise<Return>
|
>(player: PlayerMp, eventName: EventName, args?: Arguments): Promise<Return>
|
||||||
public async callClient(
|
public async callClient(
|
||||||
playerOrEventName: PlayerMp | string,
|
playerOrEventName: PlayerMp | string,
|
||||||
eventNameOrArgs?: string | unknown[],
|
eventNameOrArgs?: string | unknown[],
|
||||||
args?: unknown[],
|
args?: unknown[],
|
||||||
) {
|
) {
|
||||||
if (_is1StParamPlayer(playerOrEventName)) {
|
_is1StParamPlayer(playerOrEventName)
|
||||||
this.log(
|
? this.log(
|
||||||
'callClient',
|
'callClient',
|
||||||
eventNameOrArgs as string,
|
eventNameOrArgs as string,
|
||||||
playerOrEventName,
|
playerOrEventName,
|
||||||
eventNameOrArgs,
|
eventNameOrArgs,
|
||||||
args,
|
args,
|
||||||
)
|
)
|
||||||
} else {
|
: this.log(
|
||||||
this.log('callClient', playerOrEventName as string, eventNameOrArgs)
|
'callClient',
|
||||||
}
|
playerOrEventName as string,
|
||||||
|
eventNameOrArgs,
|
||||||
|
)
|
||||||
if (this.forceBrowserDevMode_) return
|
if (this.forceBrowserDevMode_) return
|
||||||
Utils.errorUnknownEnvironment(this.environment_)
|
Utils.errorUnknownEnvironment(this.environment_)
|
||||||
|
|
||||||
|
function _is1StParamPlayer(x: unknown): x is PlayerMp {
|
||||||
|
return typeof x === 'object'
|
||||||
|
}
|
||||||
|
|
||||||
|
function _is2NdParamEventName(x: unknown): x is string {
|
||||||
|
return typeof x === 'string'
|
||||||
|
}
|
||||||
|
|
||||||
if (this.environment_ === Environment.CLIENT) {
|
if (this.environment_ === Environment.CLIENT) {
|
||||||
// client
|
// client
|
||||||
return await this.call(
|
return await this.call(
|
||||||
@@ -251,14 +260,6 @@ class Rpc extends Wrapper {
|
|||||||
mp.trigger(Events.LOCAL_EVENT_LISTENER, dataRaw)
|
mp.trigger(Events.LOCAL_EVENT_LISTENER, dataRaw)
|
||||||
return (await this.responseHandler(state.uuid)).data
|
return (await this.responseHandler(state.uuid)).data
|
||||||
}
|
}
|
||||||
|
|
||||||
function _is1StParamPlayer(x: unknown): x is PlayerMp {
|
|
||||||
return typeof x === 'object'
|
|
||||||
}
|
|
||||||
|
|
||||||
function _is2NdParamEventName(x: unknown): x is string {
|
|
||||||
return typeof x === 'string'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -281,7 +282,7 @@ class Rpc extends Wrapper {
|
|||||||
public async callServer<
|
public async callServer<
|
||||||
Arguments extends unknown[] = unknown[],
|
Arguments extends unknown[] = unknown[],
|
||||||
EventName extends string = string,
|
EventName extends string = string,
|
||||||
Return = unknown,
|
Return extends unknown = unknown,
|
||||||
>(eventName: EventName, args?: Arguments): Promise<Return> {
|
>(eventName: EventName, args?: Arguments): Promise<Return> {
|
||||||
this.log('callServer', eventName, args)
|
this.log('callServer', eventName, args)
|
||||||
if (this.forceBrowserDevMode_)
|
if (this.forceBrowserDevMode_)
|
||||||
@@ -336,7 +337,7 @@ class Rpc extends Wrapper {
|
|||||||
public async callBrowser<
|
public async callBrowser<
|
||||||
Arguments extends unknown[] = unknown[],
|
Arguments extends unknown[] = unknown[],
|
||||||
EventName extends string = string,
|
EventName extends string = string,
|
||||||
Return = unknown,
|
Return extends unknown = unknown,
|
||||||
>(eventName: EventName, args?: Arguments): Promise<Return>
|
>(eventName: EventName, args?: Arguments): Promise<Return>
|
||||||
/**
|
/**
|
||||||
* Calls a browser-side event from server or client
|
* Calls a browser-side event from server or client
|
||||||
@@ -359,32 +360,37 @@ class Rpc extends Wrapper {
|
|||||||
public async callBrowser<
|
public async callBrowser<
|
||||||
Arguments extends unknown[] = unknown[],
|
Arguments extends unknown[] = unknown[],
|
||||||
EventName extends string = string,
|
EventName extends string = string,
|
||||||
Return = unknown,
|
Return extends unknown = unknown,
|
||||||
>(player: PlayerMp, eventName: EventName, args?: Arguments): Promise<Return>
|
>(player: PlayerMp, eventName: EventName, args?: Arguments): Promise<Return>
|
||||||
public async callBrowser(
|
public async callBrowser(
|
||||||
playerOrEventName: PlayerMp | string,
|
playerOrEventName: PlayerMp | string,
|
||||||
eventNameOrArgs?: string | unknown[],
|
eventNameOrArgs?: string | unknown[],
|
||||||
args?: unknown[],
|
args?: unknown[],
|
||||||
) {
|
) {
|
||||||
if (_is1StParamPlayer(playerOrEventName)) {
|
_is1StParamPlayer(playerOrEventName)
|
||||||
this.log(
|
? this.log(
|
||||||
'DEV callClient',
|
'DEV callClient',
|
||||||
eventNameOrArgs as string,
|
eventNameOrArgs as string,
|
||||||
playerOrEventName,
|
playerOrEventName,
|
||||||
eventNameOrArgs,
|
eventNameOrArgs,
|
||||||
args,
|
args,
|
||||||
)
|
)
|
||||||
} else {
|
: this.log(
|
||||||
this.log(
|
'DEV callClient',
|
||||||
'DEV callClient',
|
playerOrEventName as string,
|
||||||
playerOrEventName as string,
|
eventNameOrArgs,
|
||||||
eventNameOrArgs,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.forceBrowserDevMode_) return
|
if (this.forceBrowserDevMode_) return
|
||||||
Utils.errorUnknownEnvironment(this.environment_)
|
Utils.errorUnknownEnvironment(this.environment_)
|
||||||
|
|
||||||
|
function _is1StParamPlayer(x: unknown): x is PlayerMp {
|
||||||
|
return typeof x === 'object'
|
||||||
|
}
|
||||||
|
|
||||||
|
function _is2NdParamEventName(x: unknown): x is string {
|
||||||
|
return typeof x === 'string'
|
||||||
|
}
|
||||||
|
|
||||||
const state: RPCState = {
|
const state: RPCState = {
|
||||||
uuid: Utils.generateUUID(),
|
uuid: Utils.generateUUID(),
|
||||||
eventName: !_is1StParamPlayer(playerOrEventName)
|
eventName: !_is1StParamPlayer(playerOrEventName)
|
||||||
@@ -418,14 +424,6 @@ class Rpc extends Wrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (await this.responseHandler(state.uuid)).data
|
return (await this.responseHandler(state.uuid)).data
|
||||||
|
|
||||||
function _is1StParamPlayer(x: unknown): x is PlayerMp {
|
|
||||||
return typeof x === 'object'
|
|
||||||
}
|
|
||||||
|
|
||||||
function _is2NdParamEventName(x: unknown): x is string {
|
|
||||||
return typeof x === 'string'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -448,14 +446,14 @@ class Rpc extends Wrapper {
|
|||||||
public async call<
|
public async call<
|
||||||
Arguments extends unknown[] = unknown[],
|
Arguments extends unknown[] = unknown[],
|
||||||
EventName extends string = string,
|
EventName extends string = string,
|
||||||
Return = unknown,
|
Return extends unknown = unknown,
|
||||||
>(eventName: EventName, args?: Arguments): Promise<Return> {
|
>(eventName: EventName, args?: Arguments): Promise<Return> {
|
||||||
this.log('call', eventName, args)
|
this.log('call', eventName, args)
|
||||||
if (this.forceBrowserDevMode_)
|
if (this.forceBrowserDevMode_)
|
||||||
return undefined as unknown as Promise<Return>
|
return undefined as unknown as Promise<Return>
|
||||||
Utils.errorUnknownEnvironment(this.environment_)
|
Utils.errorUnknownEnvironment(this.environment_)
|
||||||
|
|
||||||
const state: RPCState = {
|
let state: RPCState = {
|
||||||
uuid: Utils.generateUUID(),
|
uuid: Utils.generateUUID(),
|
||||||
eventName,
|
eventName,
|
||||||
calledTo: this.environment_,
|
calledTo: this.environment_,
|
||||||
@@ -471,7 +469,9 @@ class Rpc extends Wrapper {
|
|||||||
/**
|
/**
|
||||||
* redirects an event in cases of it calling its own environment
|
* redirects an event in cases of it calling its own environment
|
||||||
*/
|
*/
|
||||||
private async callSelf<Return = unknown>(state: RPCState): Promise<Return> {
|
private async callSelf<Return extends unknown = unknown>(
|
||||||
|
state: RPCState,
|
||||||
|
): Promise<Return> {
|
||||||
state = this.verifyEvent_(state)
|
state = this.verifyEvent_(state)
|
||||||
if (state.knownError) {
|
if (state.knownError) {
|
||||||
this.triggerError_(state, state.knownError)
|
this.triggerError_(state, state.knownError)
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
import { Wrapper } from './wrapper'
|
import { Wrapper } from './wrapper'
|
||||||
import {
|
import {
|
||||||
type PlayerMp,
|
|
||||||
Environment,
|
Environment,
|
||||||
Events,
|
Events,
|
||||||
|
type PlayerMp,
|
||||||
RPCEventType,
|
RPCEventType,
|
||||||
RPCState,
|
RPCState,
|
||||||
RpcWrapperConfig,
|
RpcWrapperConfig,
|
||||||
@@ -20,7 +20,7 @@ export class Server extends Wrapper {
|
|||||||
) {
|
) {
|
||||||
super(options)
|
super(options)
|
||||||
|
|
||||||
if (options.forceBrowserDevMode) return
|
if (!!options.forceBrowserDevMode) return
|
||||||
|
|
||||||
// specific event to save player in context as it is not available on server -> server calls
|
// specific event to save player in context as it is not available on server -> server calls
|
||||||
mp.events.add(
|
mp.events.add(
|
||||||
@@ -35,7 +35,7 @@ export class Server extends Wrapper {
|
|||||||
* NOT INTENDED FOR OUT-OF-CONTEXT USE
|
* NOT INTENDED FOR OUT-OF-CONTEXT USE
|
||||||
*/
|
*/
|
||||||
public _resolveEmitDestination(player: PlayerMp, dataRaw: string) {
|
public _resolveEmitDestination(player: PlayerMp, dataRaw: string) {
|
||||||
const state = Utils.prepareExecution(dataRaw)
|
let state = Utils.prepareExecution(dataRaw)
|
||||||
|
|
||||||
switch (state.calledTo) {
|
switch (state.calledTo) {
|
||||||
case Environment.SERVER:
|
case Environment.SERVER:
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ export class Wrapper {
|
|||||||
|
|
||||||
// checks if event is available (registered) in current environment
|
// checks if event is available (registered) in current environment
|
||||||
protected verifyEvent_(data: string | RPCState): RPCState {
|
protected verifyEvent_(data: string | RPCState): RPCState {
|
||||||
const rpcData =
|
let rpcData =
|
||||||
typeof data === 'string' ? Utils.prepareExecution(data) : data
|
typeof data === 'string' ? Utils.prepareExecution(data) : data
|
||||||
|
|
||||||
if (!this.state_[rpcData.eventName]) {
|
if (!this.state_[rpcData.eventName]) {
|
||||||
|
|||||||
+15
-4
@@ -1,18 +1,29 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json.schemastore.org/tsconfig",
|
|
||||||
"display": "RPC",
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"target": "es6",
|
||||||
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es2022",
|
"ES6",
|
||||||
"dom"
|
"dom"
|
||||||
],
|
],
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
|
|
||||||
|
"outDir": "bin",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
|
||||||
|
"strict": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
|
"src/**/*",
|
||||||
"./index.d.ts"
|
"./index.d.ts"
|
||||||
],
|
],
|
||||||
"extends": ["../tsconfig.ragefw.json"]
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"dist"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Custom Attribution-NoDerives Software License
|
Custom Attribution-NoDerivs Software License
|
||||||
|
|
||||||
Copyright (c) 2024 Entity Seven Group
|
Copyright (c) 2024 Entity Seven Group
|
||||||
|
|
||||||
|
|||||||
+8
-20
@@ -1,38 +1,26 @@
|
|||||||
{
|
{
|
||||||
"private": false,
|
|
||||||
"name": "@entityseven/rage-fw-server",
|
"name": "@entityseven/rage-fw-server",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"types": "dist/src/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"readme.md",
|
"readme.md",
|
||||||
"LICENSE",
|
"LICENSE"
|
||||||
"package.json"
|
|
||||||
],
|
],
|
||||||
"main": "src/index.ts",
|
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./dist/index.js"
|
||||||
},
|
|
||||||
"publishConfig": {
|
|
||||||
"main": "dist/index.js",
|
|
||||||
"types": "dist/index.d.ts",
|
|
||||||
"exports": {
|
|
||||||
".": "./dist/index.js"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@entityseven/rage-fw-rpc": "workspace:*",
|
"@entityseven/rage-fw-rpc": "0.2.5",
|
||||||
"zod": "^3.24.1"
|
"zod": "^3.23.8"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "22.12.0"
|
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@entityseven/rage-fw-shared-types": "workspace:*",
|
"@entityseven/rage-fw-shared-types": "0.2.0",
|
||||||
"@ragempcommunity/types-server": "^2.1.8",
|
"@ragempcommunity/types-server": "^2.1.8"
|
||||||
"typescript": "^5.7.3"
|
|
||||||
},
|
},
|
||||||
"description": "Package used on a server-side of your Rage:MP Server",
|
"description": "Package used on a server-side of your Rage:MP Server",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
export * from './logger'
|
export * from './logger'
|
||||||
export * from './middleware'
|
|
||||||
export * from './player'
|
export * from './player'
|
||||||
export * from './rpc'
|
export * from './rpc'
|
||||||
export * from './server'
|
export * from './server'
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ const { timestamp, printf, colorize } = format
|
|||||||
|
|
||||||
/** Used to log in a server console */
|
/** Used to log in a server console */
|
||||||
export class Logger {
|
export class Logger {
|
||||||
private format = printf(({ message, level }) => {
|
private format = printf(({ message, level, timestamp }) => {
|
||||||
return `[${new Date().toLocaleTimeString()}] [${level}]: ${message}`
|
return `[${new Date(timestamp).toLocaleTimeString()}] [${level}]: ${message}`
|
||||||
})
|
})
|
||||||
|
|
||||||
private systemLogger = winston.createLogger({
|
private systemLogger = winston.createLogger({
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ export class Middleware {
|
|||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
private static async execute<EventName extends T.RageFW_ServerEvent>(
|
private static async execute<EventName extends T.RageFW_ServerEvent>(
|
||||||
middlewares: T.RageFW_MiddlewareFunction<EventName>[],
|
|
||||||
args: T.RageFW_ServerArgs<EventName>,
|
args: T.RageFW_ServerArgs<EventName>,
|
||||||
|
middlewares: T.RageFW_MiddlewareFunction<EventName>[],
|
||||||
): Promise<T.RageFW_MiddlewareResponseInternal> {
|
): Promise<T.RageFW_MiddlewareResponseInternal> {
|
||||||
for (let i = 0; i < middlewares.length; i++) {
|
for (let i = 0; i < middlewares.length; i++) {
|
||||||
const result = await middlewares[i](...args)
|
const result = await middlewares[i](...args)
|
||||||
@@ -22,25 +22,25 @@ export class Middleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async process<EventName extends T.RageFW_ServerEvent>(
|
public static async process<EventName extends T.RageFW_ServerEvent>(
|
||||||
middlewareOptions: T.RageFW_MiddlewareOptions<EventName>,
|
|
||||||
callback: T.RageFW_ServerCallback<EventName>,
|
|
||||||
args: T.RageFW_ServerArgs<EventName>,
|
args: T.RageFW_ServerArgs<EventName>,
|
||||||
) {
|
middlewareOptions?: T.RageFW_MiddlewareOptions<EventName>,
|
||||||
|
): Promise<boolean> {
|
||||||
|
if (!middlewareOptions) return true
|
||||||
|
|
||||||
if (Array.isArray(middlewareOptions)) {
|
if (Array.isArray(middlewareOptions)) {
|
||||||
const middlewaresResponse = await Middleware.execute(
|
const middlewaresResponse = await Middleware.execute(
|
||||||
middlewareOptions,
|
|
||||||
args,
|
args,
|
||||||
|
middlewareOptions,
|
||||||
)
|
)
|
||||||
|
return middlewaresResponse.success
|
||||||
if (middlewaresResponse.success) return await callback(...args)
|
|
||||||
} else {
|
} else {
|
||||||
const middlewaresResponse = await Middleware.execute(
|
const middlewaresResponse = await Middleware.execute(
|
||||||
middlewareOptions.executables,
|
|
||||||
args,
|
args,
|
||||||
|
middlewareOptions.executables,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (middlewaresResponse.success) {
|
if (middlewaresResponse.success) {
|
||||||
return await callback(...args)
|
return true
|
||||||
} else {
|
} else {
|
||||||
middlewareOptions.onError(
|
middlewareOptions.onError(
|
||||||
middlewaresResponse.message ??
|
middlewaresResponse.message ??
|
||||||
@@ -48,6 +48,7 @@ export class Middleware {
|
|||||||
middlewaresResponse.id +
|
middlewaresResponse.id +
|
||||||
' failed',
|
' failed',
|
||||||
)
|
)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { rpc } from './rpc'
|
import { rpc } from './rpc'
|
||||||
import { Middleware } from './middleware'
|
import { Middleware } from './middleware'
|
||||||
|
import { Validation } from './validation'
|
||||||
import type * as T from '../types'
|
import type * as T from '../types'
|
||||||
|
|
||||||
/** Server-side interactions */
|
/** Server-side interactions */
|
||||||
@@ -10,6 +11,7 @@ export class Server {
|
|||||||
* @param eventName - The name of the event to register
|
* @param eventName - The name of the event to register
|
||||||
* @param callback - The callback function to be executed when the event is triggered
|
* @param callback - The callback function to be executed when the event is triggered
|
||||||
* @param [options] - Optional settings for callback execution
|
* @param [options] - Optional settings for callback execution
|
||||||
|
* @param [options.validation] - Validation schema to be checked before the callback executes
|
||||||
* @param [options.middlewares] - Middleware functions to be checked before the callback executes
|
* @param [options.middlewares] - Middleware functions to be checked before the callback executes
|
||||||
* @returns {Server} The current server instance, enabling method chaining
|
* @returns {Server} The current server instance, enabling method chaining
|
||||||
*
|
*
|
||||||
@@ -44,6 +46,7 @@ export class Server {
|
|||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: T.RageFW_ServerCallback<EventName>,
|
callback: T.RageFW_ServerCallback<EventName>,
|
||||||
options?: {
|
options?: {
|
||||||
|
validation?: T.RageFW_ValidationOptions
|
||||||
middlewares?: T.RageFW_MiddlewareOptions<EventName>
|
middlewares?: T.RageFW_MiddlewareOptions<EventName>
|
||||||
},
|
},
|
||||||
): Server {
|
): Server {
|
||||||
@@ -52,9 +55,22 @@ export class Server {
|
|||||||
ReturnType<typeof callback> | Promise<unknown>,
|
ReturnType<typeof callback> | Promise<unknown>,
|
||||||
EventName
|
EventName
|
||||||
>(eventName, async (...data) => {
|
>(eventName, async (...data) => {
|
||||||
if (!options?.middlewares) return await callback(...data)
|
if (!options?.middlewares && !options?.validation)
|
||||||
|
return await callback(...data)
|
||||||
|
|
||||||
await Middleware.process(options.middlewares, callback, data)
|
const validationSuccess = Validation.process(
|
||||||
|
data,
|
||||||
|
options?.validation,
|
||||||
|
)
|
||||||
|
if (!validationSuccess) return
|
||||||
|
|
||||||
|
const middlewaresSuccess = await Middleware.process(
|
||||||
|
data,
|
||||||
|
options?.middlewares,
|
||||||
|
)
|
||||||
|
if (!middlewaresSuccess) return
|
||||||
|
|
||||||
|
return await callback(...data)
|
||||||
})
|
})
|
||||||
|
|
||||||
return this
|
return this
|
||||||
@@ -90,7 +106,3 @@ export class Server {
|
|||||||
// return rpc.call(eventName, args)
|
// return rpc.call(eventName, args)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// new Server()
|
|
||||||
// .register('customServerEvent', async (a, b, c) => true)
|
|
||||||
// .unregister('customServerEvent')
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import type * as T from '../types'
|
||||||
|
|
||||||
|
export class Validation {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
public static process<EventName extends T.RageFW_ServerEvent>(
|
||||||
|
args: T.RageFW_ServerArgs<EventName>,
|
||||||
|
validationOptions?: T.RageFW_ValidationOptions,
|
||||||
|
): boolean {
|
||||||
|
if (!validationOptions) return true
|
||||||
|
|
||||||
|
if ('schema' in validationOptions) {
|
||||||
|
const validationResponse = validationOptions.schema.safeParse(args)
|
||||||
|
|
||||||
|
if (validationResponse.success) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
validationOptions.onError(validationResponse.error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const validationResponse = validationOptions.safeParse(args)
|
||||||
|
return validationResponse.success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,3 +2,4 @@ export * from './browser'
|
|||||||
export * from './client'
|
export * from './client'
|
||||||
export * from './middleware'
|
export * from './middleware'
|
||||||
export * from './server'
|
export * from './server'
|
||||||
|
export * from './validation'
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import type { z } from 'zod'
|
||||||
|
|
||||||
|
export type RageFW_ValidationSchema = z.ZodTuple<any, any> | z.ZodArray<any>
|
||||||
|
export type RageFW_ValidationSchemaExtended = {
|
||||||
|
schema: RageFW_ValidationSchema
|
||||||
|
onError: (error: z.ZodError) => unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RageFW_ValidationOptions =
|
||||||
|
| RageFW_ValidationSchema
|
||||||
|
| RageFW_ValidationSchemaExtended
|
||||||
+21
-4
@@ -1,8 +1,25 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json.schemastore.org/tsconfig",
|
"$schema": "https://json.schemastore.org/tsconfig",
|
||||||
"display": "Server",
|
"display": "Base",
|
||||||
|
"exclude": [
|
||||||
|
"node_modules"
|
||||||
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": ["./node_modules/@ragempcommunity/types-server/index.d.ts"]
|
"incremental": false,
|
||||||
},
|
"composite": false,
|
||||||
"extends": ["../tsconfig.ragefw.json"]
|
"target": "ES2022",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"moduleDetection": "auto",
|
||||||
|
"module": "CommonJS",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": false,
|
||||||
|
"sourceMap": false,
|
||||||
|
"downlevelIteration": false,
|
||||||
|
"inlineSourceMap": false,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { defineConfig } from 'tsup'
|
import { defineConfig } from 'tsup'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
entry: ['src/**/*.ts'],
|
entry: ['./src/index.ts'],
|
||||||
outDir: './dist',
|
outDir: './dist',
|
||||||
format: ['cjs'],
|
format: ['cjs'],
|
||||||
experimentalDts: true,
|
experimentalDts: true,
|
||||||
splitting: false,
|
splitting: false,
|
||||||
bundle: false,
|
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
clean: true,
|
clean: true,
|
||||||
|
bundle: false,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Custom Attribution-NoDerives Software License
|
# Custom Attribution-NoDerivs Software License
|
||||||
|
|
||||||
This license allows you to use, copy, and distribute the RageFW (the "Software"), including for commercial purposes, provided that the following conditions are met:
|
This license allows you to use, copy, and distribute the RageFW (the "Software"), including for commercial purposes, provided that the following conditions are met:
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
{
|
{
|
||||||
"private": false,
|
"name": "@entityseven/rage-fw-shared-types",
|
||||||
|
"version": "0.2.0",
|
||||||
|
"types": "types/types/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"types/**/*",
|
"types/**/*",
|
||||||
"readme.md",
|
"readme.md",
|
||||||
"LICENSE",
|
"LICENSE"
|
||||||
"package.json"
|
|
||||||
],
|
],
|
||||||
"types": "types/types/index.d.ts",
|
|
||||||
"name": "@entityseven/rage-fw-shared-types",
|
|
||||||
"version": "0.2.0",
|
|
||||||
"description": "Package used among all environments of your Rage-FW based server",
|
"description": "Package used among all environments of your Rage-FW based server",
|
||||||
"keywords": ["rage-fw-shared-types", "rage-fw-shared","ragefw", "rage-fw", "ragemp", "rage:mp", "rage", "gta5"],
|
"keywords": ["rage-fw-shared-types", "rage-fw-shared","ragefw", "rage-fw", "ragemp", "rage:mp", "rage", "gta5"],
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -25,6 +23,6 @@
|
|||||||
"url": "https://github.com/SashaGoncharov19/"
|
"url": "https://github.com/SashaGoncharov19/"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "Custom-Attribution-NoDerives",
|
"license": "Custom-Attribution-NoDerivs",
|
||||||
"gitHead": "ffd542c1deddb3033e16e0dae7557313ae09b05f"
|
"gitHead": "ffd542c1deddb3033e16e0dae7557313ae09b05f"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2022",
|
"target": "ESNext",
|
||||||
"lib": [
|
"lib": [
|
||||||
"ESNext",
|
"ESNext",
|
||||||
"es2022",
|
"ES2019",
|
||||||
"dom"
|
"dom"
|
||||||
],
|
],
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"incremental": false,
|
|
||||||
"composite": false,
|
|
||||||
|
|
||||||
"target": "es2022",
|
|
||||||
"moduleDetection": "auto",
|
|
||||||
"module": "commonjs",
|
|
||||||
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"resolveJsonModule": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"strict": true,
|
|
||||||
|
|
||||||
"declaration": false,
|
|
||||||
"declarationMap": false,
|
|
||||||
"downlevelIteration": false,
|
|
||||||
"inlineSourceMap": false,
|
|
||||||
"sourceMap": false
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"node_modules",
|
|
||||||
"dist",
|
|
||||||
".tsup"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user