javonet-nodejs-sdk 2.6.12 → 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 (99) 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/DestructReferenceHandler.cjs +9 -2
  5. package/dist/core/handler/DtoPropertyHandler.cjs +36 -0
  6. package/dist/core/handler/Handler.cjs +14 -9
  7. package/dist/core/handler/PassDelegateHandler.cjs +1 -1
  8. package/dist/core/handler/ProjectResultAsDtoHandler.cjs +66 -0
  9. package/dist/core/handler/SetInstanceFieldHandler.cjs +1 -1
  10. package/dist/core/handler/SetStaticFieldHandler.cjs +6 -6
  11. package/dist/core/interpreter/Interpreter.cjs +14 -2
  12. package/dist/core/protocol/CommandDeserializer.cjs +8 -0
  13. package/dist/core/protocol/TypeDeserializer.cjs +4 -0
  14. package/dist/core/protocol/TypeSerializer.cjs +10 -5
  15. package/dist/core/referenceCache/ReferencesCache.cjs +8 -5
  16. package/dist/core/webSocketClient/WebSocketClient.cjs +23 -5
  17. package/dist/core/webSocketClient/WebSocketClientBrowser.cjs +23 -5
  18. package/dist/plugins/PluginImplementationRegistry.cjs +214 -0
  19. package/dist/plugins/PluginPayloadBuilder.cjs +76 -0
  20. package/dist/plugins/PluginRegistry.cjs +255 -0
  21. package/dist/plugins/index.cjs +51 -0
  22. package/dist/plugins/interfaces/ICommunityPlugin.cjs +44 -0
  23. package/dist/plugins/interfaces/ICommunityReceivingPlugin.cjs +62 -0
  24. package/dist/plugins/interfaces/ICommunitySendingPlugin.cjs +59 -0
  25. package/dist/plugins/settings/BasePluginSettings.cjs +67 -0
  26. package/dist/plugins/settings/JwtGraftocodePluginSettings.cjs +40 -0
  27. package/dist/sdk/InvocationContext.cjs +133 -12
  28. package/dist/sdk/Javonet.cjs +3 -0
  29. package/dist/sdk/RuntimeContext.cjs +27 -9
  30. package/dist/sdk/configuration/configResolvers/ConfigResolver.cjs +7 -6
  31. package/dist/sdk/tools/DtoHelper.cjs +100 -0
  32. package/dist/types/core/handler/ArraySetItemHandler.d.ts +1 -1
  33. package/dist/types/core/handler/AsDtoHandler.d.ts +7 -0
  34. package/dist/types/core/handler/AsKwargsHandler.d.ts +1 -1
  35. package/dist/types/core/handler/DestructReferenceHandler.d.ts +2 -1
  36. package/dist/types/core/handler/DtoPropertyHandler.d.ts +7 -0
  37. package/dist/types/core/handler/ProjectResultAsDtoHandler.d.ts +9 -0
  38. package/dist/types/core/handler/SetInstanceFieldHandler.d.ts +1 -1
  39. package/dist/types/core/handler/SetStaticFieldHandler.d.ts +1 -1
  40. package/dist/types/core/interpreter/Interpreter.d.ts +3 -3
  41. package/dist/types/core/protocol/CommandDeserializer.d.ts +1 -0
  42. package/dist/types/core/protocol/TypeDeserializer.d.ts +1 -0
  43. package/dist/types/core/protocol/TypeSerializer.d.ts +1 -0
  44. package/dist/types/core/referenceCache/ReferencesCache.d.ts +3 -3
  45. package/dist/types/plugins/PluginImplementationRegistry.d.ts +121 -0
  46. package/dist/types/plugins/PluginPayloadBuilder.d.ts +32 -0
  47. package/dist/types/plugins/PluginRegistry.d.ts +157 -0
  48. package/dist/types/plugins/index.d.ts +8 -0
  49. package/dist/types/plugins/interfaces/ICommunityPlugin.d.ts +14 -0
  50. package/dist/types/plugins/interfaces/ICommunityReceivingPlugin.d.ts +50 -0
  51. package/dist/types/plugins/interfaces/ICommunitySendingPlugin.d.ts +27 -0
  52. package/dist/types/plugins/settings/BasePluginSettings.d.ts +45 -0
  53. package/dist/types/plugins/settings/JwtGraftocodePluginSettings.d.ts +32 -0
  54. package/dist/types/sdk/InvocationContext.d.ts +20 -2
  55. package/dist/types/sdk/Javonet.d.ts +2 -1
  56. package/dist/types/sdk/RuntimeContext.d.ts +6 -0
  57. package/dist/types/sdk/configuration/configResolvers/ConfigResolver.d.ts +3 -6
  58. package/dist/types/sdk/tools/DtoHelper.d.ts +35 -0
  59. package/dist/types/utils/Command.d.ts +5 -0
  60. package/dist/types/utils/CommandType.d.ts +3 -0
  61. package/dist/types/utils/Type.d.ts +2 -1
  62. package/dist/utils/Command.cjs +40 -0
  63. package/dist/utils/CommandType.cjs +4 -1
  64. package/dist/utils/Type.cjs +2 -1
  65. package/lib/core/handler/ArraySetItemHandler.js +11 -10
  66. package/lib/core/handler/AsDtoHandler.js +11 -0
  67. package/lib/core/handler/AsKwargsHandler.js +1 -1
  68. package/lib/core/handler/DestructReferenceHandler.js +11 -3
  69. package/lib/core/handler/DtoPropertyHandler.js +11 -0
  70. package/lib/core/handler/Handler.js +16 -7
  71. package/lib/core/handler/PassDelegateHandler.js +2 -1
  72. package/lib/core/handler/ProjectResultAsDtoHandler.js +47 -0
  73. package/lib/core/handler/SetInstanceFieldHandler.js +1 -1
  74. package/lib/core/handler/SetStaticFieldHandler.js +6 -6
  75. package/lib/core/interpreter/Interpreter.js +18 -4
  76. package/lib/core/protocol/CommandDeserializer.js +9 -0
  77. package/lib/core/protocol/TypeDeserializer.js +5 -0
  78. package/lib/core/protocol/TypeSerializer.js +11 -8
  79. package/lib/core/referenceCache/ReferencesCache.js +9 -5
  80. package/lib/core/webSocketClient/WebSocketClient.js +30 -5
  81. package/lib/core/webSocketClient/WebSocketClientBrowser.js +29 -5
  82. package/lib/plugins/PluginImplementationRegistry.js +231 -0
  83. package/lib/plugins/PluginPayloadBuilder.js +60 -0
  84. package/lib/plugins/PluginRegistry.js +295 -0
  85. package/lib/plugins/index.js +29 -0
  86. package/lib/plugins/interfaces/ICommunityPlugin.js +25 -0
  87. package/lib/plugins/interfaces/ICommunityReceivingPlugin.js +57 -0
  88. package/lib/plugins/interfaces/ICommunitySendingPlugin.js +42 -0
  89. package/lib/plugins/settings/BasePluginSettings.js +79 -0
  90. package/lib/plugins/settings/JwtGraftocodePluginSettings.js +43 -0
  91. package/lib/sdk/InvocationContext.js +149 -14
  92. package/lib/sdk/Javonet.js +2 -0
  93. package/lib/sdk/RuntimeContext.js +33 -9
  94. package/lib/sdk/configuration/configResolvers/ConfigResolver.js +14 -8
  95. package/lib/sdk/tools/DtoHelper.js +90 -0
  96. package/lib/utils/Command.js +47 -0
  97. package/lib/utils/CommandType.js +3 -0
  98. package/lib/utils/Type.js +2 -1
  99. package/package.json +5 -1
@@ -39,17 +39,15 @@ class ConfigResolver {
39
39
  return import_RuntimeNameHandler.RuntimeNameHandler.getRuntime(normalized);
40
40
  }
41
41
  /**
42
- * Build appropriate connection data object from a host string.
43
- * - empty / null => InMemoryConnectionData
44
- * - "inmemory" or "in-memory" => InMemoryConnectionData
45
- * - ws:// or wss:// => WsConnectionData(fullAddress)
46
- * - tcp://... => parsed by parseTcp
47
- * - host:port or host:port/... => TcpConnectionData(host, port) if valid, otherwise InMemoryConnectionData
42
+ * Builds connection data from the host string from config (JSON, YAML, or connection string).
43
+ * Recognized formats: empty (in-memory), "inmemory"/"in-memory", ws://..., wss://..., tcp://host:port, host:port.
44
+ * When the value is missing, invalid, or unparseable, falls back to InMemoryConnectionData and logs the reason.
48
45
  * @param {string} hostValue
49
46
  * @returns {InMemoryConnectionData|WsConnectionData|TcpConnectionData}
50
47
  */
51
48
  static buildConnectionData(hostValue) {
52
49
  if (!hostValue || String(hostValue).trim() === "") {
50
+ console.warn("Host not specified; using in-memory.");
53
51
  return new import_InMemoryConnectionData.InMemoryConnectionData();
54
52
  }
55
53
  const hv = String(hostValue).trim();
@@ -64,6 +62,7 @@ class ConfigResolver {
64
62
  try {
65
63
  return ConfigResolver.parseTcp(hv.slice(6));
66
64
  } catch (e) {
65
+ console.warn("Invalid or unparseable tcp:// address '" + hv + "'; falling back to in-memory.");
67
66
  return new import_InMemoryConnectionData.InMemoryConnectionData();
68
67
  }
69
68
  }
@@ -84,12 +83,14 @@ class ConfigResolver {
84
83
  try {
85
84
  return new import_TcpConnectionData.TcpConnectionData(hostOnly, port);
86
85
  } catch (e) {
86
+ console.warn("Could not create TCP connection for '" + hv + "'; falling back to in-memory.");
87
87
  return new import_InMemoryConnectionData.InMemoryConnectionData();
88
88
  }
89
89
  }
90
90
  } catch (e) {
91
91
  }
92
92
  }
93
+ console.warn("Host value '" + hv + "' is not a recognized connection format (expected: empty, 'inmemory', 'in-memory', 'ws://...', 'wss://...', 'tcp://host:port', or 'host:port'). Falling back to in-memory.");
93
94
  return new import_InMemoryConnectionData.InMemoryConnectionData();
94
95
  }
95
96
  /**
@@ -0,0 +1,100 @@
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 DtoHelper_exports = {};
20
+ __export(DtoHelper_exports, {
21
+ DtoHelper: () => DtoHelper
22
+ });
23
+ module.exports = __toCommonJS(DtoHelper_exports);
24
+ var import_Command = require("../../utils/Command.cjs");
25
+ var import_CommandType = require("../../utils/CommandType.cjs");
26
+ class DtoHelper {
27
+ /**
28
+ * Attempts to retrieve a DTO field value by field name from a command chain.
29
+ *
30
+ * @param {Command | null} command - The command to search through.
31
+ * @param {string} fieldName - The name of the field to retrieve.
32
+ * @returns {any}
33
+ */
34
+ static tryGetDtoFieldValue(command, fieldName) {
35
+ let value = null;
36
+ let currentCommand = command;
37
+ while (currentCommand !== void 0 && currentCommand !== null) {
38
+ if (currentCommand.commandType === import_CommandType.CommandType.SetInstanceField && DtoHelper._tryGetDtoFieldName(currentCommand) && DtoHelper._getDtoFieldName(currentCommand) === fieldName) {
39
+ value = DtoHelper._tryGetDtoFieldValueFromCommand(currentCommand);
40
+ return value;
41
+ }
42
+ if (!currentCommand.payload || currentCommand.payload.length === 0) {
43
+ break;
44
+ }
45
+ const firstPayload = currentCommand.payload[0];
46
+ currentCommand = firstPayload instanceof import_Command.Command ? firstPayload : null;
47
+ }
48
+ return null;
49
+ }
50
+ /**
51
+ * Attempts to extract the field name from a SetInstanceField command.
52
+ * @param {Command} command
53
+ * @returns {boolean}
54
+ */
55
+ static _tryGetDtoFieldName(command) {
56
+ if (command.payload.length < 2) {
57
+ return false;
58
+ }
59
+ const nameValue = DtoHelper._tryGetPayloadValue(command.payload[1]);
60
+ return typeof nameValue === "string";
61
+ }
62
+ /**
63
+ * Extracts the field name from a SetInstanceField command.
64
+ * @param {Command} command
65
+ * @returns {string}
66
+ */
67
+ static _getDtoFieldName(command) {
68
+ if (command.payload.length < 2) {
69
+ return "";
70
+ }
71
+ const nameValue = DtoHelper._tryGetPayloadValue(command.payload[1]);
72
+ return typeof nameValue === "string" ? nameValue : "";
73
+ }
74
+ /**
75
+ * Attempts to extract the field value from a SetInstanceField command.
76
+ * @param {Command} command
77
+ * @returns {any}
78
+ */
79
+ static _tryGetDtoFieldValueFromCommand(command) {
80
+ if (command.payload.length < 3) {
81
+ return null;
82
+ }
83
+ return DtoHelper._tryGetPayloadValue(command.payload[2]);
84
+ }
85
+ /**
86
+ * Attempts to extract a value from a payload item, handling Value command types.
87
+ * @param {any} payloadItem
88
+ * @returns {any}
89
+ */
90
+ static _tryGetPayloadValue(payloadItem) {
91
+ if (payloadItem instanceof import_Command.Command && payloadItem.commandType === import_CommandType.CommandType.Value && payloadItem.payload.length > 0) {
92
+ return payloadItem.payload[0];
93
+ }
94
+ return payloadItem;
95
+ }
96
+ }
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ DtoHelper
100
+ });
@@ -7,6 +7,6 @@ export class ArraySetItemHandler extends AbstractHandler {
7
7
  /**
8
8
  * @param {Command} command
9
9
  */
10
- process(command: Command): number;
10
+ process(command: Command): any;
11
11
  }
12
12
  import { AbstractHandler } from './AbstractHandler.js';
@@ -0,0 +1,7 @@
1
+ export class AsDtoHandler extends AbstractHandler {
2
+ /**
3
+ * @param {any} command
4
+ */
5
+ process(command: any): void;
6
+ }
7
+ import { AbstractHandler } from './AbstractHandler.js';
@@ -2,6 +2,6 @@ export class AsKwargsHandler extends AbstractHandler {
2
2
  /**
3
3
  * @param {any} command
4
4
  */
5
- handleCommand(command: any): void;
5
+ process(command: any): void;
6
6
  }
7
7
  import { AbstractHandler } from './AbstractHandler.js';
@@ -3,9 +3,10 @@ export type Command = import("../../utils/Command.js").Command;
3
3
  * @typedef {import('../../utils/Command.js').Command} Command
4
4
  */
5
5
  export class DestructReferenceHandler extends AbstractHandler {
6
+ requiredParametersCount: number;
6
7
  /**
7
8
  * @param {Command} command
8
9
  */
9
- process(command: Command): number;
10
+ process(command: Command): boolean;
10
11
  }
11
12
  import { AbstractHandler } from './AbstractHandler.js';
@@ -0,0 +1,7 @@
1
+ export class DtoPropertyHandler extends AbstractHandler {
2
+ /**
3
+ * @param {any} command
4
+ */
5
+ process(command: any): void;
6
+ }
7
+ import { AbstractHandler } from './AbstractHandler.js';
@@ -0,0 +1,9 @@
1
+ export class ProjectResultAsDtoHandler extends AbstractHandler {
2
+ requiredParametersCount: number;
3
+ /**
4
+ * @param {Command} command
5
+ */
6
+ process(command: Command): any[];
7
+ }
8
+ import { AbstractHandler } from './AbstractHandler.js';
9
+ import { Command } from '../../utils/Command.js';
@@ -7,6 +7,6 @@ export class SetInstanceFieldHandler extends AbstractHandler {
7
7
  /**
8
8
  * @param {Command} command
9
9
  */
10
- process(command: Command): number;
10
+ process(command: Command): any;
11
11
  }
12
12
  import { AbstractHandler } from './AbstractHandler.js';
@@ -7,6 +7,6 @@ export class SetStaticFieldHandler extends AbstractHandler {
7
7
  /**
8
8
  * @param {Command} command
9
9
  */
10
- process(command: Command): number;
10
+ process(command: Command): any;
11
11
  }
12
12
  import { AbstractHandler } from './AbstractHandler.js';
@@ -1,11 +1,11 @@
1
1
  export class Interpreter {
2
2
  /**
3
- *
3
+ * @param {string} runtimeContextId
4
4
  * @param {Command} command
5
5
  * @param {IConnectionData} connectionData
6
6
  * @returns {Promise<Command>}
7
7
  */
8
- static execute(command: Command, connectionData: IConnectionData): Promise<Command>;
8
+ static execute(runtimeContextId: string, command: Command, connectionData: IConnectionData): Promise<Command>;
9
9
  /**
10
10
  *
11
11
  * @param {Uint8Array} messageByteArray
@@ -15,4 +15,4 @@ export class Interpreter {
15
15
  }
16
16
  export type IConnectionData = import("../../utils/connectionData/IConnectionData.js").IConnectionData;
17
17
  export type RuntimeNameType = typeof import("../../types.d.ts").RuntimeName;
18
- export type Command = import("../../utils/Command.js").Command;
18
+ import { Command } from '../../utils/Command.js';
@@ -28,5 +28,6 @@ export class CommandDeserializer {
28
28
  readUllong(): bigint;
29
29
  readUInt(): number;
30
30
  readNull(): null;
31
+ readUndefined(): undefined;
31
32
  }
32
33
  import { Command } from '../../utils/Command.js';
@@ -46,5 +46,6 @@ export class TypeDeserializer {
46
46
  */
47
47
  static deserializeUInt(encodedUInt: Uint8Array): number;
48
48
  static deserializeNull(encodedNull?: null): null;
49
+ static deserializeUndefined(encodedUndefined?: null): undefined;
49
50
  }
50
51
  import { Command } from '../../utils/Command.js';
@@ -48,6 +48,7 @@ export class TypeSerializer {
48
48
  */
49
49
  static serializeUInt(uint_value: number): Buffer<ArrayBuffer>;
50
50
  static serializeNull(): Buffer<ArrayBuffer>;
51
+ static serializeUndefined(): Buffer<ArrayBuffer>;
51
52
  /**
52
53
  * @param {number} int_value
53
54
  */
@@ -17,8 +17,8 @@ export class ReferencesCache {
17
17
  */
18
18
  resolveReference(id: string): any;
19
19
  /**
20
- * @param {string} id
21
- * @returns {number}
20
+ * @param {string} reference_guid
21
+ * @returns {boolean}
22
22
  */
23
- deleteReference(id: string): number;
23
+ deleteReference(reference_guid: string): boolean;
24
24
  }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * A registry for managing plugins and their implementations.
3
+ * Provides access to registered plugin instances and their typed variants,
4
+ * allowing for dynamic plugin resolution at runtime.
5
+ *
6
+ * This class acts as a lightweight alternative to a dependency injection container,
7
+ * supporting both singleton and transient lifecycles for plugins.
8
+ * Plugins can be resolved by type, and optionally created with constructor arguments.
9
+ */
10
+ export class PluginImplementationRegistry {
11
+ /** @type {Map<string, Function>} Map of interface names to implementation constructors for transient plugins */
12
+ static "__#2@#transientImplementations": Map<string, Function>;
13
+ /** @type {Map<Function, object>} Map of implementation types to singleton instances */
14
+ static "__#2@#singletonImplementations": Map<Function, object>;
15
+ /** @type {Map<Function, object>} Map of settings types to configuration objects */
16
+ static "__#2@#pluginConfigurations": Map<Function, object>;
17
+ /**
18
+ * Registers a transient plugin implementation. A new instance will be created each time the plugin is resolved.
19
+ *
20
+ * @param {Function} InterfaceClass - The interface or base class of the plugin (must be a class/constructor)
21
+ * @param {Function} ImplementationClass - The concrete class that implements InterfaceClass
22
+ * @throws {TypeError} If InterfaceClass is not a function/constructor
23
+ * @throws {TypeError} If ImplementationClass is not a function/constructor
24
+ *
25
+ * @example
26
+ * PluginImplementationRegistry.registerPluginTransientImplementation(IJwtAuthorize, JwtAuthorizeImpl)
27
+ */
28
+ static registerPluginTransientImplementation(InterfaceClass: Function, ImplementationClass: Function): void;
29
+ /**
30
+ * Resolves a new instance of a transiently registered plugin.
31
+ *
32
+ * @param {Function} InterfaceClass - The type of the plugin interface to resolve
33
+ * @param {...any} constructorArgs - Optional arguments to pass to the constructor
34
+ * @returns {object} A newly created instance of the registered implementation
35
+ * @throws {Error} If the plugin type has not been registered as transient
36
+ * @throws {TypeError} If InterfaceClass is not a function/constructor
37
+ *
38
+ * @example
39
+ * const jwtAuthorize = PluginImplementationRegistry.resolvePluginTransientImplementation(IJwtAuthorize)
40
+ */
41
+ static resolvePluginTransientImplementation(InterfaceClass: Function, ...constructorArgs: any[]): object;
42
+ /**
43
+ * Registers a plugin configuration/settings object.
44
+ *
45
+ * @param {Function} SettingsClass - The settings class type
46
+ * @param {object} settings - The settings instance to register
47
+ * @throws {TypeError} If SettingsClass is not a function/constructor
48
+ * @throws {TypeError} If settings is not an object
49
+ *
50
+ * @example
51
+ * const settings = new JwtGraftocodePluginSettings()
52
+ * settings.username = 'user'
53
+ * settings.secretKey = 'key'
54
+ * PluginImplementationRegistry.registerPluginConfiguration(JwtGraftocodePluginSettings, settings)
55
+ */
56
+ static registerPluginConfiguration(SettingsClass: Function, settings: object): void;
57
+ /**
58
+ * Retrieves the configuration object of the specified type for a given plugin.
59
+ *
60
+ * @param {Function} SettingsClass - The expected configuration type
61
+ * @returns {object | null} The configuration object, or null if not found
62
+ * @throws {TypeError} If SettingsClass is not a function/constructor
63
+ *
64
+ * @example
65
+ * const config = PluginImplementationRegistry.getPluginConfiguration(JwtGraftocodePluginSettings)
66
+ * if (config) {
67
+ * console.log(config.username)
68
+ * }
69
+ */
70
+ static getPluginConfiguration(SettingsClass: Function): object | null;
71
+ /**
72
+ * Checks whether a configuration has been registered for the specified plugin type.
73
+ *
74
+ * @param {Function} SettingsClass - The settings class type to check
75
+ * @returns {boolean} True if a configuration entry exists, false otherwise
76
+ * @throws {TypeError} If SettingsClass is not a function/constructor
77
+ *
78
+ * @example
79
+ * if (PluginImplementationRegistry.isPluginConfigurationAvailable(JwtGraftocodePluginSettings)) {
80
+ * // Configuration exists
81
+ * }
82
+ */
83
+ static isPluginConfigurationAvailable(SettingsClass: Function): boolean;
84
+ /**
85
+ * Registers a new plugin implementation of the specified type and stores it as a singleton instance.
86
+ *
87
+ * @param {Function} InterfaceClass - The interface or base class that the plugin implementation inherits or implements
88
+ * @param {Function} ImplementationClass - The concrete plugin type to register
89
+ * @param {...any} constructorArgs - Optional arguments to pass to the constructor
90
+ * @throws {TypeError} If InterfaceClass is not a function/constructor
91
+ * @throws {TypeError} If ImplementationClass is not a function/constructor
92
+ *
93
+ * @example
94
+ * PluginImplementationRegistry.registerPluginSingletonImplementation(IJwtAuthorize, JwtAuthorizeImpl)
95
+ * // Or with constructor arguments:
96
+ * PluginImplementationRegistry.registerPluginSingletonImplementation(IJwtAuthorize, JwtAuthorizeImpl, 'arg1', 'arg2')
97
+ */
98
+ static registerPluginSingletonImplementation(InterfaceClass: Function, ImplementationClass: Function, ...constructorArgs: any[]): void;
99
+ /**
100
+ * Resolves a registered plugin implementation by its type.
101
+ *
102
+ * @param {Function} ImplementationClass - The type of the plugin implementation to resolve
103
+ * @returns {object} The registered plugin instance
104
+ * @throws {Error} If no plugin instance of the specified type is found in the registry
105
+ * @throws {TypeError} If ImplementationClass is not a function/constructor
106
+ *
107
+ * @example
108
+ * const plugin = PluginImplementationRegistry.resolvePluginSingletonImplementation(JwtAuthorizeImpl)
109
+ */
110
+ static resolvePluginSingletonImplementation(ImplementationClass: Function): object;
111
+ /**
112
+ * Resets the entire plugin implementation registry to its initial state.
113
+ * Clears all registered plugins and configurations.
114
+ * Useful for testing or reconfiguration scenarios.
115
+ *
116
+ * @example
117
+ * PluginImplementationRegistry.reset()
118
+ * // Can now register new plugins
119
+ */
120
+ static reset(): void;
121
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Builds serialized payloads from registered plugins.
3
+ * This class is responsible for retrieving plugins from the registry,
4
+ * executing them, and serializing their output for transmission.
5
+ */
6
+ export class PluginPayloadBuilder {
7
+ /**
8
+ * Builds the plugin payload for a specific runtime context.
9
+ * Retrieves the sending plugin registered for the given runtime context ID,
10
+ * executes it, and returns the serialized result.
11
+ *
12
+ * @param {string} runtimeContextId - The UUID of the runtime context
13
+ * @returns {string} JSON-serialized plugin payload
14
+ * @throws {Error} If no plugin is found for the runtime context
15
+ * @throws {Error} If plugin execution fails
16
+ *
17
+ * @example
18
+ * const payload = PluginPayloadBuilder.buildPluginsPayload(runtimeContextId)
19
+ * // Returns: '{"token":"abc123","timestamp":1234567890}'
20
+ */
21
+ static buildPluginsPayload(runtimeContextId: string): string;
22
+ /**
23
+ * Serializes an object to JSON string.
24
+ *
25
+ * @param {object} payload - The payload object to serialize
26
+ * @returns {string} JSON-serialized string
27
+ * @throws {Error} If serialization fails
28
+ *
29
+ * @private
30
+ */
31
+ private static serializeObject;
32
+ }
@@ -0,0 +1,157 @@
1
+ /**
2
+ * A thread-safe registry for managing plugins.
3
+ * Provides access to registered plugin instances and their typed variants,
4
+ * allowing for dynamic plugin resolution at runtime.
5
+ *
6
+ * Note: JavaScript is single-threaded (event loop), so thread-safety considerations
7
+ * from the .NET implementation are not needed here. However, the freeze pattern
8
+ * is still used to prevent modifications after the registration phase.
9
+ */
10
+ export class PluginRegistry {
11
+ /** @type {Map<string, object>} Map of runtime context IDs to sending plugin instances */
12
+ static "__#1@#sendingPlugins": Map<string, object>;
13
+ /** @type {Map<string, object> | null} Immutable snapshot of sending plugins after freeze */
14
+ static "__#1@#sendingSnapshot": Map<string, object> | null;
15
+ /** @type {SendingPluginCacheEntry | null} Hot cache for last accessed plugin */
16
+ static "__#1@#sendingCache": SendingPluginCacheEntry | null;
17
+ /** @type {object | null} The receiving plugin instance */
18
+ static "__#1@#receivingPlugin": object | null;
19
+ /** @type {Function | null} The receiving plugin constructor/class */
20
+ static "__#1@#receivingPluginType": Function | null;
21
+ /** @type {string[] | null} Array of registered runtime context IDs for fast lookup */
22
+ static "__#1@#registeredKeys": string[] | null;
23
+ /** @type {boolean} Whether to create new plugin instances on each resolve */
24
+ static "__#1@#useTransientPlugins": boolean;
25
+ /** @type {boolean} Whether the registry has been frozen */
26
+ static "__#1@#isFrozen": boolean;
27
+ /**
28
+ * Checks if a receiving plugin has been registered
29
+ * @returns {boolean} True if a receiving plugin exists
30
+ */
31
+ static get hasReceivingPlugin(): boolean;
32
+ /**
33
+ * Registers a sending plugin implementation for a specific runtime context.
34
+ * The plugin is stored as a singleton instance and can later be resolved using the runtime context ID.
35
+ *
36
+ * @param {string} runtimeContextId - The UUID of the runtime context
37
+ * @param {object} plugin - Plugin instance that implements ICommunitySendingPlugin interface
38
+ * @throws {Error} If registry is already frozen
39
+ * @throws {TypeError} If plugin doesn't have required execute method
40
+ *
41
+ * @example
42
+ * const plugin = new JwtPlugin('token123')
43
+ * PluginRegistry.registerSendingPlugin(runtimeCtx.runtimeContextId, plugin)
44
+ */
45
+ static registerSendingPlugin(runtimeContextId: string, plugin: object): void;
46
+ /**
47
+ * Registers a receiving plugin implementation.
48
+ * The plugin is stored as a singleton instance and executed on the receiving side.
49
+ * Only one receiving plugin can be registered per application.
50
+ *
51
+ * @param {object} plugin - Plugin instance that implements ICommunityReceivingPlugin interface
52
+ * @throws {Error} If a receiving plugin is already registered
53
+ * @throws {Error} If registry is already frozen
54
+ * @throws {TypeError} If plugin doesn't have required execute method
55
+ *
56
+ * @example
57
+ * const plugin = new ValidationPlugin()
58
+ * PluginRegistry.registerReceivingPlugin(plugin)
59
+ */
60
+ static registerReceivingPlugin(plugin: object): void;
61
+ /**
62
+ * Resolves and returns the registered receiving plugin instance.
63
+ * If transient mode is enabled, creates a new instance.
64
+ *
65
+ * @returns {object} The receiving plugin instance
66
+ * @throws {Error} If no receiving plugin has been registered
67
+ *
68
+ * @example
69
+ * const plugin = PluginRegistry.resolveReceivingPlugin()
70
+ * const result = plugin.execute(payload, target)
71
+ */
72
+ static resolveReceivingPlugin(): object;
73
+ /**
74
+ * Attempts to retrieve a sending plugin registered for the specified runtime context.
75
+ * First checks a single-entry hot cache for the last accessed plugin,
76
+ * and if not found, falls back to the map of registered plugins.
77
+ * On a successful map lookup, the cache is updated with the resolved entry
78
+ * for faster access in subsequent calls.
79
+ *
80
+ * @param {string} runtimeContextId - The identifier of the runtime context
81
+ * @returns {{success: boolean, plugin: object | null}} Object with success flag and plugin instance
82
+ *
83
+ * @example
84
+ * const result = PluginRegistry.tryGetSendingPlugin(runtimeContextId)
85
+ * if (result.success) {
86
+ * const payload = result.plugin.execute()
87
+ * }
88
+ */
89
+ static tryGetSendingPlugin(runtimeContextId: string): {
90
+ success: boolean;
91
+ plugin: object | null;
92
+ };
93
+ /**
94
+ * Checks whether any plugins have been registered for given RuntimeContext ID.
95
+ *
96
+ * @param {string} runtimeContextId - The identifier of the runtime context
97
+ * @returns {boolean} True if at least one plugin is registered for the runtime context
98
+ *
99
+ * @example
100
+ * if (PluginRegistry.arePluginsRegisteredForRuntime(runtimeContextId)) {
101
+ * // Build and wrap command with plugin payload
102
+ * }
103
+ */
104
+ static arePluginsRegisteredForRuntime(runtimeContextId: string): boolean;
105
+ /**
106
+ * Finalizes the plugin registration phase by creating a compact snapshot of all registered keys.
107
+ * This snapshot is stored to allow extremely fast lookups on the hot path.
108
+ * After calling freeze(), no more plugins can be registered unless reset() is called.
109
+ *
110
+ * @param {boolean} useTransientPlugins - If true, creates new plugin instances on each resolve
111
+ *
112
+ * @example
113
+ * // Register all plugins
114
+ * PluginRegistry.registerSendingPlugin(rtmCtx.runtimeContextId, plugin1)
115
+ * PluginRegistry.registerSendingPlugin(rtmCtx2.runtimeContextId, plugin2)
116
+ *
117
+ * // Freeze the registry
118
+ * PluginRegistry.freeze()
119
+ *
120
+ * // Or freeze with transient mode
121
+ * PluginRegistry.freeze(true)
122
+ */
123
+ static freeze(useTransientPlugins?: boolean): void;
124
+ /**
125
+ * Resets the entire plugin registry to its initial state.
126
+ * Clears all registered plugins and unfreezes the registry.
127
+ * Useful for testing or reconfiguration scenarios.
128
+ *
129
+ * @example
130
+ * PluginRegistry.reset()
131
+ * // Can now register new plugins
132
+ */
133
+ static reset(): void;
134
+ /**
135
+ * Checks if the registry has been frozen
136
+ * @returns {boolean} True if the registry is frozen
137
+ */
138
+ static get isFrozen(): boolean;
139
+ }
140
+ export type SendingPluginCacheEntry = {
141
+ /**
142
+ * - The runtime context ID
143
+ */
144
+ key: string;
145
+ /**
146
+ * - The plugin instance
147
+ */
148
+ value: object;
149
+ /**
150
+ * - Whether the entry has a value
151
+ */
152
+ hasValue: boolean;
153
+ /**
154
+ * - The plugin constructor/class
155
+ */
156
+ type: Function;
157
+ };
@@ -0,0 +1,8 @@
1
+ export { PluginRegistry } from "./PluginRegistry.js";
2
+ export { PluginPayloadBuilder } from "./PluginPayloadBuilder.js";
3
+ export { ICommunityPlugin } from "./interfaces/ICommunityPlugin.js";
4
+ export { ICommunitySendingPlugin } from "./interfaces/ICommunitySendingPlugin.js";
5
+ export { ICommunityReceivingPlugin } from "./interfaces/ICommunityReceivingPlugin.js";
6
+ export { PluginImplementationRegistry } from "./PluginImplementationRegistry.js";
7
+ export { JwtGraftocodePluginSettings } from "./settings/JwtGraftocodePluginSettings.js";
8
+ export { BasePluginSettings, PluginLangType } from "./settings/BasePluginSettings.js";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Represents a plugin that can be registered, configured, and executed within the system.
3
+ * This is the base interface that all plugins must implement.
4
+ *
5
+ * @interface ICommunityPlugin
6
+ */
7
+ export class ICommunityPlugin {
8
+ /**
9
+ * Unique identifier for the plugin.
10
+ * This should be a string that uniquely identifies the plugin across the system.
11
+ * @type {string}
12
+ */
13
+ pluginId: string;
14
+ }