@socket-mesh/client 18.1.5 → 19.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.
@@ -1,8 +1,15 @@
1
1
  export class BatchingPlugin {
2
+ _batchingIntervalId;
3
+ _handshakeTimeoutId;
4
+ _isBatching;
5
+ batchInterval;
6
+ batchOnHandshakeDuration;
7
+ type;
2
8
  constructor(options) {
3
9
  this._isBatching = false;
4
- this.batchInterval = options?.batchInterval || 50;
5
- this.batchOnHandshakeDuration = options?.batchOnHandshakeDuration ?? false;
10
+ this.type = options.type;
11
+ this.batchInterval = options.batchInterval || 50;
12
+ this.batchOnHandshakeDuration = options.batchOnHandshakeDuration ?? false;
6
13
  this._batchingIntervalId = null;
7
14
  this._handshakeTimeoutId = null;
8
15
  }
@@ -16,6 +23,9 @@ export class BatchingPlugin {
16
23
  get isBatching() {
17
24
  return this._isBatching || this._batchingIntervalId !== null;
18
25
  }
26
+ onDisconnected() {
27
+ this.cancelBatching();
28
+ }
19
29
  onReady() {
20
30
  if (this._isBatching) {
21
31
  this.start();
@@ -27,13 +37,6 @@ export class BatchingPlugin {
27
37
  }, this.batchOnHandshakeDuration);
28
38
  }
29
39
  }
30
- onDisconnected() {
31
- this.cancelBatching();
32
- }
33
- startBatching() {
34
- this._isBatching = true;
35
- this.start();
36
- }
37
40
  start() {
38
41
  if (this._batchingIntervalId !== null) {
39
42
  return;
@@ -42,9 +45,9 @@ export class BatchingPlugin {
42
45
  this.flush();
43
46
  }, this.batchInterval);
44
47
  }
45
- stopBatching() {
46
- this._isBatching = false;
47
- this.stop();
48
+ startBatching() {
49
+ this._isBatching = true;
50
+ this.start();
48
51
  }
49
52
  stop() {
50
53
  if (this._batchingIntervalId !== null) {
@@ -57,11 +60,19 @@ export class BatchingPlugin {
57
60
  }
58
61
  this.flush();
59
62
  }
63
+ stopBatching() {
64
+ this._isBatching = false;
65
+ this.stop();
66
+ }
60
67
  }
61
68
  export class RequestBatchingPlugin extends BatchingPlugin {
69
+ _continue;
70
+ _requests;
62
71
  constructor(options) {
63
- super(options);
64
- this.type = 'requestBatching';
72
+ super({
73
+ ...(options ?? {}),
74
+ type: 'requestBatching'
75
+ });
65
76
  this._requests = [];
66
77
  this._continue = null;
67
78
  }
@@ -72,12 +83,14 @@ export class RequestBatchingPlugin extends BatchingPlugin {
72
83
  }
73
84
  flush() {
74
85
  if (this._requests.length) {
75
- this._continue(this._requests);
86
+ if (this._continue) {
87
+ this._continue(this._requests);
88
+ this._continue = null;
89
+ }
76
90
  this._requests = [];
77
- this._continue = null;
78
91
  }
79
92
  }
80
- sendRequest({ requests, cont }) {
93
+ sendRequest({ cont, requests }) {
81
94
  if (!this.isBatching) {
82
95
  cont(requests);
83
96
  return;
@@ -87,20 +100,26 @@ export class RequestBatchingPlugin extends BatchingPlugin {
87
100
  }
88
101
  }
89
102
  export class ResponseBatchingPlugin extends BatchingPlugin {
103
+ _continue;
104
+ _responses;
90
105
  constructor(options) {
91
- super(options);
92
- this.type = 'responseBatching';
106
+ super({
107
+ ...(options ?? {}),
108
+ type: 'responseBatching'
109
+ });
93
110
  this._responses = [];
94
111
  this._continue = null;
95
112
  }
96
113
  flush() {
97
114
  if (this._responses.length) {
98
- this._continue(this._responses);
115
+ if (this._continue) {
116
+ this._continue(this._responses);
117
+ this._continue = null;
118
+ }
99
119
  this._responses = [];
100
- this._continue = null;
101
120
  }
102
121
  }
103
- sendResponse({ responses, cont }) {
122
+ sendResponse({ cont, responses }) {
104
123
  if (!this.isBatching) {
105
124
  cont(responses);
106
125
  return;
@@ -1,10 +1,10 @@
1
- import { RawData } from "ws";
2
- import { MessageRawPluginArgs, MethodMap, Plugin, PluginArgs, PrivateMethodMap, PublicMethodMap, ServiceMap } from "@socket-mesh/core";
3
- export declare class InOrderPlugin<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> implements Plugin<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> {
4
- type: 'inOrder';
1
+ import { MessageRawPluginArgs, Plugin, PluginArgs } from '@socket-mesh/core';
2
+ import { RawData } from 'ws';
3
+ export declare class InOrderPlugin implements Plugin {
5
4
  private readonly _inboundMessageStream;
5
+ type: 'inOrder';
6
6
  constructor();
7
7
  handleInboundMessageStream(): void;
8
- onEnd({ transport }: PluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
9
- onMessageRaw(options: MessageRawPluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): Promise<string | RawData>;
8
+ onEnd({ transport }: PluginArgs): void;
9
+ onMessageRaw(options: MessageRawPluginArgs): Promise<RawData | string>;
10
10
  }
@@ -1,15 +1,18 @@
1
- import { WritableConsumableStream } from "@socket-mesh/writable-consumable-stream";
1
+ import { WritableConsumableStream } from '@socket-mesh/writable-consumable-stream';
2
2
  export class InOrderPlugin {
3
- //private readonly _outboundMessageStream: WritableConsumableStream<SendRequestPluginArgs<T>>;
3
+ _inboundMessageStream;
4
+ type;
5
+ // private readonly _outboundMessageStream: WritableConsumableStream<SendRequestPluginArgs<T>>;
4
6
  constructor() {
5
7
  this._inboundMessageStream = new WritableConsumableStream();
6
- //this._outboundMessageStream = new WritableConsumableStream<SendRequestPluginArgs<T>>;
8
+ // this._outboundMessageStream = new WritableConsumableStream<SendRequestPluginArgs<T>>;
9
+ this.type = 'inOrder';
7
10
  this.handleInboundMessageStream();
8
- //this.handleOutboundMessageStream();
11
+ // this.handleOutboundMessageStream();
9
12
  }
10
13
  handleInboundMessageStream() {
11
14
  (async () => {
12
- for await (let { message, callback, promise } of this._inboundMessageStream) {
15
+ for await (const { callback, message, promise } of this._inboundMessageStream) {
13
16
  callback(null, message);
14
17
  try {
15
18
  await promise;
@@ -21,36 +24,36 @@ export class InOrderPlugin {
21
24
  })();
22
25
  }
23
26
  /*
24
- handleOutboundMessageStream(): void {
25
- (async () => {
26
- for await (let { requests, cont } of this._outboundMessageStream) {
27
- await new Promise<void>((resolve) => {
28
- const reqCol = new RequestCollection(requests);
29
-
30
- if (reqCol.isDone()) {
31
- resolve();
32
- cont(requests);
33
- return;
34
- }
35
-
36
- reqCol.listen(() => {
37
- resolve();
38
- });
39
-
27
+ handleOutboundMessageStream(): void {
28
+ (async () => {
29
+ for await (let { requests, cont } of this._outboundMessageStream) {
30
+ await new Promise<void>((resolve) => {
31
+ const reqCol = new RequestCollection(requests);
32
+
33
+ if (reqCol.isDone()) {
34
+ resolve();
40
35
  cont(requests);
36
+ return;
37
+ }
38
+
39
+ reqCol.listen(() => {
40
+ resolve();
41
41
  });
42
- }
43
- })();
44
- }
45
- */
42
+
43
+ cont(requests);
44
+ });
45
+ }
46
+ })();
47
+ }
48
+ */
46
49
  onEnd({ transport }) {
47
50
  if (transport.streamCleanupMode === 'close') {
48
51
  this._inboundMessageStream.close();
49
- //this._outboundMessageStream.close();
52
+ // this._outboundMessageStream.close();
50
53
  }
51
54
  else if (transport.streamCleanupMode === 'kill') {
52
55
  this._inboundMessageStream.kill();
53
- //this._outboundMessageStream.kill();
56
+ // this._outboundMessageStream.kill();
54
57
  }
55
58
  }
56
59
  onMessageRaw(options) {
@@ -64,7 +67,7 @@ export class InOrderPlugin {
64
67
  resolve(data);
65
68
  };
66
69
  });
67
- this._inboundMessageStream.write({ callback, ...options });
70
+ this._inboundMessageStream.write({ callback: callback, ...options });
68
71
  return promise;
69
72
  }
70
73
  }
@@ -1,3 +1,3 @@
1
- export * from "./batching-plugin.js";
2
- export * from "./in-order-plugin.js";
3
- export * from "./offline-plugin.js";
1
+ export * from './batching-plugin.js';
2
+ export * from './in-order-plugin.js';
3
+ export * from './offline-plugin.js';
@@ -1,3 +1,3 @@
1
- export * from "./batching-plugin.js";
2
- export * from "./in-order-plugin.js";
3
- export * from "./offline-plugin.js";
1
+ export * from './batching-plugin.js';
2
+ export * from './in-order-plugin.js';
3
+ export * from './offline-plugin.js';
@@ -1,13 +1,13 @@
1
- import { MethodMap, Plugin, PrivateMethodMap, PublicMethodMap, SendRequestPluginArgs, ServiceMap } from "@socket-mesh/core";
2
- export declare class OfflinePlugin<TIncoming extends MethodMap, TOutgoing extends PublicMethodMap, TPrivateOutgoing extends PrivateMethodMap, TService extends ServiceMap, TState extends object> implements Plugin<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState> {
1
+ import { Plugin, SendRequestPluginArgs } from '@socket-mesh/core';
2
+ export declare class OfflinePlugin implements Plugin {
3
+ private _continue;
3
4
  private _isReady;
4
5
  private _requests;
5
- private _continue;
6
+ type: 'offline';
6
7
  constructor();
7
- type: "offline";
8
- sendRequest({ requests, cont }: SendRequestPluginArgs<TIncoming, TOutgoing, TPrivateOutgoing, TService, TState>): void;
9
- onReady(): void;
8
+ private flush;
10
9
  onClose(): void;
11
10
  onDisconnected(): void;
12
- private flush;
11
+ onReady(): void;
12
+ sendRequest({ cont, requests }: SendRequestPluginArgs): void;
13
13
  }
@@ -1,20 +1,46 @@
1
1
  const SYSTEM_METHODS = ['#handshake', '#removeAuthToken'];
2
2
  export class OfflinePlugin {
3
+ _continue;
4
+ _isReady;
5
+ _requests;
6
+ type;
3
7
  constructor() {
4
8
  this.type = 'offline';
5
9
  this._isReady = false;
6
10
  this._requests = [];
7
11
  this._continue = null;
8
12
  }
9
- sendRequest({ requests, cont }) {
13
+ flush() {
14
+ if (this._requests.length) {
15
+ if (this._continue) {
16
+ for (const reqs of this._requests) {
17
+ this._continue(reqs);
18
+ }
19
+ this._continue = null;
20
+ }
21
+ this._requests = [];
22
+ }
23
+ }
24
+ onClose() {
25
+ this._isReady = false;
26
+ }
27
+ onDisconnected() {
28
+ this._requests = [];
29
+ this._continue = null;
30
+ }
31
+ onReady() {
32
+ this._isReady = true;
33
+ this.flush();
34
+ }
35
+ sendRequest({ cont, requests }) {
10
36
  if (this._isReady) {
11
37
  cont(requests);
12
38
  return;
13
39
  }
14
- const systemRequests = requests.filter(item => SYSTEM_METHODS.indexOf(String(item.method)) > -1);
40
+ const systemRequests = requests.filter(item => SYSTEM_METHODS.indexOf(item.method) > -1);
15
41
  let otherRequests = requests;
16
42
  if (systemRequests.length) {
17
- otherRequests = (systemRequests.length === requests.length) ? [] : requests.filter(item => SYSTEM_METHODS.indexOf(String(item.method)) < 0);
43
+ otherRequests = (systemRequests.length === requests.length) ? [] : requests.filter(item => SYSTEM_METHODS.indexOf(item.method) < 0);
18
44
  }
19
45
  if (otherRequests.length) {
20
46
  this._continue = cont;
@@ -24,24 +50,4 @@ export class OfflinePlugin {
24
50
  cont(systemRequests);
25
51
  }
26
52
  }
27
- onReady() {
28
- this._isReady = true;
29
- this.flush();
30
- }
31
- onClose() {
32
- this._isReady = false;
33
- }
34
- onDisconnected() {
35
- this._requests = [];
36
- this._continue = null;
37
- }
38
- flush() {
39
- if (this._requests.length) {
40
- for (const reqs of this._requests) {
41
- this._continue(reqs);
42
- }
43
- this._requests = [];
44
- this._continue = null;
45
- }
46
- }
47
53
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@socket-mesh/client",
3
3
  "description": "A TCP socket pair for easily transmitting full messages without worrying about request size limits.",
4
- "version": "18.1.5",
4
+ "version": "19.0.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -15,8 +15,10 @@
15
15
  "scripts": {
16
16
  "build": "node ../../scripts/build.mjs && tsc --project tsconfig.build.json",
17
17
  "bundle": "rollup --config ./rollup.config.js",
18
- "deploy": "npm run build && node ../../scripts/publish.mjs",
19
- "test": "cross-env node --test --import=./run-test.js test/client-test.ts"
18
+ "deploy": "node ../../scripts/publish.mjs",
19
+ "lint": "eslint . --c ../../eslint.config.mjs",
20
+ "lint:fix": "eslint . --c ../../eslint.config.mjs --fix",
21
+ "test": "tsx --tsconfig ./tsconfig.build.json --test ./src/**/*.{spec,test}.ts ./test/**/*.{spec,test}.ts"
20
22
  },
21
23
  "repository": {
22
24
  "type": "git",
@@ -26,33 +28,33 @@
26
28
  "url": "https://github.com/socket-mesh/client-server/labels/client"
27
29
  },
28
30
  "devDependencies": {
29
- "@kineticcafe/rollup-plugin-delete": "^3.0.0",
30
- "@rollup/plugin-alias": "^5.1.0",
31
- "@rollup/plugin-commonjs": "^26.0.1",
32
- "@rollup/plugin-node-resolve": "^15.2.3",
33
- "@rollup/plugin-terser": "^0.4.4",
34
- "@rollup/plugin-typescript": "^11.1.6",
35
- "@socket-mesh/server": "*",
36
- "@socket-mesh/local-storage": "^1.0.2",
37
- "@types/clone-deep": "^4.0.4",
38
- "@types/jsonwebtoken": "^9.0.6",
39
- "@types/ws": "^8.5.10",
40
- "jsonwebtoken": "^9.0.2",
41
- "rollup": "^4.22.5",
42
- "rollup-plugin-dts": "^6.1.1",
43
- "tslib": "^2.7.0"
31
+ "@kineticcafe/rollup-plugin-delete": "catalog:rollup",
32
+ "@rollup/plugin-alias": "catalog:rollup",
33
+ "@rollup/plugin-commonjs": "catalog:rollup",
34
+ "@rollup/plugin-node-resolve": "catalog:rollup",
35
+ "@rollup/plugin-terser": "catalog:rollup",
36
+ "@rollup/plugin-typescript": "catalog:rollup",
37
+ "@socket-mesh/typescript-config": "workspace:^",
38
+ "@socket-mesh/writable-consumable-stream": "workspace:^",
39
+ "@types/clone-deep": "catalog:clone-deep",
40
+ "@types/jsonwebtoken": "catalog:json-web-token",
41
+ "@types/ws": "catalog:ws",
42
+ "jsonwebtoken": "catalog:json-web-token",
43
+ "rollup": "catalog:rollup",
44
+ "rollup-plugin-dts": "catalog:rollup",
45
+ "tslib": "catalog:"
44
46
  },
45
47
  "dependencies": {
46
- "@socket-mesh/async-stream-emitter": "^7.1.2",
47
- "@socket-mesh/auth": "^2.2.0",
48
- "@socket-mesh/channels": "^6.1.2",
49
- "@socket-mesh/core": "^1.0.3",
50
- "@socket-mesh/errors": "^3.2.0",
51
- "@socket-mesh/formatter": "^4.1.0",
52
- "buffer": "^6.0.3",
53
- "events": "^3.3.0",
54
- "isomorphic-ws": "^5.0.0",
55
- "ws": "^8.18.0"
48
+ "@socket-mesh/async-stream-emitter": "workspace:^",
49
+ "@socket-mesh/auth": "workspace:^",
50
+ "@socket-mesh/channels": "workspace:^",
51
+ "@socket-mesh/core": "workspace:^",
52
+ "@socket-mesh/errors": "workspace:^",
53
+ "@socket-mesh/formatter": "workspace:^",
54
+ "buffer": "catalog:",
55
+ "events": "catalog:",
56
+ "isomorphic-ws": "catalog:ws",
57
+ "ws": "catalog:ws"
56
58
  },
57
59
  "keywords": [
58
60
  "ncom",