@sonoransoftware/sonoran.js 1.0.0 → 1.0.1

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 (73) hide show
  1. package/.github/workflows/npm-publish.yml +34 -0
  2. package/dist/builders/cad/DispatchCall.d.ts +92 -0
  3. package/dist/builders/cad/DispatchCall.js +144 -0
  4. package/dist/builders/cad/index.d.ts +1 -0
  5. package/dist/builders/cad/index.js +17 -0
  6. package/dist/builders/index.d.ts +1 -0
  7. package/dist/builders/index.js +19 -0
  8. package/dist/constants.d.ts +156 -0
  9. package/dist/constants.js +27 -0
  10. package/dist/errors/LibraryErrors.d.ts +19 -0
  11. package/dist/errors/LibraryErrors.js +47 -0
  12. package/dist/errors/Messages.d.ts +1 -0
  13. package/dist/errors/Messages.js +8 -0
  14. package/dist/errors/index.d.ts +2 -0
  15. package/dist/errors/index.js +18 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.js +24 -0
  18. package/dist/instance/Instance.d.ts +23 -0
  19. package/dist/instance/Instance.js +134 -0
  20. package/dist/instance/instance.types.d.ts +16 -0
  21. package/dist/instance/instance.types.js +2 -0
  22. package/dist/libs/rest/src/index.d.ts +6 -0
  23. package/dist/libs/rest/src/index.js +22 -0
  24. package/dist/libs/rest/src/lib/REST.d.ts +99 -0
  25. package/dist/libs/rest/src/lib/REST.js +97 -0
  26. package/dist/libs/rest/src/lib/RequestManager.d.ts +58 -0
  27. package/dist/libs/rest/src/lib/RequestManager.js +201 -0
  28. package/dist/libs/rest/src/lib/errors/APIError.d.ts +9 -0
  29. package/dist/libs/rest/src/lib/errors/APIError.js +17 -0
  30. package/dist/libs/rest/src/lib/errors/HTTPError.d.ts +17 -0
  31. package/dist/libs/rest/src/lib/errors/HTTPError.js +23 -0
  32. package/dist/libs/rest/src/lib/errors/RateLimitError.d.ts +13 -0
  33. package/dist/libs/rest/src/lib/errors/RateLimitError.js +19 -0
  34. package/dist/libs/rest/src/lib/errors/index.d.ts +4 -0
  35. package/dist/libs/rest/src/lib/errors/index.js +20 -0
  36. package/dist/libs/rest/src/lib/handlers/IHandler.d.ts +7 -0
  37. package/dist/libs/rest/src/lib/handlers/IHandler.js +2 -0
  38. package/dist/libs/rest/src/lib/handlers/SequentialHandler.d.ts +45 -0
  39. package/dist/libs/rest/src/lib/handlers/SequentialHandler.js +155 -0
  40. package/dist/libs/rest/src/lib/utils/Utils.d.ts +1 -0
  41. package/dist/libs/rest/src/lib/utils/Utils.js +22 -0
  42. package/dist/libs/rest/src/lib/utils/constants.d.ts +493 -0
  43. package/dist/libs/rest/src/lib/utils/constants.js +408 -0
  44. package/dist/managers/BaseManager.d.ts +14 -0
  45. package/dist/managers/BaseManager.js +18 -0
  46. package/dist/managers/CADActiveUnitsManager.d.ts +15 -0
  47. package/dist/managers/CADActiveUnitsManager.js +49 -0
  48. package/dist/managers/CADManager.d.ts +27 -0
  49. package/dist/managers/CADManager.js +93 -0
  50. package/dist/managers/CADServerManager.d.ts +8 -0
  51. package/dist/managers/CADServerManager.js +37 -0
  52. package/dist/managers/CMSManager.d.ts +62 -0
  53. package/dist/managers/CMSManager.js +181 -0
  54. package/dist/managers/CMSServerManager.d.ts +8 -0
  55. package/dist/managers/CMSServerManager.js +37 -0
  56. package/dist/managers/CacheManager.d.ts +10 -0
  57. package/dist/managers/CacheManager.js +39 -0
  58. package/dist/managers/DataManager.d.ts +31 -0
  59. package/dist/managers/DataManager.js +61 -0
  60. package/dist/structures/Base.d.ts +9 -0
  61. package/dist/structures/Base.js +24 -0
  62. package/dist/structures/CADActiveUnit.d.ts +47 -0
  63. package/dist/structures/CADActiveUnit.js +66 -0
  64. package/dist/structures/CADServer.d.ts +26 -0
  65. package/dist/structures/CADServer.js +15 -0
  66. package/dist/structures/CMSServer.d.ts +18 -0
  67. package/dist/structures/CMSServer.js +12 -0
  68. package/dist/utils/index.d.ts +1 -0
  69. package/dist/utils/index.js +17 -0
  70. package/dist/utils/utils.d.ts +13 -0
  71. package/dist/utils/utils.js +82 -0
  72. package/package.json +8 -4
  73. package/tsconfig.json +3 -3
@@ -0,0 +1,62 @@
1
+ import Instance from '../instance/Instance';
2
+ import { CMSSubscriptionVersionEnum } from '../constants';
3
+ import { REST } from '../libs/rest/src';
4
+ import { BaseManager } from './BaseManager';
5
+ import * as globalTypes from '../constants';
6
+ import { CMSServerManager } from './CMSServerManager';
7
+ /**
8
+ * Manages all Sonoran CMS data and methods to interact with the public API.
9
+ */
10
+ export declare class CMSManager extends BaseManager {
11
+ readonly ready: boolean;
12
+ readonly version: CMSSubscriptionVersionEnum;
13
+ rest: REST | undefined;
14
+ servers: CMSServerManager | undefined;
15
+ constructor(instance: Instance);
16
+ protected buildManager(instance: Instance): Promise<void>;
17
+ /**
18
+ * Verifies the whitelist of a given account with the given parameters to search of said account.
19
+ * @param {Object | string} data The object or [accId | apiId as a string] that contains data to get a community account to verify if it has whitelist to the specified server. *If given as a string it will default to the set or default cms server id (1).
20
+ * @param {string} [data.accId] The account id to find a community account.
21
+ * @param {string} [data.apiId] The api id to find a community account.
22
+ * @param {string} [data.serverId] The username to find a community account.
23
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
24
+ */
25
+ verifyWhitelist(data: {
26
+ accId?: string;
27
+ apiId?: string;
28
+ serverId?: number;
29
+ } | string): Promise<globalTypes.CMSVerifyWhitelistPromiseResult>;
30
+ /**
31
+ * Gets a community account by `accId`, `apiId`, or `username`.
32
+ * @param {Object} params The object that contains parameters to get a community account.
33
+ * @param {string} [data.accId] The account id to find a community account.
34
+ * @param {string} [data.apiId] The api id to find a community account.
35
+ * @param {string} [data.username] The username to find a community account.
36
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
37
+ */
38
+ getComAccount(params: {
39
+ accId?: string;
40
+ apiId?: string;
41
+ username?: string;
42
+ }): Promise<globalTypes.CMSGetComAccountPromiseResult>;
43
+ /**
44
+ * Clocks in or out an account by `accId` or `apiId`.
45
+ * @param {Object} data The object that contains critical data to clock in or out an account.
46
+ * @param {string} [data.accId] The account id to clock in or out.
47
+ * @param {string} [data.apiId] The api id to clock in or out.
48
+ * @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
49
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
50
+ */
51
+ clockInOut(data: {
52
+ accId?: string;
53
+ apiId?: string;
54
+ forceClockIn?: boolean;
55
+ }): Promise<globalTypes.CMSClockInOutPromiseResult>;
56
+ /**
57
+ * Check if a given [apiId] is attached to any account within the community CMS.
58
+ * @param {string} apiId The api id to check for an account.
59
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
60
+ */
61
+ checkComApiId(apiId: string): Promise<globalTypes.CMSCheckComApiIdPromiseResult>;
62
+ }
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.CMSManager = void 0;
36
+ const src_1 = require("../libs/rest/src");
37
+ const BaseManager_1 = require("./BaseManager");
38
+ const globalTypes = __importStar(require("../constants"));
39
+ const CMSServerManager_1 = require("./CMSServerManager");
40
+ /**
41
+ * Manages all Sonoran CMS data and methods to interact with the public API.
42
+ */
43
+ class CMSManager extends BaseManager_1.BaseManager {
44
+ constructor(instance) {
45
+ super(instance);
46
+ this.ready = false;
47
+ this.version = 0;
48
+ this.rest = new src_1.REST(instance, this, globalTypes.productEnums.CMS, src_1.DefaultCMSRestOptions);
49
+ this.buildManager(instance);
50
+ }
51
+ buildManager(instance) {
52
+ var _a;
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ try {
55
+ const versionResp = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SUB_VERSION'));
56
+ const mutableThis = this;
57
+ mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
58
+ if (this.version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
59
+ this.servers = new CMSServerManager_1.CMSServerManager(instance, this);
60
+ }
61
+ mutableThis.ready = true;
62
+ }
63
+ catch (err) {
64
+ throw err;
65
+ }
66
+ });
67
+ }
68
+ /**
69
+ * Verifies the whitelist of a given account with the given parameters to search of said account.
70
+ * @param {Object | string} data The object or [accId | apiId as a string] that contains data to get a community account to verify if it has whitelist to the specified server. *If given as a string it will default to the set or default cms server id (1).
71
+ * @param {string} [data.accId] The account id to find a community account.
72
+ * @param {string} [data.apiId] The api id to find a community account.
73
+ * @param {string} [data.serverId] The username to find a community account.
74
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
75
+ */
76
+ verifyWhitelist(data) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
79
+ var _a, _b;
80
+ try {
81
+ const isString = typeof data === 'string';
82
+ const whitelistRequest = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('VERIFY_WHITELIST', isString ? data : data.apiId, isString ? data : data.accId, isString ? this.instance.cmsDefaultServerId : (_b = data.serverId) !== null && _b !== void 0 ? _b : this.instance.cmsDefaultServerId));
83
+ if (typeof whitelistRequest === 'string') {
84
+ resolve({ success: true, reason: whitelistRequest });
85
+ }
86
+ else {
87
+ resolve({ success: false, reason: whitelistRequest });
88
+ }
89
+ }
90
+ catch (err) {
91
+ if (err instanceof src_1.APIError) {
92
+ resolve({ success: false, reason: err.response });
93
+ }
94
+ else {
95
+ reject(err);
96
+ }
97
+ }
98
+ }));
99
+ });
100
+ }
101
+ /**
102
+ * Gets a community account by `accId`, `apiId`, or `username`.
103
+ * @param {Object} params The object that contains parameters to get a community account.
104
+ * @param {string} [data.accId] The account id to find a community account.
105
+ * @param {string} [data.apiId] The api id to find a community account.
106
+ * @param {string} [data.username] The username to find a community account.
107
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
108
+ */
109
+ getComAccount(params) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
112
+ var _a;
113
+ try {
114
+ const getAccountRequest = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId));
115
+ resolve({ success: true, data: getAccountRequest });
116
+ }
117
+ catch (err) {
118
+ if (err instanceof src_1.APIError) {
119
+ resolve({ success: false, reason: err.response });
120
+ }
121
+ else {
122
+ reject(err);
123
+ }
124
+ }
125
+ }));
126
+ });
127
+ }
128
+ /**
129
+ * Clocks in or out an account by `accId` or `apiId`.
130
+ * @param {Object} data The object that contains critical data to clock in or out an account.
131
+ * @param {string} [data.accId] The account id to clock in or out.
132
+ * @param {string} [data.apiId] The api id to clock in or out.
133
+ * @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
134
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
135
+ */
136
+ clockInOut(data) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
139
+ var _a;
140
+ try {
141
+ const clockInOutRequest = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn));
142
+ const clockInOutRequestString = clockInOutRequest;
143
+ resolve({ success: true, clockedIn: clockInOutRequestString.includes('CLOCKED IN') });
144
+ }
145
+ catch (err) {
146
+ if (err instanceof src_1.APIError) {
147
+ resolve({ success: false, reason: err.response });
148
+ }
149
+ else {
150
+ reject(err);
151
+ }
152
+ }
153
+ }));
154
+ });
155
+ }
156
+ /**
157
+ * Check if a given [apiId] is attached to any account within the community CMS.
158
+ * @param {string} apiId The api id to check for an account.
159
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
160
+ */
161
+ checkComApiId(apiId) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
164
+ var _a;
165
+ try {
166
+ const checkComApiIdRequest = yield ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CHECK_COM_APIID', apiId));
167
+ resolve({ success: true, username: checkComApiIdRequest });
168
+ }
169
+ catch (err) {
170
+ if (err instanceof src_1.APIError) {
171
+ resolve({ success: false, reason: err.response });
172
+ }
173
+ else {
174
+ reject(err);
175
+ }
176
+ }
177
+ }));
178
+ });
179
+ }
180
+ }
181
+ exports.CMSManager = CMSManager;
@@ -0,0 +1,8 @@
1
+ import Instance from '../instance/Instance';
2
+ import { CMSServerAPIStruct } from '../libs/rest/src';
3
+ import { CMSServer } from '../structures/CMSServer';
4
+ import { CacheManager } from './CacheManager';
5
+ import { CMSManager } from './CMSManager';
6
+ export declare class CMSServerManager extends CacheManager<number, CMSServer, CMSServerAPIStruct> {
7
+ constructor(instance: Instance, manager: CMSManager);
8
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CMSServerManager = void 0;
13
+ const CMSServer_1 = require("../structures/CMSServer");
14
+ const CacheManager_1 = require("./CacheManager");
15
+ class CMSServerManager extends CacheManager_1.CacheManager {
16
+ constructor(instance, manager) {
17
+ super(instance, CMSServer_1.CMSServer, []);
18
+ (() => __awaiter(this, void 0, void 0, function* () {
19
+ var _a;
20
+ try {
21
+ const serversRes = yield ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_GAME_SERVERS'));
22
+ const servers = serversRes.servers;
23
+ servers.forEach((server) => {
24
+ const serverStruct = {
25
+ id: server.id,
26
+ config: server
27
+ };
28
+ this._add(serverStruct, true, server.id);
29
+ });
30
+ }
31
+ catch (err) {
32
+ throw new Error(String(err));
33
+ }
34
+ }))();
35
+ }
36
+ }
37
+ exports.CMSServerManager = CMSServerManager;
@@ -0,0 +1,10 @@
1
+ import Collection from '@discordjs/collection';
2
+ import Instance from '../instance/Instance';
3
+ import { Constructable } from '../constants';
4
+ import { DataManager } from './DataManager';
5
+ export declare class CacheManager<K, Holds, R> extends DataManager<K, Holds, R> {
6
+ _cache: Collection<any, any> | never;
7
+ protected constructor(instance: Instance, holds: Constructable<Holds>, iterable: Iterable<any>);
8
+ get cache(): Collection<any, any>;
9
+ _add(data: any, cache?: boolean, id?: K): any;
10
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CacheManager = void 0;
7
+ const collection_1 = __importDefault(require("@discordjs/collection"));
8
+ const DataManager_1 = require("./DataManager");
9
+ class CacheManager extends DataManager_1.DataManager {
10
+ constructor(instance, holds, iterable) {
11
+ super(instance, holds);
12
+ this._cache = new collection_1.default();
13
+ if (iterable) {
14
+ for (const item of iterable) {
15
+ this._add(item);
16
+ }
17
+ }
18
+ }
19
+ get cache() {
20
+ return this._cache;
21
+ }
22
+ _add(data, cache = true, id) {
23
+ const existing = this.cache.get(id !== null && id !== void 0 ? id : data.id);
24
+ if (existing) {
25
+ if (cache) {
26
+ existing._patch(data);
27
+ return existing;
28
+ }
29
+ const clone = existing._clone();
30
+ clone._patch(data);
31
+ return clone;
32
+ }
33
+ const entry = data;
34
+ if (cache)
35
+ this.cache.set(id !== null && id !== void 0 ? id : entry.id, entry);
36
+ return entry;
37
+ }
38
+ }
39
+ exports.CacheManager = CacheManager;
@@ -0,0 +1,31 @@
1
+ import Instance from '../instance/Instance';
2
+ import { BaseManager } from './BaseManager';
3
+ import { Constructable } from '../constants';
4
+ import Collection from '@discordjs/collection';
5
+ interface DataManagerInstanceObject {
6
+ id: string;
7
+ }
8
+ export declare class DataManager<_K, Holds, _R> extends BaseManager {
9
+ holds: Constructable<Holds>;
10
+ constructor(instance: Instance, holds: any);
11
+ /**
12
+ * The cache of items for this manager.
13
+ * @type {Collection}
14
+ * @abstract
15
+ */
16
+ get cache(): Collection<any, any>;
17
+ /**
18
+ * Resolves a data entry to a data Object.
19
+ * @param idOrInstance The id or instance of something in this Manager
20
+ * @returns {?Object} An instance from this Manager
21
+ */
22
+ resolve(idOrInstance: string | object): object | null;
23
+ /**
24
+ * Resolves a data entry to an instance id.
25
+ * @param {string|Object} idOrInstance The id or instance of something in this Manager
26
+ * @returns {?Snowflake}
27
+ */
28
+ resolveId(idOrInstance: string | DataManagerInstanceObject): string | null;
29
+ valueOf(): Collection<any, any>;
30
+ }
31
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DataManager = void 0;
7
+ const BaseManager_1 = require("./BaseManager");
8
+ const errors_1 = require("../errors");
9
+ const collection_1 = __importDefault(require("@discordjs/collection"));
10
+ class DataManager extends BaseManager_1.BaseManager {
11
+ constructor(instance, holds) {
12
+ super(instance);
13
+ /**
14
+ * The data structure belonging to this manager.
15
+ * @name DataManager#holds
16
+ * @type {Function}
17
+ * @private
18
+ * @readonly
19
+ */
20
+ this.holds = holds;
21
+ }
22
+ /**
23
+ * The cache of items for this manager.
24
+ * @type {Collection}
25
+ * @abstract
26
+ */
27
+ get cache() {
28
+ throw new errors_1.GenericError('NOT_IMPLEMENTED', 'get cache', this.constructor.name);
29
+ }
30
+ /**
31
+ * Resolves a data entry to a data Object.
32
+ * @param idOrInstance The id or instance of something in this Manager
33
+ * @returns {?Object} An instance from this Manager
34
+ */
35
+ resolve(idOrInstance) {
36
+ var _a;
37
+ if (this.cache instanceof collection_1.default) {
38
+ if (typeof idOrInstance === 'object')
39
+ return idOrInstance;
40
+ if (typeof idOrInstance === 'string')
41
+ return (_a = this.cache.get(idOrInstance)) !== null && _a !== void 0 ? _a : null;
42
+ }
43
+ return null;
44
+ }
45
+ /**
46
+ * Resolves a data entry to an instance id.
47
+ * @param {string|Object} idOrInstance The id or instance of something in this Manager
48
+ * @returns {?Snowflake}
49
+ */
50
+ resolveId(idOrInstance) {
51
+ if (typeof idOrInstance === 'object')
52
+ return idOrInstance.id;
53
+ if (typeof idOrInstance === 'string')
54
+ return idOrInstance;
55
+ return null;
56
+ }
57
+ valueOf() {
58
+ return this.cache;
59
+ }
60
+ }
61
+ exports.DataManager = DataManager;
@@ -0,0 +1,9 @@
1
+ import Instance from '../instance/Instance';
2
+ export declare abstract class Base {
3
+ instance: Instance;
4
+ constructor(instance: Instance);
5
+ _clone(): any;
6
+ _patch(data: any): any;
7
+ _update(data: any): any;
8
+ toJSON(...props: Record<string, boolean | string>[]): unknown;
9
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Base = void 0;
4
+ const utils_1 = require("../utils");
5
+ class Base {
6
+ constructor(instance) {
7
+ this.instance = instance;
8
+ }
9
+ _clone() {
10
+ return Object.assign(Object.create(this), this);
11
+ }
12
+ _patch(data) {
13
+ return data;
14
+ }
15
+ _update(data) {
16
+ const clone = this._clone();
17
+ this._patch(data);
18
+ return clone;
19
+ }
20
+ toJSON(...props) {
21
+ return (0, utils_1.flatten)(this, ...props);
22
+ }
23
+ }
24
+ exports.Base = Base;
@@ -0,0 +1,47 @@
1
+ import Instance from '../instance/Instance';
2
+ import { Base } from './Base';
3
+ export interface CADActiveUnitStruct {
4
+ id: number;
5
+ accId: string;
6
+ status: number;
7
+ isPanic: boolean;
8
+ location: string;
9
+ aop: string;
10
+ isDispatch: boolean;
11
+ data: CADActiveUnitDataStruct;
12
+ }
13
+ interface CADActiveUnitStructPartial {
14
+ id: number;
15
+ accId: string;
16
+ status: number;
17
+ isPanic: boolean;
18
+ location: string;
19
+ aop: string;
20
+ isDispatch: boolean;
21
+ data: Partial<CADActiveUnitDataStruct>;
22
+ }
23
+ export interface CADActiveUnitDataStruct {
24
+ apiId1: string;
25
+ apiId2: string;
26
+ unitNum: string;
27
+ name: string;
28
+ district: string;
29
+ department: string;
30
+ subdivision: string;
31
+ rank: string;
32
+ group: string;
33
+ }
34
+ export declare type CADActiveUnitResolvable = CADActiveUnit | number;
35
+ export declare class CADActiveUnit extends Base {
36
+ id: number;
37
+ accId: string;
38
+ status: number;
39
+ isPanic: boolean;
40
+ location: string;
41
+ aop: string;
42
+ isDispatch: boolean;
43
+ data: CADActiveUnitDataStruct;
44
+ constructor(instance: Instance, data: any);
45
+ _patch(data: Partial<CADActiveUnitStructPartial>): void;
46
+ }
47
+ export {};
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CADActiveUnit = void 0;
4
+ const Base_1 = require("./Base");
5
+ class CADActiveUnit extends Base_1.Base {
6
+ constructor(instance, data) {
7
+ super(instance);
8
+ this.id = -1;
9
+ this.accId = '';
10
+ this.status = 0;
11
+ this.isPanic = false;
12
+ this.location = '';
13
+ this.aop = '';
14
+ this.isDispatch = false;
15
+ this.data = {
16
+ apiId1: '',
17
+ apiId2: '',
18
+ unitNum: '',
19
+ name: '',
20
+ district: '',
21
+ department: '',
22
+ subdivision: '',
23
+ rank: '',
24
+ group: ''
25
+ };
26
+ if (data)
27
+ this._patch(data);
28
+ }
29
+ _patch(data) {
30
+ if (data.id !== undefined)
31
+ this.id = data.id;
32
+ if (data.accId !== undefined)
33
+ this.accId = data.accId;
34
+ if (data.status !== undefined)
35
+ this.status = data.status;
36
+ if (data.isPanic !== undefined)
37
+ this.isPanic = data.isPanic;
38
+ if (data.location !== undefined)
39
+ this.location = data.location;
40
+ if (data.aop !== undefined)
41
+ this.aop = data.aop;
42
+ if (data.isDispatch !== undefined)
43
+ this.isDispatch = data.isDispatch;
44
+ if (data.data !== undefined) {
45
+ if (data.data.apiId1 !== undefined)
46
+ this.data.apiId1 = data.data.apiId1;
47
+ if (data.data.apiId2 !== undefined)
48
+ this.data.apiId2 = data.data.apiId2;
49
+ if (data.data.unitNum !== undefined)
50
+ this.data.unitNum = data.data.unitNum;
51
+ if (data.data.name !== undefined)
52
+ this.data.name = data.data.name;
53
+ if (data.data.district !== undefined)
54
+ this.data.district = data.data.district;
55
+ if (data.data.department !== undefined)
56
+ this.data.department = data.data.department;
57
+ if (data.data.subdivision !== undefined)
58
+ this.data.subdivision = data.data.subdivision;
59
+ if (data.data.rank !== undefined)
60
+ this.data.rank = data.data.rank;
61
+ if (data.data.group !== undefined)
62
+ this.data.group = data.data.group;
63
+ }
64
+ }
65
+ }
66
+ exports.CADActiveUnit = CADActiveUnit;
@@ -0,0 +1,26 @@
1
+ import Instance from '../instance/Instance';
2
+ import { Base } from './Base';
3
+ export interface CADServerData {
4
+ id: number;
5
+ config: CADServerConfig;
6
+ }
7
+ export interface CADServerConfig {
8
+ id: number;
9
+ name: string;
10
+ description: string;
11
+ signal: null;
12
+ mapUrl: string;
13
+ mapIp: string;
14
+ mapPort: string;
15
+ differingOutbound: boolean;
16
+ outboundIp: string;
17
+ listenerPort: string;
18
+ enableMap: boolean;
19
+ mapType: string;
20
+ isStatic: boolean;
21
+ }
22
+ export declare class CADServer extends Base {
23
+ id: number;
24
+ config: CADServerConfig;
25
+ constructor(instance: Instance, data: CADServerData);
26
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CADServer = void 0;
4
+ // import { CADActiveUnitsManager } from '../managers/CADActiveUnitsManager';
5
+ const Base_1 = require("./Base");
6
+ class CADServer extends Base_1.Base {
7
+ // public units!: CADActiveUnitsManager;
8
+ constructor(instance, data) {
9
+ super(instance);
10
+ this.id = data.id;
11
+ this.config = data.config;
12
+ // this.units = new CADActiveUnitsManager(instance, [], this.id);
13
+ }
14
+ }
15
+ exports.CADServer = CADServer;
@@ -0,0 +1,18 @@
1
+ import Instance from '../instance/Instance';
2
+ import { Base } from './Base';
3
+ export interface CMSServerData {
4
+ id: number;
5
+ config: CMSServerConfig;
6
+ }
7
+ export interface CMSServerConfig {
8
+ id: number;
9
+ name: string;
10
+ description: string;
11
+ allowedRanks: string[];
12
+ blockedRanks: string[];
13
+ }
14
+ export declare class CMSServer extends Base {
15
+ id: number;
16
+ config: CMSServerConfig;
17
+ constructor(instance: Instance, data: CMSServerData);
18
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CMSServer = void 0;
4
+ const Base_1 = require("./Base");
5
+ class CMSServer extends Base_1.Base {
6
+ constructor(instance, data) {
7
+ super(instance);
8
+ this.id = data.id;
9
+ this.config = data.config;
10
+ }
11
+ }
12
+ exports.CMSServer = CMSServer;
@@ -0,0 +1 @@
1
+ export * from './utils';