Refactor and enhance type safety across various modules

- Updated function parameters and return types in `page-preview.ts`, `pdf-decrypt.ts`, and `pymupdf-loader.ts` for improved type safety.
- Introduced type definitions for `CpdfInstance`, `PyMuPDFInstance`, and other related types to ensure better type checking.
- Enhanced error handling in `sanitize.ts` by creating a utility function for error messages.
- Removed unnecessary type assertions and improved type inference in `editor.ts`, `serialization.ts`, and `tools.test.ts`.
- Added type definitions for markdown-it plugins to improve compatibility and type safety.
- Enforced stricter TypeScript settings by enabling `noImplicitAny` in `tsconfig.json`.
- Cleaned up test files by refining type assertions and ensuring consistency in type usage.
This commit is contained in:
alam00000
2026-03-31 17:59:49 +05:30
parent a1fc2fc3c6
commit 9d0b68e18c
114 changed files with 2576 additions and 1867 deletions
+3 -4
View File
@@ -10,7 +10,6 @@ import { DataflowEngine } from 'rete-engine';
import type { DataflowEngineScheme } from 'rete-engine';
import { LitElement, html } from 'lit';
import type { BaseWorkflowNode } from './nodes/base-node';
// @ts-ignore -- Vite ?inline import for injecting into Shadow DOM
import phosphorCSS from '@phosphor-icons/web/regular?inline';
// Shared stylesheet for Phosphor icons (font-face already loaded globally, strip it)
@@ -305,8 +304,8 @@ export async function createWorkflowEditor(
// Override connection path to use vertical bezier curves (top-to-bottom flow)
litPlugin.addPipe((context) => {
if ((context as any).type === 'connectionpath') {
const { points } = (context as any).data;
if ('type' in context && context.type === 'connectionpath') {
const { points } = context.data;
const [start, end] = points as [
{ x: number; y: number },
{ x: number; y: number },
@@ -318,7 +317,7 @@ export async function createWorkflowEditor(
const path = `M ${start.x} ${start.y} C ${start.x} ${start.y + dy} ${end.x} ${end.y - dy} ${end.x} ${end.y}`;
return {
...context,
data: { ...(context as any).data, path },
data: { ...context.data, path },
} as typeof context;
}
return context;
+13 -28
View File
@@ -4,26 +4,15 @@ import type { ClassicScheme, LitArea2D } from '@retejs/lit-plugin';
import type { BaseWorkflowNode } from './nodes/base-node';
import { createNodeByType } from './nodes/registry';
import { ClassicPreset } from 'rete';
import type { SerializedWorkflow } from './types';
import type {
SerializedWorkflow,
SerializedNode,
SerializedConnection,
} from './types';
import { WORKFLOW_VERSION } from './types';
type AreaExtra = LitArea2D<ClassicScheme>;
interface SerializedNode {
id: string;
type: string;
position: { x: number; y: number };
controls: Record<string, unknown>;
}
interface SerializedConnection {
id: string;
source: string;
sourceOutput: string;
target: string;
targetInput: string;
}
function getNodeType(node: BaseWorkflowNode): string | null {
return node.nodeType || null;
}
@@ -78,19 +67,15 @@ async function deserializeWorkflow(
editor: NodeEditor<ClassicScheme>,
area: AreaPlugin<ClassicScheme, AreaExtra>
): Promise<void> {
if (
!data ||
!Array.isArray((data as any).nodes) ||
!Array.isArray((data as any).connections)
) {
if (!data || !Array.isArray(data.nodes) || !Array.isArray(data.connections)) {
throw new Error(
'Invalid workflow file: missing nodes or connections array.'
);
}
if ((data as any).version !== WORKFLOW_VERSION) {
if (data.version !== WORKFLOW_VERSION) {
console.warn(
`Workflow version mismatch: expected ${WORKFLOW_VERSION}, got ${(data as any).version}. Attempting load anyway.`
`Workflow version mismatch: expected ${WORKFLOW_VERSION}, got ${data.version}. Attempting load anyway.`
);
}
@@ -104,7 +89,7 @@ async function deserializeWorkflow(
const idMap = new Map<string, string>();
const skippedTypes: string[] = [];
for (const serializedNode of (data as any).nodes) {
for (const serializedNode of data.nodes) {
const node = createNodeByType(serializedNode.type);
if (!node) {
skippedTypes.push(serializedNode.type);
@@ -114,17 +99,17 @@ async function deserializeWorkflow(
for (const [key, value] of Object.entries(serializedNode.controls || {})) {
const control = node.controls[key];
if (control && 'value' in control) {
(control as any).value = value;
(control as { value: unknown }).value = value;
}
}
await editor.addNode(node as any);
await editor.addNode(node as ClassicScheme['Node']);
idMap.set(serializedNode.id, node.id);
await area.translate(node.id, serializedNode.position);
}
for (const serializedConn of (data as any).connections) {
for (const serializedConn of data.connections) {
const sourceId = idMap.get(serializedConn.source);
const targetId = idMap.get(serializedConn.target);
if (!sourceId || !targetId) continue;
@@ -139,7 +124,7 @@ async function deserializeWorkflow(
targetNode,
serializedConn.targetInput
);
await editor.addConnection(conn as any);
await editor.addConnection(conn as ClassicScheme['Connection']);
}
if (skippedTypes.length > 0) {