@trippler/tr_lib 2.6.1 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- declare const _default: (arg: object) => boolean;
1
+ declare const _default: (name: string, ...params: any[]) => boolean;
2
2
  export default _default;
@@ -1,2 +1 @@
1
- // experimental
2
- export default (arg) => SendNuiMessage(JSON.stringify(arg));
1
+ export default (name, ...params) => SendNuiMessage(JSON.stringify({ __name: name, params }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trippler/tr_lib",
3
- "version": "2.6.1",
3
+ "version": "2.7.1",
4
4
  "description": "A lightweight utility & helper library for FiveM developers. Designed to improve code reusability, consistency, and performance across and outcross Trippler resources.",
5
5
  "author": "Trippler",
6
6
  "license": "GPL-3.0",
@@ -28,7 +28,7 @@
28
28
  "README.md"
29
29
  ],
30
30
  "scripts": {
31
- "patch": "npm run build && npm version patch && npm publish",
31
+ "patch": "rmdir /s /q client server shared web && npm run build && npm version patch && npm publish",
32
32
  "build": "npm run build:shared && npm run build:client && npm run build:server && npm run build:web",
33
33
  "build:client": "npx tsc -p src/client/tsconfig.json",
34
34
  "build:server": "npx tsc -p src/server/tsconfig.json",
package/web/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  declare global {
2
2
  const GetParentResourceName: () => string;
3
3
  }
4
+ export { default as onNuiCallback } from './triggerNuiCallback';
4
5
  export { default as triggerNuiCallback } from './triggerNuiCallback';
package/web/index.js CHANGED
@@ -1 +1,2 @@
1
+ export { default as onNuiCallback } from './triggerNuiCallback';
1
2
  export { default as triggerNuiCallback } from './triggerNuiCallback';
@@ -0,0 +1,2 @@
1
+ declare const _default: <T extends any[] = any[]>(name: string, Function: (...args: T) => void) => () => void;
2
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { fatal } from "../../shared";
2
+ export default (name, Function) => {
3
+ const handler = (event) => {
4
+ const { __name, params } = event.data;
5
+ if (__name === name && Array.isArray(params)) {
6
+ try {
7
+ Function(...params);
8
+ }
9
+ catch (error) {
10
+ fatal(`Error in '${name}' callback: ${error}`);
11
+ }
12
+ }
13
+ else {
14
+ fatal(`Received invalid message in '${name}' callback: ${JSON.stringify(event.data)}`);
15
+ }
16
+ };
17
+ window.addEventListener('message', handler);
18
+ return () => window.removeEventListener('message', handler);
19
+ };