@nativewrappers/common 0.0.134 → 0.0.135
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.
- package/decors/Events.d.ts +6 -31
- package/decors/Events.js +13 -59
- package/package.json +1 -1
package/decors/Events.d.ts
CHANGED
|
@@ -2,34 +2,6 @@
|
|
|
2
2
|
* Disables pretty printing in error messages
|
|
3
3
|
*/
|
|
4
4
|
export declare const DisablePrettyPrint: () => boolean;
|
|
5
|
-
export declare enum Binding {
|
|
6
|
-
/**
|
|
7
|
-
* No one can call this
|
|
8
|
-
*/
|
|
9
|
-
None = 0,
|
|
10
|
-
/**
|
|
11
|
-
* Server only accepts server calls, client only client calls
|
|
12
|
-
*/
|
|
13
|
-
Local = 1,
|
|
14
|
-
/**
|
|
15
|
-
* Server only accepts client calls, client only server calls
|
|
16
|
-
*/
|
|
17
|
-
Remote = 2,
|
|
18
|
-
/**
|
|
19
|
-
* Accept all incoming calls
|
|
20
|
-
* Server only accepts client calls, client only server calls
|
|
21
|
-
*/
|
|
22
|
-
All = 3
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Registers the Event call for {@link eventName} to this method.
|
|
26
|
-
*
|
|
27
|
-
* This has internal pretty-printing to make errors easier to track, if
|
|
28
|
-
* you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
|
|
29
|
-
* using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
|
|
30
|
-
* @param eventName the event to bind to
|
|
31
|
-
*/
|
|
32
|
-
export declare function CfxEvent(eventName: string, binding?: Binding): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
33
5
|
/**
|
|
34
6
|
* Registers the Event call for {@link eventName} to this method.
|
|
35
7
|
*
|
|
@@ -39,7 +11,8 @@ export declare function CfxEvent(eventName: string, binding?: Binding): (origina
|
|
|
39
11
|
*
|
|
40
12
|
* @param eventName the event to bind to
|
|
41
13
|
*/
|
|
42
|
-
export declare function
|
|
14
|
+
export declare function OnEvent(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
15
|
+
export declare const Event: typeof OnEvent;
|
|
43
16
|
/**
|
|
44
17
|
* Registers the Net Event call for {@link eventName} to this method
|
|
45
18
|
*
|
|
@@ -51,7 +24,8 @@ export declare function Event(eventName: string): (originalMethod: any, context:
|
|
|
51
24
|
* @param eventName the event to bind this net event to
|
|
52
25
|
* @param remoteOnly if the event should only accept remote calls, if set to true it will ignore any local call via `emit`, defaults to true
|
|
53
26
|
*/
|
|
54
|
-
export declare function
|
|
27
|
+
export declare function OnNetEvent(eventName: string, remoteOnly?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
28
|
+
export declare const NetEvent: typeof OnNetEvent;
|
|
55
29
|
export type NuiCallback = (data: string) => void;
|
|
56
30
|
/**
|
|
57
31
|
* Registers the NUI Event call for {eventName} to this method, the function signature
|
|
@@ -63,4 +37,5 @@ export type NuiCallback = (data: string) => void;
|
|
|
63
37
|
* @param eventName the event this will listen for
|
|
64
38
|
* @param dontErrorWhenCbIsntInvoked this will just block the event fro merroring when the callback is never invoked.
|
|
65
39
|
*/
|
|
66
|
-
export declare function
|
|
40
|
+
export declare function OnNuiEvent(eventName: string, dontErrorWhenCbIsntInvoked?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
41
|
+
export declare const NuiEvent: typeof OnNuiEvent;
|
package/decors/Events.js
CHANGED
|
@@ -4,57 +4,7 @@ import { GlobalData } from "../GlobalData";
|
|
|
4
4
|
const DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
|
|
5
5
|
const AsyncFunction = (async () => {
|
|
6
6
|
}).constructor;
|
|
7
|
-
|
|
8
|
-
Binding2[Binding2["None"] = 0] = "None";
|
|
9
|
-
Binding2[Binding2["Local"] = 1] = "Local";
|
|
10
|
-
Binding2[Binding2["Remote"] = 2] = "Remote";
|
|
11
|
-
Binding2[Binding2["All"] = 3] = "All";
|
|
12
|
-
return Binding2;
|
|
13
|
-
})(Binding || {});
|
|
14
|
-
function CfxEvent(eventName, binding = 1 /* Local */) {
|
|
15
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
16
|
-
if (context.private) {
|
|
17
|
-
throw new Error("Event does not work on private methods, please mark the method as public");
|
|
18
|
-
}
|
|
19
|
-
context.addInitializer(function() {
|
|
20
|
-
const fn = (binding & 2 /* Remote */) !== 0 ? onNet : on;
|
|
21
|
-
const _t = this;
|
|
22
|
-
fn(eventName, async (...args) => {
|
|
23
|
-
const src = source;
|
|
24
|
-
if (_t.__permissionMap && binding & 2 /* Remote */) {
|
|
25
|
-
const permissions = _t.__permissionMap.get(context.name);
|
|
26
|
-
if (permissions) {
|
|
27
|
-
let hasPermission = false;
|
|
28
|
-
for (const perm of permissions) {
|
|
29
|
-
if (IsPlayerAceAllowed(src, perm)) {
|
|
30
|
-
hasPermission = true;
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (!hasPermission) {
|
|
35
|
-
emit("@nativewrappers:no_permission", { eventName, method: context.name });
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
return await originalMethod.call(this, ...args);
|
|
42
|
-
} catch (e) {
|
|
43
|
-
REMOVE_EVENT_LOG: {
|
|
44
|
-
if (!GlobalData.EnablePrettyPrint) return;
|
|
45
|
-
console.error("------- EVENT ERROR --------");
|
|
46
|
-
console.error(`Call to ${eventName} errored`);
|
|
47
|
-
console.error(`Data: ${JSON.stringify(args)}`);
|
|
48
|
-
console.error(`Error: ${e}`);
|
|
49
|
-
console.error("------- END EVENT ERROR --------");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}, "actualDecorator");
|
|
55
|
-
}
|
|
56
|
-
__name(CfxEvent, "CfxEvent");
|
|
57
|
-
function Event(eventName) {
|
|
7
|
+
function OnEvent(eventName) {
|
|
58
8
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
59
9
|
if (context.private) {
|
|
60
10
|
throw new Error("Event does not work on private methods, please mark the method as public");
|
|
@@ -77,8 +27,9 @@ function Event(eventName) {
|
|
|
77
27
|
});
|
|
78
28
|
}, "actualDecorator");
|
|
79
29
|
}
|
|
80
|
-
__name(
|
|
81
|
-
|
|
30
|
+
__name(OnEvent, "OnEvent");
|
|
31
|
+
const Event = OnEvent;
|
|
32
|
+
function OnNetEvent(eventName, remoteOnly = true) {
|
|
82
33
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
83
34
|
if (context.private) {
|
|
84
35
|
throw new Error("NetEvent does not work on private methods, please mark the method as public");
|
|
@@ -125,8 +76,9 @@ function NetEvent(eventName, remoteOnly = true) {
|
|
|
125
76
|
});
|
|
126
77
|
}, "actualDecorator");
|
|
127
78
|
}
|
|
128
|
-
__name(
|
|
129
|
-
|
|
79
|
+
__name(OnNetEvent, "OnNetEvent");
|
|
80
|
+
const NetEvent = OnNetEvent;
|
|
81
|
+
function OnNuiEvent(eventName, dontErrorWhenCbIsntInvoked = false) {
|
|
130
82
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
131
83
|
if (context.private) {
|
|
132
84
|
throw new Error("NuiEvent does not work on private methods, please mark the method as public");
|
|
@@ -152,12 +104,14 @@ function NuiEvent(eventName, dontErrorWhenCbIsntInvoked = false) {
|
|
|
152
104
|
});
|
|
153
105
|
}, "actualDecorator");
|
|
154
106
|
}
|
|
155
|
-
__name(
|
|
107
|
+
__name(OnNuiEvent, "OnNuiEvent");
|
|
108
|
+
const NuiEvent = OnNuiEvent;
|
|
156
109
|
export {
|
|
157
|
-
Binding,
|
|
158
|
-
CfxEvent,
|
|
159
110
|
DisablePrettyPrint,
|
|
160
111
|
Event,
|
|
161
112
|
NetEvent,
|
|
162
|
-
NuiEvent
|
|
113
|
+
NuiEvent,
|
|
114
|
+
OnEvent,
|
|
115
|
+
OnNetEvent,
|
|
116
|
+
OnNuiEvent
|
|
163
117
|
};
|