@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,158 +1,158 @@
1
- // import { setTimeout as sleep } from 'node:timers/promises';
2
- import { AsyncQueue } from '@sapphire/async-queue';
3
- import fetch, { RequestInit, Response } from 'node-fetch';
4
- import { AbortController } from "node-abort-controller";
5
- // import { DiscordAPIError, DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError';
6
- import { APIError } from '../errors';
7
- import { HTTPError } from '../errors/HTTPError';
8
- // import { RateLimitError } from '../errors/RateLimitError';
9
- import type { RequestManager, APIData, /**RequestData*/ } from '../RequestManager';
10
- import { RateLimitData } from '../REST';
11
- // import { RESTEvents } from '../utils/constants';
12
- // import type { RateLimitData } from '../REST';
13
- import type { IHandler } from './IHandler';
14
-
15
- export class SequentialHandler implements IHandler {
16
- /**
17
- * The unique id of the handler
18
- */
19
- public readonly id: string;
20
-
21
- /**
22
- * The total number of requests that can be made before we are rate limited
23
- */
24
- // private limit = Infinity;
25
-
26
- /**
27
- * The interface used to sequence async requests sequentially
28
- */
29
- // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
30
- #asyncQueue = new AsyncQueue();
31
-
32
- /**
33
- * @param manager The request manager
34
- * @param hash The hash that this RequestHandler handles
35
- * @param majorParameter The major parameter for this handler
36
- */
37
- public constructor(
38
- private readonly manager: RequestManager,
39
- private readonly data: APIData,
40
- ) {
41
- this.id = `${this.data.typePath}:${String(this.data.product)}`;
42
- }
43
-
44
- /**
45
- * If the bucket is currently inactive (no pending requests)
46
- */
47
- public get inactive(): boolean {
48
- return (
49
- this.#asyncQueue.remaining === 0
50
- );
51
- }
52
-
53
- public getMang(): RequestManager {
54
- return this.manager;
55
- }
56
-
57
- /**
58
- * Emits a debug message
59
- * @param message The message to debug
60
- */
61
- // private debug(message: string) {
62
- // this.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);
63
- // }
64
-
65
- /*
66
- * Determines whether the request should be queued or whether a RateLimitError should be thrown
67
- */
68
- // private async onRateLimit(rateLimitData: RateLimitData) {
69
- // const { options } = this.manager;
70
- // if (options.rejectOnRateLimit) {
71
- // throw new RateLimitError(rateLimitData);
72
- // }
73
- // }
74
-
75
- /**
76
- * Queues a request to be sent
77
- * @param routeId The generalized api route with literal ids for major parameters
78
- * @param url The url to do the request on
79
- * @param options All the information needed to make a request
80
- * @param requestData Extra data from the user's request needed for errors and additional processing
81
- */
82
- public async queueRequest(
83
- url: string,
84
- options: RequestInit,
85
- data: APIData
86
- ): Promise<unknown> {
87
- let queue = this.#asyncQueue;
88
- // Wait for any previous requests to be completed before this one is run
89
- await queue.wait();
90
- try {
91
- // Make the request, and return the results
92
- return await this.runRequest(url, options, data);
93
- } finally {
94
- // Allow the next request to fire
95
- queue.shift();
96
- }
97
- }
98
-
99
- /**
100
- * The method that actually makes the request to the api, and updates info about the bucket accordingly
101
- * @param routeId The generalized api route with literal ids for major parameters
102
- * @param url The fully resolved url to make the request to
103
- * @param options The node-fetch options needed to make the request
104
- * @param requestData Extra data from the user's request needed for errors and additional processing
105
- * @param retries The number of retries this request has already attempted (recursion)
106
- */
107
- private async runRequest(
108
- url: string,
109
- options: RequestInit,
110
- data: APIData,
111
- // retries = 0,
112
- ): Promise<unknown> {
113
- const controller = new AbortController();
114
- const timeout = setTimeout(() => controller.abort(), 30000).unref();
115
- let res: Response;
116
-
117
- try {
118
- // node-fetch typings are a bit weird, so we have to cast to any to get the correct signature
119
- // Type 'AbortSignal' is not assignable to type 'import('discord.js-modules/node_modules/@types/node-fetch/externals').AbortSignal'
120
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
121
- res = await fetch(url, { ...options, signal: controller.signal as any });
122
- } catch (error: unknown) {
123
- throw error;
124
- } finally {
125
- clearTimeout(timeout);
126
- }
127
-
128
- if (res.ok) {
129
- const parsedRes = await SequentialHandler.parseResponse(res);
130
- return parsedRes;
131
- } else if (res.status === 400 || res.status === 401 || res.status === 404) {
132
- const parsedRes = await SequentialHandler.parseResponse(res);
133
- // throw new HTTPError(String(parsedRes), res.constructor.name, res.status, data.method, url);
134
- throw new APIError(parsedRes as string, data.type, data.fullUrl, res.status, data);
135
- } else if (res.status === 429) {
136
- const timeout = setTimeout(() => {
137
- this.manager.removeRateLimit(data.requestTypeId);
138
- }, 60 * 1000);
139
- const ratelimitData: RateLimitData = {
140
- product: data.product,
141
- type: data.type,
142
- timeTill: timeout
143
- };
144
- this.manager.onRateLimit(data.requestTypeId, ratelimitData);
145
- } else if (res.status >= 500 && res.status < 600) {
146
- throw new HTTPError(res.statusText, res.constructor.name, res.status, data.method, url);
147
- }
148
- return null;
149
- }
150
-
151
- private static parseResponse(res: Response): Promise<unknown> {
152
- if (res.headers.get('Content-Type')?.startsWith('application/json')) {
153
- return res.json();
154
- }
155
-
156
- return res.text();
157
- }
1
+ // import { setTimeout as sleep } from 'node:timers/promises';
2
+ import { AsyncQueue } from '@sapphire/async-queue';
3
+ import fetch, { RequestInit, Response } from 'node-fetch';
4
+ import { AbortController } from "node-abort-controller";
5
+ // import { DiscordAPIError, DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError';
6
+ import { APIError } from '../errors';
7
+ import { HTTPError } from '../errors/HTTPError';
8
+ // import { RateLimitError } from '../errors/RateLimitError';
9
+ import type { RequestManager, APIData, /**RequestData*/ } from '../RequestManager';
10
+ import { RateLimitData } from '../REST';
11
+ // import { RESTEvents } from '../utils/constants';
12
+ // import type { RateLimitData } from '../REST';
13
+ import type { IHandler } from './IHandler';
14
+
15
+ export class SequentialHandler implements IHandler {
16
+ /**
17
+ * The unique id of the handler
18
+ */
19
+ public readonly id: string;
20
+
21
+ /**
22
+ * The total number of requests that can be made before we are rate limited
23
+ */
24
+ // private limit = Infinity;
25
+
26
+ /**
27
+ * The interface used to sequence async requests sequentially
28
+ */
29
+ // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
30
+ #asyncQueue = new AsyncQueue();
31
+
32
+ /**
33
+ * @param manager The request manager
34
+ * @param hash The hash that this RequestHandler handles
35
+ * @param majorParameter The major parameter for this handler
36
+ */
37
+ public constructor(
38
+ private readonly manager: RequestManager,
39
+ private readonly data: APIData,
40
+ ) {
41
+ this.id = `${this.data.typePath}:${String(this.data.product)}`;
42
+ }
43
+
44
+ /**
45
+ * If the bucket is currently inactive (no pending requests)
46
+ */
47
+ public get inactive(): boolean {
48
+ return (
49
+ this.#asyncQueue.remaining === 0
50
+ );
51
+ }
52
+
53
+ public getMang(): RequestManager {
54
+ return this.manager;
55
+ }
56
+
57
+ /**
58
+ * Emits a debug message
59
+ * @param message The message to debug
60
+ */
61
+ // private debug(message: string) {
62
+ // this.manager.emit(RESTEvents.Debug, `[REST ${this.id}] ${message}`);
63
+ // }
64
+
65
+ /*
66
+ * Determines whether the request should be queued or whether a RateLimitError should be thrown
67
+ */
68
+ // private async onRateLimit(rateLimitData: RateLimitData) {
69
+ // const { options } = this.manager;
70
+ // if (options.rejectOnRateLimit) {
71
+ // throw new RateLimitError(rateLimitData);
72
+ // }
73
+ // }
74
+
75
+ /**
76
+ * Queues a request to be sent
77
+ * @param routeId The generalized api route with literal ids for major parameters
78
+ * @param url The url to do the request on
79
+ * @param options All the information needed to make a request
80
+ * @param requestData Extra data from the user's request needed for errors and additional processing
81
+ */
82
+ public async queueRequest(
83
+ url: string,
84
+ options: RequestInit,
85
+ data: APIData
86
+ ): Promise<unknown> {
87
+ let queue = this.#asyncQueue;
88
+ // Wait for any previous requests to be completed before this one is run
89
+ await queue.wait();
90
+ try {
91
+ // Make the request, and return the results
92
+ return await this.runRequest(url, options, data);
93
+ } finally {
94
+ // Allow the next request to fire
95
+ queue.shift();
96
+ }
97
+ }
98
+
99
+ /**
100
+ * The method that actually makes the request to the api, and updates info about the bucket accordingly
101
+ * @param routeId The generalized api route with literal ids for major parameters
102
+ * @param url The fully resolved url to make the request to
103
+ * @param options The node-fetch options needed to make the request
104
+ * @param requestData Extra data from the user's request needed for errors and additional processing
105
+ * @param retries The number of retries this request has already attempted (recursion)
106
+ */
107
+ private async runRequest(
108
+ url: string,
109
+ options: RequestInit,
110
+ data: APIData,
111
+ // retries = 0,
112
+ ): Promise<unknown> {
113
+ const controller = new AbortController();
114
+ const timeout = setTimeout(() => controller.abort(), 30000).unref();
115
+ let res: Response;
116
+
117
+ try {
118
+ // node-fetch typings are a bit weird, so we have to cast to any to get the correct signature
119
+ // Type 'AbortSignal' is not assignable to type 'import('discord.js-modules/node_modules/@types/node-fetch/externals').AbortSignal'
120
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
121
+ res = await fetch(url, { ...options, signal: controller.signal as any });
122
+ } catch (error: unknown) {
123
+ throw error;
124
+ } finally {
125
+ clearTimeout(timeout);
126
+ }
127
+
128
+ if (res.ok) {
129
+ const parsedRes = await SequentialHandler.parseResponse(res);
130
+ return parsedRes;
131
+ } else if (res.status === 400 || res.status === 401 || res.status === 404) {
132
+ const parsedRes = await SequentialHandler.parseResponse(res);
133
+ // throw new HTTPError(String(parsedRes), res.constructor.name, res.status, data.method, url);
134
+ throw new APIError(parsedRes as string, data.type, data.fullUrl, res.status, data);
135
+ } else if (res.status === 429) {
136
+ const timeout = setTimeout(() => {
137
+ this.manager.removeRateLimit(data.requestTypeId);
138
+ }, 60 * 1000);
139
+ const ratelimitData: RateLimitData = {
140
+ product: data.product,
141
+ type: data.type,
142
+ timeTill: timeout
143
+ };
144
+ this.manager.onRateLimit(data.requestTypeId, ratelimitData);
145
+ } else if (res.status >= 500 && res.status < 600) {
146
+ throw new HTTPError(res.statusText, res.constructor.name, res.status, data.method, url);
147
+ }
148
+ return null;
149
+ }
150
+
151
+ private static parseResponse(res: Response): Promise<unknown> {
152
+ if (res.headers.get('Content-Type')?.startsWith('application/json')) {
153
+ return res.json();
154
+ }
155
+
156
+ return res.text();
157
+ }
158
158
  }
@@ -347,6 +347,24 @@ export const GeneralCMSAPITypes: APITypeData[] = [
347
347
  method: 'POST', // Would've been 'GET' but fetch doesn't allow body with GET requests.
348
348
  minVersion: 3
349
349
  },
350
+ {
351
+ type: 'GET_ACCOUNT_RANKS',
352
+ path: 'general/get_account_ranks',
353
+ method: 'POST', // Would've been 'GET' but fetch doesn't allow body with GET requests.
354
+ minVersion: 2,
355
+ },
356
+ {
357
+ type: 'SET_ACCOUNT_RANKS',
358
+ path: 'general/set_account_ranks',
359
+ method: 'POST', // Would've been 'GET' but fetch doesn't allow body with GET requests.
360
+ minVersion: 2,
361
+ },
362
+ {
363
+ type: 'GET_DEPARTMENTS',
364
+ path: 'general/get_departments',
365
+ method: 'POST', // Would've been 'GET' but fetch doesn't allow body with GET requests.
366
+ minVersion: 2,
367
+ },
350
368
  {
351
369
  type: 'GET_SUB_VERSION',
352
370
  path: 'general/get_sub_version',
@@ -379,6 +397,12 @@ export const ServersCMSAPITypes: APITypeData[] = [
379
397
  path: 'servers/verify_whitelist',
380
398
  method: 'POST',
381
399
  minVersion: 3
400
+ },
401
+ {
402
+ type: 'FULL_WHITELIST',
403
+ path: 'servers/full_whitelist',
404
+ method: 'POST',
405
+ minVersion: 3
382
406
  }
383
407
  ];
384
408
 
@@ -393,7 +417,7 @@ function formatForAll(array: APITypeData[], product: productEnums): AllAPITypeDa
393
417
 
394
418
  export const AllAPITypes: AllAPITypeData[] = [ ...formatForAll(GeneralCADAPITypes, productEnums.CAD), ...formatForAll(CivilianCADAPITypes, productEnums.CAD), ...formatForAll(EmergencyCADAPITypes, productEnums.CAD), ...formatForAll(GeneralCMSAPITypes, productEnums.CMS), ...formatForAll(ServersCMSAPITypes, productEnums.CMS) ];
395
419
 
396
- export type AllAPITypesType = 'GET_SERVERS' | 'SET_SERVERS' | 'GET_VERSION' | 'SET_PENAL_CODES' | 'SET_API_ID' | 'GET_TEMPLATES' | 'NEW_RECORD' | 'EDIT_RECORD' | 'REMOVE_RECORD' | 'LOOKUP_INT' | 'LOOKUP' | 'GET_ACCOUNT' | 'CHECK_APIID' | 'APPLY_PERMISSION_KEY' | 'SET_ACCOUNT_PERMISSIONS' | 'BAN_USER' | 'VERIFY_SECRET' | 'AUTH_STREETSIGNS' | 'SET_POSTALS' | 'SEND_PHOTO' | 'GET_CHARACTERS' | 'NEW_CHARACTER' | 'EDIT_CHARACTER' | 'REMOVE_CHARACTER' | 'GET_IDENTIFIERS' | 'MODIFY_IDENTIFIER' | 'SET_IDENTIFIER' | 'UNIT_PANIC' | 'UNIT_STATUS' | 'GET_BLIPS' | 'ADD_BLIP' | 'MODIFY_BLIP' | 'REMOVE_BLIP' | '911_CALL' | 'REMOVE_911' | 'GET_CALLS' | 'GET_ACTIVE_UNITS' | 'KICK_UNIT' | 'NEW_DISPATCH' | 'ATTACH_UNIT' | 'DETACH_UNIT' | 'SET_CALL_POSTAL' | 'SET_CALL_PRIMARY' | 'ADD_CALL_NOTE' | 'CLOSE_CALL' | 'UNIT_LOCATION' | 'SET_STREETSIGN_CONFIG' | 'UPDATE_STREETSIGN' | 'GET_COM_ACCOUNT' | 'GET_SUB_VERSION' | 'CHECK_COM_APIID' | 'VERIFY_WHITELIST' | 'CLOCK_IN_OUT';
420
+ export type AllAPITypesType = 'GET_SERVERS' | 'SET_SERVERS' | 'GET_VERSION' | 'SET_PENAL_CODES' | 'SET_API_ID' | 'GET_TEMPLATES' | 'NEW_RECORD' | 'EDIT_RECORD' | 'REMOVE_RECORD' | 'LOOKUP_INT' | 'LOOKUP' | 'GET_ACCOUNT' | 'CHECK_APIID' | 'APPLY_PERMISSION_KEY' | 'SET_ACCOUNT_PERMISSIONS' | 'BAN_USER' | 'VERIFY_SECRET' | 'AUTH_STREETSIGNS' | 'SET_POSTALS' | 'SEND_PHOTO' | 'GET_CHARACTERS' | 'NEW_CHARACTER' | 'EDIT_CHARACTER' | 'REMOVE_CHARACTER' | 'GET_IDENTIFIERS' | 'MODIFY_IDENTIFIER' | 'SET_IDENTIFIER' | 'UNIT_PANIC' | 'UNIT_STATUS' | 'GET_BLIPS' | 'ADD_BLIP' | 'MODIFY_BLIP' | 'REMOVE_BLIP' | '911_CALL' | 'REMOVE_911' | 'GET_CALLS' | 'GET_ACTIVE_UNITS' | 'KICK_UNIT' | 'NEW_DISPATCH' | 'ATTACH_UNIT' | 'DETACH_UNIT' | 'SET_CALL_POSTAL' | 'SET_CALL_PRIMARY' | 'ADD_CALL_NOTE' | 'CLOSE_CALL' | 'UNIT_LOCATION' | 'SET_STREETSIGN_CONFIG' | 'UPDATE_STREETSIGN' | 'GET_COM_ACCOUNT' | 'GET_DEPARTMENTS' | 'GET_SUB_VERSION' | 'CHECK_COM_APIID' | 'VERIFY_WHITELIST' | 'CLOCK_IN_OUT' | 'FULL_WHITELIST' | 'GET_ACCOUNT_RANKS' | 'SET_ACCOUNT_RANKS';
397
421
 
398
422
  export interface CMSServerAPIStruct {
399
423
  id: number;
@@ -782,7 +806,8 @@ export interface RESTTypedAPIDataStructs {
782
806
  GET_COM_ACCOUNT: [
783
807
  apiId?: string,
784
808
  username?: string,
785
- accId?: string
809
+ accId?: string,
810
+ discord?: string,
786
811
  ];
787
812
  GET_SUB_VERSION: [];
788
813
  CHECK_COM_APIID: [apiId: string];
@@ -791,6 +816,22 @@ export interface RESTTypedAPIDataStructs {
791
816
  accId?: string,
792
817
  forceClockIn?: boolean
793
818
  ];
819
+ GET_DEPARTMENTS: [];
820
+ GET_ACCOUNT_RANKS: [
821
+ apiId?: string,
822
+ username?: string,
823
+ accId?: string,
824
+ discord?: string,
825
+ ],
826
+ SET_ACCOUNT_RANKS: [
827
+ accountId: string,
828
+ set?: {
829
+ primary?: string | null,
830
+ secondary?: string[]
831
+ },
832
+ add?: string[],
833
+ remove?: string[],
834
+ ],
794
835
  // CMS - Servers
795
836
  GET_GAME_SERVERS: [];
796
837
  VERIFY_WHITELIST: [
@@ -798,6 +839,9 @@ export interface RESTTypedAPIDataStructs {
798
839
  accId: string | undefined,
799
840
  serverId: number
800
841
  ];
842
+ FULL_WHITELIST: [
843
+ serverId?: number,
844
+ ]
801
845
  }
802
846
 
803
847
  export type PossibleRequestData =
@@ -916,4 +960,13 @@ export type PossibleRequestData =
916
960
  {
917
961
  apiId: string;
918
962
  forceClockIn: boolean;
963
+ } |
964
+ {
965
+ accountId: string,
966
+ set?: {
967
+ primary: string[],
968
+ secondary: string[]
969
+ },
970
+ add?: string[],
971
+ remove?: string[],
919
972
  };
@@ -1,18 +1,18 @@
1
- export function convertSubNumToName(subLevel: number) {
2
- switch (subLevel) {
3
- case 0:
4
- return 'FREE';
5
- case 1:
6
- return 'STARTER';
7
- case 2:
8
- return 'STANDARD';
9
- case 3:
10
- return 'PLUS';
11
- case 4:
12
- return 'PRO';
13
- case 6:
14
- return 'ONE';
15
- default:
16
- return 'FREE';
17
- }
1
+ export function convertSubNumToName(subLevel: number) {
2
+ switch (subLevel) {
3
+ case 0:
4
+ return 'FREE';
5
+ case 1:
6
+ return 'STARTER';
7
+ case 2:
8
+ return 'STANDARD';
9
+ case 3:
10
+ return 'PLUS';
11
+ case 4:
12
+ return 'PRO';
13
+ case 6:
14
+ return 'ONE';
15
+ default:
16
+ return 'FREE';
17
+ }
18
18
  }
@@ -1,15 +1,15 @@
1
- import { Instance } from '../instance/Instance';
2
-
3
- /**
4
- * Manages the API methods of a data model or a specific product methods.
5
- * @abstract
6
- */
7
- export abstract class BaseManager {
8
- /**
9
- *
10
- * @param {Instance} instance The instance that instantiated this Manager
11
- * @readonly
12
- */
13
- constructor(public readonly instance: Instance) {
14
- }
15
- }
1
+ import { Instance } from '../instance/Instance';
2
+
3
+ /**
4
+ * Manages the API methods of a data model or a specific product methods.
5
+ * @abstract
6
+ */
7
+ export abstract class BaseManager {
8
+ /**
9
+ *
10
+ * @param {Instance} instance The instance that instantiated this Manager
11
+ * @readonly
12
+ */
13
+ constructor(public readonly instance: Instance) {
14
+ }
15
+ }
@@ -1,50 +1,50 @@
1
- // Work in progress still...
2
-
3
- // import { CADActiveUnitFetchOptions } from '../constants';
4
- import { Instance } from '../instance/Instance';
5
- import { CADActiveUnit, CADActiveUnitResolvable, CADActiveUnitStruct } from '../structures/CADActiveUnit';
6
- import { CacheManager } from './CacheManager';
7
-
8
- export class CADActiveUnitsManager extends CacheManager<number, CADActiveUnit, CADActiveUnitResolvable> {
9
- public serverId: number;
10
- public instance: Instance;
11
- constructor(instance: Instance, iterable: Iterable<CADActiveUnitStruct>, serverId: number) {
12
- super(instance, CADActiveUnit, iterable);
13
- this.instance = instance;
14
- this.serverId = serverId;
15
- }
16
-
17
- _add(data: any, cache = true) {
18
- return super._add(data, cache, data.id);
19
- }
20
-
21
- fetch(/*options: CADActiveUnitResolvable | CADActiveUnitFetchOptions**/) {
22
- // if (!options) return this._fetchMany();
23
- this._fetchSingle({
24
- unit: -1,
25
- includeOffline: false,
26
- force: false
27
- });
28
- }
29
-
30
- async _fetchSingle({
31
- unit,
32
- includeOffline = false,
33
- force = false
34
- }:{
35
- unit: CADActiveUnitResolvable;
36
- includeOffline: boolean;
37
- force: boolean;
38
- }) {
39
- if (!force) {
40
- const existing = this.cache.get(unit);
41
- if (existing) return existing;
42
- }
43
-
44
- const data = await this.instance.cad?.rest?.request('GET_ACTIVE_UNITS', {
45
- serverId: this.serverId,
46
- includeOffline
47
- });
48
- console.log(data);
49
- }
1
+ // Work in progress still...
2
+
3
+ // import { CADActiveUnitFetchOptions } from '../constants';
4
+ import { Instance } from '../instance/Instance';
5
+ import { CADActiveUnit, CADActiveUnitResolvable, CADActiveUnitStruct } from '../structures/CADActiveUnit';
6
+ import { CacheManager } from './CacheManager';
7
+
8
+ export class CADActiveUnitsManager extends CacheManager<number, CADActiveUnit, CADActiveUnitResolvable> {
9
+ public serverId: number;
10
+ public instance: Instance;
11
+ constructor(instance: Instance, iterable: Iterable<CADActiveUnitStruct>, serverId: number) {
12
+ super(instance, CADActiveUnit, iterable);
13
+ this.instance = instance;
14
+ this.serverId = serverId;
15
+ }
16
+
17
+ _add(data: any, cache = true) {
18
+ return super._add(data, cache, data.id);
19
+ }
20
+
21
+ fetch(/*options: CADActiveUnitResolvable | CADActiveUnitFetchOptions**/) {
22
+ // if (!options) return this._fetchMany();
23
+ this._fetchSingle({
24
+ unit: -1,
25
+ includeOffline: false,
26
+ force: false
27
+ });
28
+ }
29
+
30
+ async _fetchSingle({
31
+ unit,
32
+ includeOffline = false,
33
+ force = false
34
+ }:{
35
+ unit: CADActiveUnitResolvable;
36
+ includeOffline: boolean;
37
+ force: boolean;
38
+ }) {
39
+ if (!force) {
40
+ const existing = this.cache.get(unit);
41
+ if (existing) return existing;
42
+ }
43
+
44
+ const data = await this.instance.cad?.rest?.request('GET_ACTIVE_UNITS', {
45
+ serverId: this.serverId,
46
+ includeOffline
47
+ });
48
+ console.log(data);
49
+ }
50
50
  }