A Rete.js plugin for advanced type checking through customizable socket comparison logic.
Rete's default Socket compares by name only. This plugin provides CallbackSocket with custom type compatibility checking for sophisticated type validation.
npm install rete-callback-sockets-pluginimport { CallbackSocketsPlugin } from 'rete-callback-sockets-plugin';
const socketsPlugin = new CallbackSocketsPlugin();
editor.use(socketsPlugin);import { CallbackSocket } from 'rete-callback-sockets-plugin';
interface MyType {
assignableBy(other: MyType): boolean;
}
const socket = new CallbackSocket(myType);Important: Always use the plugin to maintain connection validity.
// ✅ Correct
await socketsPlugin.updateSocket(node, 'output', 'result', newSocket);
// ❌ Wrong - bypasses validation
node.outputs['result'].socket = newSocket;await socketsPlugin.removePort(node, 'input', 'value');socketsPlugin.addPortListener(node, 'input', 'value', async (event) => {
switch (event.type) {
case 'connectioncreated':
console.log('Connected to:', event.otherSocket.type);
break;
case 'connectionremoved':
console.log('Disconnected');
break;
case 'connectionchanged':
console.log('Type changed:', event.otherSocket.type);
break;
}
});socketsPlugin.addNodeListener(node, async (event) => {
console.log('Connection event:', event);
});socketsPlugin.addSocketChangedListeners(async (node, side, key, newSocket) => {
console.log(`${side}.${key} updated to:`, newSocket.type);
});// Disable during bulk operations
socketsPlugin.disableTypeValidation();
// Re-enable and revalidate
socketsPlugin.enableTypeValidation();
await socketsPlugin.updateAllTypes();
// Revalidate specific node
await socketsPlugin.updateTypes(nodeId);Your types must implement assignableBy:
interface TypeInterface {
assignableBy(other: TypeInterface): boolean;
}
class NumberType implements TypeInterface {
assignableBy(other: TypeInterface): boolean {
return other instanceof NumberType;
}
}
class AnyType implements TypeInterface {
assignableBy(other: TypeInterface): boolean {
return true;
}
}- Always
awaitasync operations - Use the plugin for all socket/port modifications
MIT