node-ts 6.1.3 → 8.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/lib/index.js CHANGED
@@ -1,17 +1 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./node-ts"), exports);
1
+ export * from "./node-ts";
package/lib/node-ts.d.ts CHANGED
@@ -2,8 +2,9 @@
2
2
  * @autor Niklas Mollenhauer <holzig@outlook.com>
3
3
  * @autor Tim Kluge <timklge@wh2.tu-dresden.de>
4
4
  */
5
- import { EventEmitter } from "events";
6
- import type { MapLike } from "./types";
5
+ import { EventEmitter } from "node:events";
6
+ /** Represents a Key-Value object. */
7
+ type MapLike<T> = Record<string, T>;
7
8
  /**
8
9
  * Client that can be used to connect to a TeamSpeak server query API.
9
10
  */
@@ -1188,3 +1189,4 @@ export declare enum TokenType {
1188
1189
  */
1189
1190
  CHANNEL_GROUP = 1
1190
1191
  }
1192
+ export {};
package/lib/node-ts.js CHANGED
@@ -2,34 +2,22 @@
2
2
  * @autor Niklas Mollenhauer <holzig@outlook.com>
3
3
  * @autor Tim Kluge <timklge@wh2.tu-dresden.de>
4
4
  */
5
- "use strict";
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
- var __asyncValues = (this && this.__asyncValues) || function (o) {
16
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
- var m = o[Symbol.asyncIterator], i;
18
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
19
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
20
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.TokenType = exports.PermissionGroupTypes = exports.PermissionGroupDatabaseTypes = exports.ReasonIdentifier = exports.LogLevel = exports.TextMessageTargetMode = exports.CodecEncryptionMode = exports.Codec = exports.HostBannerMode = exports.HostMessageMode = exports.YesNo = exports.TeamSpeakClient = void 0;
24
- const net = require("net");
25
- const events_1 = require("events");
26
- const util_1 = require("util");
27
- const stringio_1 = require("@rauschma/stringio");
28
- const queryStrings_1 = require("./queryStrings");
5
+ import * as net from "node:net";
6
+ import { EventEmitter } from "node:events";
7
+ import { chunksToLinesAsync, chomp } from "@rauschma/stringio";
8
+ import { escape, unescape } from "./queryStrings.js";
29
9
  /**
30
10
  * Client that can be used to connect to a TeamSpeak server query API.
31
11
  */
32
- class TeamSpeakClient extends events_1.EventEmitter {
12
+ export class TeamSpeakClient extends EventEmitter {
13
+ host;
14
+ port;
15
+ queue = [];
16
+ _executing;
17
+ socket;
18
+ isConnected = false;
19
+ static DefaultHost = "localhost";
20
+ static DefaultPort = 10011;
33
21
  /**
34
22
  * Creates a new instance of TeamSpeakClient for a specific remote host:port.
35
23
  * @param {string = TeamSpeakClient.DefaultHost} host Remote host of the TeamSpeak server. Can be an IP address or a host name.
@@ -40,8 +28,6 @@ class TeamSpeakClient extends events_1.EventEmitter {
40
28
  super();
41
29
  this.host = host;
42
30
  this.port = port;
43
- this.queue = [];
44
- this.isConnected = false;
45
31
  }
46
32
  connect() {
47
33
  this.isConnected = false;
@@ -59,49 +45,34 @@ class TeamSpeakClient extends events_1.EventEmitter {
59
45
  /**
60
46
  * Gets called on an opened connection
61
47
  */
62
- onConnect(connectionEstablished, error) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- var _a, e_1, _b, _c;
65
- const lineGenerator = (0, stringio_1.chunksToLinesAsync)(this.socket);
66
- let lineCounter = 0;
67
- try {
68
- for (var _d = true, lineGenerator_1 = __asyncValues(lineGenerator), lineGenerator_1_1; lineGenerator_1_1 = yield lineGenerator_1.next(), _a = lineGenerator_1_1.done, !_a; _d = true) {
69
- _c = lineGenerator_1_1.value;
70
- _d = false;
71
- const lineWithNewLine = _c;
72
- const line = (0, stringio_1.chomp)(lineWithNewLine).trim();
73
- if (line === "")
74
- continue;
75
- ++lineCounter;
76
- switch (lineCounter) {
77
- case 1: {
78
- if (line !== "TS3") {
79
- this.isConnected = false;
80
- error(new Error("Remove server is not a TS3 Query Server endpoint."));
81
- return;
82
- }
83
- continue;
84
- }
85
- case 2:
86
- // We have read a second non-empty line, so we are ready to take commands
87
- this.isConnected = true;
88
- connectionEstablished();
89
- continue; // Welcome message, followed by empty line (which is skipped)
90
- default: {
91
- this.handleSingleLine(line);
92
- this.checkQueue();
93
- }
48
+ async onConnect(connectionEstablished, error) {
49
+ const lineGenerator = chunksToLinesAsync(this.socket);
50
+ let lineCounter = 0;
51
+ for await (const lineWithNewLine of lineGenerator) {
52
+ const line = chomp(lineWithNewLine).trim();
53
+ if (line === "")
54
+ continue;
55
+ ++lineCounter;
56
+ switch (lineCounter) {
57
+ case 1: {
58
+ if (line !== "TS3") {
59
+ this.isConnected = false;
60
+ error(new Error("Remove server is not a TS3 Query Server endpoint."));
61
+ return;
94
62
  }
63
+ continue;
95
64
  }
96
- }
97
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
98
- finally {
99
- try {
100
- if (!_d && !_a && (_b = lineGenerator_1.return)) yield _b.call(lineGenerator_1);
65
+ case 2:
66
+ // We have read a second non-empty line, so we are ready to take commands
67
+ this.isConnected = true;
68
+ connectionEstablished();
69
+ continue; // Welcome message, followed by empty line (which is skipped)
70
+ default: {
71
+ this.handleSingleLine(line);
72
+ this.checkQueue();
101
73
  }
102
- finally { if (e_1) throw e_1.error; }
103
74
  }
104
- });
75
+ }
105
76
  }
106
77
  handleSingleLine(line) {
107
78
  // Server answers with:
@@ -158,22 +129,22 @@ class TeamSpeakClient extends events_1.EventEmitter {
158
129
  return Promise.reject(new Error("Empty command"));
159
130
  if (!this.isConnected)
160
131
  return Promise.reject(new Error("Not connected to any server. Call \"connect()\" before sending anything."));
161
- let tosend = (0, queryStrings_1.escape)(cmd);
132
+ let tosend = escape(cmd);
162
133
  for (const v of options)
163
- tosend += " -" + (0, queryStrings_1.escape)(v);
134
+ tosend += ` -${escape(v)}`;
164
135
  for (const key in params) {
165
136
  if (!params.hasOwnProperty(key))
166
137
  continue;
167
138
  const value = params[key];
168
- if (!(0, util_1.isArray)(value)) {
169
- tosend += " " + (0, queryStrings_1.escape)(key.toString()) + "=" + (0, queryStrings_1.escape)(value.toString());
139
+ if (!Array.isArray(value)) {
140
+ tosend += ` ${escape(key.toString())}=${escape(value.toString())}`;
170
141
  }
171
142
  }
172
143
  // Handle multiple arrays correctly
173
144
  // Get all array in the params
174
145
  const arrayParamKeys = [];
175
146
  for (const key in params) {
176
- if (params.hasOwnProperty(key) && (0, util_1.isArray)(params[key]))
147
+ if (params.hasOwnProperty(key) && Array.isArray(params[key]))
177
148
  arrayParamKeys.push(key);
178
149
  }
179
150
  if (arrayParamKeys.length > 0) {
@@ -181,13 +152,13 @@ class TeamSpeakClient extends events_1.EventEmitter {
181
152
  const firstArray = params[arrayParamKeys[0]];
182
153
  for (let i = 0; i < firstArray.length; ++i) {
183
154
  let segment = "";
184
- for (var key of arrayParamKeys) {
185
- segment += (0, queryStrings_1.escape)(key) + "=" + (0, queryStrings_1.escape)(params[key][i]) + " ";
155
+ for (const key of arrayParamKeys) {
156
+ segment += `${escape(key)}=${escape(params[key][i])} `;
186
157
  }
187
- escapedSegments += segment.slice(0, -1) + "|";
158
+ escapedSegments += `${segment.slice(0, -1)}|`;
188
159
  }
189
160
  if (escapedSegments.length > 0)
190
- tosend += " " + escapedSegments.slice(0, -1);
161
+ tosend += ` ${escapedSegments.slice(0, -1)}`;
191
162
  }
192
163
  return new Promise((resolve, reject) => {
193
164
  this.queue.push({
@@ -237,9 +208,9 @@ class TeamSpeakClient extends events_1.EventEmitter {
237
208
  thisrec[v] = "";
238
209
  continue;
239
210
  }
240
- const key = (0, queryStrings_1.unescape)(v.substr(0, v.indexOf("=")));
241
- const value = (0, queryStrings_1.unescape)(v.substr(v.indexOf("=") + 1));
242
- thisrec[key] = (parseInt(value, 10).toString() == value) ? parseInt(value, 10) : value;
211
+ const key = unescape(v.substr(0, v.indexOf("=")));
212
+ const value = unescape(v.substr(v.indexOf("=") + 1));
213
+ thisrec[key] = (Number.parseInt(value, 10).toString() == value) ? Number.parseInt(value, 10) : value;
243
214
  }
244
215
  return thisrec;
245
216
  });
@@ -292,20 +263,17 @@ class TeamSpeakClient extends events_1.EventEmitter {
292
263
  return this.setTimeout(0);
293
264
  }
294
265
  }
295
- exports.TeamSpeakClient = TeamSpeakClient;
296
- TeamSpeakClient.DefaultHost = "localhost";
297
- TeamSpeakClient.DefaultPort = 10011;
298
266
  /*
299
267
 
300
268
  Enums imported from documentation.
301
269
 
302
270
  */
303
- var YesNo;
271
+ export var YesNo;
304
272
  (function (YesNo) {
305
273
  YesNo[YesNo["No"] = 0] = "No";
306
274
  YesNo[YesNo["Yes"] = 1] = "Yes";
307
- })(YesNo || (exports.YesNo = YesNo = {}));
308
- var HostMessageMode;
275
+ })(YesNo || (YesNo = {}));
276
+ export var HostMessageMode;
309
277
  (function (HostMessageMode) {
310
278
  /**
311
279
  * 1: display message in chatlog
@@ -319,8 +287,8 @@ var HostMessageMode;
319
287
  * 3: display message in modal dialog and close connection
320
288
  */
321
289
  HostMessageMode[HostMessageMode["MODALQUIT"] = 3] = "MODALQUIT";
322
- })(HostMessageMode || (exports.HostMessageMode = HostMessageMode = {}));
323
- var HostBannerMode;
290
+ })(HostMessageMode || (HostMessageMode = {}));
291
+ export var HostBannerMode;
324
292
  (function (HostBannerMode) {
325
293
  /**
326
294
  * 0: do not adjust
@@ -334,8 +302,8 @@ var HostBannerMode;
334
302
  * 2: adjust and keep aspect ratio
335
303
  */
336
304
  HostBannerMode[HostBannerMode["KEEPASPECT"] = 2] = "KEEPASPECT";
337
- })(HostBannerMode || (exports.HostBannerMode = HostBannerMode = {}));
338
- var Codec;
305
+ })(HostBannerMode || (HostBannerMode = {}));
306
+ export var Codec;
339
307
  (function (Codec) {
340
308
  /**
341
309
  * 0: speex narrowband (mono, 16bit, 8kHz)
@@ -353,8 +321,8 @@ var Codec;
353
321
  * 3: celt mono (mono, 16bit, 48kHz)
354
322
  */
355
323
  Codec[Codec["CELT_MONO"] = 3] = "CELT_MONO";
356
- })(Codec || (exports.Codec = Codec = {}));
357
- var CodecEncryptionMode;
324
+ })(Codec || (Codec = {}));
325
+ export var CodecEncryptionMode;
358
326
  (function (CodecEncryptionMode) {
359
327
  /**
360
328
  * 0: configure per channel
@@ -368,8 +336,8 @@ var CodecEncryptionMode;
368
336
  * 2: globally enabled
369
337
  */
370
338
  CodecEncryptionMode[CodecEncryptionMode["ENABLED"] = 2] = "ENABLED";
371
- })(CodecEncryptionMode || (exports.CodecEncryptionMode = CodecEncryptionMode = {}));
372
- var TextMessageTargetMode;
339
+ })(CodecEncryptionMode || (CodecEncryptionMode = {}));
340
+ export var TextMessageTargetMode;
373
341
  (function (TextMessageTargetMode) {
374
342
  /**
375
343
  * 1: target is a client
@@ -383,8 +351,8 @@ var TextMessageTargetMode;
383
351
  * 3: target is a virtual server
384
352
  */
385
353
  TextMessageTargetMode[TextMessageTargetMode["SERVER"] = 3] = "SERVER";
386
- })(TextMessageTargetMode || (exports.TextMessageTargetMode = TextMessageTargetMode = {}));
387
- var LogLevel;
354
+ })(TextMessageTargetMode || (TextMessageTargetMode = {}));
355
+ export var LogLevel;
388
356
  (function (LogLevel) {
389
357
  /**
390
358
  * 1: everything that is really bad
@@ -402,8 +370,8 @@ var LogLevel;
402
370
  * 4: informational output
403
371
  */
404
372
  LogLevel[LogLevel["INFO"] = 4] = "INFO";
405
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
406
- var ReasonIdentifier;
373
+ })(LogLevel || (LogLevel = {}));
374
+ export var ReasonIdentifier;
407
375
  (function (ReasonIdentifier) {
408
376
  /**
409
377
  * 4: kick client from channel
@@ -413,8 +381,8 @@ var ReasonIdentifier;
413
381
  * 5: kick client from server
414
382
  */
415
383
  ReasonIdentifier[ReasonIdentifier["SERVER"] = 5] = "SERVER";
416
- })(ReasonIdentifier || (exports.ReasonIdentifier = ReasonIdentifier = {}));
417
- var PermissionGroupDatabaseTypes;
384
+ })(ReasonIdentifier || (ReasonIdentifier = {}));
385
+ export var PermissionGroupDatabaseTypes;
418
386
  (function (PermissionGroupDatabaseTypes) {
419
387
  /**
420
388
  * 0: template group (used for new virtual servers)
@@ -428,8 +396,8 @@ var PermissionGroupDatabaseTypes;
428
396
  * 2: global query group (used for ServerQuery clients)
429
397
  */
430
398
  PermissionGroupDatabaseTypes[PermissionGroupDatabaseTypes["QUERY"] = 2] = "QUERY";
431
- })(PermissionGroupDatabaseTypes || (exports.PermissionGroupDatabaseTypes = PermissionGroupDatabaseTypes = {}));
432
- var PermissionGroupTypes;
399
+ })(PermissionGroupDatabaseTypes || (PermissionGroupDatabaseTypes = {}));
400
+ export var PermissionGroupTypes;
433
401
  (function (PermissionGroupTypes) {
434
402
  /**
435
403
  * 0: server group permission
@@ -451,8 +419,8 @@ var PermissionGroupTypes;
451
419
  * 4: channel-client specific permission
452
420
  */
453
421
  PermissionGroupTypes[PermissionGroupTypes["CHANNEL_CLIENT"] = 4] = "CHANNEL_CLIENT";
454
- })(PermissionGroupTypes || (exports.PermissionGroupTypes = PermissionGroupTypes = {}));
455
- var TokenType;
422
+ })(PermissionGroupTypes || (PermissionGroupTypes = {}));
423
+ export var TokenType;
456
424
  (function (TokenType) {
457
425
  /**
458
426
  * 0: server group token (id1={groupID} id2=0)
@@ -462,4 +430,4 @@ var TokenType;
462
430
  * 1: channel group token (id1={groupID} id2={channelID})
463
431
  */
464
432
  TokenType[TokenType["CHANNEL_GROUP"] = 1] = "CHANNEL_GROUP";
465
- })(TokenType || (exports.TokenType = TokenType = {}));
433
+ })(TokenType || (TokenType = {}));
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.escape = escape;
4
- exports.unescape = unescape;
5
1
  /**
6
2
  * Escapes a string so it can be safely used for querying the api.
7
3
  * @param {string} s The string to escape.
8
4
  * @return {string} An escaped string.
9
5
  */
10
- function escape(s) {
6
+ export function escape(s) {
11
7
  let r = String(s);
12
8
  r = r.replace(/\\/g, "\\\\"); // Backslash
13
9
  r = r.replace(/\//g, "\\/"); // Slash
@@ -25,7 +21,7 @@ function escape(s) {
25
21
  * @param {string} s The string to unescape.
26
22
  * @return {string} An unescaped string.
27
23
  */
28
- function unescape(s) {
24
+ export function unescape(s) {
29
25
  let r = String(s);
30
26
  r = r.replace(/\\s/g, " "); // Whitespace
31
27
  r = r.replace(/\\p/g, "|"); // Pipe
package/package.json CHANGED
@@ -2,20 +2,21 @@
2
2
  "author": "Niklas Mollenhauer <nikeee@outlook.com>",
3
3
  "name": "node-ts",
4
4
  "description": "TeamSpeak® 3 Server Query client for node.js implemented using TypeScript",
5
- "version": "6.1.3",
5
+ "version": "8.0.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git://github.com/nikeee/node-ts.git"
9
9
  },
10
10
  "main": "lib/index.js",
11
+ "type": "module",
11
12
  "types": "lib/index.d.ts",
12
13
  "dependencies": {
13
14
  "@rauschma/stringio": "^1.4.0",
14
- "@types/node": "^22.6.0"
15
+ "@types/node": "^22.13.1"
15
16
  },
16
17
  "devDependencies": {
17
18
  "rimraf": "^6.0.1",
18
- "typescript": "^5.6.2"
19
+ "typescript": "^5.7.3"
19
20
  },
20
21
  "scripts": {
21
22
  "test": "tsc --noEmit",
@@ -32,8 +33,7 @@
32
33
  ],
33
34
  "optionalDependencies": {},
34
35
  "engines": {
35
- "node": ">=18.0.0"
36
+ "node": ">=22.0.0"
36
37
  },
37
- "license": "LGPL-3.0",
38
- "readmeFilename": "README.md"
38
+ "license": "LGPL-3.0"
39
39
  }
@@ -1 +0,0 @@
1
- github: nikeee
@@ -1,11 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: "npm"
4
- directory: "/"
5
- schedule:
6
- interval: "monthly"
7
-
8
- - package-ecosystem: "github-actions"
9
- directory: "/"
10
- schedule:
11
- interval: "monthly"
@@ -1,34 +0,0 @@
1
- name: CD
2
-
3
- on:
4
- push:
5
- branches:
6
- - "!*"
7
- tags:
8
- - "v*"
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
-
14
- permissions:
15
- contents: read
16
- id-token: write
17
-
18
- steps:
19
- - uses: actions/checkout@v4
20
-
21
- - uses: actions/setup-node@v4
22
- with:
23
- node-version: 20
24
- cache: npm
25
- registry-url: https://registry.npmjs.org
26
-
27
- - run: npm ci
28
- - run: npm run compile
29
- - run: npm test
30
- env:
31
- CI: true
32
- - run: npm publish --provenance --access public
33
- env:
34
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -1,27 +0,0 @@
1
- name: Node.js CI
2
-
3
- on: [push]
4
-
5
- jobs:
6
- build:
7
-
8
- runs-on: ubuntu-latest
9
-
10
- strategy:
11
- matrix:
12
- node-version: [16.x, 18.x, 20.x]
13
-
14
- steps:
15
- - uses: actions/checkout@v4
16
-
17
- - name: Use Node.js ${{ matrix.node-version }}
18
- uses: actions/setup-node@v4
19
- with:
20
- node-version: ${{ matrix.node-version }}
21
- cache: npm
22
-
23
- - run: npm ci
24
- - run: npm run compile
25
- - run: npm test
26
- env:
27
- CI: true
package/lib/types.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Represents a Key-Value object.
3
- */
4
- export type MapLike<T> = Record<string, T>;
package/lib/types.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- /**
3
- * Represents a Key-Value object.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });