airdcpp-apisocket 2.4.4 → 2.5.0-beta.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 (137) hide show
  1. package/GUIDE.md +7 -7
  2. package/README.md +3 -2
  3. package/babel.config.cjs +6 -0
  4. package/dist/ApiConstants.d.ts +6 -6
  5. package/dist/ApiConstants.js +7 -7
  6. package/dist/NodeSocket.d.ts +4 -4
  7. package/dist/NodeSocket.js +24 -20
  8. package/dist/NodeSocket.js.map +1 -1
  9. package/dist/Promise.d.ts +8 -8
  10. package/dist/Promise.js +26 -26
  11. package/dist/Promise.js.map +1 -1
  12. package/dist/PublicHelpers.d.ts +2 -2
  13. package/dist/PublicHelpers.js +94 -192
  14. package/dist/PublicHelpers.js.map +1 -1
  15. package/dist/SocketBase.d.ts +4 -4
  16. package/dist/SocketBase.js +351 -359
  17. package/dist/SocketBase.js.map +1 -1
  18. package/dist/SocketLogger.d.ts +9 -9
  19. package/dist/SocketLogger.js +74 -84
  20. package/dist/SocketLogger.js.map +1 -1
  21. package/dist/SocketRequestHandler.d.ts +14 -14
  22. package/dist/SocketRequestHandler.js +168 -176
  23. package/dist/SocketRequestHandler.js.map +1 -1
  24. package/dist/SocketSubscriptionHandler.d.ts +11 -11
  25. package/dist/SocketSubscriptionHandler.js +161 -173
  26. package/dist/SocketSubscriptionHandler.js.map +1 -1
  27. package/dist/types/api.d.ts +30 -30
  28. package/dist/types/api.js +3 -3
  29. package/dist/types/api_internal.d.ts +24 -24
  30. package/dist/types/api_internal.js +2 -2
  31. package/dist/types/index.d.ts +7 -7
  32. package/dist/types/index.js +23 -19
  33. package/dist/types/index.js.map +1 -1
  34. package/dist/types/logger.d.ts +6 -6
  35. package/dist/types/logger.js +2 -2
  36. package/dist/types/options.d.ts +31 -31
  37. package/dist/types/options.js +3 -3
  38. package/dist/types/public_helpers.d.ts +19 -14
  39. package/dist/types/public_helpers.js +2 -2
  40. package/dist/types/public_helpers_internal.d.ts +27 -25
  41. package/dist/types/public_helpers_internal.js +2 -2
  42. package/dist/types/requests.d.ts +14 -14
  43. package/dist/types/requests.js +2 -2
  44. package/dist/types/socket.d.ts +23 -23
  45. package/dist/types/socket.js +2 -3
  46. package/dist/types/socket.js.map +1 -1
  47. package/dist/types/subscriptions.d.ts +20 -20
  48. package/dist/types/subscriptions.js +2 -2
  49. package/dist/utils.d.ts +2 -2
  50. package/dist/utils.js +15 -15
  51. package/dist/utils.js.map +1 -1
  52. package/dist-es/ApiConstants.d.ts +6 -6
  53. package/dist-es/ApiConstants.js +5 -5
  54. package/dist-es/NodeSocket.d.ts +4 -4
  55. package/dist-es/NodeSocket.js +4 -4
  56. package/dist-es/NodeSocket.js.map +1 -1
  57. package/dist-es/Promise.d.ts +8 -8
  58. package/dist-es/Promise.js +24 -24
  59. package/dist-es/Promise.js.map +1 -1
  60. package/dist-es/PublicHelpers.d.ts +2 -2
  61. package/dist-es/PublicHelpers.js +90 -188
  62. package/dist-es/PublicHelpers.js.map +1 -1
  63. package/dist-es/SocketBase.d.ts +4 -4
  64. package/dist-es/SocketBase.js +346 -354
  65. package/dist-es/SocketBase.js.map +1 -1
  66. package/dist-es/SocketLogger.d.ts +9 -9
  67. package/dist-es/SocketLogger.js +68 -78
  68. package/dist-es/SocketLogger.js.map +1 -1
  69. package/dist-es/SocketRequestHandler.d.ts +14 -14
  70. package/dist-es/SocketRequestHandler.js +163 -171
  71. package/dist-es/SocketRequestHandler.js.map +1 -1
  72. package/dist-es/SocketSubscriptionHandler.d.ts +11 -11
  73. package/dist-es/SocketSubscriptionHandler.js +156 -168
  74. package/dist-es/SocketSubscriptionHandler.js.map +1 -1
  75. package/dist-es/types/api.d.ts +30 -30
  76. package/dist-es/types/api.js +2 -2
  77. package/dist-es/types/api_internal.d.ts +24 -24
  78. package/dist-es/types/api_internal.js +1 -1
  79. package/dist-es/types/index.d.ts +7 -7
  80. package/dist-es/types/index.js +7 -7
  81. package/dist-es/types/index.js.map +1 -1
  82. package/dist-es/types/logger.d.ts +6 -6
  83. package/dist-es/types/logger.js +1 -1
  84. package/dist-es/types/options.d.ts +31 -31
  85. package/dist-es/types/options.js +2 -2
  86. package/dist-es/types/public_helpers.d.ts +19 -14
  87. package/dist-es/types/public_helpers.js +1 -1
  88. package/dist-es/types/public_helpers_internal.d.ts +27 -25
  89. package/dist-es/types/public_helpers_internal.js +1 -1
  90. package/dist-es/types/requests.d.ts +14 -14
  91. package/dist-es/types/requests.js +1 -1
  92. package/dist-es/types/socket.d.ts +23 -23
  93. package/dist-es/types/socket.js +1 -2
  94. package/dist-es/types/socket.js.map +1 -1
  95. package/dist-es/types/subscriptions.d.ts +20 -20
  96. package/dist-es/types/subscriptions.js +1 -1
  97. package/dist-es/utils.d.ts +2 -2
  98. package/dist-es/utils.js +11 -11
  99. package/dist-es/utils.js.map +1 -1
  100. package/jest.config.js +15 -3
  101. package/package.json +15 -13
  102. package/src/NodeSocket.ts +3 -3
  103. package/src/PublicHelpers.ts +11 -10
  104. package/src/SocketBase.ts +9 -9
  105. package/src/SocketLogger.ts +6 -6
  106. package/src/SocketRequestHandler.ts +10 -10
  107. package/src/SocketSubscriptionHandler.ts +10 -10
  108. package/src/tests/Socket.test.ts +29 -26
  109. package/src/tests/helpers.ts +14 -8
  110. package/src/tests/public_helpers.test.ts +7 -6
  111. package/src/types/api_internal.ts +1 -1
  112. package/src/types/index.ts +7 -7
  113. package/src/types/public_helpers.ts +7 -1
  114. package/src/types/public_helpers_internal.ts +3 -1
  115. package/src/types/requests.ts +1 -1
  116. package/src/types/socket.ts +4 -20
  117. package/src/types/subscriptions.ts +1 -1
  118. package/src/utils.ts +1 -1
  119. package/tsconfig.json +5 -10
  120. package/dist/tests/Socket.test.d.ts +0 -1
  121. package/dist/tests/Socket.test.js +0 -758
  122. package/dist/tests/Socket.test.js.map +0 -1
  123. package/dist/tests/helpers.d.ts +0 -57
  124. package/dist/tests/helpers.js +0 -178
  125. package/dist/tests/helpers.js.map +0 -1
  126. package/dist/tests/public_helpers.test.d.ts +0 -1
  127. package/dist/tests/public_helpers.test.js +0 -241
  128. package/dist/tests/public_helpers.test.js.map +0 -1
  129. package/dist-es/tests/Socket.test.d.ts +0 -1
  130. package/dist-es/tests/Socket.test.js +0 -734
  131. package/dist-es/tests/Socket.test.js.map +0 -1
  132. package/dist-es/tests/helpers.d.ts +0 -57
  133. package/dist-es/tests/helpers.js +0 -168
  134. package/dist-es/tests/helpers.js.map +0 -1
  135. package/dist-es/tests/public_helpers.test.d.ts +0 -1
  136. package/dist-es/tests/public_helpers.test.js +0 -236
  137. package/dist-es/tests/public_helpers.test.js.map +0 -1
@@ -1,22 +1,26 @@
1
1
  import {
2
2
  AUTH_RESPONSE, CONNECT_PARAMS,
3
- getConnectedSocket, getMockServer, getSocket
4
- } from './helpers';
3
+ getConnectedSocket, getMockServer, getSocket, waitForExpect
4
+ } from './helpers.js';
5
5
 
6
- import ApiConstants from '../ApiConstants';
6
+ import ApiConstants from '../ApiConstants.js';
7
7
 
8
- import { HookCallback, HookSubscriberInfo } from '../types/subscriptions';
9
- import { IncomingSubscriptionEvent } from '../types/api_internal';
10
-
11
- import * as MockDate from 'mockdate';
12
- import waitForExpectOriginal from 'wait-for-expect';
8
+ import { HookCallback, HookSubscriberInfo, SubscriptionRemoveHandler } from '../types/subscriptions.js';
9
+ import { IncomingSubscriptionEvent } from '../types/api_internal.js';
13
10
 
11
+ import { jest } from '@jest/globals';
14
12
 
15
13
  let server: ReturnType<typeof getMockServer>;
16
14
 
17
- const EXCEPT_TIMEOUT = 1000;
18
- const waitForExpect = (func: () => void | Promise<void>) => waitForExpectOriginal(func, EXCEPT_TIMEOUT);
15
+ const dummyfn = () => {
16
+ // ..
17
+ };
19
18
 
19
+ const useFakeTimers = () => {
20
+ // Mocking performance would cause an error with Node 19, can be removed when using
21
+ // the latest version of Jest
22
+ jest.useFakeTimers({doNotFake: ['performance']});
23
+ };
20
24
 
21
25
  // tslint:disable:no-empty
22
26
  describe('socket', () => {
@@ -27,7 +31,6 @@ describe('socket', () => {
27
31
  afterEach(() => {
28
32
  server.stop();
29
33
  jest.useRealTimers();
30
- MockDate.reset();
31
34
  });
32
35
 
33
36
  describe('auth', () => {
@@ -129,10 +132,10 @@ describe('socket', () => {
129
132
 
130
133
  // Dummy listener
131
134
  server.addDataHandler('POST', 'hubs/listeners/hub_updated', undefined);
132
- await socket.addListener('hubs', 'hub_updated', _ => {});
135
+ await socket.addListener('hubs', 'hub_updated', dummyfn);
133
136
 
134
137
  // Dummy pending request
135
- socket.delete('dummyLogoutDelete').catch(error => {
138
+ socket.delete('dummyLogoutDelete').catch((error: Error) => {
136
139
  // TODO: fix, too unreliable at the moment (depends on the timings)
137
140
  //expect(error.message).toEqual('Socket disconnected');
138
141
  });
@@ -190,7 +193,7 @@ describe('socket', () => {
190
193
  test('should handle auto reconnect', async () => {
191
194
  const { socket, mockConsole } = await getConnectedSocket(server);
192
195
 
193
- jest.useFakeTimers();
196
+ useFakeTimers();
194
197
 
195
198
  socket.disconnect(true);
196
199
  jest.runOnlyPendingTimers();
@@ -231,7 +234,7 @@ describe('socket', () => {
231
234
  test('should cancel auto reconnect', async () => {
232
235
  const { socket, mockConsole } = await getConnectedSocket(server);
233
236
 
234
- jest.useFakeTimers();
237
+ useFakeTimers();
235
238
 
236
239
  // Disconnect with auto reconnect
237
240
  socket.disconnect(true);
@@ -278,7 +281,7 @@ describe('socket', () => {
278
281
  // Connect and disconnect
279
282
  const { socket, mockConsole } = await getConnectedSocket(server);
280
283
 
281
- jest.useFakeTimers();
284
+ useFakeTimers();
282
285
  socket.disconnect();
283
286
  jest.runOnlyPendingTimers();
284
287
  expect(socket.isActive()).toEqual(false);
@@ -294,7 +297,7 @@ describe('socket', () => {
294
297
  socket.reconnect();
295
298
 
296
299
  {
297
- const waitForExpectTask = waitForExpectOriginal(
300
+ const waitForExpectTask = waitForExpect(
298
301
  () => {
299
302
  jest.runOnlyPendingTimers();
300
303
  expect(authCallback.mock.calls.length).toBe(1);
@@ -331,15 +334,15 @@ describe('socket', () => {
331
334
  test('should report request timeouts', async () => {
332
335
  const { socket, mockConsole } = await getConnectedSocket(server);
333
336
 
334
- jest.useFakeTimers();
335
- socket.addListener('hubs', 'hub_updated', _ => {})
337
+ useFakeTimers();
338
+ socket.addListener('hubs', 'hub_updated', dummyfn)
336
339
  .catch(() => {});
337
- socket.addListener('hubs', 'hub_added', _ => {})
340
+ socket.addListener('hubs', 'hub_added', dummyfn)
338
341
  .catch(() => {});
339
342
 
340
343
  jest.advanceTimersByTime(35000);
341
344
 
342
- MockDate.set(Date.now() + 35000);
345
+ jest.setSystemTime(new Date(Date.now() + 35000));
343
346
  (socket as any).reportRequestTimeouts();
344
347
 
345
348
  expect(mockConsole.warn.mock.calls.length).toBe(2);
@@ -422,8 +425,8 @@ describe('socket', () => {
422
425
  server.addDataHandler('POST', 'hubs/listeners/hub_updated', undefined, subscribeCallback);
423
426
 
424
427
  // Add two simultaneous pending add events
425
- const p1 = socket.addListener('hubs', 'hub_updated', _ => {});
426
- const p2 = socket.addListener('hubs', 'hub_updated', _ => {});
428
+ const p1 = socket.addListener('hubs', 'hub_updated', dummyfn);
429
+ const p2 = socket.addListener('hubs', 'hub_updated', dummyfn);
427
430
 
428
431
  expect(socket.hasListeners()).toBe(false);
429
432
  expect(socket.getPendingSubscriptionCount()).toBe(1);
@@ -486,7 +489,7 @@ describe('socket', () => {
486
489
 
487
490
  test('should handle hook actions', async () => {
488
491
  const { socket, mockConsole } = await getConnectedSocket(server);
489
- let removeListener = null;
492
+ let removeListener: SubscriptionRemoveHandler | null = null;
490
493
 
491
494
  // Add hook
492
495
  {
@@ -500,7 +503,7 @@ describe('socket', () => {
500
503
  hookSubscriberInfo
501
504
  );
502
505
 
503
- expect(hookAddCallback.mock.calls[0][0].data).toEqual(hookSubscriberInfo);
506
+ expect((hookAddCallback.mock.calls[0][0] as any).data).toEqual(hookSubscriberInfo);
504
507
  expect(hookAddCallback.mock.calls.length).toBe(1);
505
508
  }
506
509
 
@@ -532,7 +535,7 @@ describe('socket', () => {
532
535
  });
533
536
 
534
537
  socket.disconnect(true);
535
- await socket.delete('dummyLogDeleteWarning').catch(error => {
538
+ await socket.delete('dummyLogDeleteWarning').catch((error: Error) => {
536
539
  //...
537
540
  });
538
541
 
@@ -1,11 +1,17 @@
1
- import { Socket } from '../NodeSocket';
2
- import { WebSocket, Server } from 'mock-socket';
1
+ import { Socket } from '../NodeSocket.js';
2
+ import { Client, Server, WebSocket } from 'mock-socket';
3
+ import { jest } from '@jest/globals';
3
4
 
4
- import { OutgoingRequest, RequestSuccessResponse, RequestErrorResponse } from '../types/api_internal';
5
- import * as Options from '../types/options';
6
- import ApiConstants from '../ApiConstants';
5
+ import { OutgoingRequest, RequestSuccessResponse, RequestErrorResponse } from '../types/api_internal.js';
6
+ import * as Options from '../types/options.js';
7
+ import ApiConstants from '../ApiConstants.js';
7
8
  import { EventEmitter } from 'events';
8
9
 
10
+ import waitForExpectOriginal from 'wait-for-expect';
11
+
12
+ const EXCEPT_TIMEOUT = 1000;
13
+ //@ts-ignore
14
+ export const waitForExpect = (func: () => void | Promise<void>) => waitForExpectOriginal.default(func, EXCEPT_TIMEOUT);
9
15
 
10
16
  const VERBOSE = false;
11
17
 
@@ -101,7 +107,7 @@ const toEmitId = (path: string, method: string) => {
101
107
 
102
108
  const getMockServer = () => {
103
109
  const mockServer = new Server(CONNECT_PARAMS.url);
104
- let socket: WebSocket;
110
+ let socket: Client;
105
111
  const emitter = new EventEmitter();
106
112
 
107
113
  const addServerHandler = <DataT extends object | undefined>(
@@ -130,8 +136,8 @@ const getMockServer = () => {
130
136
  mockServer.on('connection', s => {
131
137
  socket = s;
132
138
 
133
- socket.on('message', (messageObj: string) => {
134
- const request: OutgoingRequest = JSON.parse(messageObj);
139
+ socket.on('message', (messageObj) => {
140
+ const request: OutgoingRequest = JSON.parse(messageObj as string);
135
141
  emitter.emit(toEmitId(request.path, request.method), request, s);
136
142
  });
137
143
  });
@@ -1,14 +1,15 @@
1
1
  import {
2
2
  getMockServer,
3
3
  getConnectedSocket,
4
- } from './helpers';
4
+ waitForExpect,
5
+ } from './helpers.js';
5
6
 
6
- import waitForExpect from 'wait-for-expect';
7
+ import { jest } from '@jest/globals';
7
8
 
8
- import { addContextMenuItems } from '../PublicHelpers';
9
- import { SelectedMenuItemListenerData, MenuItemListHookData, MenuItemListHookAcceptData } from '../types/public_helpers_internal';
10
- import { HookSubscriberInfo } from '../types';
11
- import { IncomingSubscriptionEvent } from '../types/api_internal';
9
+ import { addContextMenuItems } from '../PublicHelpers.js';
10
+ import { SelectedMenuItemListenerData, MenuItemListHookData, MenuItemListHookAcceptData } from '../types/public_helpers_internal.js';
11
+ import { HookSubscriberInfo } from '../types/index.js';
12
+ import { IncomingSubscriptionEvent } from '../types/api_internal.js';
12
13
 
13
14
 
14
15
  let server: ReturnType<typeof getMockServer>;
@@ -5,7 +5,7 @@ export type CompletionIdType = number;
5
5
 
6
6
  // REQUESTS
7
7
 
8
- import { ErrorBase, FieldError, EntityId } from './api';
8
+ import { ErrorBase, FieldError, EntityId } from './api.js';
9
9
 
10
10
  export interface RequestResponseBase {
11
11
  code: number;
@@ -1,10 +1,10 @@
1
- export * from './api';
1
+ export * from './api.js';
2
2
 
3
- export * from './logger';
4
- export * from './requests';
5
- export * from './subscriptions';
3
+ export * from './logger.js';
4
+ export * from './requests.js';
5
+ export * from './subscriptions.js';
6
6
 
7
- export * from './socket';
8
- export * from './options';
7
+ export * from './socket.js';
8
+ export * from './options.js';
9
9
 
10
- export * from './public_helpers';
10
+ export * from './public_helpers.js';
@@ -1,3 +1,4 @@
1
+ import { HookSubscriberInfo } from './subscriptions.js';
1
2
 
2
3
  type AsyncCallbackProperty<IdT, EntityIdT, ReturnT> = (
3
4
  selectedIds: IdT[],
@@ -6,10 +7,15 @@ type AsyncCallbackProperty<IdT, EntityIdT, ReturnT> = (
6
7
  supports: string[]
7
8
  ) => ReturnT | Promise<ReturnT>;
8
9
 
10
+ export type ContextMenuIcon = { [key in string]: string };
11
+
12
+ export interface ContextMenu extends HookSubscriberInfo {
13
+ icon?: ContextMenuIcon;
14
+ }
9
15
  export interface ContextMenuItem<IdT, EntityIdT> {
10
16
  id: string;
11
17
  title: string;
12
- icon?: { [key in string]: string };
18
+ icon?: ContextMenuIcon;
13
19
  urls?: string[] | AsyncCallbackProperty<IdT, EntityIdT, string[] | undefined>;
14
20
  onClick?: (
15
21
  selectedIds: IdT[],
@@ -1,4 +1,4 @@
1
- import { ContextMenuItem } from './public_helpers';
1
+ import { ContextMenuIcon, ContextMenuItem } from './public_helpers.js';
2
2
 
3
3
 
4
4
  export interface SelectedMenuItemListenerData<IdT, EntityIdT> {
@@ -28,4 +28,6 @@ export type ResponseMenuItem<IdT, EntityIdT> = Omit<ContextMenuItem<IdT, EntityI
28
28
 
29
29
  export interface MenuItemListHookAcceptData<IdT, EntityIdT> {
30
30
  menuitems: ResponseMenuItem<IdT, EntityIdT>[];
31
+ icon?: ContextMenuIcon;
32
+ title?: string;
31
33
  }
@@ -1,4 +1,4 @@
1
- import * as API from './api';
1
+ import * as API from './api.js';
2
2
 
3
3
 
4
4
  export interface SocketRequestMethods {
@@ -1,23 +1,7 @@
1
- // REQUESTS
2
-
3
-
4
-
5
-
6
- // SUBSCRIPTIONS
7
-
8
-
9
-
10
-
11
- // LOGGER
12
-
13
-
14
-
15
- // GENERIC
16
-
17
- import { AuthTokenType, LogoutResponse, AuthenticationResponse } from './api';
18
- import { Logger } from './logger';
19
- import { SocketRequestMethods } from './requests';
20
- import { SocketSubscriptions } from './subscriptions';
1
+ import { AuthTokenType, LogoutResponse, AuthenticationResponse } from './api.js';
2
+ import { Logger } from './logger.js';
3
+ import { SocketRequestMethods } from './requests.js';
4
+ import { SocketSubscriptions } from './subscriptions.js';
21
5
 
22
6
 
23
7
  export type ConnectedCallback = (data: AuthenticationResponse) => void;
@@ -1,4 +1,4 @@
1
- import * as API from './api';
1
+ import * as API from './api.js';
2
2
 
3
3
 
4
4
  // SUBSCRIPTIONS
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as Options from './types/options';
1
+ import * as Options from './types/options.js';
2
2
 
3
3
 
4
4
  export const eventIgnored = (path: string, ignoredEvents?: Options.IgnoreMatcher) => {
package/tsconfig.json CHANGED
@@ -2,17 +2,16 @@
2
2
  "compilerOptions": {
3
3
  "outDir": "build/dist",
4
4
  "module": "esnext",
5
- "target": "es5",
6
- "lib": ["es6", "dom", "esnext.asynciterable", "es2018"],
5
+ "target": "ES2018",
6
+ "lib": ["dom", "esnext.asynciterable", "ES2018"],
7
7
  "sourceMap": true,
8
- "moduleResolution": "node",
8
+ "moduleResolution": "nodenext",
9
9
  "rootDir": "src",
10
10
  "forceConsistentCasingInFileNames": true,
11
11
  "noImplicitReturns": true,
12
12
  "noImplicitThis": true,
13
13
  "noImplicitAny": true,
14
14
  "strictNullChecks": true,
15
- "suppressImplicitAnyIndexErrors": true,
16
15
  "noUnusedLocals": true,
17
16
  "baseUrl": ".",
18
17
  "experimentalDecorators": true,
@@ -20,11 +19,7 @@
20
19
  "esModuleInterop": true
21
20
  },
22
21
  "exclude": [
23
- "coverage",
24
- "devtools",
25
- "dist",
26
- "node_modules",
27
- "scripts",
28
- "jest",
22
+ "src/tests",
23
+ "jest.config.js",
29
24
  ]
30
25
  }
@@ -1 +0,0 @@
1
- export {};