javonet-nodejs-sdk 2.6.13 → 2.6.15

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 (100) 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/configuration/configResolvers/ConnectionStringConfigResolver.cjs +2 -2
  29. package/dist/sdk/configuration/configResolvers/JsonConfigResolver.cjs +2 -2
  30. package/dist/sdk/configuration/configResolvers/YamlConfigResolver.cjs +3 -3
  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/DtoPropertyHandler.d.ts +7 -0
  36. package/dist/types/core/handler/ProjectResultAsDtoHandler.d.ts +9 -0
  37. package/dist/types/core/handler/SetInstanceFieldHandler.d.ts +1 -1
  38. package/dist/types/core/handler/SetStaticFieldHandler.d.ts +1 -1
  39. package/dist/types/core/interpreter/Interpreter.d.ts +3 -3
  40. package/dist/types/core/protocol/CommandDeserializer.d.ts +1 -0
  41. package/dist/types/core/protocol/TypeDeserializer.d.ts +1 -0
  42. package/dist/types/core/protocol/TypeSerializer.d.ts +1 -0
  43. package/dist/types/plugins/PluginImplementationRegistry.d.ts +121 -0
  44. package/dist/types/plugins/PluginPayloadBuilder.d.ts +32 -0
  45. package/dist/types/plugins/PluginRegistry.d.ts +157 -0
  46. package/dist/types/plugins/index.d.ts +8 -0
  47. package/dist/types/plugins/interfaces/ICommunityPlugin.d.ts +14 -0
  48. package/dist/types/plugins/interfaces/ICommunityReceivingPlugin.d.ts +50 -0
  49. package/dist/types/plugins/interfaces/ICommunitySendingPlugin.d.ts +27 -0
  50. package/dist/types/plugins/settings/BasePluginSettings.d.ts +45 -0
  51. package/dist/types/plugins/settings/JwtGraftocodePluginSettings.d.ts +32 -0
  52. package/dist/types/sdk/InvocationContext.d.ts +20 -2
  53. package/dist/types/sdk/RuntimeContext.d.ts +6 -0
  54. package/dist/types/sdk/configuration/configResolvers/ConfigResolver.d.ts +3 -6
  55. package/dist/types/sdk/configuration/configResolvers/YamlConfigResolver.d.ts +2 -1
  56. package/dist/types/sdk/tools/DtoHelper.d.ts +35 -0
  57. package/dist/types/utils/Command.d.ts +5 -0
  58. package/dist/types/utils/CommandType.d.ts +3 -0
  59. package/dist/types/utils/Type.d.ts +2 -1
  60. package/dist/utils/Command.cjs +40 -0
  61. package/dist/utils/CommandType.cjs +4 -1
  62. package/dist/utils/Type.cjs +2 -1
  63. package/lib/core/handler/ArraySetItemHandler.js +11 -10
  64. package/lib/core/handler/AsDtoHandler.js +11 -0
  65. package/lib/core/handler/AsKwargsHandler.js +1 -1
  66. package/lib/core/handler/DtoPropertyHandler.js +11 -0
  67. package/lib/core/handler/Handler.js +16 -7
  68. package/lib/core/handler/PassDelegateHandler.js +2 -1
  69. package/lib/core/handler/ProjectResultAsDtoHandler.js +47 -0
  70. package/lib/core/handler/SetInstanceFieldHandler.js +1 -1
  71. package/lib/core/handler/SetStaticFieldHandler.js +6 -6
  72. package/lib/core/interpreter/Interpreter.js +18 -4
  73. package/lib/core/protocol/CommandDeserializer.js +9 -0
  74. package/lib/core/protocol/TypeDeserializer.js +5 -0
  75. package/lib/core/protocol/TypeSerializer.js +11 -8
  76. package/lib/core/webSocketClient/WebSocketClient.js +30 -5
  77. package/lib/core/webSocketClient/WebSocketClientBrowser.js +29 -5
  78. package/lib/plugins/PluginImplementationRegistry.js +231 -0
  79. package/lib/plugins/PluginPayloadBuilder.js +60 -0
  80. package/lib/plugins/PluginRegistry.js +295 -0
  81. package/lib/plugins/index.js +29 -0
  82. package/lib/plugins/interfaces/ICommunityPlugin.js +25 -0
  83. package/lib/plugins/interfaces/ICommunityReceivingPlugin.js +57 -0
  84. package/lib/plugins/interfaces/ICommunitySendingPlugin.js +42 -0
  85. package/lib/plugins/settings/BasePluginSettings.js +79 -0
  86. package/lib/plugins/settings/JwtGraftocodePluginSettings.js +43 -0
  87. package/lib/sdk/InvocationContext.js +149 -14
  88. package/lib/sdk/RuntimeContext.js +33 -9
  89. package/lib/sdk/configuration/configResolvers/ConfigResolver.js +14 -8
  90. package/lib/sdk/configuration/configResolvers/ConnectionStringConfigResolver.js +2 -2
  91. package/lib/sdk/configuration/configResolvers/JsonConfigResolver.js +2 -2
  92. package/lib/sdk/configuration/configResolvers/YamlConfigResolver.js +5 -5
  93. package/lib/sdk/tools/DtoHelper.js +90 -0
  94. package/lib/utils/Command.js +47 -0
  95. package/lib/utils/CommandType.js +3 -0
  96. package/lib/utils/Type.js +2 -1
  97. package/package.json +5 -1
  98. package/dist/sdk/tools/ActivationHelper.cjs +0 -66
  99. package/dist/types/sdk/tools/ActivationHelper.d.ts +0 -20
  100. package/lib/sdk/tools/ActivationHelper.js +0 -51
@@ -0,0 +1,214 @@
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 PluginImplementationRegistry_exports = {};
20
+ __export(PluginImplementationRegistry_exports, {
21
+ PluginImplementationRegistry: () => PluginImplementationRegistry
22
+ });
23
+ module.exports = __toCommonJS(PluginImplementationRegistry_exports);
24
+ class PluginImplementationRegistry {
25
+ /** @type {Map<string, Function>} Map of interface names to implementation constructors for transient plugins */
26
+ static #transientImplementations = /* @__PURE__ */ new Map();
27
+ /** @type {Map<Function, object>} Map of implementation types to singleton instances */
28
+ static #singletonImplementations = /* @__PURE__ */ new Map();
29
+ /** @type {Map<Function, object>} Map of settings types to configuration objects */
30
+ static #pluginConfigurations = /* @__PURE__ */ new Map();
31
+ /**
32
+ * Registers a transient plugin implementation. A new instance will be created each time the plugin is resolved.
33
+ *
34
+ * @param {Function} InterfaceClass - The interface or base class of the plugin (must be a class/constructor)
35
+ * @param {Function} ImplementationClass - The concrete class that implements InterfaceClass
36
+ * @throws {TypeError} If InterfaceClass is not a function/constructor
37
+ * @throws {TypeError} If ImplementationClass is not a function/constructor
38
+ *
39
+ * @example
40
+ * PluginImplementationRegistry.registerPluginTransientImplementation(IJwtAuthorize, JwtAuthorizeImpl)
41
+ */
42
+ static registerPluginTransientImplementation(InterfaceClass, ImplementationClass) {
43
+ if (typeof InterfaceClass !== "function") {
44
+ throw new TypeError(`${InterfaceClass?.name || "InterfaceClass"} is not a function. Only classes/constructors are allowed.`);
45
+ }
46
+ if (typeof ImplementationClass !== "function") {
47
+ throw new TypeError(`${ImplementationClass?.name || "ImplementationClass"} is not a function. Only classes/constructors are allowed.`);
48
+ }
49
+ const interfaceName = InterfaceClass.name || InterfaceClass.toString();
50
+ PluginImplementationRegistry.#transientImplementations.set(interfaceName, ImplementationClass);
51
+ }
52
+ /**
53
+ * Resolves a new instance of a transiently registered plugin.
54
+ *
55
+ * @param {Function} InterfaceClass - The type of the plugin interface to resolve
56
+ * @param {...any} constructorArgs - Optional arguments to pass to the constructor
57
+ * @returns {object} A newly created instance of the registered implementation
58
+ * @throws {Error} If the plugin type has not been registered as transient
59
+ * @throws {TypeError} If InterfaceClass is not a function/constructor
60
+ *
61
+ * @example
62
+ * const jwtAuthorize = PluginImplementationRegistry.resolvePluginTransientImplementation(IJwtAuthorize)
63
+ */
64
+ static resolvePluginTransientImplementation(InterfaceClass, ...constructorArgs) {
65
+ if (typeof InterfaceClass !== "function") {
66
+ throw new TypeError(`${InterfaceClass?.name || "InterfaceClass"} is not a function. Only classes/constructors are allowed.`);
67
+ }
68
+ const interfaceName = InterfaceClass.name || InterfaceClass.toString();
69
+ const ImplementationClass = PluginImplementationRegistry.#transientImplementations.get(interfaceName);
70
+ if (!ImplementationClass) {
71
+ throw new Error(`No transient implementation registered for ${interfaceName}.`);
72
+ }
73
+ try {
74
+ const instance = constructorArgs.length > 0 ? new ImplementationClass(...constructorArgs) : new ImplementationClass();
75
+ if (!instance) {
76
+ throw new Error(`Could not instantiate ${ImplementationClass.name || "implementation"}.`);
77
+ }
78
+ return instance;
79
+ } catch (error) {
80
+ throw new Error(`Failed to create instance of ${ImplementationClass.name || "implementation"}: ${error.message}`);
81
+ }
82
+ }
83
+ /**
84
+ * Registers a plugin configuration/settings object.
85
+ *
86
+ * @param {Function} SettingsClass - The settings class type
87
+ * @param {object} settings - The settings instance to register
88
+ * @throws {TypeError} If SettingsClass is not a function/constructor
89
+ * @throws {TypeError} If settings is not an object
90
+ *
91
+ * @example
92
+ * const settings = new JwtGraftocodePluginSettings()
93
+ * settings.username = 'user'
94
+ * settings.secretKey = 'key'
95
+ * PluginImplementationRegistry.registerPluginConfiguration(JwtGraftocodePluginSettings, settings)
96
+ */
97
+ static registerPluginConfiguration(SettingsClass, settings) {
98
+ if (typeof SettingsClass !== "function") {
99
+ throw new TypeError(`${SettingsClass?.name || "SettingsClass"} is not a function. Only classes/constructors are allowed.`);
100
+ }
101
+ if (!settings || typeof settings !== "object") {
102
+ throw new TypeError("settings must be an object");
103
+ }
104
+ PluginImplementationRegistry.#pluginConfigurations.set(SettingsClass, settings);
105
+ }
106
+ /**
107
+ * Retrieves the configuration object of the specified type for a given plugin.
108
+ *
109
+ * @param {Function} SettingsClass - The expected configuration type
110
+ * @returns {object | null} The configuration object, or null if not found
111
+ * @throws {TypeError} If SettingsClass is not a function/constructor
112
+ *
113
+ * @example
114
+ * const config = PluginImplementationRegistry.getPluginConfiguration(JwtGraftocodePluginSettings)
115
+ * if (config) {
116
+ * console.log(config.username)
117
+ * }
118
+ */
119
+ static getPluginConfiguration(SettingsClass) {
120
+ if (typeof SettingsClass !== "function") {
121
+ throw new TypeError(`${SettingsClass?.name || "SettingsClass"} is not a function. Only classes/constructors are allowed.`);
122
+ }
123
+ const config = PluginImplementationRegistry.#pluginConfigurations.get(SettingsClass);
124
+ return config || null;
125
+ }
126
+ /**
127
+ * Checks whether a configuration has been registered for the specified plugin type.
128
+ *
129
+ * @param {Function} SettingsClass - The settings class type to check
130
+ * @returns {boolean} True if a configuration entry exists, false otherwise
131
+ * @throws {TypeError} If SettingsClass is not a function/constructor
132
+ *
133
+ * @example
134
+ * if (PluginImplementationRegistry.isPluginConfigurationAvailable(JwtGraftocodePluginSettings)) {
135
+ * // Configuration exists
136
+ * }
137
+ */
138
+ static isPluginConfigurationAvailable(SettingsClass) {
139
+ if (typeof SettingsClass !== "function") {
140
+ throw new TypeError(`${SettingsClass?.name || "SettingsClass"} is not a function. Only classes/constructors are allowed.`);
141
+ }
142
+ return PluginImplementationRegistry.#pluginConfigurations.has(SettingsClass);
143
+ }
144
+ /**
145
+ * Registers a new plugin implementation of the specified type and stores it as a singleton instance.
146
+ *
147
+ * @param {Function} InterfaceClass - The interface or base class that the plugin implementation inherits or implements
148
+ * @param {Function} ImplementationClass - The concrete plugin type to register
149
+ * @param {...any} constructorArgs - Optional arguments to pass to the constructor
150
+ * @throws {TypeError} If InterfaceClass is not a function/constructor
151
+ * @throws {TypeError} If ImplementationClass is not a function/constructor
152
+ *
153
+ * @example
154
+ * PluginImplementationRegistry.registerPluginSingletonImplementation(IJwtAuthorize, JwtAuthorizeImpl)
155
+ * // Or with constructor arguments:
156
+ * PluginImplementationRegistry.registerPluginSingletonImplementation(IJwtAuthorize, JwtAuthorizeImpl, 'arg1', 'arg2')
157
+ */
158
+ static registerPluginSingletonImplementation(InterfaceClass, ImplementationClass, ...constructorArgs) {
159
+ if (typeof InterfaceClass !== "function") {
160
+ throw new TypeError(`${InterfaceClass?.name || "InterfaceClass"} is not a function. Only classes/constructors are allowed.`);
161
+ }
162
+ if (typeof ImplementationClass !== "function") {
163
+ throw new TypeError(`${ImplementationClass?.name || "ImplementationClass"} is not a function. Only classes/constructors are allowed.`);
164
+ }
165
+ try {
166
+ const instance = constructorArgs.length > 0 ? new ImplementationClass(...constructorArgs) : new ImplementationClass();
167
+ if (!instance) {
168
+ throw new Error(`Could not create instance of ${ImplementationClass.name || "implementation"}.`);
169
+ }
170
+ PluginImplementationRegistry.#singletonImplementations.set(ImplementationClass, instance);
171
+ } catch (error) {
172
+ throw new Error(`Failed to register singleton implementation: ${error.message}`);
173
+ }
174
+ }
175
+ /**
176
+ * Resolves a registered plugin implementation by its type.
177
+ *
178
+ * @param {Function} ImplementationClass - The type of the plugin implementation to resolve
179
+ * @returns {object} The registered plugin instance
180
+ * @throws {Error} If no plugin instance of the specified type is found in the registry
181
+ * @throws {TypeError} If ImplementationClass is not a function/constructor
182
+ *
183
+ * @example
184
+ * const plugin = PluginImplementationRegistry.resolvePluginSingletonImplementation(JwtAuthorizeImpl)
185
+ */
186
+ static resolvePluginSingletonImplementation(ImplementationClass) {
187
+ if (typeof ImplementationClass !== "function") {
188
+ throw new TypeError(`${ImplementationClass?.name || "ImplementationClass"} is not a function. Only classes/constructors are allowed.`);
189
+ }
190
+ const instance = PluginImplementationRegistry.#singletonImplementations.get(ImplementationClass);
191
+ if (!instance) {
192
+ throw new Error(`No singleton implementation registered for ${ImplementationClass.name || "implementation"}.`);
193
+ }
194
+ return instance;
195
+ }
196
+ /**
197
+ * Resets the entire plugin implementation registry to its initial state.
198
+ * Clears all registered plugins and configurations.
199
+ * Useful for testing or reconfiguration scenarios.
200
+ *
201
+ * @example
202
+ * PluginImplementationRegistry.reset()
203
+ * // Can now register new plugins
204
+ */
205
+ static reset() {
206
+ PluginImplementationRegistry.#transientImplementations.clear();
207
+ PluginImplementationRegistry.#singletonImplementations.clear();
208
+ PluginImplementationRegistry.#pluginConfigurations.clear();
209
+ }
210
+ }
211
+ // Annotate the CommonJS export names for ESM import in node:
212
+ 0 && (module.exports = {
213
+ PluginImplementationRegistry
214
+ });
@@ -0,0 +1,76 @@
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 PluginPayloadBuilder_exports = {};
20
+ __export(PluginPayloadBuilder_exports, {
21
+ PluginPayloadBuilder: () => PluginPayloadBuilder
22
+ });
23
+ module.exports = __toCommonJS(PluginPayloadBuilder_exports);
24
+ var import_PluginRegistry = require("./PluginRegistry.cjs");
25
+ class PluginPayloadBuilder {
26
+ /**
27
+ * Builds the plugin payload for a specific runtime context.
28
+ * Retrieves the sending plugin registered for the given runtime context ID,
29
+ * executes it, and returns the serialized result.
30
+ *
31
+ * @param {string} runtimeContextId - The UUID of the runtime context
32
+ * @returns {string} JSON-serialized plugin payload
33
+ * @throws {Error} If no plugin is found for the runtime context
34
+ * @throws {Error} If plugin execution fails
35
+ *
36
+ * @example
37
+ * const payload = PluginPayloadBuilder.buildPluginsPayload(runtimeContextId)
38
+ * // Returns: '{"token":"abc123","timestamp":1234567890}'
39
+ */
40
+ static buildPluginsPayload(runtimeContextId) {
41
+ const result = import_PluginRegistry.PluginRegistry.tryGetSendingPlugin(runtimeContextId);
42
+ if (result.success && result.plugin) {
43
+ try {
44
+ const payload = result.plugin.execute();
45
+ if (!result?.plugin?.pluginId) {
46
+ throw new Error("Plugin execution failed pluginId is not defined");
47
+ }
48
+ const objectPayload = { [result?.plugin?.pluginId]: payload };
49
+ return PluginPayloadBuilder.serializeObject(objectPayload);
50
+ } catch (error) {
51
+ throw new Error(`Plugin execution failed for runtime context ${runtimeContextId}: ${error.message}`);
52
+ }
53
+ }
54
+ throw new Error(`Plugin for runtime context ${runtimeContextId} not found.`);
55
+ }
56
+ /**
57
+ * Serializes an object to JSON string.
58
+ *
59
+ * @param {object} payload - The payload object to serialize
60
+ * @returns {string} JSON-serialized string
61
+ * @throws {Error} If serialization fails
62
+ *
63
+ * @private
64
+ */
65
+ static serializeObject(payload) {
66
+ try {
67
+ return JSON.stringify(payload);
68
+ } catch (error) {
69
+ throw new Error(`Failed to serialize plugin payload: ${error.message}`);
70
+ }
71
+ }
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ PluginPayloadBuilder
76
+ });
@@ -0,0 +1,255 @@
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 PluginRegistry_exports = {};
20
+ __export(PluginRegistry_exports, {
21
+ PluginRegistry: () => PluginRegistry
22
+ });
23
+ module.exports = __toCommonJS(PluginRegistry_exports);
24
+ class PluginRegistry {
25
+ // Private static fields (ES2022 private fields)
26
+ /** @type {Map<string, object>} Map of runtime context IDs to sending plugin instances */
27
+ static #sendingPlugins = /* @__PURE__ */ new Map();
28
+ /** @type {Map<string, object> | null} Immutable snapshot of sending plugins after freeze */
29
+ static #sendingSnapshot = null;
30
+ /** @type {SendingPluginCacheEntry | null} Hot cache for last accessed plugin */
31
+ static #sendingCache = null;
32
+ /** @type {object | null} The receiving plugin instance */
33
+ static #receivingPlugin = null;
34
+ /** @type {Function | null} The receiving plugin constructor/class */
35
+ static #receivingPluginType = null;
36
+ /** @type {string[] | null} Array of registered runtime context IDs for fast lookup */
37
+ static #registeredKeys = null;
38
+ /** @type {boolean} Whether to create new plugin instances on each resolve */
39
+ static #useTransientPlugins = false;
40
+ /** @type {boolean} Whether the registry has been frozen */
41
+ static #isFrozen = false;
42
+ /**
43
+ * Checks if a receiving plugin has been registered
44
+ * @returns {boolean} True if a receiving plugin exists
45
+ */
46
+ static get hasReceivingPlugin() {
47
+ return PluginRegistry.#receivingPlugin !== null;
48
+ }
49
+ /**
50
+ * Registers a sending plugin implementation for a specific runtime context.
51
+ * The plugin is stored as a singleton instance and can later be resolved using the runtime context ID.
52
+ *
53
+ * @param {string} runtimeContextId - The UUID of the runtime context
54
+ * @param {object} plugin - Plugin instance that implements ICommunitySendingPlugin interface
55
+ * @throws {Error} If registry is already frozen
56
+ * @throws {TypeError} If plugin doesn't have required execute method
57
+ *
58
+ * @example
59
+ * const plugin = new JwtPlugin('token123')
60
+ * PluginRegistry.registerSendingPlugin(runtimeCtx.runtimeContextId, plugin)
61
+ */
62
+ static registerSendingPlugin(runtimeContextId, plugin) {
63
+ if (PluginRegistry.#isFrozen) {
64
+ throw new Error("Cannot register plugins after registry has been frozen. Call reset() first.");
65
+ }
66
+ if (!plugin || typeof plugin.execute !== "function") {
67
+ throw new TypeError("Plugin must have an execute() method");
68
+ }
69
+ if (!plugin.pluginId) {
70
+ throw new TypeError("Plugin must have a pluginId property");
71
+ }
72
+ if (!runtimeContextId || typeof runtimeContextId !== "string") {
73
+ throw new TypeError("runtimeContextId must be a non-empty string");
74
+ }
75
+ PluginRegistry.#sendingPlugins.set(runtimeContextId, plugin);
76
+ PluginRegistry.#sendingCache = {
77
+ key: runtimeContextId,
78
+ value: plugin,
79
+ hasValue: true,
80
+ type: plugin.constructor
81
+ };
82
+ }
83
+ /**
84
+ * Registers a receiving plugin implementation.
85
+ * The plugin is stored as a singleton instance and executed on the receiving side.
86
+ * Only one receiving plugin can be registered per application.
87
+ *
88
+ * @param {object} plugin - Plugin instance that implements ICommunityReceivingPlugin interface
89
+ * @throws {Error} If a receiving plugin is already registered
90
+ * @throws {Error} If registry is already frozen
91
+ * @throws {TypeError} If plugin doesn't have required execute method
92
+ *
93
+ * @example
94
+ * const plugin = new ValidationPlugin()
95
+ * PluginRegistry.registerReceivingPlugin(plugin)
96
+ */
97
+ static registerReceivingPlugin(plugin) {
98
+ if (PluginRegistry.#isFrozen) {
99
+ throw new Error("Cannot register plugins after registry has been frozen. Call reset() first.");
100
+ }
101
+ if (PluginRegistry.#receivingPlugin !== null) {
102
+ throw new Error("A receiving plugin is already registered. Only one receiving plugin is allowed.");
103
+ }
104
+ if (!plugin || typeof plugin.execute !== "function") {
105
+ throw new TypeError("Plugin must have an execute(commandPayload, executionTarget) method");
106
+ }
107
+ if (!plugin.pluginId) {
108
+ throw new TypeError("Plugin must have a pluginId property");
109
+ }
110
+ PluginRegistry.#receivingPlugin = plugin;
111
+ PluginRegistry.#receivingPluginType = plugin.constructor;
112
+ }
113
+ /**
114
+ * Resolves and returns the registered receiving plugin instance.
115
+ * If transient mode is enabled, creates a new instance.
116
+ *
117
+ * @returns {object} The receiving plugin instance
118
+ * @throws {Error} If no receiving plugin has been registered
119
+ *
120
+ * @example
121
+ * const plugin = PluginRegistry.resolveReceivingPlugin()
122
+ * const result = plugin.execute(payload, target)
123
+ */
124
+ static resolveReceivingPlugin() {
125
+ if (PluginRegistry.#useTransientPlugins && PluginRegistry.#receivingPluginType) {
126
+ return new PluginRegistry.#receivingPluginType();
127
+ }
128
+ if (PluginRegistry.#receivingPlugin === null) {
129
+ throw new Error("No receiving plugin has been registered");
130
+ }
131
+ return PluginRegistry.#receivingPlugin;
132
+ }
133
+ /**
134
+ * Attempts to retrieve a sending plugin registered for the specified runtime context.
135
+ * First checks a single-entry hot cache for the last accessed plugin,
136
+ * and if not found, falls back to the map of registered plugins.
137
+ * On a successful map lookup, the cache is updated with the resolved entry
138
+ * for faster access in subsequent calls.
139
+ *
140
+ * @param {string} runtimeContextId - The identifier of the runtime context
141
+ * @returns {{success: boolean, plugin: object | null}} Object with success flag and plugin instance
142
+ *
143
+ * @example
144
+ * const result = PluginRegistry.tryGetSendingPlugin(runtimeContextId)
145
+ * if (result.success) {
146
+ * const payload = result.plugin.execute()
147
+ * }
148
+ */
149
+ static tryGetSendingPlugin(runtimeContextId) {
150
+ const localCache = PluginRegistry.#sendingCache;
151
+ if (PluginRegistry.#useTransientPlugins && localCache && localCache.hasValue && localCache.key === runtimeContextId) {
152
+ return {
153
+ success: true,
154
+ plugin: new localCache.type()
155
+ };
156
+ }
157
+ if (localCache && localCache.hasValue && localCache.key === runtimeContextId) {
158
+ return {
159
+ success: true,
160
+ plugin: localCache.value
161
+ };
162
+ }
163
+ const snapshot = PluginRegistry.#sendingSnapshot;
164
+ if (snapshot && snapshot.has(runtimeContextId)) {
165
+ const plugin = snapshot.get(runtimeContextId);
166
+ PluginRegistry.#sendingCache = {
167
+ key: runtimeContextId,
168
+ value: plugin,
169
+ hasValue: true,
170
+ type: plugin.constructor
171
+ };
172
+ return {
173
+ success: true,
174
+ plugin
175
+ };
176
+ }
177
+ return {
178
+ success: false,
179
+ plugin: null
180
+ };
181
+ }
182
+ /**
183
+ * Checks whether any plugins have been registered for given RuntimeContext ID.
184
+ *
185
+ * @param {string} runtimeContextId - The identifier of the runtime context
186
+ * @returns {boolean} True if at least one plugin is registered for the runtime context
187
+ *
188
+ * @example
189
+ * if (PluginRegistry.arePluginsRegisteredForRuntime(runtimeContextId)) {
190
+ * // Build and wrap command with plugin payload
191
+ * }
192
+ */
193
+ static arePluginsRegisteredForRuntime(runtimeContextId) {
194
+ const keys = PluginRegistry.#registeredKeys;
195
+ if (!keys || keys.length === 0) {
196
+ return false;
197
+ }
198
+ return keys.includes(runtimeContextId);
199
+ }
200
+ /**
201
+ * Finalizes the plugin registration phase by creating a compact snapshot of all registered keys.
202
+ * This snapshot is stored to allow extremely fast lookups on the hot path.
203
+ * After calling freeze(), no more plugins can be registered unless reset() is called.
204
+ *
205
+ * @param {boolean} useTransientPlugins - If true, creates new plugin instances on each resolve
206
+ *
207
+ * @example
208
+ * // Register all plugins
209
+ * PluginRegistry.registerSendingPlugin(rtmCtx.runtimeContextId, plugin1)
210
+ * PluginRegistry.registerSendingPlugin(rtmCtx2.runtimeContextId, plugin2)
211
+ *
212
+ * // Freeze the registry
213
+ * PluginRegistry.freeze()
214
+ *
215
+ * // Or freeze with transient mode
216
+ * PluginRegistry.freeze(true)
217
+ */
218
+ static freeze(useTransientPlugins = false) {
219
+ PluginRegistry.#useTransientPlugins = useTransientPlugins;
220
+ PluginRegistry.#registeredKeys = Array.from(PluginRegistry.#sendingPlugins.keys());
221
+ PluginRegistry.#sendingSnapshot = new Map(PluginRegistry.#sendingPlugins);
222
+ PluginRegistry.#sendingPlugins.clear();
223
+ PluginRegistry.#isFrozen = true;
224
+ }
225
+ /**
226
+ * Resets the entire plugin registry to its initial state.
227
+ * Clears all registered plugins and unfreezes the registry.
228
+ * Useful for testing or reconfiguration scenarios.
229
+ *
230
+ * @example
231
+ * PluginRegistry.reset()
232
+ * // Can now register new plugins
233
+ */
234
+ static reset() {
235
+ PluginRegistry.#sendingPlugins.clear();
236
+ PluginRegistry.#sendingSnapshot = null;
237
+ PluginRegistry.#sendingCache = null;
238
+ PluginRegistry.#receivingPlugin = null;
239
+ PluginRegistry.#receivingPluginType = null;
240
+ PluginRegistry.#registeredKeys = null;
241
+ PluginRegistry.#useTransientPlugins = false;
242
+ PluginRegistry.#isFrozen = false;
243
+ }
244
+ /**
245
+ * Checks if the registry has been frozen
246
+ * @returns {boolean} True if the registry is frozen
247
+ */
248
+ static get isFrozen() {
249
+ return PluginRegistry.#isFrozen;
250
+ }
251
+ }
252
+ // Annotate the CommonJS export names for ESM import in node:
253
+ 0 && (module.exports = {
254
+ PluginRegistry
255
+ });
@@ -0,0 +1,51 @@
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 plugins_exports = {};
20
+ __export(plugins_exports, {
21
+ BasePluginSettings: () => import_BasePluginSettings.BasePluginSettings,
22
+ ICommunityPlugin: () => import_ICommunityPlugin.ICommunityPlugin,
23
+ ICommunityReceivingPlugin: () => import_ICommunityReceivingPlugin.ICommunityReceivingPlugin,
24
+ ICommunitySendingPlugin: () => import_ICommunitySendingPlugin.ICommunitySendingPlugin,
25
+ JwtGraftocodePluginSettings: () => import_JwtGraftocodePluginSettings.JwtGraftocodePluginSettings,
26
+ PluginImplementationRegistry: () => import_PluginImplementationRegistry.PluginImplementationRegistry,
27
+ PluginLangType: () => import_BasePluginSettings.PluginLangType,
28
+ PluginPayloadBuilder: () => import_PluginPayloadBuilder.PluginPayloadBuilder,
29
+ PluginRegistry: () => import_PluginRegistry.PluginRegistry
30
+ });
31
+ module.exports = __toCommonJS(plugins_exports);
32
+ var import_PluginRegistry = require("./PluginRegistry.cjs");
33
+ var import_PluginPayloadBuilder = require("./PluginPayloadBuilder.cjs");
34
+ var import_ICommunityPlugin = require("./interfaces/ICommunityPlugin.cjs");
35
+ var import_ICommunitySendingPlugin = require("./interfaces/ICommunitySendingPlugin.cjs");
36
+ var import_ICommunityReceivingPlugin = require("./interfaces/ICommunityReceivingPlugin.cjs");
37
+ var import_PluginImplementationRegistry = require("./PluginImplementationRegistry.cjs");
38
+ var import_BasePluginSettings = require("./settings/BasePluginSettings.cjs");
39
+ var import_JwtGraftocodePluginSettings = require("./settings/JwtGraftocodePluginSettings.cjs");
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ BasePluginSettings,
43
+ ICommunityPlugin,
44
+ ICommunityReceivingPlugin,
45
+ ICommunitySendingPlugin,
46
+ JwtGraftocodePluginSettings,
47
+ PluginImplementationRegistry,
48
+ PluginLangType,
49
+ PluginPayloadBuilder,
50
+ PluginRegistry
51
+ });
@@ -0,0 +1,44 @@
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 ICommunityPlugin_exports = {};
20
+ __export(ICommunityPlugin_exports, {
21
+ ICommunityPlugin: () => ICommunityPlugin
22
+ });
23
+ module.exports = __toCommonJS(ICommunityPlugin_exports);
24
+ class ICommunityPlugin {
25
+ /**
26
+ * Unique identifier for the plugin.
27
+ * This should be a string that uniquely identifies the plugin across the system.
28
+ * @type {string}
29
+ */
30
+ pluginId;
31
+ /**
32
+ * Creates an instance of ICommunityPlugin
33
+ * This is a base class and should not be instantiated directly.
34
+ */
35
+ constructor() {
36
+ if (new.target === ICommunityPlugin) {
37
+ throw new TypeError("Cannot construct ICommunityPlugin instances directly");
38
+ }
39
+ }
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ ICommunityPlugin
44
+ });