@sonoransoftware/sonoran.js 1.0.2 → 1.0.5

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.
Files changed (43) hide show
  1. package/dist/constants.d.ts +84 -10
  2. package/dist/index.d.ts +1 -2
  3. package/dist/index.js +1 -1
  4. package/dist/libs/rest/src/lib/REST.js +23 -1
  5. package/dist/libs/rest/src/lib/utils/constants.d.ts +30 -2
  6. package/dist/libs/rest/src/lib/utils/constants.js +24 -0
  7. package/dist/managers/CMSManager.d.ts +40 -2
  8. package/dist/managers/CMSManager.js +109 -7
  9. package/dist/managers/CMSServerManager.js +6 -0
  10. package/package.json +2 -2
  11. package/src/builders/cad/DispatchCall.ts +158 -158
  12. package/src/builders/index.ts +2 -2
  13. package/src/constants.ts +85 -10
  14. package/src/errors/LibraryErrors.ts +42 -42
  15. package/src/errors/Messages.ts +6 -6
  16. package/src/errors/index.ts +1 -1
  17. package/src/index.ts +4 -12
  18. package/src/instance/Instance.ts +117 -117
  19. package/src/instance/instance.types.ts +16 -16
  20. package/src/libs/rest/src/index.ts +5 -5
  21. package/src/libs/rest/src/lib/REST.ts +23 -1
  22. package/src/libs/rest/src/lib/RequestManager.ts +255 -255
  23. package/src/libs/rest/src/lib/errors/APIError.ts +14 -14
  24. package/src/libs/rest/src/lib/errors/HTTPError.ts +21 -21
  25. package/src/libs/rest/src/lib/errors/RateLimitError.ts +20 -20
  26. package/src/libs/rest/src/lib/errors/index.ts +3 -3
  27. package/src/libs/rest/src/lib/handlers/IHandler.ts +12 -12
  28. package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +157 -157
  29. package/src/libs/rest/src/lib/utils/constants.ts +55 -2
  30. package/src/libs/rest/src/lib/utils/utils.ts +17 -17
  31. package/src/managers/BaseManager.ts +15 -15
  32. package/src/managers/CADActiveUnitsManager.ts +49 -49
  33. package/src/managers/CADManager.ts +58 -58
  34. package/src/managers/CADServerManager.ts +26 -26
  35. package/src/managers/CMSManager.ts +103 -11
  36. package/src/managers/CMSServerManager.ts +6 -0
  37. package/src/managers/CacheManager.ts +37 -37
  38. package/src/managers/DataManager.ts +63 -63
  39. package/src/structures/Base.ts +27 -27
  40. package/src/structures/CADActiveUnit.ts +84 -84
  41. package/src/structures/CADServer.ts +36 -36
  42. package/src/structures/CMSServer.ts +25 -25
  43. package/src/utils/utils.ts +74 -74
@@ -1,85 +1,85 @@
1
- import { Instance } from '../instance/Instance';
2
- import { Base } from './Base';
3
-
4
- export interface CADActiveUnitStruct {
5
- id: number;
6
- accId: string;
7
- status: number;
8
- isPanic: boolean;
9
- location: string;
10
- aop: string;
11
- isDispatch: boolean;
12
- data: CADActiveUnitDataStruct;
13
- }
14
-
15
- interface CADActiveUnitStructPartial {
16
- id: number;
17
- accId: string;
18
- status: number;
19
- isPanic: boolean;
20
- location: string;
21
- aop: string;
22
- isDispatch: boolean;
23
- data: Partial<CADActiveUnitDataStruct>;
24
- }
25
-
26
- export interface CADActiveUnitDataStruct {
27
- apiId1: string;
28
- apiId2: string;
29
- unitNum: string;
30
- name: string;
31
- district: string;
32
- department: string;
33
- subdivision: string;
34
- rank: string;
35
- group: string;
36
- }
37
-
38
- export type CADActiveUnitResolvable = CADActiveUnit | number;
39
-
40
- export class CADActiveUnit extends Base {
41
- public id: number = -1;
42
- public accId: string = '';
43
- public status: number = 0;
44
- public isPanic: boolean = false;
45
- public location: string = '';
46
- public aop: string = '';
47
- public isDispatch: boolean = false;
48
- public data: CADActiveUnitDataStruct = {
49
- apiId1: '',
50
- apiId2: '',
51
- unitNum: '',
52
- name: '',
53
- district: '',
54
- department: '',
55
- subdivision: '',
56
- rank: '',
57
- group: ''
58
- };
59
-
60
- constructor(instance: Instance, data: any) {
61
- super(instance);
62
- if (data) this._patch(data);
63
- }
64
-
65
- public _patch(data: Partial<CADActiveUnitStructPartial>) {
66
- if (data.id !== undefined) this.id = data.id;
67
- if (data.accId !== undefined) this.accId = data.accId;
68
- if (data.status !== undefined) this.status = data.status;
69
- if (data.isPanic !== undefined) this.isPanic = data.isPanic;
70
- if (data.location !== undefined) this.location = data.location;
71
- if (data.aop !== undefined) this.aop = data.aop;
72
- if (data.isDispatch !== undefined) this.isDispatch = data.isDispatch;
73
- if (data.data !== undefined) {
74
- if (data.data.apiId1 !== undefined) this.data.apiId1 = data.data.apiId1;
75
- if (data.data.apiId2 !== undefined) this.data.apiId2 = data.data.apiId2;
76
- if (data.data.unitNum !== undefined) this.data.unitNum = data.data.unitNum;
77
- if (data.data.name !== undefined) this.data.name = data.data.name;
78
- if (data.data.district !== undefined) this.data.district = data.data.district;
79
- if (data.data.department !== undefined) this.data.department = data.data.department;
80
- if (data.data.subdivision !== undefined) this.data.subdivision = data.data.subdivision;
81
- if (data.data.rank !== undefined) this.data.rank = data.data.rank;
82
- if (data.data.group !== undefined) this.data.group = data.data.group;
83
- }
84
- }
1
+ import { Instance } from '../instance/Instance';
2
+ import { Base } from './Base';
3
+
4
+ export interface CADActiveUnitStruct {
5
+ id: number;
6
+ accId: string;
7
+ status: number;
8
+ isPanic: boolean;
9
+ location: string;
10
+ aop: string;
11
+ isDispatch: boolean;
12
+ data: CADActiveUnitDataStruct;
13
+ }
14
+
15
+ interface CADActiveUnitStructPartial {
16
+ id: number;
17
+ accId: string;
18
+ status: number;
19
+ isPanic: boolean;
20
+ location: string;
21
+ aop: string;
22
+ isDispatch: boolean;
23
+ data: Partial<CADActiveUnitDataStruct>;
24
+ }
25
+
26
+ export interface CADActiveUnitDataStruct {
27
+ apiId1: string;
28
+ apiId2: string;
29
+ unitNum: string;
30
+ name: string;
31
+ district: string;
32
+ department: string;
33
+ subdivision: string;
34
+ rank: string;
35
+ group: string;
36
+ }
37
+
38
+ export type CADActiveUnitResolvable = CADActiveUnit | number;
39
+
40
+ export class CADActiveUnit extends Base {
41
+ public id: number = -1;
42
+ public accId: string = '';
43
+ public status: number = 0;
44
+ public isPanic: boolean = false;
45
+ public location: string = '';
46
+ public aop: string = '';
47
+ public isDispatch: boolean = false;
48
+ public data: CADActiveUnitDataStruct = {
49
+ apiId1: '',
50
+ apiId2: '',
51
+ unitNum: '',
52
+ name: '',
53
+ district: '',
54
+ department: '',
55
+ subdivision: '',
56
+ rank: '',
57
+ group: ''
58
+ };
59
+
60
+ constructor(instance: Instance, data: any) {
61
+ super(instance);
62
+ if (data) this._patch(data);
63
+ }
64
+
65
+ public _patch(data: Partial<CADActiveUnitStructPartial>) {
66
+ if (data.id !== undefined) this.id = data.id;
67
+ if (data.accId !== undefined) this.accId = data.accId;
68
+ if (data.status !== undefined) this.status = data.status;
69
+ if (data.isPanic !== undefined) this.isPanic = data.isPanic;
70
+ if (data.location !== undefined) this.location = data.location;
71
+ if (data.aop !== undefined) this.aop = data.aop;
72
+ if (data.isDispatch !== undefined) this.isDispatch = data.isDispatch;
73
+ if (data.data !== undefined) {
74
+ if (data.data.apiId1 !== undefined) this.data.apiId1 = data.data.apiId1;
75
+ if (data.data.apiId2 !== undefined) this.data.apiId2 = data.data.apiId2;
76
+ if (data.data.unitNum !== undefined) this.data.unitNum = data.data.unitNum;
77
+ if (data.data.name !== undefined) this.data.name = data.data.name;
78
+ if (data.data.district !== undefined) this.data.district = data.data.district;
79
+ if (data.data.department !== undefined) this.data.department = data.data.department;
80
+ if (data.data.subdivision !== undefined) this.data.subdivision = data.data.subdivision;
81
+ if (data.data.rank !== undefined) this.data.rank = data.data.rank;
82
+ if (data.data.group !== undefined) this.data.group = data.data.group;
83
+ }
84
+ }
85
85
  }
@@ -1,37 +1,37 @@
1
- import { Instance } from '../instance/Instance';
2
- // import { CADActiveUnitsManager } from '../managers/CADActiveUnitsManager';
3
- import { Base } from './Base';
4
-
5
- export interface CADServerData {
6
- id: number;
7
- config: CADServerConfig;
8
- }
9
-
10
- export interface CADServerConfig {
11
- id: number;
12
- name: string;
13
- description: string;
14
- signal: null;
15
- mapUrl: string;
16
- mapIp: string;
17
- mapPort: string;
18
- differingOutbound: boolean;
19
- outboundIp: string;
20
- listenerPort: string;
21
- enableMap: boolean;
22
- mapType: string;
23
- isStatic: boolean;
24
- }
25
-
26
- export class CADServer extends Base {
27
- public id: number;
28
- public config!: CADServerConfig;
29
- // public units!: CADActiveUnitsManager;
30
-
31
- constructor(instance: Instance, data: CADServerData) {
32
- super(instance);
33
- this.id = data.id;
34
- this.config = data.config;
35
- // this.units = new CADActiveUnitsManager(instance, [], this.id);
36
- }
1
+ import { Instance } from '../instance/Instance';
2
+ // import { CADActiveUnitsManager } from '../managers/CADActiveUnitsManager';
3
+ import { Base } from './Base';
4
+
5
+ export interface CADServerData {
6
+ id: number;
7
+ config: CADServerConfig;
8
+ }
9
+
10
+ export interface CADServerConfig {
11
+ id: number;
12
+ name: string;
13
+ description: string;
14
+ signal: null;
15
+ mapUrl: string;
16
+ mapIp: string;
17
+ mapPort: string;
18
+ differingOutbound: boolean;
19
+ outboundIp: string;
20
+ listenerPort: string;
21
+ enableMap: boolean;
22
+ mapType: string;
23
+ isStatic: boolean;
24
+ }
25
+
26
+ export class CADServer extends Base {
27
+ public id: number;
28
+ public config!: CADServerConfig;
29
+ // public units!: CADActiveUnitsManager;
30
+
31
+ constructor(instance: Instance, data: CADServerData) {
32
+ super(instance);
33
+ this.id = data.id;
34
+ this.config = data.config;
35
+ // this.units = new CADActiveUnitsManager(instance, [], this.id);
36
+ }
37
37
  }
@@ -1,26 +1,26 @@
1
- import { Instance } from '../instance/Instance';
2
- import { Base } from './Base';
3
-
4
- export interface CMSServerData {
5
- id: number;
6
- config: CMSServerConfig;
7
- }
8
-
9
- export interface CMSServerConfig {
10
- id: number;
11
- name: string;
12
- description: string;
13
- allowedRanks: string[];
14
- blockedRanks: string[];
15
- }
16
-
17
- export class CMSServer extends Base {
18
- public id: number;
19
- public config!: CMSServerConfig;
20
-
21
- constructor(instance: Instance, data: CMSServerData) {
22
- super(instance);
23
- this.id = data.id;
24
- this.config = data.config;
25
- }
1
+ import { Instance } from '../instance/Instance';
2
+ import { Base } from './Base';
3
+
4
+ export interface CMSServerData {
5
+ id: number;
6
+ config: CMSServerConfig;
7
+ }
8
+
9
+ export interface CMSServerConfig {
10
+ id: number;
11
+ name: string;
12
+ description: string;
13
+ allowedRanks: string[];
14
+ blockedRanks: string[];
15
+ }
16
+
17
+ export class CMSServer extends Base {
18
+ public id: number;
19
+ public config!: CMSServerConfig;
20
+
21
+ constructor(instance: Instance, data: CMSServerData) {
22
+ super(instance);
23
+ this.id = data.id;
24
+ this.config = data.config;
25
+ }
26
26
  }
@@ -1,75 +1,75 @@
1
- import Collection from '@discordjs/collection';
2
-
3
- const isObject = (d: any) => typeof d === 'object' && d !== null;
4
-
5
- export function mergeDefault(def: any, given: any) {
6
- if (!given) return def;
7
- for (const key in def) {
8
- if (!Object.prototype.hasOwnProperty.call(given, key) || given[key] === undefined) {
9
- given[key] = def[key];
10
- } else if (given[key] === Object(given[key])) {
11
- given[key] = mergeDefault(def[key], given[key]);
12
- }
13
- }
14
- return given;
15
- }
16
-
17
- /**
18
- * Shallow-copies an object with its class/prototype intact.
19
- * @param {Object} obj Object to clone
20
- * @returns {Object}
21
- * @private
22
- */
23
- export function cloneObject(obj: any) {
24
- return Object.assign(Object.create(obj), obj);
25
- }
26
-
27
- export function flatten(obj: any, ...props: any[]) {
28
- if (!isObject(obj)) return obj;
29
-
30
- const objProps: any[] = Object.keys(obj)
31
- .filter((k) => !k.startsWith('_'))
32
- .map((k) => ({ [k]: true }));
33
-
34
- props = objProps.length ? Object.assign([...objProps], ...props) : Object.assign({}, ...props); // eslint-disable-line
35
-
36
- const out: Record<any, any> = {};
37
-
38
- for (let [prop, newProp] of Object.entries(props)) {
39
- if (!newProp) continue;
40
- newProp = newProp === true ? prop : newProp;
41
-
42
- const element = obj[prop];
43
- const elemIsObj = isObject(element);
44
- const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
45
-
46
- // If it's a Collection, make the array of keys
47
- if (element instanceof Collection) out[newProp] = Array.from(element.keys());
48
- // If the valueOf is a Collection, use its array of keys
49
- else if (valueOf instanceof Collection) out[newProp] = Array.from(valueOf.keys());
50
- // If it's an array, flatten each element
51
- else if (Array.isArray(element)) out[newProp] = element.map(e => flatten(e));
52
- // If it's an object with a primitive `valueOf`, use that value
53
- else if (typeof valueOf !== 'object') out[newProp] = valueOf;
54
- // If it's a primitive
55
- else if (!elemIsObj) out[newProp] = element;
56
- }
57
-
58
- return out;
59
- }
60
-
61
- export function warnLog(message: string): void {
62
- return console.log(`[Sonoran.js - DEBUG] ${message}`);
63
- }
64
-
65
- export function infoLog(message: string): void {
66
- return console.log(`[Sonoran.js - INFO] ${message}`);
67
- }
68
-
69
- export function errorLog(message: string): void {
70
- return console.log(`[Sonoran.js - ERROR] ${message}`);
71
- }
72
-
73
- export function debugLog(message: string): void {
74
- return console.log(`[Sonoran.js - DEBUG] ${message}`);
1
+ import Collection from '@discordjs/collection';
2
+
3
+ const isObject = (d: any) => typeof d === 'object' && d !== null;
4
+
5
+ export function mergeDefault(def: any, given: any) {
6
+ if (!given) return def;
7
+ for (const key in def) {
8
+ if (!Object.prototype.hasOwnProperty.call(given, key) || given[key] === undefined) {
9
+ given[key] = def[key];
10
+ } else if (given[key] === Object(given[key])) {
11
+ given[key] = mergeDefault(def[key], given[key]);
12
+ }
13
+ }
14
+ return given;
15
+ }
16
+
17
+ /**
18
+ * Shallow-copies an object with its class/prototype intact.
19
+ * @param {Object} obj Object to clone
20
+ * @returns {Object}
21
+ * @private
22
+ */
23
+ export function cloneObject(obj: any) {
24
+ return Object.assign(Object.create(obj), obj);
25
+ }
26
+
27
+ export function flatten(obj: any, ...props: any[]) {
28
+ if (!isObject(obj)) return obj;
29
+
30
+ const objProps: any[] = Object.keys(obj)
31
+ .filter((k) => !k.startsWith('_'))
32
+ .map((k) => ({ [k]: true }));
33
+
34
+ props = objProps.length ? Object.assign([...objProps], ...props) : Object.assign({}, ...props); // eslint-disable-line
35
+
36
+ const out: Record<any, any> = {};
37
+
38
+ for (let [prop, newProp] of Object.entries(props)) {
39
+ if (!newProp) continue;
40
+ newProp = newProp === true ? prop : newProp;
41
+
42
+ const element = obj[prop];
43
+ const elemIsObj = isObject(element);
44
+ const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
45
+
46
+ // If it's a Collection, make the array of keys
47
+ if (element instanceof Collection) out[newProp] = Array.from(element.keys());
48
+ // If the valueOf is a Collection, use its array of keys
49
+ else if (valueOf instanceof Collection) out[newProp] = Array.from(valueOf.keys());
50
+ // If it's an array, flatten each element
51
+ else if (Array.isArray(element)) out[newProp] = element.map(e => flatten(e));
52
+ // If it's an object with a primitive `valueOf`, use that value
53
+ else if (typeof valueOf !== 'object') out[newProp] = valueOf;
54
+ // If it's a primitive
55
+ else if (!elemIsObj) out[newProp] = element;
56
+ }
57
+
58
+ return out;
59
+ }
60
+
61
+ export function warnLog(message: string): void {
62
+ return console.log(`[Sonoran.js - DEBUG] ${message}`);
63
+ }
64
+
65
+ export function infoLog(message: string): void {
66
+ return console.log(`[Sonoran.js - INFO] ${message}`);
67
+ }
68
+
69
+ export function errorLog(message: string): void {
70
+ return console.log(`[Sonoran.js - ERROR] ${message}`);
71
+ }
72
+
73
+ export function debugLog(message: string): void {
74
+ return console.log(`[Sonoran.js - DEBUG] ${message}`);
75
75
  }