diff --git a/packages/core/src/schema/nodes/level.test.ts b/packages/core/src/schema/nodes/level.test.ts index e9e0efa9..f950f122 100644 --- a/packages/core/src/schema/nodes/level.test.ts +++ b/packages/core/src/schema/nodes/level.test.ts @@ -50,10 +50,10 @@ describe('LevelNode', () => { }) test('accepts level child IDs minted by plugins', () => { - expect( - LevelNode.parse({ - children: ['tree_plugin-child', 'flower_plugin-child', 'grass_plugin-child'], - }).children, - ).toEqual(['tree_plugin-child', 'flower_plugin-child', 'grass_plugin-child']) + const children = LevelNode.parse({ + children: ['tree_plugin-child', 'flower_plugin-child', 'grass_plugin-child'], + }).children as string[] + + expect(children).toEqual(['tree_plugin-child', 'flower_plugin-child', 'grass_plugin-child']) }) }) diff --git a/packages/core/src/schema/nodes/level.ts b/packages/core/src/schema/nodes/level.ts index 1055648b..0360598f 100644 --- a/packages/core/src/schema/nodes/level.ts +++ b/packages/core/src/schema/nodes/level.ts @@ -1,13 +1,63 @@ import dedent from 'dedent' import { z } from 'zod' import { BaseNode, nodeType, objectId } from '../base' +import type { CeilingNode } from './ceiling' +import type { ColumnNode } from './column' +import type { DuctFittingNode } from './duct-fitting' +import type { DuctSegmentNode } from './duct-segment' +import type { DuctTerminalNode } from './duct-terminal' +import type { FenceNode } from './fence' +import type { GuideNode } from './guide' +import type { HvacEquipmentNode } from './hvac-equipment' +import type { ItemNode } from './item' +import type { LinesetNode } from './lineset' +import type { LiquidLineNode } from './liquid-line' +import type { MeasurementNode } from './measurement' +import type { PipeFittingNode } from './pipe-fitting' +import type { PipeSegmentNode } from './pipe-segment' +import type { PipeTrapNode } from './pipe-trap' +import type { RoofNode } from './roof' +import type { ScanNode } from './scan' +import type { ShelfNode } from './shelf' +import type { SlabNode } from './slab' +import type { SpawnNode } from './spawn' +import type { StairNode } from './stair' +import type { WallNode } from './wall' +import type { ZoneNode } from './zone' + +type CoreLevelChildId = + | WallNode['id'] + | FenceNode['id'] + | ColumnNode['id'] + | ItemNode['id'] + | ZoneNode['id'] + | SlabNode['id'] + | CeilingNode['id'] + | RoofNode['id'] + | StairNode['id'] + | ScanNode['id'] + | GuideNode['id'] + | MeasurementNode['id'] + | SpawnNode['id'] + | ShelfNode['id'] + | DuctSegmentNode['id'] + | DuctFittingNode['id'] + | DuctTerminalNode['id'] + | HvacEquipmentNode['id'] + | LinesetNode['id'] + | LiquidLineNode['id'] + | PipeSegmentNode['id'] + | PipeFittingNode['id'] + | PipeTrapNode['id'] + +const LevelChildId = z.string().transform((id) => id as CoreLevelChildId) export const LevelNode = BaseNode.extend({ id: objectId('level'), type: nodeType('level'), // The node registry owns child-kind validity. Persisted level relationships // must also admit IDs minted by plugins that core cannot enumerate. - children: z.array(z.string()).default([]), + children: z.array(LevelChildId).default([]), // Specific props level: z.number().default(0), }).describe(