@sonoransoftware/sonoran.js 1.0.3 → 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 (41) hide show
  1. package/dist/constants.d.ts +56 -0
  2. package/dist/libs/rest/src/lib/REST.js +18 -1
  3. package/dist/libs/rest/src/lib/utils/constants.d.ts +23 -3
  4. package/dist/libs/rest/src/lib/utils/constants.js +12 -0
  5. package/dist/managers/CMSManager.d.ts +19 -0
  6. package/dist/managers/CMSManager.js +61 -6
  7. package/dist/managers/CMSServerManager.js +6 -0
  8. package/package.json +2 -2
  9. package/src/builders/cad/DispatchCall.ts +158 -158
  10. package/src/builders/index.ts +2 -2
  11. package/src/constants.ts +58 -0
  12. package/src/errors/LibraryErrors.ts +42 -42
  13. package/src/errors/Messages.ts +6 -6
  14. package/src/errors/index.ts +1 -1
  15. package/src/index.ts +3 -3
  16. package/src/instance/Instance.ts +117 -117
  17. package/src/instance/instance.types.ts +16 -16
  18. package/src/libs/rest/src/index.ts +5 -5
  19. package/src/libs/rest/src/lib/REST.ts +18 -1
  20. package/src/libs/rest/src/lib/RequestManager.ts +255 -255
  21. package/src/libs/rest/src/lib/errors/APIError.ts +14 -14
  22. package/src/libs/rest/src/lib/errors/HTTPError.ts +21 -21
  23. package/src/libs/rest/src/lib/errors/RateLimitError.ts +20 -20
  24. package/src/libs/rest/src/lib/errors/index.ts +3 -3
  25. package/src/libs/rest/src/lib/handlers/IHandler.ts +12 -12
  26. package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +157 -157
  27. package/src/libs/rest/src/lib/utils/constants.ts +35 -2
  28. package/src/libs/rest/src/lib/utils/utils.ts +17 -17
  29. package/src/managers/BaseManager.ts +15 -15
  30. package/src/managers/CADActiveUnitsManager.ts +49 -49
  31. package/src/managers/CADManager.ts +58 -58
  32. package/src/managers/CADServerManager.ts +26 -26
  33. package/src/managers/CMSManager.ts +60 -11
  34. package/src/managers/CMSServerManager.ts +6 -0
  35. package/src/managers/CacheManager.ts +37 -37
  36. package/src/managers/DataManager.ts +63 -63
  37. package/src/structures/Base.ts +27 -27
  38. package/src/structures/CADActiveUnit.ts +84 -84
  39. package/src/structures/CADServer.ts +36 -36
  40. package/src/structures/CMSServer.ts +25 -25
  41. 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
  }
@@ -353,6 +353,18 @@ export const GeneralCMSAPITypes: APITypeData[] = [
353
353
  method: 'POST', // Would've been 'GET' but fetch doesn't allow body with GET requests.
354
354
  minVersion: 2,
355
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
+ },
356
368
  {
357
369
  type: 'GET_SUB_VERSION',
358
370
  path: 'general/get_sub_version',
@@ -405,7 +417,7 @@ function formatForAll(array: APITypeData[], product: productEnums): AllAPITypeDa
405
417
 
406
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) ];
407
419
 
408
- 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' | 'FULL_WHITELIST' | 'GET_ACCOUNT_RANKS';
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';
409
421
 
410
422
  export interface CMSServerAPIStruct {
411
423
  id: number;
@@ -794,7 +806,8 @@ export interface RESTTypedAPIDataStructs {
794
806
  GET_COM_ACCOUNT: [
795
807
  apiId?: string,
796
808
  username?: string,
797
- accId?: string
809
+ accId?: string,
810
+ discord?: string,
798
811
  ];
799
812
  GET_SUB_VERSION: [];
800
813
  CHECK_COM_APIID: [apiId: string];
@@ -803,10 +816,21 @@ export interface RESTTypedAPIDataStructs {
803
816
  accId?: string,
804
817
  forceClockIn?: boolean
805
818
  ];
819
+ GET_DEPARTMENTS: [];
806
820
  GET_ACCOUNT_RANKS: [
807
821
  apiId?: string,
808
822
  username?: string,
809
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[],
810
834
  ],
811
835
  // CMS - Servers
812
836
  GET_GAME_SERVERS: [];
@@ -936,4 +960,13 @@ export type PossibleRequestData =
936
960
  {
937
961
  apiId: string;
938
962
  forceClockIn: boolean;
963
+ } |
964
+ {
965
+ accountId: string,
966
+ set?: {
967
+ primary: string[],
968
+ secondary: string[]
969
+ },
970
+ add?: string[],
971
+ remove?: string[],
939
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
  }