@knotx/core 0.2.13 → 0.2.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.
@@ -1,4 +1,4 @@
1
1
  import 'jsonschema';
2
2
  import 'rxjs';
3
- export { C as Container, E as Edge, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, e as EdgeRenderType, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, h as IPluginInfo, i as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, d as NodeRenderType, P as Plugin, o as PluginConfigs, f as PluginData, g as PluginTools, n as Position, R as RenderType, V as VerticalAlignment } from './shared/core.Cwp_TTTs.cjs';
3
+ export { C as Container, E as Edge, t as EdgeOperation, r as EdgeOperationPipe, v as EdgeOperatorFunction, n as EdgeProps, e as EdgeRenderType, h as EngineTools, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, i as IPluginInfo, j as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, l as NodeMeasured, s as NodeOperation, q as NodeOperationPipe, u as NodeOperatorFunction, k as NodePosition, m as NodeProps, d as NodeRenderType, P as Plugin, p as PluginConfigs, f as PluginData, g as PluginTools, o as Position, R as RenderType, V as VerticalAlignment } from './shared/core.B-u2ysAC.cjs';
4
4
  import '@knotx/data';
@@ -1,4 +1,4 @@
1
1
  import 'jsonschema';
2
2
  import 'rxjs';
3
- export { C as Container, E as Edge, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, e as EdgeRenderType, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, h as IPluginInfo, i as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, d as NodeRenderType, P as Plugin, o as PluginConfigs, f as PluginData, g as PluginTools, n as Position, R as RenderType, V as VerticalAlignment } from './shared/core.Cwp_TTTs.mjs';
3
+ export { C as Container, E as Edge, t as EdgeOperation, r as EdgeOperationPipe, v as EdgeOperatorFunction, n as EdgeProps, e as EdgeRenderType, h as EngineTools, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, i as IPluginInfo, j as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, l as NodeMeasured, s as NodeOperation, q as NodeOperationPipe, u as NodeOperatorFunction, k as NodePosition, m as NodeProps, d as NodeRenderType, P as Plugin, p as PluginConfigs, f as PluginData, g as PluginTools, o as Position, R as RenderType, V as VerticalAlignment } from './shared/core.B-u2ysAC.mjs';
4
4
  import '@knotx/data';
@@ -1,4 +1,4 @@
1
1
  import 'jsonschema';
2
2
  import 'rxjs';
3
- export { C as Container, E as Edge, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, e as EdgeRenderType, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, h as IPluginInfo, i as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, d as NodeRenderType, P as Plugin, o as PluginConfigs, f as PluginData, g as PluginTools, n as Position, R as RenderType, V as VerticalAlignment } from './shared/core.Cwp_TTTs.js';
3
+ export { C as Container, E as Edge, t as EdgeOperation, r as EdgeOperationPipe, v as EdgeOperatorFunction, n as EdgeProps, e as EdgeRenderType, h as EngineTools, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, i as IPluginInfo, j as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, l as NodeMeasured, s as NodeOperation, q as NodeOperationPipe, u as NodeOperatorFunction, k as NodePosition, m as NodeProps, d as NodeRenderType, P as Plugin, p as PluginConfigs, f as PluginData, g as PluginTools, o as Position, R as RenderType, V as VerticalAlignment } from './shared/core.B-u2ysAC.js';
4
4
  import '@knotx/data';
package/dist/index.cjs CHANGED
@@ -92,17 +92,17 @@ class InteractionManager {
92
92
  }
93
93
 
94
94
  var __defProp$3 = Object.defineProperty;
95
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
96
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
97
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
95
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
96
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
97
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
98
98
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
99
- var __spreadValues$1 = (a, b) => {
99
+ var __spreadValues$2 = (a, b) => {
100
100
  for (var prop in b || (b = {}))
101
- if (__hasOwnProp$1.call(b, prop))
101
+ if (__hasOwnProp$2.call(b, prop))
102
102
  __defNormalProp$3(a, prop, b[prop]);
103
- if (__getOwnPropSymbols$1)
104
- for (var prop of __getOwnPropSymbols$1(b)) {
105
- if (__propIsEnum$1.call(b, prop))
103
+ if (__getOwnPropSymbols$2)
104
+ for (var prop of __getOwnPropSymbols$2(b)) {
105
+ if (__propIsEnum$2.call(b, prop))
106
106
  __defNormalProp$3(a, prop, b[prop]);
107
107
  }
108
108
  return a;
@@ -112,7 +112,7 @@ function getLayerRenders(plugin) {
112
112
  const components = [];
113
113
  let isRenderConsumed = false;
114
114
  for (const [name, layer] of Object.entries((_a = Reflect.get(plugin, utils.getSymbol("layer"))) != null ? _a : {})) {
115
- components.push(__spreadValues$1({
115
+ components.push(__spreadValues$2({
116
116
  plugin: plugin.name,
117
117
  name: `${plugin.name}:${name}`,
118
118
  render: wrapRender(Reflect.get(plugin, name), plugin)
@@ -137,7 +137,24 @@ function wrapRender(render, plugin) {
137
137
  }
138
138
 
139
139
  var __defProp$2 = Object.defineProperty;
140
+ var __defProps$1 = Object.defineProperties;
141
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
142
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
143
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
144
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
140
145
  var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
146
+ var __spreadValues$1 = (a, b) => {
147
+ for (var prop in b || (b = {}))
148
+ if (__hasOwnProp$1.call(b, prop))
149
+ __defNormalProp$2(a, prop, b[prop]);
150
+ if (__getOwnPropSymbols$1)
151
+ for (var prop of __getOwnPropSymbols$1(b)) {
152
+ if (__propIsEnum$1.call(b, prop))
153
+ __defNormalProp$2(a, prop, b[prop]);
154
+ }
155
+ return a;
156
+ };
157
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
141
158
  var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
142
159
  class Engine {
143
160
  constructor(options) {
@@ -154,7 +171,39 @@ class Engine {
154
171
  __publicField$2(this, "edgeRenderers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
155
172
  __publicField$2(this, "_pluginDataContainer", {});
156
173
  __publicField$2(this, "_pluginToolsContainer", {});
157
- __publicField$2(this, "toolParamsValidator", new jsonschema.Validator());
174
+ __publicField$2(this, "engineTools", new Map([
175
+ {
176
+ type: "function",
177
+ name: "listPlugins",
178
+ description: "List all plugins",
179
+ parameters: {}
180
+ },
181
+ {
182
+ type: "function",
183
+ name: "listPluginTools",
184
+ description: "List all tools of a plugin",
185
+ parameters: {
186
+ type: "object",
187
+ properties: {
188
+ pluginName: { type: "string" }
189
+ },
190
+ required: ["pluginName"]
191
+ }
192
+ },
193
+ {
194
+ type: "function",
195
+ name: "getNodes",
196
+ description: "Get all nodes",
197
+ parameters: {}
198
+ },
199
+ {
200
+ type: "function",
201
+ name: "getEdges",
202
+ description: "Get all edges",
203
+ parameters: {}
204
+ }
205
+ ].map((tool) => [tool.name, tool])));
206
+ __publicField$2(this, "toolParametersValidator", new jsonschema.Validator());
158
207
  var _a;
159
208
  this.runtime = (_a = options.runtime) != null ? _a : {};
160
209
  this.container$.next(options.container);
@@ -303,18 +352,26 @@ class Engine {
303
352
  endInteraction(pluginId, type) {
304
353
  this.interactionManager.endInteraction(pluginId, type);
305
354
  }
306
- callTool(pluginName, toolName, ...args) {
307
- const toolDefinition = lodashEs.get(this, ["_pluginToolsContainer", pluginName, toolName]);
355
+ callTool(pluginNameOrEngineToolName, ...args) {
356
+ let toolDefinition;
357
+ let toolDisplayName;
358
+ if (this.engineTools.has(pluginNameOrEngineToolName)) {
359
+ toolDefinition = __spreadProps$1(__spreadValues$1({}, this.engineTools.get(pluginNameOrEngineToolName)), { func: this[pluginNameOrEngineToolName].bind(this) });
360
+ toolDisplayName = toolDefinition.name;
361
+ } else {
362
+ toolDefinition = lodashEs.get(this, ["_pluginToolsContainer", pluginNameOrEngineToolName, args == null ? void 0 : args[0]]);
363
+ toolDisplayName = `${pluginNameOrEngineToolName}.${args == null ? void 0 : args[0]}`;
364
+ }
308
365
  const tool = toolDefinition == null ? void 0 : toolDefinition.func;
309
366
  if (!tool || typeof tool !== "function") {
310
- throw new Error(`Tool ${String(toolName)} not found in plugin ${pluginName}`);
367
+ throw new Error(`Tool ${String(toolDisplayName)} not found`);
311
368
  }
312
- const params = args[0];
313
- const validator = this.toolParamsValidator.validate(params, toolDefinition.params);
369
+ const parameters = args[args.length - 1];
370
+ const validator = this.toolParametersValidator.validate(parameters, toolDefinition.parameters);
314
371
  if (validator.errors.length > 0) {
315
- throw new Error(`Invalid tool params: ${validator.errors.map((e) => e.stack).join(", ")}`);
372
+ throw new Error(`Invalid tool parameters: ${validator.errors.map((e) => e.stack).join(", ")}`);
316
373
  }
317
- return tool(params);
374
+ return tool(parameters);
318
375
  }
319
376
  listPlugins() {
320
377
  return Array.from(this.plugins$.value.values()).map((plugin) => ({
@@ -322,35 +379,16 @@ class Engine {
322
379
  description: plugin.description
323
380
  }));
324
381
  }
325
- listPluginTools(pluginName) {
382
+ listPluginTools({ pluginName }) {
326
383
  return Object.entries(lodashEs.get(this, ["_pluginToolsContainer", pluginName]) || {}).map(([toolName, toolDefinition]) => ({
327
384
  type: "function",
328
385
  name: toolName,
329
386
  description: toolDefinition.description,
330
- parameters: toolDefinition.params
387
+ parameters: toolDefinition.parameters
331
388
  }));
332
389
  }
333
390
  listEngineTools() {
334
- return [
335
- {
336
- type: "function",
337
- name: "listPlugins",
338
- description: "List all plugins",
339
- parameters: {}
340
- },
341
- {
342
- type: "function",
343
- name: "listPluginTools",
344
- description: "List all tools of a plugin",
345
- parameters: {
346
- type: "object",
347
- properties: {
348
- pluginName: { type: "string" }
349
- },
350
- required: ["pluginName"]
351
- }
352
- }
353
- ];
391
+ return Array.from(this.engineTools.values());
354
392
  }
355
393
  destroy() {
356
394
  this.plugins$.value.forEach((plugin) => {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as IRecord, C as Container, P as Plugin, N as Node, E as Edge, a as IEngineRuntime, R as RenderType, L as LayerComponent, b as IPlugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as IPluginInfo, i as IPluginToolInfo } from './shared/core.Cwp_TTTs.cjs';
2
- export { B as BasePlugin, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, H as HorizontalAlignment, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, o as PluginConfigs, n as Position, V as VerticalAlignment } from './shared/core.Cwp_TTTs.cjs';
1
+ import { R as RenderType, I as IRecord, a as IEngineRuntime, N as Node, E as Edge, C as Container, L as LayerComponent, b as IPlugin, P as Plugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as EngineTools, i as IPluginInfo, j as IPluginToolInfo } from './shared/core.B-u2ysAC.cjs';
2
+ export { B as BasePlugin, t as EdgeOperation, r as EdgeOperationPipe, v as EdgeOperatorFunction, n as EdgeProps, H as HorizontalAlignment, l as NodeMeasured, s as NodeOperation, q as NodeOperationPipe, u as NodeOperatorFunction, k as NodePosition, m as NodeProps, p as PluginConfigs, o as Position, V as VerticalAlignment } from './shared/core.B-u2ysAC.cjs';
3
3
  import { Schema } from 'jsonschema';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
@@ -93,6 +93,14 @@ interface EngineOptions<TNode extends IRecord = IRecord, TEdge extends IRecord =
93
93
  edges?: Edge<TEdge>[];
94
94
  runtime?: IEngineRuntime;
95
95
  }
96
+ declare module '@knotx/core' {
97
+ interface EngineTools {
98
+ listPlugins: Engine['listPlugins'];
99
+ listPluginTools: Engine['listPluginTools'];
100
+ getNodes: Engine['getNodes'];
101
+ getEdges: Engine['getEdges'];
102
+ }
103
+ }
96
104
  declare class Engine<TRenderType extends RenderType = RenderType, TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
97
105
  readonly runtime: IEngineRuntime;
98
106
  readonly interactionManager: InteractionManager;
@@ -107,7 +115,8 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
107
115
  private edgeRenderers$;
108
116
  private _pluginDataContainer;
109
117
  private _pluginToolsContainer;
110
- private toolParamsValidator;
118
+ private engineTools;
119
+ private toolParametersValidator;
111
120
  get container(): Container;
112
121
  set container(value: Container);
113
122
  get nodes(): Node<TNode>[];
@@ -135,7 +144,7 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
135
144
  resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
145
  registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
146
  description: string;
138
- params: Schema;
147
+ parameters: Schema;
139
148
  func: PluginTools[T][TP];
140
149
  }): void;
141
150
  resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
@@ -144,9 +153,12 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
144
153
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
154
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
146
155
  endInteraction(pluginId: string, type: string): void;
147
- callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): any;
156
+ callTool<T extends keyof EngineTools>(engineToolName: T, ...args: Parameters<EngineTools[T]>): ReturnType<EngineTools[T]>;
157
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): ReturnType<PluginTools[T][TP]>;
148
158
  listPlugins(): IPluginInfo[];
149
- listPluginTools(pluginName: string): IPluginToolInfo[];
159
+ listPluginTools({ pluginName }: {
160
+ pluginName: string;
161
+ }): IPluginToolInfo[];
150
162
  listEngineTools(): IPluginToolInfo[];
151
163
  destroy(): void;
152
164
  }
@@ -214,4 +226,4 @@ declare function use<T, TContext>(hook: () => {
214
226
  __contextValue__: TContext;
215
227
  }, context: TContext): T;
216
228
 
217
- export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
229
+ export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, type EngineTools, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as IRecord, C as Container, P as Plugin, N as Node, E as Edge, a as IEngineRuntime, R as RenderType, L as LayerComponent, b as IPlugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as IPluginInfo, i as IPluginToolInfo } from './shared/core.Cwp_TTTs.mjs';
2
- export { B as BasePlugin, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, H as HorizontalAlignment, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, o as PluginConfigs, n as Position, V as VerticalAlignment } from './shared/core.Cwp_TTTs.mjs';
1
+ import { R as RenderType, I as IRecord, a as IEngineRuntime, N as Node, E as Edge, C as Container, L as LayerComponent, b as IPlugin, P as Plugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as EngineTools, i as IPluginInfo, j as IPluginToolInfo } from './shared/core.B-u2ysAC.mjs';
2
+ export { B as BasePlugin, t as EdgeOperation, r as EdgeOperationPipe, v as EdgeOperatorFunction, n as EdgeProps, H as HorizontalAlignment, l as NodeMeasured, s as NodeOperation, q as NodeOperationPipe, u as NodeOperatorFunction, k as NodePosition, m as NodeProps, p as PluginConfigs, o as Position, V as VerticalAlignment } from './shared/core.B-u2ysAC.mjs';
3
3
  import { Schema } from 'jsonschema';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
@@ -93,6 +93,14 @@ interface EngineOptions<TNode extends IRecord = IRecord, TEdge extends IRecord =
93
93
  edges?: Edge<TEdge>[];
94
94
  runtime?: IEngineRuntime;
95
95
  }
96
+ declare module '@knotx/core' {
97
+ interface EngineTools {
98
+ listPlugins: Engine['listPlugins'];
99
+ listPluginTools: Engine['listPluginTools'];
100
+ getNodes: Engine['getNodes'];
101
+ getEdges: Engine['getEdges'];
102
+ }
103
+ }
96
104
  declare class Engine<TRenderType extends RenderType = RenderType, TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
97
105
  readonly runtime: IEngineRuntime;
98
106
  readonly interactionManager: InteractionManager;
@@ -107,7 +115,8 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
107
115
  private edgeRenderers$;
108
116
  private _pluginDataContainer;
109
117
  private _pluginToolsContainer;
110
- private toolParamsValidator;
118
+ private engineTools;
119
+ private toolParametersValidator;
111
120
  get container(): Container;
112
121
  set container(value: Container);
113
122
  get nodes(): Node<TNode>[];
@@ -135,7 +144,7 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
135
144
  resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
145
  registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
146
  description: string;
138
- params: Schema;
147
+ parameters: Schema;
139
148
  func: PluginTools[T][TP];
140
149
  }): void;
141
150
  resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
@@ -144,9 +153,12 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
144
153
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
154
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
146
155
  endInteraction(pluginId: string, type: string): void;
147
- callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): any;
156
+ callTool<T extends keyof EngineTools>(engineToolName: T, ...args: Parameters<EngineTools[T]>): ReturnType<EngineTools[T]>;
157
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): ReturnType<PluginTools[T][TP]>;
148
158
  listPlugins(): IPluginInfo[];
149
- listPluginTools(pluginName: string): IPluginToolInfo[];
159
+ listPluginTools({ pluginName }: {
160
+ pluginName: string;
161
+ }): IPluginToolInfo[];
150
162
  listEngineTools(): IPluginToolInfo[];
151
163
  destroy(): void;
152
164
  }
@@ -214,4 +226,4 @@ declare function use<T, TContext>(hook: () => {
214
226
  __contextValue__: TContext;
215
227
  }, context: TContext): T;
216
228
 
217
- export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
229
+ export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, type EngineTools, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as IRecord, C as Container, P as Plugin, N as Node, E as Edge, a as IEngineRuntime, R as RenderType, L as LayerComponent, b as IPlugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as IPluginInfo, i as IPluginToolInfo } from './shared/core.Cwp_TTTs.js';
2
- export { B as BasePlugin, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, H as HorizontalAlignment, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, o as PluginConfigs, n as Position, V as VerticalAlignment } from './shared/core.Cwp_TTTs.js';
1
+ import { R as RenderType, I as IRecord, a as IEngineRuntime, N as Node, E as Edge, C as Container, L as LayerComponent, b as IPlugin, P as Plugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as EngineTools, i as IPluginInfo, j as IPluginToolInfo } from './shared/core.B-u2ysAC.js';
2
+ export { B as BasePlugin, t as EdgeOperation, r as EdgeOperationPipe, v as EdgeOperatorFunction, n as EdgeProps, H as HorizontalAlignment, l as NodeMeasured, s as NodeOperation, q as NodeOperationPipe, u as NodeOperatorFunction, k as NodePosition, m as NodeProps, p as PluginConfigs, o as Position, V as VerticalAlignment } from './shared/core.B-u2ysAC.js';
3
3
  import { Schema } from 'jsonschema';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
@@ -93,6 +93,14 @@ interface EngineOptions<TNode extends IRecord = IRecord, TEdge extends IRecord =
93
93
  edges?: Edge<TEdge>[];
94
94
  runtime?: IEngineRuntime;
95
95
  }
96
+ declare module '@knotx/core' {
97
+ interface EngineTools {
98
+ listPlugins: Engine['listPlugins'];
99
+ listPluginTools: Engine['listPluginTools'];
100
+ getNodes: Engine['getNodes'];
101
+ getEdges: Engine['getEdges'];
102
+ }
103
+ }
96
104
  declare class Engine<TRenderType extends RenderType = RenderType, TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
97
105
  readonly runtime: IEngineRuntime;
98
106
  readonly interactionManager: InteractionManager;
@@ -107,7 +115,8 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
107
115
  private edgeRenderers$;
108
116
  private _pluginDataContainer;
109
117
  private _pluginToolsContainer;
110
- private toolParamsValidator;
118
+ private engineTools;
119
+ private toolParametersValidator;
111
120
  get container(): Container;
112
121
  set container(value: Container);
113
122
  get nodes(): Node<TNode>[];
@@ -135,7 +144,7 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
135
144
  resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
145
  registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
146
  description: string;
138
- params: Schema;
147
+ parameters: Schema;
139
148
  func: PluginTools[T][TP];
140
149
  }): void;
141
150
  resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
@@ -144,9 +153,12 @@ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends
144
153
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
154
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
146
155
  endInteraction(pluginId: string, type: string): void;
147
- callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): any;
156
+ callTool<T extends keyof EngineTools>(engineToolName: T, ...args: Parameters<EngineTools[T]>): ReturnType<EngineTools[T]>;
157
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): ReturnType<PluginTools[T][TP]>;
148
158
  listPlugins(): IPluginInfo[];
149
- listPluginTools(pluginName: string): IPluginToolInfo[];
159
+ listPluginTools({ pluginName }: {
160
+ pluginName: string;
161
+ }): IPluginToolInfo[];
150
162
  listEngineTools(): IPluginToolInfo[];
151
163
  destroy(): void;
152
164
  }
@@ -214,4 +226,4 @@ declare function use<T, TContext>(hook: () => {
214
226
  __contextValue__: TContext;
215
227
  }, context: TContext): T;
216
228
 
217
- export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
229
+ export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, type EngineTools, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
package/dist/index.js CHANGED
@@ -92,17 +92,17 @@ class InteractionManager {
92
92
  }
93
93
 
94
94
  var __defProp$3 = Object.defineProperty;
95
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
96
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
97
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
95
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
96
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
97
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
98
98
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
99
- var __spreadValues$1 = (a, b) => {
99
+ var __spreadValues$2 = (a, b) => {
100
100
  for (var prop in b || (b = {}))
101
- if (__hasOwnProp$1.call(b, prop))
101
+ if (__hasOwnProp$2.call(b, prop))
102
102
  __defNormalProp$3(a, prop, b[prop]);
103
- if (__getOwnPropSymbols$1)
104
- for (var prop of __getOwnPropSymbols$1(b)) {
105
- if (__propIsEnum$1.call(b, prop))
103
+ if (__getOwnPropSymbols$2)
104
+ for (var prop of __getOwnPropSymbols$2(b)) {
105
+ if (__propIsEnum$2.call(b, prop))
106
106
  __defNormalProp$3(a, prop, b[prop]);
107
107
  }
108
108
  return a;
@@ -112,7 +112,7 @@ function getLayerRenders(plugin) {
112
112
  const components = [];
113
113
  let isRenderConsumed = false;
114
114
  for (const [name, layer] of Object.entries((_a = Reflect.get(plugin, getSymbol("layer"))) != null ? _a : {})) {
115
- components.push(__spreadValues$1({
115
+ components.push(__spreadValues$2({
116
116
  plugin: plugin.name,
117
117
  name: `${plugin.name}:${name}`,
118
118
  render: wrapRender(Reflect.get(plugin, name), plugin)
@@ -137,7 +137,24 @@ function wrapRender(render, plugin) {
137
137
  }
138
138
 
139
139
  var __defProp$2 = Object.defineProperty;
140
+ var __defProps$1 = Object.defineProperties;
141
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
142
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
143
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
144
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
140
145
  var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
146
+ var __spreadValues$1 = (a, b) => {
147
+ for (var prop in b || (b = {}))
148
+ if (__hasOwnProp$1.call(b, prop))
149
+ __defNormalProp$2(a, prop, b[prop]);
150
+ if (__getOwnPropSymbols$1)
151
+ for (var prop of __getOwnPropSymbols$1(b)) {
152
+ if (__propIsEnum$1.call(b, prop))
153
+ __defNormalProp$2(a, prop, b[prop]);
154
+ }
155
+ return a;
156
+ };
157
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
141
158
  var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
142
159
  class Engine {
143
160
  constructor(options) {
@@ -154,7 +171,39 @@ class Engine {
154
171
  __publicField$2(this, "edgeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
155
172
  __publicField$2(this, "_pluginDataContainer", {});
156
173
  __publicField$2(this, "_pluginToolsContainer", {});
157
- __publicField$2(this, "toolParamsValidator", new Validator());
174
+ __publicField$2(this, "engineTools", new Map([
175
+ {
176
+ type: "function",
177
+ name: "listPlugins",
178
+ description: "List all plugins",
179
+ parameters: {}
180
+ },
181
+ {
182
+ type: "function",
183
+ name: "listPluginTools",
184
+ description: "List all tools of a plugin",
185
+ parameters: {
186
+ type: "object",
187
+ properties: {
188
+ pluginName: { type: "string" }
189
+ },
190
+ required: ["pluginName"]
191
+ }
192
+ },
193
+ {
194
+ type: "function",
195
+ name: "getNodes",
196
+ description: "Get all nodes",
197
+ parameters: {}
198
+ },
199
+ {
200
+ type: "function",
201
+ name: "getEdges",
202
+ description: "Get all edges",
203
+ parameters: {}
204
+ }
205
+ ].map((tool) => [tool.name, tool])));
206
+ __publicField$2(this, "toolParametersValidator", new Validator());
158
207
  var _a;
159
208
  this.runtime = (_a = options.runtime) != null ? _a : {};
160
209
  this.container$.next(options.container);
@@ -303,18 +352,26 @@ class Engine {
303
352
  endInteraction(pluginId, type) {
304
353
  this.interactionManager.endInteraction(pluginId, type);
305
354
  }
306
- callTool(pluginName, toolName, ...args) {
307
- const toolDefinition = get(this, ["_pluginToolsContainer", pluginName, toolName]);
355
+ callTool(pluginNameOrEngineToolName, ...args) {
356
+ let toolDefinition;
357
+ let toolDisplayName;
358
+ if (this.engineTools.has(pluginNameOrEngineToolName)) {
359
+ toolDefinition = __spreadProps$1(__spreadValues$1({}, this.engineTools.get(pluginNameOrEngineToolName)), { func: this[pluginNameOrEngineToolName].bind(this) });
360
+ toolDisplayName = toolDefinition.name;
361
+ } else {
362
+ toolDefinition = get(this, ["_pluginToolsContainer", pluginNameOrEngineToolName, args == null ? void 0 : args[0]]);
363
+ toolDisplayName = `${pluginNameOrEngineToolName}.${args == null ? void 0 : args[0]}`;
364
+ }
308
365
  const tool = toolDefinition == null ? void 0 : toolDefinition.func;
309
366
  if (!tool || typeof tool !== "function") {
310
- throw new Error(`Tool ${String(toolName)} not found in plugin ${pluginName}`);
367
+ throw new Error(`Tool ${String(toolDisplayName)} not found`);
311
368
  }
312
- const params = args[0];
313
- const validator = this.toolParamsValidator.validate(params, toolDefinition.params);
369
+ const parameters = args[args.length - 1];
370
+ const validator = this.toolParametersValidator.validate(parameters, toolDefinition.parameters);
314
371
  if (validator.errors.length > 0) {
315
- throw new Error(`Invalid tool params: ${validator.errors.map((e) => e.stack).join(", ")}`);
372
+ throw new Error(`Invalid tool parameters: ${validator.errors.map((e) => e.stack).join(", ")}`);
316
373
  }
317
- return tool(params);
374
+ return tool(parameters);
318
375
  }
319
376
  listPlugins() {
320
377
  return Array.from(this.plugins$.value.values()).map((plugin) => ({
@@ -322,35 +379,16 @@ class Engine {
322
379
  description: plugin.description
323
380
  }));
324
381
  }
325
- listPluginTools(pluginName) {
382
+ listPluginTools({ pluginName }) {
326
383
  return Object.entries(get(this, ["_pluginToolsContainer", pluginName]) || {}).map(([toolName, toolDefinition]) => ({
327
384
  type: "function",
328
385
  name: toolName,
329
386
  description: toolDefinition.description,
330
- parameters: toolDefinition.params
387
+ parameters: toolDefinition.parameters
331
388
  }));
332
389
  }
333
390
  listEngineTools() {
334
- return [
335
- {
336
- type: "function",
337
- name: "listPlugins",
338
- description: "List all plugins",
339
- parameters: {}
340
- },
341
- {
342
- type: "function",
343
- name: "listPluginTools",
344
- description: "List all tools of a plugin",
345
- parameters: {
346
- type: "object",
347
- properties: {
348
- pluginName: { type: "string" }
349
- },
350
- required: ["pluginName"]
351
- }
352
- }
353
- ];
391
+ return Array.from(this.engineTools.values());
354
392
  }
355
393
  destroy() {
356
394
  this.plugins$.value.forEach((plugin) => {
@@ -117,6 +117,8 @@ interface PluginData {
117
117
  */
118
118
  interface PluginTools {
119
119
  }
120
+ interface EngineTools {
121
+ }
120
122
  interface IPluginInfo {
121
123
  name: string;
122
124
  description?: string;
@@ -143,4 +145,4 @@ interface IEngineRuntime {
143
145
  };
144
146
  }
145
147
 
146
- export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type IPluginInfo as h, type IPluginToolInfo as i, type NodePosition as j, type NodeMeasured as k, type NodeProps as l, type EdgeProps as m, type Position as n, type PluginConfigs as o, type NodeOperationPipe as p, type EdgeOperationPipe as q, type NodeOperation as r, type EdgeOperation as s, type NodeOperatorFunction as t, type EdgeOperatorFunction as u };
148
+ export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type EngineTools as h, type IPluginInfo as i, type IPluginToolInfo as j, type NodePosition as k, type NodeMeasured as l, type NodeProps as m, type EdgeProps as n, type Position as o, type PluginConfigs as p, type NodeOperationPipe as q, type EdgeOperationPipe as r, type NodeOperation as s, type EdgeOperation as t, type NodeOperatorFunction as u, type EdgeOperatorFunction as v };
@@ -117,6 +117,8 @@ interface PluginData {
117
117
  */
118
118
  interface PluginTools {
119
119
  }
120
+ interface EngineTools {
121
+ }
120
122
  interface IPluginInfo {
121
123
  name: string;
122
124
  description?: string;
@@ -143,4 +145,4 @@ interface IEngineRuntime {
143
145
  };
144
146
  }
145
147
 
146
- export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type IPluginInfo as h, type IPluginToolInfo as i, type NodePosition as j, type NodeMeasured as k, type NodeProps as l, type EdgeProps as m, type Position as n, type PluginConfigs as o, type NodeOperationPipe as p, type EdgeOperationPipe as q, type NodeOperation as r, type EdgeOperation as s, type NodeOperatorFunction as t, type EdgeOperatorFunction as u };
148
+ export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type EngineTools as h, type IPluginInfo as i, type IPluginToolInfo as j, type NodePosition as k, type NodeMeasured as l, type NodeProps as m, type EdgeProps as n, type Position as o, type PluginConfigs as p, type NodeOperationPipe as q, type EdgeOperationPipe as r, type NodeOperation as s, type EdgeOperation as t, type NodeOperatorFunction as u, type EdgeOperatorFunction as v };
@@ -117,6 +117,8 @@ interface PluginData {
117
117
  */
118
118
  interface PluginTools {
119
119
  }
120
+ interface EngineTools {
121
+ }
120
122
  interface IPluginInfo {
121
123
  name: string;
122
124
  description?: string;
@@ -143,4 +145,4 @@ interface IEngineRuntime {
143
145
  };
144
146
  }
145
147
 
146
- export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type IPluginInfo as h, type IPluginToolInfo as i, type NodePosition as j, type NodeMeasured as k, type NodeProps as l, type EdgeProps as m, type Position as n, type PluginConfigs as o, type NodeOperationPipe as p, type EdgeOperationPipe as q, type NodeOperation as r, type EdgeOperation as s, type NodeOperatorFunction as t, type EdgeOperatorFunction as u };
148
+ export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type EngineTools as h, type IPluginInfo as i, type IPluginToolInfo as j, type NodePosition as k, type NodeMeasured as l, type NodeProps as m, type EdgeProps as n, type Position as o, type PluginConfigs as p, type NodeOperationPipe as q, type EdgeOperationPipe as r, type NodeOperation as s, type EdgeOperation as t, type NodeOperatorFunction as u, type EdgeOperatorFunction as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/core",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Core for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -46,14 +46,14 @@
46
46
  "jsonschema": "^1.5.0",
47
47
  "lodash-es": "^4.17.21",
48
48
  "rxjs": "^7.8.1",
49
- "@knotx/data": "0.2.12",
50
- "@knotx/utils": "0.2.12"
49
+ "@knotx/data": "0.2.13",
50
+ "@knotx/utils": "0.2.13"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/lodash-es": "^4.17.12",
54
- "@knotx/build-config": "0.2.12",
55
- "@knotx/eslint-config": "0.2.12",
56
- "@knotx/typescript-config": "0.2.12"
54
+ "@knotx/build-config": "0.2.13",
55
+ "@knotx/eslint-config": "0.2.13",
56
+ "@knotx/typescript-config": "0.2.13"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "unbuild",