Skip to content

Commit c15e6b5

Browse files
refactor: type toSerializable() as serialized data, not the class
The return type was `ComfyNodeDefImpl & { display_name; description }`, which promised `nodePath`, `nodeLifeCycleBadgeText` and `toSerializable` on an object `Object.assign` never copies them onto — the same accessor-vs-runtime gap this PR exists to close. `SerializableComfyNodeDef` omits every accessor and method, so reading one off a serialized def is now a compile error rather than a runtime undefined.
1 parent 343a0bc commit c15e6b5

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/stores/nodeDefStore.serialization.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ describe('ComfyNodeDefImpl.toSerializable', () => {
4343
expect(crossed.display_name).toBeUndefined()
4444
expect(crossed.description).toBeUndefined()
4545
})
46+
47+
it('emits no other accessor, so the type must not promise one', () => {
48+
const serialized: Record<string, unknown> = new ComfyNodeDefImpl(
49+
backendDef
50+
).toSerializable()
51+
52+
expect(serialized.nodePath).toBeUndefined()
53+
expect(serialized.nodeLifeCycleBadgeText).toBeUndefined()
54+
expect(serialized.toSerializable).toBeUndefined()
55+
})
4656
})

src/stores/nodeDefStore.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,7 @@ export class ComfyNodeDefImpl
214214
* arrive `undefined` — which is how the release locale collector would have
215215
* written every node's `display_name` as its internal `name`.
216216
*/
217-
toSerializable(): ComfyNodeDefImpl & {
218-
display_name: string
219-
description: string
220-
} {
217+
toSerializable(): SerializableComfyNodeDef {
221218
return Object.assign({}, this, {
222219
display_name: this.display_name,
223220
description: this.description
@@ -246,6 +243,22 @@ export class ComfyNodeDefImpl
246243
}
247244
}
248245

246+
/**
247+
* What `toSerializable()` emits: own data properties plus the two resolved
248+
* strings. `Object.assign` copies neither accessors nor methods, so naming them
249+
* here would repeat the defect this type exists to prevent.
250+
*/
251+
export type SerializableComfyNodeDef = Omit<
252+
ComfyNodeDefImpl,
253+
| 'display_name'
254+
| 'description'
255+
| 'nodePath'
256+
| 'isDummyFolder'
257+
| 'nodeLifeCycleBadgeText'
258+
| 'postProcessSearchScores'
259+
| 'toSerializable'
260+
> & { display_name: string; description: string }
261+
249262
export const SYSTEM_NODE_DEFS: Record<string, ComfyNodeDefV1> = {
250263
PrimitiveNode: {
251264
name: 'PrimitiveNode',

0 commit comments

Comments
 (0)