@sonoransoftware/sonoran.js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +11 -0
- package/.prettierrc.js +7 -0
- package/docs/CAD-Methods-and-Usage.md +59 -0
- package/docs/CMS-Methods-and-Usage.md +212 -0
- package/docs/REST-Methods-and-Usage.md +47 -0
- package/package.json +42 -0
- package/readme.md +54 -0
- package/src/builders/cad/DispatchCall.ts +159 -0
- package/src/builders/cad/index.ts +1 -0
- package/src/builders/index.ts +3 -0
- package/src/constants.ts +174 -0
- package/src/errors/LibraryErrors.ts +43 -0
- package/src/errors/Messages.ts +7 -0
- package/src/errors/index.ts +2 -0
- package/src/index.ts +12 -0
- package/src/instance/Instance.ts +118 -0
- package/src/instance/instance.types.ts +17 -0
- package/src/libs/rest/src/index.ts +6 -0
- package/src/libs/rest/src/lib/REST.ts +201 -0
- package/src/libs/rest/src/lib/RequestManager.ts +256 -0
- package/src/libs/rest/src/lib/errors/APIError.ts +15 -0
- package/src/libs/rest/src/lib/errors/HTTPError.ts +22 -0
- package/src/libs/rest/src/lib/errors/RateLimitError.ts +21 -0
- package/src/libs/rest/src/lib/errors/index.ts +4 -0
- package/src/libs/rest/src/lib/handlers/IHandler.ts +13 -0
- package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +157 -0
- package/src/libs/rest/src/lib/utils/constants.ts +919 -0
- package/src/libs/rest/src/lib/utils/utils.ts +18 -0
- package/src/managers/BaseManager.ts +15 -0
- package/src/managers/CADActiveUnitsManager.ts +50 -0
- package/src/managers/CADManager.ts +58 -0
- package/src/managers/CADServerManager.ts +27 -0
- package/src/managers/CMSManager.ts +133 -0
- package/src/managers/CMSServerManager.ts +27 -0
- package/src/managers/CacheManager.ts +38 -0
- package/src/managers/DataManager.ts +64 -0
- package/src/structures/Base.ts +28 -0
- package/src/structures/CADActiveUnit.ts +85 -0
- package/src/structures/CADServer.ts +37 -0
- package/src/structures/CMSServer.ts +26 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +75 -0
- package/tsconfig.json +71 -0
|
@@ -0,0 +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
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Instance from '../instance/Instance';
|
|
2
|
+
import { CADSubscriptionVersionEnum } from '../constants';
|
|
3
|
+
import { APIError, DefaultCADRestOptions, REST } from '../libs/rest/src';
|
|
4
|
+
import { BaseManager } from './BaseManager';
|
|
5
|
+
import * as globalTypes from '../constants';
|
|
6
|
+
import type { Mutable } from '../constants';
|
|
7
|
+
import { CADServerManager } from './CADServerManager';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Manages all Sonoran CAD data and methods to interact with the public API.
|
|
11
|
+
*/
|
|
12
|
+
export class CADManager extends BaseManager {
|
|
13
|
+
public readonly version: CADSubscriptionVersionEnum = 0;
|
|
14
|
+
public rest: REST | undefined;
|
|
15
|
+
public servers: CADServerManager | undefined;
|
|
16
|
+
|
|
17
|
+
constructor(instance: Instance) {
|
|
18
|
+
super(instance);
|
|
19
|
+
|
|
20
|
+
this.rest = new REST(instance, this, globalTypes.productEnums.CAD, DefaultCADRestOptions);
|
|
21
|
+
this.buildManager(instance);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected async buildManager(instance: Instance) {
|
|
25
|
+
try {
|
|
26
|
+
const versionResp: any = await this.rest?.request('GET_VERSION');
|
|
27
|
+
const mutableThis = this as Mutable<CADManager>;
|
|
28
|
+
mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i,'$1'));
|
|
29
|
+
if (this.version >= globalTypes.CADSubscriptionVersionEnum.STANDARD) {
|
|
30
|
+
this.servers = new CADServerManager(instance, this);
|
|
31
|
+
}
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.log(err);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Gets a community account by `accId` or `apiId`.
|
|
39
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
40
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
41
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
42
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
43
|
+
*/
|
|
44
|
+
public async getAccount(params: { apiId?: string, username?: string }): Promise<globalTypes.CADGetAccountPromiseResult> {
|
|
45
|
+
return new Promise(async (resolve, reject) => {
|
|
46
|
+
try {
|
|
47
|
+
const getAccountRequest: any = await this.rest?.request('GET_ACCOUNT', params.apiId, params.username);
|
|
48
|
+
resolve({ success: true, data: getAccountRequest });
|
|
49
|
+
} catch (err) {
|
|
50
|
+
if (err instanceof APIError) {
|
|
51
|
+
resolve({ success: false, reason: err.response });
|
|
52
|
+
} else {
|
|
53
|
+
reject(err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Instance from '../instance/Instance';
|
|
2
|
+
import { CADServerAPIStruct } from '../libs/rest/src';
|
|
3
|
+
import { CADServer } from '../structures/CADServer';
|
|
4
|
+
import { CacheManager } from './CacheManager';
|
|
5
|
+
import { CADManager } from './CADManager';
|
|
6
|
+
|
|
7
|
+
export class CADServerManager extends CacheManager<number, CADServer, CADServerAPIStruct> {
|
|
8
|
+
constructor(instance: Instance, manager: CADManager) {
|
|
9
|
+
super(instance, CADServer, []);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const serversRes: any = await manager.rest?.request('GET_SERVERS');
|
|
14
|
+
const servers = JSON.parse(serversRes).servers;
|
|
15
|
+
servers.forEach((server: CADServerAPIStruct) => {
|
|
16
|
+
const serverStruct = {
|
|
17
|
+
id: server.id,
|
|
18
|
+
config: server
|
|
19
|
+
};
|
|
20
|
+
this._add(serverStruct, true, server.id);
|
|
21
|
+
});
|
|
22
|
+
} catch (err) {
|
|
23
|
+
throw new Error(String(err));
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import Instance from '../instance/Instance';
|
|
2
|
+
import { CMSSubscriptionVersionEnum } from '../constants';
|
|
3
|
+
import { APIError, DefaultCMSRestOptions, REST } from '../libs/rest/src';
|
|
4
|
+
import { BaseManager } from './BaseManager';
|
|
5
|
+
import * as globalTypes from '../constants';
|
|
6
|
+
import type { Mutable } from '../constants';
|
|
7
|
+
import { CMSServerManager } from './CMSServerManager';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Manages all Sonoran CMS data and methods to interact with the public API.
|
|
11
|
+
*/
|
|
12
|
+
export class CMSManager extends BaseManager {
|
|
13
|
+
public readonly ready: boolean = false;
|
|
14
|
+
public readonly version: CMSSubscriptionVersionEnum = 0;
|
|
15
|
+
public rest: REST | undefined;
|
|
16
|
+
public servers: CMSServerManager | undefined;
|
|
17
|
+
|
|
18
|
+
constructor(instance: Instance) {
|
|
19
|
+
super(instance);
|
|
20
|
+
|
|
21
|
+
this.rest = new REST(instance, this, globalTypes.productEnums.CMS, DefaultCMSRestOptions);
|
|
22
|
+
this.buildManager(instance);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected async buildManager(instance: Instance) {
|
|
26
|
+
try {
|
|
27
|
+
const versionResp: any = await this.rest?.request('GET_SUB_VERSION');
|
|
28
|
+
const mutableThis = this as Mutable<CMSManager>;
|
|
29
|
+
mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i,'$1'));
|
|
30
|
+
if (this.version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
|
|
31
|
+
this.servers = new CMSServerManager(instance, this);
|
|
32
|
+
}
|
|
33
|
+
mutableThis.ready = true;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Verifies the whitelist of a given account with the given parameters to search of said account.
|
|
41
|
+
* @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).
|
|
42
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
43
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
44
|
+
* @param {string} [data.serverId] The username to find a community account.
|
|
45
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
46
|
+
*/
|
|
47
|
+
public async verifyWhitelist(data: { accId?: string, apiId?: string, serverId?: number } | string): Promise<globalTypes.CMSVerifyWhitelistPromiseResult> {
|
|
48
|
+
return new Promise(async (resolve, reject) => {
|
|
49
|
+
try {
|
|
50
|
+
const isString = typeof data === 'string';
|
|
51
|
+
const whitelistRequest: any = await this.rest?.request('VERIFY_WHITELIST', isString ? data : data.apiId, isString ? data : data.accId, isString ? this.instance.cmsDefaultServerId : data.serverId ?? this.instance.cmsDefaultServerId);
|
|
52
|
+
if (typeof whitelistRequest === 'string') {
|
|
53
|
+
resolve({ success: true, reason: whitelistRequest });
|
|
54
|
+
} else {
|
|
55
|
+
resolve({ success: false, reason: whitelistRequest });
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
if (err instanceof APIError) {
|
|
59
|
+
resolve({ success: false, reason: err.response });
|
|
60
|
+
} else {
|
|
61
|
+
reject(err);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Gets a community account by `accId`, `apiId`, or `username`.
|
|
69
|
+
* @param {Object} params The object that contains parameters to get a community account.
|
|
70
|
+
* @param {string} [data.accId] The account id to find a community account.
|
|
71
|
+
* @param {string} [data.apiId] The api id to find a community account.
|
|
72
|
+
* @param {string} [data.username] The username to find a community account.
|
|
73
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed and the account data object if found.
|
|
74
|
+
*/
|
|
75
|
+
public async getComAccount(params: { accId?: string, apiId?: string, username?: string }): Promise<globalTypes.CMSGetComAccountPromiseResult> {
|
|
76
|
+
return new Promise(async (resolve, reject) => {
|
|
77
|
+
try {
|
|
78
|
+
const getAccountRequest: any = await this.rest?.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId);
|
|
79
|
+
resolve({ success: true, data: getAccountRequest });
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (err instanceof APIError) {
|
|
82
|
+
resolve({ success: false, reason: err.response });
|
|
83
|
+
} else {
|
|
84
|
+
reject(err);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Clocks in or out an account by `accId` or `apiId`.
|
|
92
|
+
* @param {Object} data The object that contains critical data to clock in or out an account.
|
|
93
|
+
* @param {string} [data.accId] The account id to clock in or out.
|
|
94
|
+
* @param {string} [data.apiId] The api id to clock in or out.
|
|
95
|
+
* @param {boolean} [data.forceClockIn] If true, it will override any current clock in with a new clock in at the time of the request.
|
|
96
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
97
|
+
*/
|
|
98
|
+
public async clockInOut(data: { accId?: string, apiId?: string, forceClockIn?: boolean }): Promise<globalTypes.CMSClockInOutPromiseResult> {
|
|
99
|
+
return new Promise(async (resolve, reject) => {
|
|
100
|
+
try {
|
|
101
|
+
const clockInOutRequest: any = await this.rest?.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn);
|
|
102
|
+
const clockInOutRequestString: string = clockInOutRequest as string;
|
|
103
|
+
resolve({ success: true, clockedIn: clockInOutRequestString.includes('CLOCKED IN') });
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (err instanceof APIError) {
|
|
106
|
+
resolve({ success: false, reason: err.response });
|
|
107
|
+
} else {
|
|
108
|
+
reject(err);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Check if a given [apiId] is attached to any account within the community CMS.
|
|
116
|
+
* @param {string} apiId The api id to check for an account.
|
|
117
|
+
* @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
|
|
118
|
+
*/
|
|
119
|
+
public async checkComApiId(apiId: string): Promise<globalTypes.CMSCheckComApiIdPromiseResult> {
|
|
120
|
+
return new Promise(async (resolve, reject) => {
|
|
121
|
+
try {
|
|
122
|
+
const checkComApiIdRequest: any = await this.rest?.request('CHECK_COM_APIID', apiId);
|
|
123
|
+
resolve({ success: true, username: checkComApiIdRequest as string });
|
|
124
|
+
} catch (err) {
|
|
125
|
+
if (err instanceof APIError) {
|
|
126
|
+
resolve({ success: false, reason: err.response });
|
|
127
|
+
} else {
|
|
128
|
+
reject(err);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
7
|
+
export class CMSServerManager extends CacheManager<number, CMSServer, CMSServerAPIStruct> {
|
|
8
|
+
constructor(instance: Instance, manager: CMSManager) {
|
|
9
|
+
super(instance, CMSServer, []);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const serversRes: any = await manager.rest?.request('GET_GAME_SERVERS');
|
|
14
|
+
const servers = serversRes.servers;
|
|
15
|
+
servers.forEach((server: CMSServerAPIStruct) => {
|
|
16
|
+
const serverStruct = {
|
|
17
|
+
id: server.id,
|
|
18
|
+
config: server
|
|
19
|
+
};
|
|
20
|
+
this._add(serverStruct, true, server.id);
|
|
21
|
+
});
|
|
22
|
+
} catch (err) {
|
|
23
|
+
throw new Error(String(err));
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Collection from '@discordjs/collection';
|
|
2
|
+
import Instance from '../instance/Instance';
|
|
3
|
+
import { Constructable } from '../constants';
|
|
4
|
+
import { DataManager } from './DataManager';
|
|
5
|
+
|
|
6
|
+
export class CacheManager<K, Holds, R> extends DataManager<K, Holds, R> {
|
|
7
|
+
public _cache: Collection<any, any> | never;
|
|
8
|
+
protected constructor(instance: Instance, holds: Constructable<Holds>, iterable: Iterable<any>) {
|
|
9
|
+
super(instance, holds);
|
|
10
|
+
this._cache = new Collection();
|
|
11
|
+
if (iterable) {
|
|
12
|
+
for (const item of iterable) {
|
|
13
|
+
this._add(item);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get cache() {
|
|
19
|
+
return this._cache;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_add(data: any, cache: boolean = true, id?: K) {
|
|
23
|
+
const existing = this.cache.get(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
|
+
|
|
34
|
+
const entry = data;
|
|
35
|
+
if (cache) this.cache.set(id ?? entry.id, entry);
|
|
36
|
+
return entry;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Instance from '../instance/Instance';
|
|
2
|
+
import { BaseManager } from './BaseManager';
|
|
3
|
+
import { GenericError } from '../errors';
|
|
4
|
+
import { Constructable } from '../constants';
|
|
5
|
+
|
|
6
|
+
import Collection from '@discordjs/collection';
|
|
7
|
+
|
|
8
|
+
interface DataManagerInstanceObject {
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class DataManager<_K, Holds, _R> extends BaseManager {
|
|
13
|
+
public holds: Constructable<Holds>;
|
|
14
|
+
|
|
15
|
+
constructor(instance: Instance, holds: any) {
|
|
16
|
+
super(instance);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The data structure belonging to this manager.
|
|
20
|
+
* @name DataManager#holds
|
|
21
|
+
* @type {Function}
|
|
22
|
+
* @private
|
|
23
|
+
* @readonly
|
|
24
|
+
*/
|
|
25
|
+
this.holds = holds;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The cache of items for this manager.
|
|
30
|
+
* @type {Collection}
|
|
31
|
+
* @abstract
|
|
32
|
+
*/
|
|
33
|
+
get cache(): Collection<any, any> {
|
|
34
|
+
throw new GenericError('NOT_IMPLEMENTED', 'get cache', this.constructor.name);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Resolves a data entry to a data Object.
|
|
39
|
+
* @param idOrInstance The id or instance of something in this Manager
|
|
40
|
+
* @returns {?Object} An instance from this Manager
|
|
41
|
+
*/
|
|
42
|
+
public resolve(idOrInstance: string | object): object | null {
|
|
43
|
+
if (this.cache instanceof Collection) {
|
|
44
|
+
if (typeof idOrInstance === 'object') return idOrInstance;
|
|
45
|
+
if (typeof idOrInstance === 'string') return this.cache.get(idOrInstance) ?? null;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Resolves a data entry to an instance id.
|
|
52
|
+
* @param {string|Object} idOrInstance The id or instance of something in this Manager
|
|
53
|
+
* @returns {?Snowflake}
|
|
54
|
+
*/
|
|
55
|
+
resolveId(idOrInstance: string | DataManagerInstanceObject): string | null {
|
|
56
|
+
if (typeof idOrInstance === 'object') return idOrInstance.id;
|
|
57
|
+
if (typeof idOrInstance === 'string') return idOrInstance;
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
valueOf() {
|
|
62
|
+
return this.cache;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Instance from '../instance/Instance';
|
|
2
|
+
import { flatten } from '../utils';
|
|
3
|
+
|
|
4
|
+
export abstract class Base {
|
|
5
|
+
public instance: Instance;
|
|
6
|
+
constructor(instance: Instance) {
|
|
7
|
+
this.instance = instance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public _clone() {
|
|
11
|
+
return Object.assign(Object.create(this), this);
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public _patch(data: any) {
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public _update(data: any) {
|
|
20
|
+
const clone = this._clone();
|
|
21
|
+
this._patch(data);
|
|
22
|
+
return clone;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public toJSON(...props: Record<string, boolean | string>[]): unknown {
|
|
26
|
+
return flatten(this, ...props);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|