@nativewrappers/common 0.0.64 → 0.0.65

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/GlobalData.d.ts CHANGED
@@ -4,4 +4,5 @@ export declare class GlobalData {
4
4
  static IS_CLIENT: boolean;
5
5
  static NetworkTick: number | null;
6
6
  static NetworkedTicks: any[];
7
+ static EnablePrettyPrint: boolean;
7
8
  }
package/GlobalData.js CHANGED
@@ -4,4 +4,5 @@ export class GlobalData {
4
4
  static IS_CLIENT = !GlobalData.IS_SERVER;
5
5
  static NetworkTick = null;
6
6
  static NetworkedTicks = [];
7
+ static EnablePrettyPrint = true;
7
8
  }
@@ -4,11 +4,51 @@ export declare enum ConVarType {
4
4
  Float = 2,
5
5
  Boolean = 3
6
6
  }
7
+ /**
8
+ * Disables pretty printing in error messages
9
+ */
10
+ export declare const DisablePrettyPrint: () => boolean;
7
11
  export declare function Exports(exportName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
12
+ /**
13
+ * Registers the Event call for {@link eventName} to this method.
14
+ *
15
+ * This has internal pretty-printing to make errors easier to track, if
16
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
17
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
18
+ *
19
+ * @param eventName the event to bind to
20
+ */
8
21
  export declare function Event(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
22
+ /**
23
+ * Registers the Net Event call for {@link eventName} to this method
24
+ *
25
+ *
26
+ * This has internal pretty-printing to make errors easier to track, if
27
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
28
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
29
+ *
30
+ * @param eventName the event to bind this net event to
31
+ * @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
32
+ */
9
33
  export declare function NetEvent(eventName: string, remoteOnly?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
34
+ /**
35
+ * Registers the NUI Event call for {eventName} to this method, the function signature
36
+ * should be (data: unknown, cb: (data?: any) => void) => void
37
+ * You shoud always execute `cb` with 'ok' if you don't want to send data back to
38
+ * the UI, otherwise you'll cause a network error for the `fetch` request
39
+ * @param eventName the event this will listen for
40
+ */
10
41
  export declare function NuiEvent(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
11
42
  type DeserializeFn<T> = (data: T) => unknown;
12
- export declare function ConVar<T>(name: string, is_floating_point?: boolean, deserialize?: DeserializeFn<T>): (_initialValue: any, context: ClassFieldDecoratorContext, ...args: any[]) => void;
43
+ /**
44
+ * Gets the specified `ConVar`s value, this will bind to the param.
45
+ * @param name the convar name
46
+ * @param is_floating_point if the convar is floating point, this should be explicitly set to true if your convar will be a float
47
+ */
48
+ export declare function ConVar<T>(name: string, is_floating_point?: boolean, deserialize?: DeserializeFn<T>): (_initialValue: any, context: ClassFieldDecoratorContext, ..._args: any[]) => void;
49
+ /**
50
+ * Gets called per server/client tick, this is asyncronous though, if you await
51
+ * in it, it will not be called until whatever was being awaited resolves.
52
+ */
13
53
  export declare function SetTick(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
14
54
  export {};
package/decors/Events.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { GlobalData } from "../GlobalData";
1
2
  export var ConVarType;
2
3
  (function (ConVarType) {
3
4
  ConVarType[ConVarType["String"] = 0] = "String";
@@ -5,6 +6,10 @@ export var ConVarType;
5
6
  ConVarType[ConVarType["Float"] = 2] = "Float";
6
7
  ConVarType[ConVarType["Boolean"] = 3] = "Boolean";
7
8
  })(ConVarType || (ConVarType = {}));
9
+ /**
10
+ * Disables pretty printing in error messages
11
+ */
12
+ export const DisablePrettyPrint = () => (GlobalData.EnablePrettyPrint = false);
8
13
  // TODO: Have a way to clean all of this up (maybe hook Symbol.disposable
9
14
  // somehow?)
10
15
  /*
@@ -23,8 +28,14 @@ export function Exports(exportName) {
23
28
  });
24
29
  };
25
30
  }
26
- /*
27
- * Registers the Event call for {eventName} to this method
31
+ /**
32
+ * Registers the Event call for {@link eventName} to this method.
33
+ *
34
+ * This has internal pretty-printing to make errors easier to track, if
35
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
36
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
37
+ *
38
+ * @param eventName the event to bind to
28
39
  */
29
40
  export function Event(eventName) {
30
41
  return function actualDecorator(originalMethod, context) {
@@ -39,6 +50,8 @@ export function Event(eventName) {
39
50
  }
40
51
  catch (e) {
41
52
  REMOVE_EVENT_LOG: {
53
+ if (!GlobalData.EnablePrettyPrint)
54
+ return;
42
55
  console.error(`------- EVENT ERROR --------`);
43
56
  console.error(`Call to ${eventName} errored`);
44
57
  console.error(`Data: ${JSON.stringify(args)}`);
@@ -50,10 +63,18 @@ export function Event(eventName) {
50
63
  });
51
64
  };
52
65
  }
53
- /*
54
- * Registers the Net Event call for {eventName} to this method
66
+ /**
67
+ * Registers the Net Event call for {@link eventName} to this method
68
+ *
69
+ *
70
+ * This has internal pretty-printing to make errors easier to track, if
71
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
72
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
73
+ *
74
+ * @param eventName the event to bind this net event to
75
+ * @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
55
76
  */
56
- export function NetEvent(eventName, remoteOnly = false) {
77
+ export function NetEvent(eventName, remoteOnly = true) {
57
78
  return function actualDecorator(originalMethod, context) {
58
79
  if (context.private) {
59
80
  throw new Error("NetEvent does not work on private methods, please mark the method as public");
@@ -72,6 +93,8 @@ export function NetEvent(eventName, remoteOnly = false) {
72
93
  }
73
94
  catch (e) {
74
95
  REMOVE_NET_EVENT_LOG: {
96
+ if (!GlobalData.EnablePrettyPrint)
97
+ return;
75
98
  console.error(`------- NET EVENT ERROR --------`);
76
99
  console.error(`Call to ${eventName} errored`);
77
100
  console.error(`Caller: ${src}`);
@@ -84,11 +107,12 @@ export function NetEvent(eventName, remoteOnly = false) {
84
107
  });
85
108
  };
86
109
  }
87
- /*
110
+ /**
88
111
  * Registers the NUI Event call for {eventName} to this method, the function signature
89
112
  * should be (data: unknown, cb: (data?: any) => void) => void
90
- * You shoud always execute `cb` with '' if you don't want to send data back to
113
+ * You shoud always execute `cb` with 'ok' if you don't want to send data back to
91
114
  * the UI, otherwise you'll cause a network error for the `fetch` request
115
+ * @param eventName the event this will listen for
92
116
  */
93
117
  export function NuiEvent(eventName) {
94
118
  return function actualDecorator(originalMethod, context) {
@@ -113,19 +137,21 @@ const get_convar_fn = (con_var_type) => {
113
137
  return GetConvarFloat;
114
138
  case ConVarType.Boolean:
115
139
  return GetConvarBool;
140
+ // needed so typescript wont complain about "unreachable code" for the error below
141
+ default:
116
142
  }
117
143
  // never guess people wont manage to hit this
118
144
  throw new Error("Got invalid ConVarType");
119
145
  };
120
- /*
121
- * Gets the specified `ConVar`s value, do note that if you *expect* the convar
122
- * to be a float you should explicitly set is_floating_point, otherwise some
123
- * bundlers will remove the float
146
+ /**
147
+ * Gets the specified `ConVar`s value, this will bind to the param.
148
+ * @param name the convar name
149
+ * @param is_floating_point if the convar is floating point, this should be explicitly set to true if your convar will be a float
124
150
  */
125
151
  export function ConVar(name, is_floating_point, deserialize) {
126
152
  // the implementation shows that this will be _initialValue, but it doesn't
127
153
  // seem to actually be???
128
- return function actualDecorator(_initialValue, context, ...args) {
154
+ return function actualDecorator(_initialValue, context, ..._args) {
129
155
  if (context.private) {
130
156
  throw new Error("ConVar does not work on private types, please mark the field as public");
131
157
  }
@@ -166,13 +192,13 @@ export function ConVar(name, is_floating_point, deserialize) {
166
192
  return deserialize ? deserialize(data) : data;
167
193
  };
168
194
  Reflect.set(t, context.name, get_convar_value());
169
- AddConvarChangeListener(name, (con_var_name) => {
195
+ AddConvarChangeListener(name, () => {
170
196
  Reflect.set(t, context.name, get_convar_value());
171
197
  });
172
198
  });
173
199
  };
174
200
  }
175
- /*
201
+ /**
176
202
  * Gets called per server/client tick, this is asyncronous though, if you await
177
203
  * in it, it will not be called until whatever was being awaited resolves.
178
204
  */
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Native wrappers and utilities for use with Cfx.re's scripting runtimes.",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "0.0.64",
6
+ "version": "0.0.65",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/nativewrappers/nativewrappers.git"