@nativewrappers/common 0.0.136 → 0.0.137

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
@@ -1,3 +1,11 @@
1
+ export declare enum ErrorType {
2
+ Event = 0,
3
+ NetEvent = 1,
4
+ Export = 2,
5
+ Nui = 3,
6
+ Tick = 4,
7
+ Immediate = 5
8
+ }
1
9
  export declare class GlobalData {
2
10
  static CurrentResource: string;
3
11
  static GameName: string;
@@ -9,4 +17,5 @@ export declare class GlobalData {
9
17
  static NetworkTick: number | null;
10
18
  static NetworkedTicks: any[];
11
19
  static EnablePrettyPrint: boolean;
20
+ static OnError: (type: ErrorType, err: Error) => void;
12
21
  }
package/GlobalData.js CHANGED
@@ -1,5 +1,14 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
4
+ ErrorType2[ErrorType2["Event"] = 0] = "Event";
5
+ ErrorType2[ErrorType2["NetEvent"] = 1] = "NetEvent";
6
+ ErrorType2[ErrorType2["Export"] = 2] = "Export";
7
+ ErrorType2[ErrorType2["Nui"] = 3] = "Nui";
8
+ ErrorType2[ErrorType2["Tick"] = 4] = "Tick";
9
+ ErrorType2[ErrorType2["Immediate"] = 5] = "Immediate";
10
+ return ErrorType2;
11
+ })(ErrorType || {});
3
12
  class GlobalData {
4
13
  static {
5
14
  __name(this, "GlobalData");
@@ -14,7 +23,13 @@ class GlobalData {
14
23
  static NetworkTick = null;
15
24
  static NetworkedTicks = [];
16
25
  static EnablePrettyPrint = true;
26
+ /*
27
+ * Called when one of the decors errors
28
+ */
29
+ static OnError = /* @__PURE__ */ __name((type, err) => {
30
+ }, "OnError");
17
31
  }
18
32
  export {
33
+ ErrorType,
19
34
  GlobalData
20
35
  };
@@ -0,0 +1,18 @@
1
+ export declare class CircularBuffer<T> {
2
+ private buffer;
3
+ private tail;
4
+ private count;
5
+ private max_size;
6
+ constructor(max_size: number);
7
+ push(item: T): void;
8
+ pop(): T | undefined;
9
+ peek(): T | undefined;
10
+ [Symbol.iterator](): Iterator<T>;
11
+ for_each(callback: (item: T, index: number) => void): void;
12
+ average(this: CircularBuffer<number>): number;
13
+ is_empty(): boolean;
14
+ is_full(): boolean;
15
+ size(): number;
16
+ capacity(): number;
17
+ clear(): void;
18
+ }
@@ -0,0 +1,92 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ class CircularBuffer {
4
+ static {
5
+ __name(this, "CircularBuffer");
6
+ }
7
+ buffer;
8
+ tail = 0;
9
+ count = 0;
10
+ max_size;
11
+ constructor(max_size) {
12
+ if (max_size <= 0) {
13
+ throw new Error("Buffer size must be greater than 0");
14
+ }
15
+ this.max_size = max_size;
16
+ this.buffer = new Array(max_size);
17
+ }
18
+ push(item) {
19
+ this.buffer[this.tail] = item;
20
+ this.tail++;
21
+ if (this.tail >= this.max_size) {
22
+ this.tail = 0;
23
+ }
24
+ if (this.count < this.max_size) {
25
+ this.count++;
26
+ }
27
+ }
28
+ pop() {
29
+ if (this.is_empty()) {
30
+ return void 0;
31
+ }
32
+ this.tail--;
33
+ if (this.tail < 0) {
34
+ this.tail = this.max_size - 1;
35
+ }
36
+ const item = this.buffer[this.tail];
37
+ this.buffer[this.tail] = void 0;
38
+ this.count--;
39
+ return item;
40
+ }
41
+ peek() {
42
+ if (this.is_empty()) {
43
+ return void 0;
44
+ }
45
+ let peek_index = this.tail - 1;
46
+ if (peek_index < 0) {
47
+ peek_index = this.max_size - 1;
48
+ }
49
+ return this.buffer[peek_index];
50
+ }
51
+ *[Symbol.iterator]() {
52
+ for (let i = 0; i < this.count; i++) {
53
+ yield this.buffer[i];
54
+ }
55
+ }
56
+ for_each(callback) {
57
+ let i = 0;
58
+ for (const item of this) {
59
+ callback(item, i++);
60
+ }
61
+ }
62
+ average() {
63
+ if (this.is_empty()) {
64
+ return 0;
65
+ }
66
+ let sum = 0;
67
+ for (const item of this) {
68
+ sum += item;
69
+ }
70
+ return sum / this.count;
71
+ }
72
+ is_empty() {
73
+ return this.count === 0;
74
+ }
75
+ is_full() {
76
+ return this.count === this.max_size;
77
+ }
78
+ size() {
79
+ return this.count;
80
+ }
81
+ capacity() {
82
+ return this.max_size;
83
+ }
84
+ clear() {
85
+ this.buffer = new Array(this.max_size);
86
+ this.tail = 0;
87
+ this.count = 0;
88
+ }
89
+ }
90
+ export {
91
+ CircularBuffer
92
+ };
@@ -0,0 +1,9 @@
1
+ declare class Stack<T> {
2
+ private items;
3
+ push(item: T): void;
4
+ pop(): T | undefined;
5
+ peek(): T | undefined;
6
+ is_empty(): boolean;
7
+ size(): number;
8
+ clear(): void;
9
+ }
File without changes
package/decors/Events.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { GlobalData } from "../GlobalData";
3
+ import { ErrorType, GlobalData } from "../GlobalData";
4
4
  const DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
5
5
  const AsyncFunction = (async () => {
6
6
  }).constructor;
@@ -14,6 +14,7 @@ function OnEvent(eventName) {
14
14
  try {
15
15
  return await originalMethod.call(this, ...args);
16
16
  } catch (e) {
17
+ GlobalData.OnError(ErrorType.Event, e);
17
18
  REMOVE_EVENT_LOG: {
18
19
  if (!GlobalData.EnablePrettyPrint) return;
19
20
  console.error("------- EVENT ERROR --------");
@@ -62,6 +63,7 @@ function OnNetEvent(eventName, remoteOnly = true) {
62
63
  }
63
64
  return await originalMethod.call(this, ...args);
64
65
  } catch (e) {
66
+ GlobalData.OnError(ErrorType.NetEvent, e);
65
67
  REMOVE_NET_EVENT_LOG: {
66
68
  if (!GlobalData.EnablePrettyPrint) return;
67
69
  console.error("------- NET EVENT ERROR --------");
@@ -90,7 +92,13 @@ function OnNuiEvent(eventName, dontErrorWhenCbIsntInvoked = false) {
90
92
  wasInvoked = true;
91
93
  cb(args);
92
94
  }, "cbWrapper");
93
- const retData = await originalMethod.call(this, data, cbWrapper);
95
+ let retData;
96
+ try {
97
+ retData = await originalMethod.call(this, data, cbWrapper);
98
+ } catch (e) {
99
+ GlobalData.OnError(ErrorType.Nui, e);
100
+ return;
101
+ }
94
102
  if (!wasInvoked && !retData) {
95
103
  if (dontErrorWhenCbIsntInvoked) return;
96
104
  throw new Error(
package/decors/Exports.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { GlobalData } from "../GlobalData";
3
+ import { ErrorType, GlobalData } from "../GlobalData";
4
4
  const AsyncFunction = (async () => {
5
5
  }).constructor;
6
6
  function Exports(exportName) {
@@ -15,6 +15,7 @@ function Exports(exportName) {
15
15
  try {
16
16
  return await originalMethod.call(this, ...args);
17
17
  } catch (err) {
18
+ GlobalData.OnError(ErrorType.Export, err);
18
19
  REMOVE_EVENT_LOG: {
19
20
  if (!GlobalData.EnablePrettyPrint) return;
20
21
  console.error("------- EXPORT ERROR --------");
@@ -31,6 +32,7 @@ function Exports(exportName) {
31
32
  try {
32
33
  return originalMethod.call(this, ...args);
33
34
  } catch (err) {
35
+ GlobalData.OnError(ErrorType.Export, err);
34
36
  REMOVE_EVENT_LOG: {
35
37
  if (!GlobalData.EnablePrettyPrint) return;
36
38
  console.error("------- EXPORT ERROR --------");
package/decors/Ticks.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { ErrorType, GlobalData } from "../GlobalData";
3
4
  function SetTick() {
4
5
  return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
5
6
  if (context.private) {
@@ -7,7 +8,11 @@ function SetTick() {
7
8
  }
8
9
  context.addInitializer(function() {
9
10
  setTick(async () => {
10
- await originalMethod.call(this);
11
+ try {
12
+ await originalMethod.call(this);
13
+ } catch (e) {
14
+ GlobalData.OnError(ErrorType.Tick, e);
15
+ }
11
16
  });
12
17
  });
13
18
  }, "actualDecorator");
@@ -20,7 +25,11 @@ function SetImmediate() {
20
25
  }
21
26
  context.addInitializer(function() {
22
27
  setImmediate(async () => {
23
- await originalMethod.call(this);
28
+ try {
29
+ await originalMethod.call(this);
30
+ } catch (e) {
31
+ GlobalData.OnError(ErrorType.Immediate, e);
32
+ }
24
33
  });
25
34
  });
26
35
  }, "actualDecorator");
package/index.d.ts CHANGED
@@ -23,4 +23,6 @@ export * from "./decors/Events";
23
23
  export * from "./decors/Exports";
24
24
  export * from "./decors/Permissions";
25
25
  export * from "./decors/Resources";
26
- export * from "./decors/Ticks";
26
+ export * from "./decors/Ticks";
27
+ export * from "./collections/CircularBuffer";
28
+ export * from "./collections/Stack";
package/index.js CHANGED
@@ -23,4 +23,6 @@ export * from "./decors/Events";
23
23
  export * from "./decors/Exports";
24
24
  export * from "./decors/Permissions";
25
25
  export * from "./decors/Resources";
26
- export * from "./decors/Ticks";
26
+ export * from "./decors/Ticks";
27
+ export * from "./collections/CircularBuffer";
28
+ export * from "./collections/Stack";
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.136",
11
+ "version": "0.0.137",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"