Files
bentopdf/src/js/workflow/nodes/base-node.ts
T

47 lines
1.2 KiB
TypeScript

import { ClassicPreset } from 'rete';
import type { NodeCategory, NodeMeta, SocketData } from '../types';
export abstract class BaseWorkflowNode extends ClassicPreset.Node {
abstract readonly category: NodeCategory;
abstract readonly icon: string;
abstract description: string;
width = 280;
height = 140;
execStatus: 'idle' | 'running' | 'completed' | 'error' = 'idle';
nodeType: string = '';
constructor(label: string) {
super(label);
}
abstract data(
inputs: Record<string, SocketData[]>
): Promise<Record<string, SocketData>>;
getMeta(): NodeMeta {
return {
id: this.id,
label: this.label,
category: this.category,
icon: this.icon,
description: this.description,
};
}
sanitizeControlValue(key: string, value: unknown): unknown {
const control = this.controls[key];
if (!control || typeof control !== 'object' || !('value' in control)) {
return value;
}
const current = (control as { value: unknown }).value;
if (current === null || current === undefined) {
return value;
}
if (typeof value !== typeof current) {
return current;
}
return value;
}
}