@knotx/core 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import 'jsonschema';
1
2
  import 'rxjs';
2
- export { C as Container, E as EdgeData, o as EdgeOperation, m as EdgeOperationPipe, q as EdgeOperatorFunction, i as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, b as Layer, L as LayerComponent, N as NodeData, g as NodeMeasured, n as NodeOperation, l as NodeOperationPipe, p as NodeOperatorFunction, f as NodePosition, h as NodeProps, c as NodeRenderType, P as Plugin, k as PluginConfigs, e as PluginData, j as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BKaZlwmj.cjs';
3
+ export { C as Container, E as EdgeData, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, g as IPluginInfo, h as IPluginToolInfo, b as Layer, L as LayerComponent, N as NodeData, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, c as NodeRenderType, P as Plugin, n as PluginConfigs, e as PluginData, f as PluginTools, m as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BUBec6Va.cjs';
3
4
  import '@knotx/data';
@@ -1,3 +1,4 @@
1
+ import 'jsonschema';
1
2
  import 'rxjs';
2
- export { C as Container, E as EdgeData, o as EdgeOperation, m as EdgeOperationPipe, q as EdgeOperatorFunction, i as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, b as Layer, L as LayerComponent, N as NodeData, g as NodeMeasured, n as NodeOperation, l as NodeOperationPipe, p as NodeOperatorFunction, f as NodePosition, h as NodeProps, c as NodeRenderType, P as Plugin, k as PluginConfigs, e as PluginData, j as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BKaZlwmj.mjs';
3
+ export { C as Container, E as EdgeData, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, g as IPluginInfo, h as IPluginToolInfo, b as Layer, L as LayerComponent, N as NodeData, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, c as NodeRenderType, P as Plugin, n as PluginConfigs, e as PluginData, f as PluginTools, m as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BUBec6Va.mjs';
3
4
  import '@knotx/data';
@@ -1,3 +1,4 @@
1
+ import 'jsonschema';
1
2
  import 'rxjs';
2
- export { C as Container, E as EdgeData, o as EdgeOperation, m as EdgeOperationPipe, q as EdgeOperatorFunction, i as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, b as Layer, L as LayerComponent, N as NodeData, g as NodeMeasured, n as NodeOperation, l as NodeOperationPipe, p as NodeOperatorFunction, f as NodePosition, h as NodeProps, c as NodeRenderType, P as Plugin, k as PluginConfigs, e as PluginData, j as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BKaZlwmj.js';
3
+ export { C as Container, E as EdgeData, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, g as IPluginInfo, h as IPluginToolInfo, b as Layer, L as LayerComponent, N as NodeData, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, c as NodeRenderType, P as Plugin, n as PluginConfigs, e as PluginData, f as PluginTools, m as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BUBec6Va.js';
3
4
  import '@knotx/data';
package/dist/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const definition = require('./definition.cjs');
4
+ const jsonschema = require('jsonschema');
4
5
  const lodashEs = require('lodash-es');
5
6
  const rxjs = require('rxjs');
6
7
  const core = require('@knotx/core');
@@ -148,6 +149,8 @@ class Engine {
148
149
  __publicField$2(this, "nodeRenderers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
149
150
  __publicField$2(this, "edgeRenderers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
150
151
  __publicField$2(this, "_pluginDataContainer", {});
152
+ __publicField$2(this, "toolParamsValidator", new jsonschema.Validator());
153
+ __publicField$2(this, "_pluginToolsContainer", {});
151
154
  var _a;
152
155
  this.runtime = (_a = options.runtime) != null ? _a : {};
153
156
  this.container$.next(options.container);
@@ -184,6 +187,7 @@ class Engine {
184
187
  continue;
185
188
  }
186
189
  this._pluginDataContainer[plugin.name] = {};
190
+ this._pluginToolsContainer[plugin.name] = {};
187
191
  const engineSymbol = utils.getSymbol("engine");
188
192
  if (!Reflect.has(plugin, engineSymbol)) {
189
193
  Reflect.set(plugin, engineSymbol, new rxjs.BehaviorSubject(null));
@@ -258,6 +262,15 @@ class Engine {
258
262
  registerPluginData(pluginName, property, data) {
259
263
  lodashEs.set(this, ["_pluginDataContainer", pluginName, property], data);
260
264
  }
265
+ resetPluginData(pluginName) {
266
+ lodashEs.set(this, ["_pluginDataContainer", pluginName], void 0);
267
+ }
268
+ registerPluginTool(pluginName, property, data) {
269
+ lodashEs.set(this, ["_pluginToolsContainer", pluginName, property], data);
270
+ }
271
+ resetPluginTool(pluginName) {
272
+ lodashEs.set(this, ["_pluginToolsContainer", pluginName], void 0);
273
+ }
261
274
  registerNodeRenderer(type, renderer) {
262
275
  const nodeRenderers = this.nodeRenderers$.value;
263
276
  nodeRenderers.set(type, renderer);
@@ -287,6 +300,54 @@ class Engine {
287
300
  endInteraction(pluginId, type) {
288
301
  this.interactionManager.endInteraction(pluginId, type);
289
302
  }
303
+ callTool(pluginName, toolName, params) {
304
+ const toolDefinition = lodashEs.get(this, ["_pluginToolsContainer", pluginName, toolName]);
305
+ const tool = toolDefinition == null ? void 0 : toolDefinition.func;
306
+ if (!tool || typeof tool !== "function") {
307
+ throw new Error(`Tool ${String(toolName)} not found in plugin ${pluginName}`);
308
+ }
309
+ const validator = this.toolParamsValidator.validate(params, toolDefinition.params);
310
+ if (validator.errors.length > 0) {
311
+ throw new Error(`Invalid tool params: ${validator.errors.map((e) => e.stack).join(", ")}`);
312
+ }
313
+ return tool(params);
314
+ }
315
+ listPlugins() {
316
+ return this.plugins$.value.map((plugin) => ({
317
+ name: plugin.name,
318
+ description: plugin.description
319
+ }));
320
+ }
321
+ listPluginTools(pluginName) {
322
+ return Object.entries(lodashEs.get(this, ["_pluginToolsContainer", pluginName]) || {}).map(([toolName, toolDefinition]) => ({
323
+ type: "function",
324
+ name: toolName,
325
+ description: toolDefinition.description,
326
+ parameters: toolDefinition.params
327
+ }));
328
+ }
329
+ listEngineTools() {
330
+ return [
331
+ {
332
+ type: "function",
333
+ name: "listPlugins",
334
+ description: "List all plugins",
335
+ parameters: {}
336
+ },
337
+ {
338
+ type: "function",
339
+ name: "listPluginTools",
340
+ description: "List all tools of a plugin",
341
+ parameters: {
342
+ type: "object",
343
+ properties: {
344
+ pluginName: { type: "string" }
345
+ },
346
+ required: ["pluginName"]
347
+ }
348
+ }
349
+ ];
350
+ }
290
351
  destroy() {
291
352
  this.plugins$.value.forEach((plugin) => {
292
353
  var _a;
@@ -299,6 +360,8 @@ class Engine {
299
360
  this.edges$.complete();
300
361
  this.nodeRenderers$.complete();
301
362
  this.edgeRenderers$.complete();
363
+ this._pluginToolsContainer = {};
364
+ this._pluginDataContainer = {};
302
365
  }
303
366
  }
304
367
 
@@ -319,7 +382,6 @@ const _BasePlugin = class _BasePlugin {
319
382
  return `${this.name}:${this._instanceId}`;
320
383
  }
321
384
  onDestroy() {
322
- var _a;
323
385
  this.subscriptions.forEach((subscription) => {
324
386
  if (typeof subscription === "function") {
325
387
  subscription();
@@ -327,7 +389,10 @@ const _BasePlugin = class _BasePlugin {
327
389
  subscription.unsubscribe();
328
390
  }
329
391
  });
330
- (_a = Reflect.get(this, utils.getSymbol("engine"))) == null ? void 0 : _a.complete();
392
+ const engin$ = Reflect.get(this, utils.getSymbol("engine"));
393
+ engin$.value.resetPluginData(this.name);
394
+ engin$.value.resetPluginTool(this.name);
395
+ engin$.complete();
331
396
  }
332
397
  };
333
398
  __publicField$1(_BasePlugin, "_instanceId", 0);
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData } from './shared/core.BKaZlwmj.cjs';
2
- export { B as BasePlugin, o as EdgeOperation, m as EdgeOperationPipe, q as EdgeOperatorFunction, i as EdgeProps, H as HorizontalAlignment, g as NodeMeasured, n as NodeOperation, l as NodeOperationPipe, p as NodeOperatorFunction, f as NodePosition, h as NodeProps, k as PluginConfigs, j as Position, V as VerticalAlignment } from './shared/core.BKaZlwmj.cjs';
1
+ import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData, f as PluginTools, g as IPluginInfo, h as IPluginToolInfo } from './shared/core.BUBec6Va.cjs';
2
+ export { B as BasePlugin, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, H as HorizontalAlignment, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, n as PluginConfigs, m as Position, V as VerticalAlignment } from './shared/core.BUBec6Va.cjs';
3
+ import { Schema } from 'jsonschema';
3
4
  import { BehaviorSubject } from 'rxjs';
4
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
5
6
  export * from '@knotx/data';
@@ -105,6 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
105
106
  private nodeRenderers$;
106
107
  private edgeRenderers$;
107
108
  private _pluginDataContainer;
109
+ private toolParamsValidator;
110
+ private _pluginToolsContainer;
108
111
  get container(): Container;
109
112
  set container(value: Container);
110
113
  get nodes(): NodeData<any>[];
@@ -129,11 +132,22 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
129
132
  getEdges(): EdgeData[];
130
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
131
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
135
+ resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
+ registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
+ description: string;
138
+ params: Schema;
139
+ func: PluginTools[T][TP];
140
+ }): void;
141
+ resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
132
142
  registerNodeRenderer(type: string, renderer: NodeRenderType): () => void;
133
143
  registerEdgeRenderer(type: string, renderer: EdgeRenderType): (() => void);
134
144
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
135
145
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
136
146
  endInteraction(pluginId: string, type: string): void;
147
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, params: any): any;
148
+ listPlugins(): IPluginInfo[];
149
+ listPluginTools(pluginName: string): IPluginToolInfo[];
150
+ listEngineTools(): IPluginToolInfo[];
137
151
  destroy(): void;
138
152
  }
139
153
 
@@ -200,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
200
214
  __contextValue__: TContext;
201
215
  }, context: TContext): T;
202
216
 
203
- export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, RenderType, Runtime, getLayerRenders, use };
217
+ export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData } from './shared/core.BKaZlwmj.mjs';
2
- export { B as BasePlugin, o as EdgeOperation, m as EdgeOperationPipe, q as EdgeOperatorFunction, i as EdgeProps, H as HorizontalAlignment, g as NodeMeasured, n as NodeOperation, l as NodeOperationPipe, p as NodeOperatorFunction, f as NodePosition, h as NodeProps, k as PluginConfigs, j as Position, V as VerticalAlignment } from './shared/core.BKaZlwmj.mjs';
1
+ import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData, f as PluginTools, g as IPluginInfo, h as IPluginToolInfo } from './shared/core.BUBec6Va.mjs';
2
+ export { B as BasePlugin, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, H as HorizontalAlignment, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, n as PluginConfigs, m as Position, V as VerticalAlignment } from './shared/core.BUBec6Va.mjs';
3
+ import { Schema } from 'jsonschema';
3
4
  import { BehaviorSubject } from 'rxjs';
4
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
5
6
  export * from '@knotx/data';
@@ -105,6 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
105
106
  private nodeRenderers$;
106
107
  private edgeRenderers$;
107
108
  private _pluginDataContainer;
109
+ private toolParamsValidator;
110
+ private _pluginToolsContainer;
108
111
  get container(): Container;
109
112
  set container(value: Container);
110
113
  get nodes(): NodeData<any>[];
@@ -129,11 +132,22 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
129
132
  getEdges(): EdgeData[];
130
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
131
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
135
+ resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
+ registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
+ description: string;
138
+ params: Schema;
139
+ func: PluginTools[T][TP];
140
+ }): void;
141
+ resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
132
142
  registerNodeRenderer(type: string, renderer: NodeRenderType): () => void;
133
143
  registerEdgeRenderer(type: string, renderer: EdgeRenderType): (() => void);
134
144
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
135
145
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
136
146
  endInteraction(pluginId: string, type: string): void;
147
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, params: any): any;
148
+ listPlugins(): IPluginInfo[];
149
+ listPluginTools(pluginName: string): IPluginToolInfo[];
150
+ listEngineTools(): IPluginToolInfo[];
137
151
  destroy(): void;
138
152
  }
139
153
 
@@ -200,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
200
214
  __contextValue__: TContext;
201
215
  }, context: TContext): T;
202
216
 
203
- export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, RenderType, Runtime, getLayerRenders, use };
217
+ export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData } from './shared/core.BKaZlwmj.js';
2
- export { B as BasePlugin, o as EdgeOperation, m as EdgeOperationPipe, q as EdgeOperatorFunction, i as EdgeProps, H as HorizontalAlignment, g as NodeMeasured, n as NodeOperation, l as NodeOperationPipe, p as NodeOperatorFunction, f as NodePosition, h as NodeProps, k as PluginConfigs, j as Position, V as VerticalAlignment } from './shared/core.BKaZlwmj.js';
1
+ import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData, f as PluginTools, g as IPluginInfo, h as IPluginToolInfo } from './shared/core.BUBec6Va.js';
2
+ export { B as BasePlugin, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, H as HorizontalAlignment, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, n as PluginConfigs, m as Position, V as VerticalAlignment } from './shared/core.BUBec6Va.js';
3
+ import { Schema } from 'jsonschema';
3
4
  import { BehaviorSubject } from 'rxjs';
4
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
5
6
  export * from '@knotx/data';
@@ -105,6 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
105
106
  private nodeRenderers$;
106
107
  private edgeRenderers$;
107
108
  private _pluginDataContainer;
109
+ private toolParamsValidator;
110
+ private _pluginToolsContainer;
108
111
  get container(): Container;
109
112
  set container(value: Container);
110
113
  get nodes(): NodeData<any>[];
@@ -129,11 +132,22 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
129
132
  getEdges(): EdgeData[];
130
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
131
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
135
+ resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
+ registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
+ description: string;
138
+ params: Schema;
139
+ func: PluginTools[T][TP];
140
+ }): void;
141
+ resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
132
142
  registerNodeRenderer(type: string, renderer: NodeRenderType): () => void;
133
143
  registerEdgeRenderer(type: string, renderer: EdgeRenderType): (() => void);
134
144
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
135
145
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
136
146
  endInteraction(pluginId: string, type: string): void;
147
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, params: any): any;
148
+ listPlugins(): IPluginInfo[];
149
+ listPluginTools(pluginName: string): IPluginToolInfo[];
150
+ listEngineTools(): IPluginToolInfo[];
137
151
  destroy(): void;
138
152
  }
139
153
 
@@ -200,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
200
214
  __contextValue__: TContext;
201
215
  }, context: TContext): T;
202
216
 
203
- export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, RenderType, Runtime, getLayerRenders, use };
217
+ export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Layer } from './definition.js';
2
+ import { Validator } from 'jsonschema';
2
3
  import { set, get } from 'lodash-es';
3
4
  import { BehaviorSubject, identity } from 'rxjs';
4
5
  import { Layer } from '@knotx/core';
@@ -148,6 +149,8 @@ class Engine {
148
149
  __publicField$2(this, "nodeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
149
150
  __publicField$2(this, "edgeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
150
151
  __publicField$2(this, "_pluginDataContainer", {});
152
+ __publicField$2(this, "toolParamsValidator", new Validator());
153
+ __publicField$2(this, "_pluginToolsContainer", {});
151
154
  var _a;
152
155
  this.runtime = (_a = options.runtime) != null ? _a : {};
153
156
  this.container$.next(options.container);
@@ -184,6 +187,7 @@ class Engine {
184
187
  continue;
185
188
  }
186
189
  this._pluginDataContainer[plugin.name] = {};
190
+ this._pluginToolsContainer[plugin.name] = {};
187
191
  const engineSymbol = getSymbol("engine");
188
192
  if (!Reflect.has(plugin, engineSymbol)) {
189
193
  Reflect.set(plugin, engineSymbol, new BehaviorSubject(null));
@@ -258,6 +262,15 @@ class Engine {
258
262
  registerPluginData(pluginName, property, data) {
259
263
  set(this, ["_pluginDataContainer", pluginName, property], data);
260
264
  }
265
+ resetPluginData(pluginName) {
266
+ set(this, ["_pluginDataContainer", pluginName], void 0);
267
+ }
268
+ registerPluginTool(pluginName, property, data) {
269
+ set(this, ["_pluginToolsContainer", pluginName, property], data);
270
+ }
271
+ resetPluginTool(pluginName) {
272
+ set(this, ["_pluginToolsContainer", pluginName], void 0);
273
+ }
261
274
  registerNodeRenderer(type, renderer) {
262
275
  const nodeRenderers = this.nodeRenderers$.value;
263
276
  nodeRenderers.set(type, renderer);
@@ -287,6 +300,54 @@ class Engine {
287
300
  endInteraction(pluginId, type) {
288
301
  this.interactionManager.endInteraction(pluginId, type);
289
302
  }
303
+ callTool(pluginName, toolName, params) {
304
+ const toolDefinition = get(this, ["_pluginToolsContainer", pluginName, toolName]);
305
+ const tool = toolDefinition == null ? void 0 : toolDefinition.func;
306
+ if (!tool || typeof tool !== "function") {
307
+ throw new Error(`Tool ${String(toolName)} not found in plugin ${pluginName}`);
308
+ }
309
+ const validator = this.toolParamsValidator.validate(params, toolDefinition.params);
310
+ if (validator.errors.length > 0) {
311
+ throw new Error(`Invalid tool params: ${validator.errors.map((e) => e.stack).join(", ")}`);
312
+ }
313
+ return tool(params);
314
+ }
315
+ listPlugins() {
316
+ return this.plugins$.value.map((plugin) => ({
317
+ name: plugin.name,
318
+ description: plugin.description
319
+ }));
320
+ }
321
+ listPluginTools(pluginName) {
322
+ return Object.entries(get(this, ["_pluginToolsContainer", pluginName]) || {}).map(([toolName, toolDefinition]) => ({
323
+ type: "function",
324
+ name: toolName,
325
+ description: toolDefinition.description,
326
+ parameters: toolDefinition.params
327
+ }));
328
+ }
329
+ listEngineTools() {
330
+ return [
331
+ {
332
+ type: "function",
333
+ name: "listPlugins",
334
+ description: "List all plugins",
335
+ parameters: {}
336
+ },
337
+ {
338
+ type: "function",
339
+ name: "listPluginTools",
340
+ description: "List all tools of a plugin",
341
+ parameters: {
342
+ type: "object",
343
+ properties: {
344
+ pluginName: { type: "string" }
345
+ },
346
+ required: ["pluginName"]
347
+ }
348
+ }
349
+ ];
350
+ }
290
351
  destroy() {
291
352
  this.plugins$.value.forEach((plugin) => {
292
353
  var _a;
@@ -299,6 +360,8 @@ class Engine {
299
360
  this.edges$.complete();
300
361
  this.nodeRenderers$.complete();
301
362
  this.edgeRenderers$.complete();
363
+ this._pluginToolsContainer = {};
364
+ this._pluginDataContainer = {};
302
365
  }
303
366
  }
304
367
 
@@ -319,7 +382,6 @@ const _BasePlugin = class _BasePlugin {
319
382
  return `${this.name}:${this._instanceId}`;
320
383
  }
321
384
  onDestroy() {
322
- var _a;
323
385
  this.subscriptions.forEach((subscription) => {
324
386
  if (typeof subscription === "function") {
325
387
  subscription();
@@ -327,7 +389,10 @@ const _BasePlugin = class _BasePlugin {
327
389
  subscription.unsubscribe();
328
390
  }
329
391
  });
330
- (_a = Reflect.get(this, getSymbol("engine"))) == null ? void 0 : _a.complete();
392
+ const engin$ = Reflect.get(this, getSymbol("engine"));
393
+ engin$.value.resetPluginData(this.name);
394
+ engin$.value.resetPluginTool(this.name);
395
+ engin$.complete();
331
396
  }
332
397
  };
333
398
  __publicField$1(_BasePlugin, "_instanceId", 0);
@@ -1,3 +1,4 @@
1
+ import { Schema } from 'jsonschema';
1
2
  import { SubscriptionLike, BehaviorSubject } from 'rxjs';
2
3
  import { DataOperationPipe, DataOperation } from '@knotx/data';
3
4
 
@@ -79,6 +80,7 @@ interface LayerComponent<TRenderType> {
79
80
  interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
80
81
  name: TPluginName;
81
82
  pluginId: string;
83
+ description?: string;
82
84
  onInit?: (config: TPluginConfig) => void;
83
85
  onConfigChange?: (config: TPluginConfig) => void;
84
86
  onDestroy?: () => void;
@@ -101,6 +103,29 @@ type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugi
101
103
  */
102
104
  interface PluginData {
103
105
  }
106
+ /**
107
+ * plugin tools host
108
+ * @example
109
+ * `declare module '@knotx/core' {
110
+ * interface PluginTools {
111
+ * pluginName: {
112
+ * toolName: (params: any) => any
113
+ * }
114
+ * }
115
+ * }`
116
+ */
117
+ interface PluginTools {
118
+ }
119
+ interface IPluginInfo {
120
+ name: string;
121
+ description?: string;
122
+ }
123
+ interface IPluginToolInfo {
124
+ type: 'function';
125
+ name: string;
126
+ description: string;
127
+ parameters: Schema;
128
+ }
104
129
  type NodeOperationPipe<T = any> = DataOperationPipe<NodeData<T>>;
105
130
  type EdgeOperationPipe<T = any> = DataOperationPipe<EdgeData<T>>;
106
131
  type NodeOperation<T = any> = DataOperation<NodeData<T>>;
@@ -117,4 +142,4 @@ interface IEngineRuntime {
117
142
  };
118
143
  }
119
144
 
120
- export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type NodePosition as f, type NodeMeasured as g, type NodeProps as h, type EdgeProps as i, type Position as j, type PluginConfigs as k, type NodeOperationPipe as l, type EdgeOperationPipe as m, type NodeOperation as n, type EdgeOperation as o, type NodeOperatorFunction as p, type EdgeOperatorFunction as q };
145
+ export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type PluginTools as f, type IPluginInfo as g, type IPluginToolInfo as h, type NodePosition as i, type NodeMeasured as j, type NodeProps as k, type EdgeProps as l, type Position as m, type PluginConfigs as n, type NodeOperationPipe as o, type EdgeOperationPipe as p, type NodeOperation as q, type EdgeOperation as r, type NodeOperatorFunction as s, type EdgeOperatorFunction as t };
@@ -1,3 +1,4 @@
1
+ import { Schema } from 'jsonschema';
1
2
  import { SubscriptionLike, BehaviorSubject } from 'rxjs';
2
3
  import { DataOperationPipe, DataOperation } from '@knotx/data';
3
4
 
@@ -79,6 +80,7 @@ interface LayerComponent<TRenderType> {
79
80
  interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
80
81
  name: TPluginName;
81
82
  pluginId: string;
83
+ description?: string;
82
84
  onInit?: (config: TPluginConfig) => void;
83
85
  onConfigChange?: (config: TPluginConfig) => void;
84
86
  onDestroy?: () => void;
@@ -101,6 +103,29 @@ type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugi
101
103
  */
102
104
  interface PluginData {
103
105
  }
106
+ /**
107
+ * plugin tools host
108
+ * @example
109
+ * `declare module '@knotx/core' {
110
+ * interface PluginTools {
111
+ * pluginName: {
112
+ * toolName: (params: any) => any
113
+ * }
114
+ * }
115
+ * }`
116
+ */
117
+ interface PluginTools {
118
+ }
119
+ interface IPluginInfo {
120
+ name: string;
121
+ description?: string;
122
+ }
123
+ interface IPluginToolInfo {
124
+ type: 'function';
125
+ name: string;
126
+ description: string;
127
+ parameters: Schema;
128
+ }
104
129
  type NodeOperationPipe<T = any> = DataOperationPipe<NodeData<T>>;
105
130
  type EdgeOperationPipe<T = any> = DataOperationPipe<EdgeData<T>>;
106
131
  type NodeOperation<T = any> = DataOperation<NodeData<T>>;
@@ -117,4 +142,4 @@ interface IEngineRuntime {
117
142
  };
118
143
  }
119
144
 
120
- export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type NodePosition as f, type NodeMeasured as g, type NodeProps as h, type EdgeProps as i, type Position as j, type PluginConfigs as k, type NodeOperationPipe as l, type EdgeOperationPipe as m, type NodeOperation as n, type EdgeOperation as o, type NodeOperatorFunction as p, type EdgeOperatorFunction as q };
145
+ export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type PluginTools as f, type IPluginInfo as g, type IPluginToolInfo as h, type NodePosition as i, type NodeMeasured as j, type NodeProps as k, type EdgeProps as l, type Position as m, type PluginConfigs as n, type NodeOperationPipe as o, type EdgeOperationPipe as p, type NodeOperation as q, type EdgeOperation as r, type NodeOperatorFunction as s, type EdgeOperatorFunction as t };
@@ -1,3 +1,4 @@
1
+ import { Schema } from 'jsonschema';
1
2
  import { SubscriptionLike, BehaviorSubject } from 'rxjs';
2
3
  import { DataOperationPipe, DataOperation } from '@knotx/data';
3
4
 
@@ -79,6 +80,7 @@ interface LayerComponent<TRenderType> {
79
80
  interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
80
81
  name: TPluginName;
81
82
  pluginId: string;
83
+ description?: string;
82
84
  onInit?: (config: TPluginConfig) => void;
83
85
  onConfigChange?: (config: TPluginConfig) => void;
84
86
  onDestroy?: () => void;
@@ -101,6 +103,29 @@ type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugi
101
103
  */
102
104
  interface PluginData {
103
105
  }
106
+ /**
107
+ * plugin tools host
108
+ * @example
109
+ * `declare module '@knotx/core' {
110
+ * interface PluginTools {
111
+ * pluginName: {
112
+ * toolName: (params: any) => any
113
+ * }
114
+ * }
115
+ * }`
116
+ */
117
+ interface PluginTools {
118
+ }
119
+ interface IPluginInfo {
120
+ name: string;
121
+ description?: string;
122
+ }
123
+ interface IPluginToolInfo {
124
+ type: 'function';
125
+ name: string;
126
+ description: string;
127
+ parameters: Schema;
128
+ }
104
129
  type NodeOperationPipe<T = any> = DataOperationPipe<NodeData<T>>;
105
130
  type EdgeOperationPipe<T = any> = DataOperationPipe<EdgeData<T>>;
106
131
  type NodeOperation<T = any> = DataOperation<NodeData<T>>;
@@ -117,4 +142,4 @@ interface IEngineRuntime {
117
142
  };
118
143
  }
119
144
 
120
- export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type NodePosition as f, type NodeMeasured as g, type NodeProps as h, type EdgeProps as i, type Position as j, type PluginConfigs as k, type NodeOperationPipe as l, type EdgeOperationPipe as m, type NodeOperation as n, type EdgeOperation as o, type NodeOperatorFunction as p, type EdgeOperatorFunction as q };
145
+ export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type PluginTools as f, type IPluginInfo as g, type IPluginToolInfo as h, type NodePosition as i, type NodeMeasured as j, type NodeProps as k, type EdgeProps as l, type Position as m, type PluginConfigs as n, type NodeOperationPipe as o, type EdgeOperationPipe as p, type NodeOperation as q, type EdgeOperation as r, type NodeOperatorFunction as s, type EdgeOperatorFunction as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/core",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Core for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -43,16 +43,17 @@
43
43
  "dist"
44
44
  ],
45
45
  "dependencies": {
46
+ "jsonschema": "^1.5.0",
46
47
  "lodash-es": "^4.17.21",
47
48
  "rxjs": "^7.8.1",
48
- "@knotx/data": "0.2.5",
49
- "@knotx/utils": "0.2.5"
49
+ "@knotx/data": "0.2.7",
50
+ "@knotx/utils": "0.2.7"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@types/lodash-es": "^4.17.12",
53
- "@knotx/build-config": "0.2.5",
54
- "@knotx/eslint-config": "0.2.5",
55
- "@knotx/typescript-config": "0.2.5"
54
+ "@knotx/build-config": "0.2.7",
55
+ "@knotx/eslint-config": "0.2.7",
56
+ "@knotx/typescript-config": "0.2.7"
56
57
  },
57
58
  "scripts": {
58
59
  "build": "unbuild",