Compare commits

...

1 Commits

Author SHA1 Message Date
bymyself
9d92680ce4 refactor: consolidate NodeId type aliases (pre-work for adr008)
Issue #11428 identified three competing `NodeId` definitions:
  - src/lib/litegraph/src/LGraphNode.ts        (number | string)
  - src/platform/workflow/validation/schemas/workflowSchema.ts (number | string)
  - src/renderer/core/layout/types.ts          (string)

Make `LGraphNode.NodeId` the canonical source. `workflowSchema.ts`
now re-exports it (same shape, single definition) and `zNodeId` gets
a `satisfies z.ZodType<NodeId>` guard so the validator and the type
can never drift. The renderer's narrower `string`-only alias is kept
as an intentional layered variant and documented as such.

No behavior change. Existing import sites continue to work via the
re-export. Sweep of the ~151 bare-string `nodeId` typings will land
in follow-up PRs scoped by domain (litegraph internals, renderer,
stores, Vue props).

Refs #11428
2026-05-01 23:53:03 -07:00
3 changed files with 44 additions and 2 deletions

View File

@@ -98,6 +98,21 @@ import type { WidgetTypeMap } from './widgets/widgetMap'
// #region Types
/**
* Canonical identifier type for a litegraph node.
*
* This is the single source of truth for node IDs across the litegraph
* library and the workflow schema layer. Other modules SHOULD import
* `NodeId` from here (or via the workflow schema re-export) rather than
* declaring local `string` / `number | string` aliases.
*
* Note: `src/renderer/core/layout/types.ts` deliberately defines a
* narrower `NodeId = string` for the Vue-node renderer, where IDs are
* normalized to strings. That is a separate, intentionally-narrower
* layered alias — see the JSDoc there.
*
* Tracking issue for full migration: #11428.
*/
export type NodeId = number | string
export type NodeProperty = string | number | boolean | object

View File

@@ -1,7 +1,9 @@
import { z } from 'zod'
import type { SafeParseReturnType } from 'zod'
import { fromZodError } from 'zod-validation-error'
import type { RendererType } from '@/lib/litegraph/src/LGraph'
import type { NodeId } from '@/lib/litegraph/src/LGraphNode'
const zRendererType = z.enum([
'LG',
@@ -12,9 +14,20 @@ const zRendererType = z.enum([
// GroupNode is hacking node id to be a string, so we need to allow that.
// innerNode.id = `${this.node.id}:${i}`
// Remove it after GroupNode is redesigned.
export const zNodeId = z.union([z.number().int(), z.string()])
export const zNodeId = z.union([
z.number().int(),
z.string()
]) satisfies z.ZodType<NodeId>
const zNodeInputName = z.string()
export type NodeId = z.infer<typeof zNodeId>
/**
* Re-export of the canonical {@link NodeId} type defined in
* `src/lib/litegraph/src/LGraphNode.ts`. Kept here for ergonomic imports
* alongside `zNodeId` (the runtime validator) and historical call sites.
*
* See issue #11428 for the consolidation rationale.
*/
export type { NodeId }
/**
* UUID identifier for a saved workflow.

View File

@@ -37,6 +37,20 @@ export interface NodeBoundsUpdate {
bounds: Bounds
}
/**
* Renderer-internal node identifier.
*
* Intentionally narrower than the canonical {@link NodeId} in
* `src/lib/litegraph/src/LGraphNode.ts` (which is `number | string`).
* The Vue-node renderer normalizes all incoming IDs to strings before
* they enter the layout system, so this layered alias documents and
* enforces that contract at the renderer boundary.
*
* If you need a node ID at the litegraph or workflow-schema layer,
* import `NodeId` from `@/lib/litegraph/src/LGraphNode` instead.
*
* See issue #11428 for the layered-types decision.
*/
export type NodeId = string
export type LinkId = number
export type RerouteId = number