javonet-nodejs-sdk 2.6.13 → 2.6.14

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 (90) hide show
  1. package/dist/core/handler/ArraySetItemHandler.cjs +9 -8
  2. package/dist/core/handler/AsDtoHandler.cjs +36 -0
  3. package/dist/core/handler/AsKwargsHandler.cjs +1 -1
  4. package/dist/core/handler/DtoPropertyHandler.cjs +36 -0
  5. package/dist/core/handler/Handler.cjs +14 -9
  6. package/dist/core/handler/PassDelegateHandler.cjs +1 -1
  7. package/dist/core/handler/ProjectResultAsDtoHandler.cjs +66 -0
  8. package/dist/core/handler/SetInstanceFieldHandler.cjs +1 -1
  9. package/dist/core/handler/SetStaticFieldHandler.cjs +6 -6
  10. package/dist/core/interpreter/Interpreter.cjs +14 -2
  11. package/dist/core/protocol/CommandDeserializer.cjs +8 -0
  12. package/dist/core/protocol/TypeDeserializer.cjs +4 -0
  13. package/dist/core/protocol/TypeSerializer.cjs +10 -5
  14. package/dist/core/webSocketClient/WebSocketClient.cjs +23 -5
  15. package/dist/core/webSocketClient/WebSocketClientBrowser.cjs +23 -5
  16. package/dist/plugins/PluginImplementationRegistry.cjs +214 -0
  17. package/dist/plugins/PluginPayloadBuilder.cjs +76 -0
  18. package/dist/plugins/PluginRegistry.cjs +255 -0
  19. package/dist/plugins/index.cjs +51 -0
  20. package/dist/plugins/interfaces/ICommunityPlugin.cjs +44 -0
  21. package/dist/plugins/interfaces/ICommunityReceivingPlugin.cjs +62 -0
  22. package/dist/plugins/interfaces/ICommunitySendingPlugin.cjs +59 -0
  23. package/dist/plugins/settings/BasePluginSettings.cjs +67 -0
  24. package/dist/plugins/settings/JwtGraftocodePluginSettings.cjs +40 -0
  25. package/dist/sdk/InvocationContext.cjs +133 -12
  26. package/dist/sdk/RuntimeContext.cjs +27 -9
  27. package/dist/sdk/configuration/configResolvers/ConfigResolver.cjs +7 -6
  28. package/dist/sdk/tools/DtoHelper.cjs +100 -0
  29. package/dist/types/core/handler/ArraySetItemHandler.d.ts +1 -1
  30. package/dist/types/core/handler/AsDtoHandler.d.ts +7 -0
  31. package/dist/types/core/handler/AsKwargsHandler.d.ts +1 -1
  32. package/dist/types/core/handler/DtoPropertyHandler.d.ts +7 -0
  33. package/dist/types/core/handler/ProjectResultAsDtoHandler.d.ts +9 -0
  34. package/dist/types/core/handler/SetInstanceFieldHandler.d.ts +1 -1
  35. package/dist/types/core/handler/SetStaticFieldHandler.d.ts +1 -1
  36. package/dist/types/core/interpreter/Interpreter.d.ts +3 -3
  37. package/dist/types/core/protocol/CommandDeserializer.d.ts +1 -0
  38. package/dist/types/core/protocol/TypeDeserializer.d.ts +1 -0
  39. package/dist/types/core/protocol/TypeSerializer.d.ts +1 -0
  40. package/dist/types/plugins/PluginImplementationRegistry.d.ts +121 -0
  41. package/dist/types/plugins/PluginPayloadBuilder.d.ts +32 -0
  42. package/dist/types/plugins/PluginRegistry.d.ts +157 -0
  43. package/dist/types/plugins/index.d.ts +8 -0
  44. package/dist/types/plugins/interfaces/ICommunityPlugin.d.ts +14 -0
  45. package/dist/types/plugins/interfaces/ICommunityReceivingPlugin.d.ts +50 -0
  46. package/dist/types/plugins/interfaces/ICommunitySendingPlugin.d.ts +27 -0
  47. package/dist/types/plugins/settings/BasePluginSettings.d.ts +45 -0
  48. package/dist/types/plugins/settings/JwtGraftocodePluginSettings.d.ts +32 -0
  49. package/dist/types/sdk/InvocationContext.d.ts +20 -2
  50. package/dist/types/sdk/RuntimeContext.d.ts +6 -0
  51. package/dist/types/sdk/configuration/configResolvers/ConfigResolver.d.ts +3 -6
  52. package/dist/types/sdk/tools/DtoHelper.d.ts +35 -0
  53. package/dist/types/utils/Command.d.ts +5 -0
  54. package/dist/types/utils/CommandType.d.ts +3 -0
  55. package/dist/types/utils/Type.d.ts +2 -1
  56. package/dist/utils/Command.cjs +40 -0
  57. package/dist/utils/CommandType.cjs +4 -1
  58. package/dist/utils/Type.cjs +2 -1
  59. package/lib/core/handler/ArraySetItemHandler.js +11 -10
  60. package/lib/core/handler/AsDtoHandler.js +11 -0
  61. package/lib/core/handler/AsKwargsHandler.js +1 -1
  62. package/lib/core/handler/DtoPropertyHandler.js +11 -0
  63. package/lib/core/handler/Handler.js +16 -7
  64. package/lib/core/handler/PassDelegateHandler.js +2 -1
  65. package/lib/core/handler/ProjectResultAsDtoHandler.js +47 -0
  66. package/lib/core/handler/SetInstanceFieldHandler.js +1 -1
  67. package/lib/core/handler/SetStaticFieldHandler.js +6 -6
  68. package/lib/core/interpreter/Interpreter.js +18 -4
  69. package/lib/core/protocol/CommandDeserializer.js +9 -0
  70. package/lib/core/protocol/TypeDeserializer.js +5 -0
  71. package/lib/core/protocol/TypeSerializer.js +11 -8
  72. package/lib/core/webSocketClient/WebSocketClient.js +30 -5
  73. package/lib/core/webSocketClient/WebSocketClientBrowser.js +29 -5
  74. package/lib/plugins/PluginImplementationRegistry.js +231 -0
  75. package/lib/plugins/PluginPayloadBuilder.js +60 -0
  76. package/lib/plugins/PluginRegistry.js +295 -0
  77. package/lib/plugins/index.js +29 -0
  78. package/lib/plugins/interfaces/ICommunityPlugin.js +25 -0
  79. package/lib/plugins/interfaces/ICommunityReceivingPlugin.js +57 -0
  80. package/lib/plugins/interfaces/ICommunitySendingPlugin.js +42 -0
  81. package/lib/plugins/settings/BasePluginSettings.js +79 -0
  82. package/lib/plugins/settings/JwtGraftocodePluginSettings.js +43 -0
  83. package/lib/sdk/InvocationContext.js +149 -14
  84. package/lib/sdk/RuntimeContext.js +33 -9
  85. package/lib/sdk/configuration/configResolvers/ConfigResolver.js +14 -8
  86. package/lib/sdk/tools/DtoHelper.js +90 -0
  87. package/lib/utils/Command.js +47 -0
  88. package/lib/utils/CommandType.js +3 -0
  89. package/lib/utils/Type.js +2 -1
  90. package/package.json +5 -1
@@ -35,23 +35,24 @@ class ArraySetItemHandler extends import_AbstractHandler.AbstractHandler {
35
35
  if (command.payload.length < this.requiredParametersCount) {
36
36
  throw new Error("Array Set Item parameters mismatch");
37
37
  }
38
- let array = command.payload[0];
38
+ let data = command.payload[0];
39
+ let indexes_from_payload = command.payload[1];
39
40
  let value = command.payload[2];
40
41
  let indexes;
41
- if (Array.isArray(command.payload[1])) {
42
- indexes = command.payload[1];
42
+ if (Array.isArray(indexes_from_payload)) {
43
+ indexes = indexes_from_payload;
43
44
  } else {
44
- indexes = [command.payload[1]];
45
+ indexes = [indexes_from_payload];
45
46
  }
46
47
  if (indexes.length === 1) {
47
- array[indexes[0]] = value;
48
+ data[indexes[0]] = value;
48
49
  } else {
49
50
  for (let i = 0; i < indexes.length - 1; i++) {
50
- array = array[indexes[i]];
51
+ data = data[indexes[i]];
51
52
  }
52
- array[indexes[indexes.length - 1]] = value;
53
+ data[indexes[indexes.length - 1]] = value;
53
54
  }
54
- return 0;
55
+ return data;
55
56
  } catch (error) {
56
57
  throw this.process_stack_trace(error, this.constructor.name);
57
58
  }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var AsDtoHandler_exports = {};
20
+ __export(AsDtoHandler_exports, {
21
+ AsDtoHandler: () => AsDtoHandler
22
+ });
23
+ module.exports = __toCommonJS(AsDtoHandler_exports);
24
+ var import_AbstractHandler = require("./AbstractHandler.cjs");
25
+ class AsDtoHandler extends import_AbstractHandler.AbstractHandler {
26
+ /**
27
+ * @param {any} command
28
+ */
29
+ process(command) {
30
+ throw new Error(`${this.constructor.name} is not implemented in Node.js`);
31
+ }
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ AsDtoHandler
36
+ });
@@ -26,7 +26,7 @@ class AsKwargsHandler extends import_AbstractHandler.AbstractHandler {
26
26
  /**
27
27
  * @param {any} command
28
28
  */
29
- handleCommand(command) {
29
+ process(command) {
30
30
  throw new Error(`${this.constructor.name} is not implemented in Node.js`);
31
31
  }
32
32
  }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var DtoPropertyHandler_exports = {};
20
+ __export(DtoPropertyHandler_exports, {
21
+ DtoPropertyHandler: () => DtoPropertyHandler
22
+ });
23
+ module.exports = __toCommonJS(DtoPropertyHandler_exports);
24
+ var import_AbstractHandler = require("./AbstractHandler.cjs");
25
+ class DtoPropertyHandler extends import_AbstractHandler.AbstractHandler {
26
+ /**
27
+ * @param {any} command
28
+ */
29
+ process(command) {
30
+ throw new Error(`${this.constructor.name} is not implemented in Node.js`);
31
+ }
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ DtoPropertyHandler
36
+ });
@@ -78,6 +78,9 @@ var import_GetResultTypeHandler = require("./GetResultTypeHandler.cjs");
78
78
  var import_GetGlobalFieldHandler = require("./GetGlobalFieldHandler.cjs");
79
79
  var import_RegisterForUpdateHandler = require("./RegisterForUpdateHandler.cjs");
80
80
  var import_ValueForUpdateHandler = require("./ValueForUpdateHandler.cjs");
81
+ var import_AsDtoHandler = require("./AsDtoHandler.cjs");
82
+ var import_DtoPropertyHandler = require("./DtoPropertyHandler.cjs");
83
+ var import_ProjectResultAsDtoHandler = require("./ProjectResultAsDtoHandler.cjs");
81
84
  const handlers = {
82
85
  [import_CommandType.CommandType.Value]: new import_ValueHandler.ValueHandler(),
83
86
  [import_CommandType.CommandType.LoadLibrary]: new import_LoadLibraryHandler.LoadLibraryHandler(),
@@ -128,7 +131,10 @@ const handlers = {
128
131
  [import_CommandType.CommandType.GetResultType]: new import_GetResultTypeHandler.GetResultTypeHandler(),
129
132
  [import_CommandType.CommandType.GetGlobalField]: new import_GetGlobalFieldHandler.GetGlobalFieldHandler(),
130
133
  [import_CommandType.CommandType.RegisterForUpdate]: new import_RegisterForUpdateHandler.RegisterForUpdateHandler(),
131
- [import_CommandType.CommandType.ValueForUpdate]: new import_ValueForUpdateHandler.ValueForUpdateHandler()
134
+ [import_CommandType.CommandType.ValueForUpdate]: new import_ValueForUpdateHandler.ValueForUpdateHandler(),
135
+ [import_CommandType.CommandType.AsDto]: new import_AsDtoHandler.AsDtoHandler(),
136
+ [import_CommandType.CommandType.DtoProperty]: new import_DtoPropertyHandler.DtoPropertyHandler(),
137
+ [import_CommandType.CommandType.ProjectResultAsDto]: new import_ProjectResultAsDtoHandler.ProjectResultAsDtoHandler()
132
138
  };
133
139
  class Handler {
134
140
  static _initialized = false;
@@ -157,6 +163,9 @@ class Handler {
157
163
  return import_Command.Command.createArrayResponse(responseArray, command.runtimeName);
158
164
  }
159
165
  const response = handlers[command.commandType].handleCommand(command);
166
+ if (command.commandType === import_CommandType.CommandType.ProjectResultAsDto) {
167
+ return import_Command.Command.createArrayResponse(response, command.runtimeName);
168
+ }
160
169
  return Handler.parseCommand(response, command.runtimeName);
161
170
  } catch (e) {
162
171
  return Handler.resolveException(e, command);
@@ -196,14 +205,10 @@ class Handler {
196
205
  const refCache = import_ReferencesCache.ReferencesCache.getInstance();
197
206
  for (const [contextKey, instance] of invocationContexts.entries()) {
198
207
  const instanceGuid = refCache.cacheReference(instance);
199
- const updateContextCommand = new import_Command.Command(
200
- runtimeName,
201
- import_CommandType.CommandType.ValueForUpdate,
202
- [
203
- contextKey.toString(),
204
- instanceGuid
205
- ]
206
- );
208
+ const updateContextCommand = new import_Command.Command(runtimeName, import_CommandType.CommandType.ValueForUpdate, [
209
+ contextKey.toString(),
210
+ instanceGuid
211
+ ]);
207
212
  if (typeof responseCommand.addArgToPayload === "function") {
208
213
  responseCommand = responseCommand.addArgToPayload(updateContextCommand);
209
214
  } else {
@@ -121,7 +121,7 @@ class PassDelegateHandler extends import_AbstractHandler.AbstractHandler {
121
121
  */
122
122
  async createExecuteCall(command) {
123
123
  const { Interpreter } = await import("../interpreter/Interpreter.js");
124
- return Interpreter.execute(command, new import_InMemoryConnectionData.InMemoryConnectionData());
124
+ return Interpreter.execute("runtimeContextId", command, new import_InMemoryConnectionData.InMemoryConnectionData());
125
125
  }
126
126
  /**
127
127
  * Retrieves the response payload from the execution call.
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var ProjectResultAsDtoHandler_exports = {};
20
+ __export(ProjectResultAsDtoHandler_exports, {
21
+ ProjectResultAsDtoHandler: () => ProjectResultAsDtoHandler
22
+ });
23
+ module.exports = __toCommonJS(ProjectResultAsDtoHandler_exports);
24
+ var import_AbstractHandler = require("./AbstractHandler.cjs");
25
+ var import_GetInstanceFieldHandler = require("./GetInstanceFieldHandler.cjs");
26
+ var import_Command = require("../../utils/Command.cjs");
27
+ var import_CommandType = require("../../utils/CommandType.cjs");
28
+ class ProjectResultAsDtoHandler extends import_AbstractHandler.AbstractHandler {
29
+ constructor() {
30
+ super();
31
+ this.requiredParametersCount = 1;
32
+ }
33
+ /**
34
+ * @param {Command} command
35
+ */
36
+ process(command) {
37
+ if (command.payload.length < this.requiredParametersCount) {
38
+ throw new Error(`${this.constructor.name} parameters mismatch`);
39
+ }
40
+ const instance = command.payload[0];
41
+ const responseArray = new Array(command.payload.length + 1);
42
+ responseArray[0] = instance;
43
+ let typeName = "Object";
44
+ if (instance !== null && instance !== void 0) {
45
+ typeName = instance.constructor ? instance.constructor.name : "Object";
46
+ }
47
+ responseArray[1] = new import_Command.Command(command.runtimeName, import_CommandType.CommandType.GetType, [typeName]);
48
+ const getInstanceFieldHandler = new import_GetInstanceFieldHandler.GetInstanceFieldHandler();
49
+ for (let i = 1; i < command.payload.length; i++) {
50
+ const propertyName = command.payload[i];
51
+ const propertyValue = getInstanceFieldHandler.process(
52
+ new import_Command.Command(command.runtimeName, import_CommandType.CommandType.GetInstanceField, [instance, propertyName])
53
+ );
54
+ responseArray[i + 1] = new import_Command.Command(
55
+ command.runtimeName,
56
+ import_CommandType.CommandType.DtoProperty,
57
+ [propertyName, propertyValue]
58
+ );
59
+ }
60
+ return responseArray;
61
+ }
62
+ }
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ ProjectResultAsDtoHandler
66
+ });
@@ -50,7 +50,7 @@ class SetInstanceFieldHandler extends import_AbstractHandler.AbstractHandler {
50
50
  throw new Error(message);
51
51
  }
52
52
  instance[field] = value;
53
- return 0;
53
+ return instance;
54
54
  } catch (error) {
55
55
  throw this.process_stack_trace(error, this.constructor.name);
56
56
  }
@@ -36,10 +36,10 @@ class SetStaticFieldHandler extends import_AbstractHandler.AbstractHandler {
36
36
  throw new Error("Set static field parameters mismatch");
37
37
  }
38
38
  const { payload } = command;
39
- let [obj, field, value] = payload;
40
- if (typeof obj[field] === "undefined") {
41
- let fields = Object.keys(obj);
42
- let message = `Field ${field} not found in class ${obj.constructor.name}. Available fields:
39
+ let [type, field, value] = payload;
40
+ if (typeof type[field] === "undefined") {
41
+ let fields = Object.keys(type);
42
+ let message = `Field ${field} not found in class ${type.constructor.name}. Available fields:
43
43
  `;
44
44
  fields.forEach((fieldIter) => {
45
45
  message += `${fieldIter}
@@ -47,8 +47,8 @@ class SetStaticFieldHandler extends import_AbstractHandler.AbstractHandler {
47
47
  });
48
48
  throw new Error(message);
49
49
  }
50
- obj[field] = value;
51
- return 0;
50
+ type[field] = value;
51
+ return type;
52
52
  } catch (error) {
53
53
  throw this.process_stack_trace(error, this.constructor.name);
54
54
  }
@@ -29,6 +29,10 @@ var import_CommandSerializer = require("../protocol/CommandSerializer.cjs");
29
29
  var import_TransmitterWebsocketBrowser = require("../transmitter/TransmitterWebsocketBrowser.cjs");
30
30
  var import_TransmitterWebsocket = require("../transmitter/TransmitterWebsocket.cjs");
31
31
  var import_Handler = require("../handler/Handler.cjs");
32
+ var import_PluginRegistry = require("../../plugins/PluginRegistry.cjs");
33
+ var import_PluginPayloadBuilder = require("../../plugins/PluginPayloadBuilder.cjs");
34
+ var import_Command = require("../../utils/Command.cjs");
35
+ var import_CommandType = require("../../utils/CommandType.cjs");
32
36
  const import_meta = {};
33
37
  let _Receiver;
34
38
  let _Transmitter;
@@ -36,13 +40,21 @@ let _TransmitterWebsocket = (0, import_Runtime.isNodejsRuntime)() ? import_Trans
36
40
  const requireDynamic = (0, import_Runtime.getRequire)(import_meta.url);
37
41
  class Interpreter {
38
42
  /**
39
- *
43
+ * @param {string} runtimeContextId
40
44
  * @param {Command} command
41
45
  * @param {IConnectionData} connectionData
42
46
  * @returns {Promise<Command>}
43
47
  */
44
- static async execute(command, connectionData) {
48
+ static async execute(runtimeContextId, command, connectionData) {
45
49
  try {
50
+ if (import_PluginRegistry.PluginRegistry.arePluginsRegisteredForRuntime(runtimeContextId)) {
51
+ const serializedPlugins = import_PluginPayloadBuilder.PluginPayloadBuilder.buildPluginsPayload(runtimeContextId);
52
+ command = new import_Command.Command(
53
+ command.runtimeName,
54
+ import_CommandType.CommandType.PluginWrapper,
55
+ [serializedPlugins, command]
56
+ );
57
+ }
46
58
  let messageByteArray = import_CommandSerializer.CommandSerializer.serialize(command, connectionData);
47
59
  if (!(messageByteArray instanceof Uint8Array)) {
48
60
  throw new Error("Serialized message is not Uint8Array");
@@ -78,6 +78,8 @@ class CommandDeserializer {
78
78
  return this.readUInt();
79
79
  case "JAVONET_NULL":
80
80
  return this.readNull();
81
+ case "JAVONET_UNDEFINED":
82
+ return this.readUndefined();
81
83
  default:
82
84
  throw "Unknown type - not supported in JavaScript";
83
85
  }
@@ -189,6 +191,12 @@ class CommandDeserializer {
189
191
  this.position += size;
190
192
  return import_TypeDeserializer.TypeDeserializer.deserializeNull();
191
193
  }
194
+ readUndefined() {
195
+ const size = 1;
196
+ this.position += 2;
197
+ this.position += size;
198
+ return import_TypeDeserializer.TypeDeserializer.deserializeUndefined();
199
+ }
192
200
  }
193
201
  // Annotate the CommonJS export names for ESM import in node:
194
202
  0 && (module.exports = {
@@ -119,6 +119,10 @@ class TypeDeserializer {
119
119
  static deserializeNull(encodedNull = null) {
120
120
  return null;
121
121
  }
122
+ // eslint-disable-next-line no-unused-vars
123
+ static deserializeUndefined(encodedUndefined = null) {
124
+ return void 0;
125
+ }
122
126
  }
123
127
  // Annotate the CommonJS export names for ESM import in node:
124
128
  0 && (module.exports = {
@@ -35,6 +35,9 @@ class TypeSerializer {
35
35
  if (payload_item === null) {
36
36
  return TypeSerializer.serializeNull();
37
37
  }
38
+ if (payload_item === void 0) {
39
+ return TypeSerializer.serializeUndefined();
40
+ }
38
41
  if (payload_item instanceof import_Command.Command) {
39
42
  return TypeSerializer.serializeCommand(payload_item);
40
43
  } else if (typeof payload_item === "number") {
@@ -52,11 +55,6 @@ class TypeSerializer {
52
55
  const message = "Unsupported payload item type: " + (payload_item?.constructor?.name || typeof payload_item) + " for payload item: " + payload_item;
53
56
  throw new import_CustomError.CustomError(message, "JAVONET_PROMISE");
54
57
  }
55
- if (payload_item === void 0) {
56
- throw Error(
57
- "Unsupported payload item type: " + typeof payload_item + " for payload item: " + payload_item
58
- );
59
- }
60
58
  throw Error(
61
59
  "Unsupported payload item type: " + (payload_item?.constructor?.name || typeof payload_item) + " for payload item: " + payload_item
62
60
  );
@@ -182,6 +180,13 @@ class TypeSerializer {
182
180
  buffer.writeUInt8(0, 2);
183
181
  return buffer;
184
182
  }
183
+ static serializeUndefined() {
184
+ const buffer = import_buffer.Buffer.alloc(3);
185
+ buffer.writeUInt8(import_Type.Type.JAVONET_UNDEFINED, 0);
186
+ buffer.writeUInt8(1, 1);
187
+ buffer.writeUInt8(0, 2);
188
+ return buffer;
189
+ }
185
190
  /**
186
191
  * @param {number} int_value
187
192
  */
@@ -151,7 +151,9 @@ class WebSocketClient {
151
151
  }
152
152
  if (messageQueue[this.url]) {
153
153
  messageQueue[this.url].forEach(({ reject }) => {
154
- reject(new Error("WebSocket disconnected"));
154
+ reject(new Error(
155
+ `WebSocket to ${this.url} was disconnected. The connection was closed before the operation completed.`
156
+ ));
155
157
  });
156
158
  delete messageQueue[this.url];
157
159
  }
@@ -172,24 +174,40 @@ class WebSocketClient {
172
174
  /** @type {{ code?: string }} */
173
175
  error.code === "MODULE_NOT_FOUND"
174
176
  ) {
175
- throw new Error("ws module not found. Please install it using npm install ws");
177
+ throw new Error(
178
+ 'WebSocket connection failed: the "ws" package is not installed. Install it with: npm install ws'
179
+ );
176
180
  }
177
181
  throw error;
178
182
  }
179
183
  }
180
184
  return new Promise((resolve, reject) => {
181
185
  if (!WebSocket) {
182
- return reject(new Error("ws client is null"));
186
+ return reject(new Error(
187
+ 'WebSocket connection failed: ws client is not available. In Node.js ensure the "ws" package is installed (npm install ws).'
188
+ ));
183
189
  }
184
190
  let client = clients[this.url];
185
191
  if (!client) {
186
192
  client = new WebSocket(this.url);
187
193
  clients[this.url] = client;
188
194
  }
195
+ const wrapReject = (err) => {
196
+ const msg = err instanceof Error ? err.message : String(err);
197
+ const wrapped = new Error(
198
+ `WebSocket connection to ${this.url} failed: ${msg}. Check that the server is running, the URL is correct (ws:// or wss://), and that no firewall or proxy is blocking the connection.`
199
+ );
200
+ if (err instanceof Error && "cause" in Error.prototype) {
201
+ wrapped.cause = err;
202
+ }
203
+ reject(wrapped);
204
+ };
189
205
  client.on(WebSocketStateEvent.OPEN, () => resolve(client));
190
- client.on(WebSocketStateEvent.ERROR, (error) => reject(error));
206
+ client.on(WebSocketStateEvent.ERROR, (error) => wrapReject(error));
191
207
  client.on(WebSocketStateEvent.CLOSE, () => {
192
- reject(new Error("Connection closed before receiving message"));
208
+ reject(new Error(
209
+ `WebSocket connection to ${this.url} was closed before it could be established. The server may have refused the connection, closed immediately, or a network error occurred. Check that the server is running and the URL is correct.`
210
+ ));
193
211
  });
194
212
  });
195
213
  }
@@ -128,7 +128,9 @@ class WebSocketClientBrowser {
128
128
  }
129
129
  if (messageQueue[this.url]) {
130
130
  messageQueue[this.url].forEach(({ reject }) => {
131
- reject(new Error("WebSocket disconnected"));
131
+ reject(new Error(
132
+ `WebSocket to ${this.url} was disconnected. The connection was closed before the operation completed.`
133
+ ));
132
134
  });
133
135
  delete messageQueue[this.url];
134
136
  }
@@ -143,7 +145,9 @@ class WebSocketClientBrowser {
143
145
  _connect() {
144
146
  return new Promise((resolve, reject) => {
145
147
  if (!WsClient) {
146
- return reject(new Error("missing WebSocket client"));
148
+ return reject(new Error(
149
+ `WebSocket connection to ${this.url} failed: WebSocket API is not available in this environment. Ensure the code runs in a browser or environment that supports WebSocket.`
150
+ ));
147
151
  }
148
152
  let client = clients[this.url];
149
153
  if (!client) {
@@ -151,10 +155,22 @@ class WebSocketClientBrowser {
151
155
  client.binaryType = "arraybuffer";
152
156
  clients[this.url] = client;
153
157
  }
158
+ const wrapReject = (err) => {
159
+ const msg = err instanceof Error ? err.message : err instanceof Event && err.type ? `Event: ${err.type}` : String(err);
160
+ const wrapped = new Error(
161
+ `WebSocket connection to ${this.url} failed: ${msg}. Check that the server is running, the URL is correct (ws:// or wss://), and that no firewall, CORS, or proxy is blocking the connection.`
162
+ );
163
+ if (err instanceof Error && "cause" in Error.prototype) {
164
+ wrapped.cause = err;
165
+ }
166
+ reject(wrapped);
167
+ };
154
168
  client.addEventListener(WebSocketState.OPEN, () => resolve(client));
155
- client.addEventListener(WebSocketState.ERROR, reject);
169
+ client.addEventListener(WebSocketState.ERROR, (e) => wrapReject(e));
156
170
  client.addEventListener(WebSocketState.CLOSE, () => {
157
- reject(new Error("Connection closed before receiving message"));
171
+ reject(new Error(
172
+ `WebSocket connection to ${this.url} was closed before it could be established. The server may have refused the connection or a network error occurred. Check that the server is running and the URL is correct.`
173
+ ));
158
174
  });
159
175
  });
160
176
  }
@@ -172,7 +188,9 @@ class WebSocketClientBrowser {
172
188
  client.send(arrayBuffer);
173
189
  const handleMessage = (message) => {
174
190
  if (!message?.data) {
175
- return reject(new Error("Invalid message received"));
191
+ return reject(new Error(
192
+ `WebSocket to ${this.url}: invalid message received (no data). The server response may be malformed.`
193
+ ));
176
194
  }
177
195
  const byteArray = new Uint8Array(message?.data);
178
196
  resolve(byteArray);