@vgai/engine 0.5.4 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/adapter-surface.d.ts +30 -0
- package/dist/adapter/adapter-surface.d.ts.map +1 -0
- package/dist/adapter/adapter-surface.js +18 -0
- package/dist/adapter/authoring.d.ts +597 -0
- package/dist/adapter/authoring.d.ts.map +1 -0
- package/dist/adapter/authoring.js +22 -0
- package/dist/adapter/colyseus-networking-adapter.d.ts +77 -0
- package/dist/adapter/colyseus-networking-adapter.d.ts.map +1 -0
- package/dist/adapter/colyseus-networking-adapter.js +76 -0
- package/dist/adapter/first-party-systems.d.ts +23 -0
- package/dist/adapter/first-party-systems.d.ts.map +1 -0
- package/dist/adapter/first-party-systems.js +196 -0
- package/dist/adapter/host-context.d.ts +194 -0
- package/dist/adapter/host-context.d.ts.map +1 -0
- package/dist/adapter/host-context.js +80 -0
- package/dist/adapter/index.d.ts +33 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/index.js +25 -0
- package/dist/adapter/ingest/game-contract.d.ts +53 -0
- package/dist/adapter/ingest/game-contract.d.ts.map +1 -0
- package/dist/adapter/ingest/game-contract.js +30 -0
- package/dist/adapter/ingest/scene-capture.d.ts +121 -0
- package/dist/adapter/ingest/scene-capture.d.ts.map +1 -0
- package/dist/adapter/ingest/scene-capture.js +270 -0
- package/dist/adapter/ingest/structural-ids.d.ts +64 -0
- package/dist/adapter/ingest/structural-ids.d.ts.map +1 -0
- package/dist/adapter/ingest/structural-ids.js +110 -0
- package/dist/adapter/ingest/upstream-pin.d.ts +44 -0
- package/dist/adapter/ingest/upstream-pin.d.ts.map +1 -0
- package/dist/adapter/ingest/upstream-pin.js +47 -0
- package/dist/adapter/loop-gate-report.d.ts +34 -0
- package/dist/adapter/loop-gate-report.d.ts.map +1 -0
- package/dist/adapter/loop-gate-report.js +37 -0
- package/dist/adapter/rapier-physics-adapter.d.ts +69 -0
- package/dist/adapter/rapier-physics-adapter.d.ts.map +1 -0
- package/dist/adapter/rapier-physics-adapter.js +135 -0
- package/dist/adapter/root-adapter.d.ts +195 -0
- package/dist/adapter/root-adapter.d.ts.map +1 -0
- package/dist/adapter/root-adapter.js +25 -0
- package/dist/adapter/setup-three-root-adapter.d.ts +87 -0
- package/dist/adapter/setup-three-root-adapter.d.ts.map +1 -0
- package/dist/adapter/setup-three-root-adapter.js +791 -0
- package/dist/adapter/system-adapter.d.ts +453 -0
- package/dist/adapter/system-adapter.d.ts.map +1 -0
- package/dist/adapter/system-adapter.js +13 -0
- package/dist/adapter/transform.d.ts +18 -0
- package/dist/adapter/transform.d.ts.map +1 -0
- package/dist/adapter/transform.js +1 -0
- package/dist/ai/navigation.d.ts +78 -0
- package/dist/ai/navigation.d.ts.map +1 -0
- package/dist/ai/navigation.js +152 -0
- package/dist/animation/anim-graph-types.d.ts +25 -0
- package/dist/animation/anim-graph-types.d.ts.map +1 -0
- package/dist/animation/anim-graph-types.js +1 -0
- package/dist/animation/animation-clock.d.ts +213 -0
- package/dist/animation/animation-clock.d.ts.map +1 -0
- package/dist/animation/animation-clock.js +301 -0
- package/dist/animation/blend-node.d.ts +22 -0
- package/dist/animation/blend-node.d.ts.map +1 -0
- package/dist/animation/blend-node.js +97 -0
- package/dist/animation/camera-ownership.d.ts +249 -0
- package/dist/animation/camera-ownership.d.ts.map +1 -0
- package/dist/animation/camera-ownership.js +169 -0
- package/dist/animation/cinematic-cues.d.ts +200 -0
- package/dist/animation/cinematic-cues.d.ts.map +1 -0
- package/dist/animation/cinematic-cues.js +213 -0
- package/dist/animation/clip-map.d.ts +12 -0
- package/dist/animation/clip-map.d.ts.map +1 -0
- package/dist/animation/clip-map.js +31 -0
- package/dist/animation/cubic-spline-interpolant.d.ts +54 -0
- package/dist/animation/cubic-spline-interpolant.d.ts.map +1 -0
- package/dist/animation/cubic-spline-interpolant.js +111 -0
- package/dist/animation/theatre-clock-binding.d.ts +89 -0
- package/dist/animation/theatre-clock-binding.d.ts.map +1 -0
- package/dist/animation/theatre-clock-binding.js +29 -0
- package/dist/animation/theatre-director.d.ts +277 -0
- package/dist/animation/theatre-director.d.ts.map +1 -0
- package/dist/animation/theatre-director.js +248 -0
- package/dist/animation/theatre-object-binding.d.ts +305 -0
- package/dist/animation/theatre-object-binding.d.ts.map +1 -0
- package/dist/animation/theatre-object-binding.js +351 -0
- package/dist/animation/xstate-animation-binding.d.ts +119 -0
- package/dist/animation/xstate-animation-binding.d.ts.map +1 -0
- package/dist/animation/xstate-animation-binding.js +349 -0
- package/dist/animation/xstate-animation-meta.d.ts +266 -0
- package/dist/animation/xstate-animation-meta.d.ts.map +1 -0
- package/dist/animation/xstate-animation-meta.js +252 -0
- package/dist/asset-formats/camera.d.ts +15 -0
- package/dist/asset-formats/camera.d.ts.map +1 -0
- package/dist/asset-formats/camera.js +15 -0
- package/dist/asset-formats/collider.d.ts +21 -0
- package/dist/asset-formats/collider.d.ts.map +1 -0
- package/dist/asset-formats/collider.js +53 -0
- package/dist/asset-formats/index.d.ts +46 -0
- package/dist/asset-formats/index.d.ts.map +1 -0
- package/dist/asset-formats/index.js +36 -0
- package/dist/asset-formats/instances.d.ts +17 -0
- package/dist/asset-formats/instances.d.ts.map +1 -0
- package/dist/asset-formats/instances.js +31 -0
- package/dist/asset-formats/light.d.ts +21 -0
- package/dist/asset-formats/light.d.ts.map +1 -0
- package/dist/asset-formats/light.js +35 -0
- package/dist/asset-formats/material.d.ts +129 -0
- package/dist/asset-formats/material.d.ts.map +1 -0
- package/dist/asset-formats/material.js +88 -0
- package/dist/asset-formats/mesh.d.ts +22 -0
- package/dist/asset-formats/mesh.d.ts.map +1 -0
- package/dist/asset-formats/mesh.js +64 -0
- package/dist/asset-formats/parse.d.ts +20 -0
- package/dist/asset-formats/parse.d.ts.map +1 -0
- package/dist/asset-formats/parse.js +34 -0
- package/dist/asset-formats/particles.d.ts +1390 -0
- package/dist/asset-formats/particles.d.ts.map +1 -0
- package/dist/asset-formats/particles.js +319 -0
- package/dist/asset-formats/render-env.d.ts +387 -0
- package/dist/asset-formats/render-env.d.ts.map +1 -0
- package/dist/asset-formats/render-env.js +300 -0
- package/dist/asset-formats/tuples.d.ts +12 -0
- package/dist/asset-formats/tuples.d.ts.map +1 -0
- package/dist/asset-formats/tuples.js +14 -0
- package/dist/asset-loaders.d.ts +97 -0
- package/dist/asset-loaders.d.ts.map +1 -0
- package/dist/asset-loaders.js +209 -0
- package/dist/asset-parse-error.d.ts +24 -0
- package/dist/asset-parse-error.d.ts.map +1 -0
- package/dist/asset-parse-error.js +29 -0
- package/dist/asset-registry.d.ts +38 -0
- package/dist/asset-registry.d.ts.map +1 -0
- package/dist/asset-registry.js +66 -0
- package/dist/assets.d.ts +26 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +55 -0
- package/dist/audio/wav-encode.d.ts +38 -0
- package/dist/audio/wav-encode.d.ts.map +1 -0
- package/dist/audio/wav-encode.js +97 -0
- package/dist/canvas-react/engine-bridge.d.ts +45 -0
- package/dist/canvas-react/engine-bridge.d.ts.map +1 -0
- package/dist/canvas-react/engine-bridge.js +45 -0
- package/dist/canvas-react/index.d.ts +42 -0
- package/dist/canvas-react/index.d.ts.map +1 -0
- package/dist/canvas-react/index.js +41 -0
- package/dist/canvas-react/pixi-primitive.d.ts +85 -0
- package/dist/canvas-react/pixi-primitive.d.ts.map +1 -0
- package/dist/canvas-react/pixi-primitive.js +181 -0
- package/dist/canvas-react/pixi-react-adapter.d.ts +71 -0
- package/dist/canvas-react/pixi-react-adapter.d.ts.map +1 -0
- package/dist/canvas-react/pixi-react-adapter.js +229 -0
- package/dist/canvas-react/pixi-react-root-factory.d.ts +56 -0
- package/dist/canvas-react/pixi-react-root-factory.d.ts.map +1 -0
- package/dist/canvas-react/pixi-react-root-factory.js +73 -0
- package/dist/canvas-react/world-context.d.ts +88 -0
- package/dist/canvas-react/world-context.d.ts.map +1 -0
- package/dist/canvas-react/world-context.js +212 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +8 -0
- package/dist/core/frame-pacing.d.ts +90 -0
- package/dist/core/frame-pacing.d.ts.map +1 -0
- package/dist/core/frame-pacing.js +89 -0
- package/dist/core/game-loop.d.ts +62 -0
- package/dist/core/game-loop.d.ts.map +1 -0
- package/dist/core/game-loop.js +189 -0
- package/dist/core/seeded-random.d.ts +69 -0
- package/dist/core/seeded-random.d.ts.map +1 -0
- package/dist/core/seeded-random.js +121 -0
- package/dist/core/sim-clock.d.ts +199 -0
- package/dist/core/sim-clock.d.ts.map +1 -0
- package/dist/core/sim-clock.js +291 -0
- package/dist/core/system-runner.d.ts +96 -0
- package/dist/core/system-runner.d.ts.map +1 -0
- package/dist/core/system-runner.js +253 -0
- package/dist/core/types.d.ts +111 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +25 -0
- package/dist/data/data-asset.d.ts +101 -0
- package/dist/data/data-asset.d.ts.map +1 -0
- package/dist/data/data-asset.js +122 -0
- package/dist/data/data-check-core.d.ts +109 -0
- package/dist/data/data-check-core.d.ts.map +1 -0
- package/dist/data/data-check-core.js +177 -0
- package/dist/data/data-ref.d.ts +79 -0
- package/dist/data/data-ref.d.ts.map +1 -0
- package/dist/data/data-ref.js +130 -0
- package/dist/data/vite-plugin-data.d.ts +79 -0
- package/dist/data/vite-plugin-data.d.ts.map +1 -0
- package/dist/data/vite-plugin-data.js +217 -0
- package/dist/defaults.d.ts +233 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +137 -0
- package/dist/dev/chrome-trace.d.ts +45 -0
- package/dist/dev/chrome-trace.d.ts.map +1 -0
- package/dist/dev/chrome-trace.js +114 -0
- package/dist/dev/console-bridge.d.ts +22 -0
- package/dist/dev/console-bridge.d.ts.map +1 -0
- package/dist/dev/console-bridge.js +71 -0
- package/dist/dev/debug-draw.d.ts +24 -0
- package/dist/dev/debug-draw.d.ts.map +1 -0
- package/dist/dev/debug-draw.js +73 -0
- package/dist/dev/instruments.d.ts +133 -0
- package/dist/dev/instruments.d.ts.map +1 -0
- package/dist/dev/instruments.js +231 -0
- package/dist/dev/logger.d.ts +30 -0
- package/dist/dev/logger.d.ts.map +1 -0
- package/dist/dev/logger.js +90 -0
- package/dist/dev/performance-profiler.d.ts +111 -0
- package/dist/dev/performance-profiler.d.ts.map +1 -0
- package/dist/dev/performance-profiler.js +215 -0
- package/dist/dev/render-debug-adapter.d.ts +57 -0
- package/dist/dev/render-debug-adapter.d.ts.map +1 -0
- package/dist/dev/render-debug-adapter.js +141 -0
- package/dist/dev/render-memory.d.ts +53 -0
- package/dist/dev/render-memory.d.ts.map +1 -0
- package/dist/dev/render-memory.js +190 -0
- package/dist/dev/webgl-frame-capture.d.ts +134 -0
- package/dist/dev/webgl-frame-capture.d.ts.map +1 -0
- package/dist/dev/webgl-frame-capture.js +270 -0
- package/dist/dev/webgl-gpu-timer.d.ts +8 -0
- package/dist/dev/webgl-gpu-timer.d.ts.map +1 -0
- package/dist/dev/webgl-gpu-timer.js +52 -0
- package/dist/ecs/scene-index.d.ts +179 -0
- package/dist/ecs/scene-index.d.ts.map +1 -0
- package/dist/ecs/scene-index.js +331 -0
- package/dist/ecs/scene-query.d.ts +6 -0
- package/dist/ecs/scene-query.d.ts.map +1 -0
- package/dist/ecs/scene-query.js +40 -0
- package/dist/ecs/user-data.d.ts +193 -0
- package/dist/ecs/user-data.d.ts.map +1 -0
- package/dist/ecs/user-data.js +145 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/input/input-manager.d.ts +944 -0
- package/dist/input/input-manager.d.ts.map +1 -0
- package/dist/input/input-manager.js +2209 -0
- package/dist/input/input-types.d.ts +174 -0
- package/dist/input/input-types.d.ts.map +1 -0
- package/dist/input/input-types.js +1 -0
- package/dist/input/prompt-labels.d.ts +21 -0
- package/dist/input/prompt-labels.d.ts.map +1 -0
- package/dist/input/prompt-labels.js +121 -0
- package/dist/input/rebind-controller.d.ts +59 -0
- package/dist/input/rebind-controller.d.ts.map +1 -0
- package/dist/input/rebind-controller.js +85 -0
- package/dist/input/schema.d.ts +16 -0
- package/dist/input/schema.d.ts.map +1 -0
- package/dist/input/schema.js +228 -0
- package/dist/loader.d.ts +76 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +114 -0
- package/dist/manifest/editor-port.d.ts +53 -0
- package/dist/manifest/editor-port.d.ts.map +1 -0
- package/dist/manifest/editor-port.js +67 -0
- package/dist/manifest/filename.d.ts +14 -0
- package/dist/manifest/filename.d.ts.map +1 -0
- package/dist/manifest/filename.js +43 -0
- package/dist/manifest/index.d.ts +6 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +9 -0
- package/dist/manifest/load-file.d.ts +7 -0
- package/dist/manifest/load-file.d.ts.map +1 -0
- package/dist/manifest/load-file.js +23 -0
- package/dist/manifest/load.d.ts +161 -0
- package/dist/manifest/load.d.ts.map +1 -0
- package/dist/manifest/load.js +269 -0
- package/dist/manifest/locate.d.ts +24 -0
- package/dist/manifest/locate.d.ts.map +1 -0
- package/dist/manifest/locate.js +48 -0
- package/dist/manifest/schema.d.ts +293 -0
- package/dist/manifest/schema.d.ts.map +1 -0
- package/dist/manifest/schema.js +633 -0
- package/dist/physics/collider-dimensions.d.ts +63 -0
- package/dist/physics/collider-dimensions.d.ts.map +1 -0
- package/dist/physics/collider-dimensions.js +98 -0
- package/dist/physics/collision-system.d.ts +41 -0
- package/dist/physics/collision-system.d.ts.map +1 -0
- package/dist/physics/collision-system.js +64 -0
- package/dist/physics/physics-registry.d.ts +45 -0
- package/dist/physics/physics-registry.d.ts.map +1 -0
- package/dist/physics/physics-registry.js +65 -0
- package/dist/physics/transform-writer.d.ts +16 -0
- package/dist/physics/transform-writer.d.ts.map +1 -0
- package/dist/physics/transform-writer.js +38 -0
- package/dist/pixi/authoring.d.ts +93 -0
- package/dist/pixi/authoring.d.ts.map +1 -0
- package/dist/pixi/authoring.js +207 -0
- package/dist/pixi/index.d.ts +16 -0
- package/dist/pixi/index.d.ts.map +1 -0
- package/dist/pixi/index.js +15 -0
- package/dist/pixi/ingest-iframe.d.ts +82 -0
- package/dist/pixi/ingest-iframe.d.ts.map +1 -0
- package/dist/pixi/ingest-iframe.js +166 -0
- package/dist/pixi/ingest.d.ts +97 -0
- package/dist/pixi/ingest.d.ts.map +1 -0
- package/dist/pixi/ingest.js +40 -0
- package/dist/pixi/physics-registry.d.ts +24 -0
- package/dist/pixi/physics-registry.d.ts.map +1 -0
- package/dist/pixi/physics-registry.js +38 -0
- package/dist/pixi/scene-capture.d.ts +43 -0
- package/dist/pixi/scene-capture.d.ts.map +1 -0
- package/dist/pixi/scene-capture.js +92 -0
- package/dist/pixi/system-adapters.d.ts +16 -0
- package/dist/pixi/system-adapters.d.ts.map +1 -0
- package/dist/pixi/system-adapters.js +37 -0
- package/dist/react/unmanaged-root-detector.d.ts +18 -0
- package/dist/react/unmanaged-root-detector.d.ts.map +1 -0
- package/dist/react/unmanaged-root-detector.js +70 -0
- package/dist/react/use-data.d.ts +60 -0
- package/dist/react/use-data.d.ts.map +1 -0
- package/dist/react/use-data.js +101 -0
- package/dist/react/use-selection.d.ts +54 -0
- package/dist/react/use-selection.d.ts.map +1 -0
- package/dist/react/use-selection.js +71 -0
- package/dist/react/world-state.d.ts +154 -0
- package/dist/react/world-state.d.ts.map +1 -0
- package/dist/react/world-state.js +220 -0
- package/dist/render/auto-batcher.d.ts +34 -0
- package/dist/render/auto-batcher.d.ts.map +1 -0
- package/dist/render/auto-batcher.js +140 -0
- package/dist/render/instance-mesh.d.ts +5 -0
- package/dist/render/instance-mesh.d.ts.map +1 -0
- package/dist/render/instance-mesh.js +19 -0
- package/dist/render/light-camera-factory.d.ts +24 -0
- package/dist/render/light-camera-factory.d.ts.map +1 -0
- package/dist/render/light-camera-factory.js +71 -0
- package/dist/render/lod.d.ts +13 -0
- package/dist/render/lod.d.ts.map +1 -0
- package/dist/render/lod.js +16 -0
- package/dist/render/material-factory.d.ts +15 -0
- package/dist/render/material-factory.d.ts.map +1 -0
- package/dist/render/material-factory.js +186 -0
- package/dist/render/mesh-shadow.d.ts +11 -0
- package/dist/render/mesh-shadow.d.ts.map +1 -0
- package/dist/render/mesh-shadow.js +19 -0
- package/dist/render/particles-factory.d.ts +99 -0
- package/dist/render/particles-factory.d.ts.map +1 -0
- package/dist/render/particles-factory.js +361 -0
- package/dist/render/render-batch-system.d.ts +33 -0
- package/dist/render/render-batch-system.d.ts.map +1 -0
- package/dist/render/render-batch-system.js +223 -0
- package/dist/render/render-features.d.ts +47 -0
- package/dist/render/render-features.d.ts.map +1 -0
- package/dist/render/render-features.js +105 -0
- package/dist/render/render-settings.d.ts +35 -0
- package/dist/render/render-settings.d.ts.map +1 -0
- package/dist/render/render-settings.js +51 -0
- package/dist/render/spark-renderer-lifecycle.d.ts +18 -0
- package/dist/render/spark-renderer-lifecycle.d.ts.map +1 -0
- package/dist/render/spark-renderer-lifecycle.js +57 -0
- package/dist/render/viewport-shading.d.ts +17 -0
- package/dist/render/viewport-shading.d.ts.map +1 -0
- package/dist/render/viewport-shading.js +87 -0
- package/dist/runtime/create-runtime.d.ts +259 -0
- package/dist/runtime/create-runtime.d.ts.map +1 -0
- package/dist/runtime/create-runtime.js +666 -0
- package/dist/runtime/debug-bridge.d.ts +288 -0
- package/dist/runtime/debug-bridge.d.ts.map +1 -0
- package/dist/runtime/debug-bridge.js +277 -0
- package/dist/runtime/debug-registry.d.ts +287 -0
- package/dist/runtime/debug-registry.d.ts.map +1 -0
- package/dist/runtime/debug-registry.js +528 -0
- package/dist/runtime/dev-layers.d.ts +34 -0
- package/dist/runtime/dev-layers.d.ts.map +1 -0
- package/dist/runtime/dev-layers.js +40 -0
- package/dist/runtime/frame-selector-cache.d.ts +41 -0
- package/dist/runtime/frame-selector-cache.d.ts.map +1 -0
- package/dist/runtime/frame-selector-cache.js +65 -0
- package/dist/runtime/game.d.ts +576 -0
- package/dist/runtime/game.d.ts.map +1 -0
- package/dist/runtime/game.js +1003 -0
- package/dist/runtime/gameplay-rng-trap.d.ts +47 -0
- package/dist/runtime/gameplay-rng-trap.d.ts.map +1 -0
- package/dist/runtime/gameplay-rng-trap.js +95 -0
- package/dist/runtime/input-router.d.ts +78 -0
- package/dist/runtime/input-router.d.ts.map +1 -0
- package/dist/runtime/input-router.js +171 -0
- package/dist/runtime/mount-game.d.ts +126 -0
- package/dist/runtime/mount-game.d.ts.map +1 -0
- package/dist/runtime/mount-game.js +159 -0
- package/dist/runtime/mount-manifest.d.ts +174 -0
- package/dist/runtime/mount-manifest.d.ts.map +1 -0
- package/dist/runtime/mount-manifest.js +304 -0
- package/dist/runtime/presentation.d.ts +85 -0
- package/dist/runtime/presentation.d.ts.map +1 -0
- package/dist/runtime/presentation.js +92 -0
- package/dist/runtime/render-audio-control.d.ts +126 -0
- package/dist/runtime/render-audio-control.d.ts.map +1 -0
- package/dist/runtime/render-audio-control.js +116 -0
- package/dist/runtime/render-control.d.ts +347 -0
- package/dist/runtime/render-control.d.ts.map +1 -0
- package/dist/runtime/render-control.js +317 -0
- package/dist/runtime/render-seed.d.ts +56 -0
- package/dist/runtime/render-seed.d.ts.map +1 -0
- package/dist/runtime/render-seed.js +73 -0
- package/dist/runtime/state-bridge.d.ts +60 -0
- package/dist/runtime/state-bridge.d.ts.map +1 -0
- package/dist/runtime/state-bridge.js +62 -0
- package/dist/runtime/types.d.ts +285 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/unexported-game-trap.d.ts +36 -0
- package/dist/runtime/unexported-game-trap.d.ts.map +1 -0
- package/dist/runtime/unexported-game-trap.js +80 -0
- package/dist/setup/setup-audio.d.ts +20 -0
- package/dist/setup/setup-audio.d.ts.map +1 -0
- package/dist/setup/setup-audio.js +41 -0
- package/dist/setup/setup-particles.d.ts +17 -0
- package/dist/setup/setup-particles.d.ts.map +1 -0
- package/dist/setup/setup-particles.js +16 -0
- package/dist/setup/setup-physics.d.ts +25 -0
- package/dist/setup/setup-physics.d.ts.map +1 -0
- package/dist/setup/setup-physics.js +51 -0
- package/dist/setup/setup-renderer.d.ts +82 -0
- package/dist/setup/setup-renderer.d.ts.map +1 -0
- package/dist/setup/setup-renderer.js +381 -0
- package/dist/world3d-react/engine-bridge.d.ts +47 -0
- package/dist/world3d-react/engine-bridge.d.ts.map +1 -0
- package/dist/world3d-react/engine-bridge.js +48 -0
- package/dist/world3d-react/index.d.ts +47 -0
- package/dist/world3d-react/index.d.ts.map +1 -0
- package/dist/world3d-react/index.js +46 -0
- package/dist/world3d-react/r3f-adapter.d.ts +51 -0
- package/dist/world3d-react/r3f-adapter.d.ts.map +1 -0
- package/dist/world3d-react/r3f-adapter.js +368 -0
- package/dist/world3d-react/r3f-root-factory.d.ts +62 -0
- package/dist/world3d-react/r3f-root-factory.d.ts.map +1 -0
- package/dist/world3d-react/r3f-root-factory.js +79 -0
- package/dist/world3d-react/rapier-physics-bridge.d.ts +76 -0
- package/dist/world3d-react/rapier-physics-bridge.d.ts.map +1 -0
- package/dist/world3d-react/rapier-physics-bridge.js +120 -0
- package/dist/world3d-react/renderer-config.d.ts +58 -0
- package/dist/world3d-react/renderer-config.d.ts.map +1 -0
- package/dist/world3d-react/renderer-config.js +96 -0
- package/dist/world3d-react/world-context.d.ts +123 -0
- package/dist/world3d-react/world-context.d.ts.map +1 -0
- package/dist/world3d-react/world-context.js +204 -0
- package/dist-config/config.js +303 -0
- package/dist-config/config.js.map +7 -0
- package/package.json +14 -3
- package/src/adapter/rapier-physics-adapter.ts +77 -34
- package/src/config.ts +8 -0
- package/src/core/frame-pacing.ts +26 -0
- package/src/core/game-loop.ts +4 -3
- package/src/dev/instruments.ts +302 -0
- package/src/runtime/mount-game.ts +6 -0
- package/src/runtime/unexported-game-trap.ts +82 -0
- package/src/setup/setup-renderer.ts +2 -0
- package/src/world3d-react/index.ts +9 -0
- package/src/world3d-react/rapier-physics-bridge.tsx +137 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System execution phases, in order.
|
|
3
|
+
* Each frame, systems run in this exact sequence.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SystemPhase: {
|
|
6
|
+
readonly INPUT: "input";
|
|
7
|
+
readonly PRE_PHYSICS: "prePhysics";
|
|
8
|
+
readonly PHYSICS: "physics";
|
|
9
|
+
readonly POST_PHYSICS: "postPhysics";
|
|
10
|
+
readonly GAME_LOGIC: "gameLogic";
|
|
11
|
+
readonly ANIMATION: "animation";
|
|
12
|
+
readonly PRE_RENDER: "preRender";
|
|
13
|
+
readonly RENDER: "render";
|
|
14
|
+
};
|
|
15
|
+
export type SystemPhaseName = (typeof SystemPhase)[keyof typeof SystemPhase];
|
|
16
|
+
/** Order of phase execution */
|
|
17
|
+
export declare const PHASE_ORDER: SystemPhaseName[];
|
|
18
|
+
/** A system is just a function that takes delta time */
|
|
19
|
+
export type SystemFn = (dt: number) => void;
|
|
20
|
+
export interface SystemOptions {
|
|
21
|
+
/** Stable diagnostic label; falls back to the function name. */
|
|
22
|
+
readonly name?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SystemRunObserver {
|
|
25
|
+
beginSystem(scope: string, phase: SystemPhaseName, name: string): void;
|
|
26
|
+
endSystem(scope: string, phase: SystemPhaseName, name: string): void;
|
|
27
|
+
}
|
|
28
|
+
/** A lifecycle system with init/update/dispose hooks. */
|
|
29
|
+
export interface SystemDef {
|
|
30
|
+
/** Stable diagnostic label; falls back to the update function name. */
|
|
31
|
+
readonly name?: string;
|
|
32
|
+
/** Which phase the update function runs in */
|
|
33
|
+
phase: SystemPhaseName;
|
|
34
|
+
/** One-time setup after all entities are spawned, before the first frame */
|
|
35
|
+
init?(): void;
|
|
36
|
+
/** Per-frame update */
|
|
37
|
+
update: SystemFn;
|
|
38
|
+
/** Cleanup when the system is removed or the scene unloads */
|
|
39
|
+
dispose?(): void;
|
|
40
|
+
}
|
|
41
|
+
export interface GameLoopConfig {
|
|
42
|
+
/** Fixed timestep in seconds (default: 1/60) */
|
|
43
|
+
fixedTimestep?: number;
|
|
44
|
+
/** Max physics substeps per frame to prevent spiral of death (default: 8) */
|
|
45
|
+
maxSubSteps?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Called once per consumed fixed substep — the SIM half. A real frame whose
|
|
48
|
+
* accumulator produces zero substeps calls this zero times, which is exactly
|
|
49
|
+
* why {@link GameLoopConfig.render} exists.
|
|
50
|
+
*
|
|
51
|
+
* Whether the `render`/`preRender` phases run inside this call is the
|
|
52
|
+
* CALLER's choice, not this loop's: a host that also passes `render` below
|
|
53
|
+
* asks `Game.runFrame` to skip them (`skipRenderPhases`), a host that does
|
|
54
|
+
* not keeps them here as the tail of `PHASE_ORDER`. See `game-loop.ts`'s
|
|
55
|
+
* module doc.
|
|
56
|
+
*/
|
|
57
|
+
update: (dt: number) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Called EXACTLY ONCE per real (rAF) frame — the PRESENTATION half
|
|
60
|
+
* (WO-P13, `docs/WORK.md` §2 P13; this is the callback whose absence the
|
|
61
|
+
* former D1 decision recorded).
|
|
62
|
+
*
|
|
63
|
+
* - `alpha` — `accumulator / fixedDt` after this frame's substeps were
|
|
64
|
+
* consumed, in `[0, 1]`: how far presentation sits past the last
|
|
65
|
+
* completed fixed state. `core/frame-pacing.ts` computes it.
|
|
66
|
+
* - `displayDt` — this display frame's own delta in seconds, clamped and
|
|
67
|
+
* `timeScale`d exactly like the sim's time. Integrate per-display-frame
|
|
68
|
+
* motion against this, never against `fixedTimestep`.
|
|
69
|
+
*
|
|
70
|
+
* Optional. Never invoked at all in {@link GameLoopConfig.externalDrive}
|
|
71
|
+
* mode, where `frame()` itself never runs.
|
|
72
|
+
*/
|
|
73
|
+
render?: (alpha: number, displayDt: number) => void;
|
|
74
|
+
/**
|
|
75
|
+
* External-drive mode (I2): when `true`, `start()` never arms a
|
|
76
|
+
* `requestAnimationFrame` chain and never installs the
|
|
77
|
+
* `visibilitychange`/`document.hidden` auto-stop handler — so a
|
|
78
|
+
* headless/backgrounded capture page cannot have its loop silently killed by
|
|
79
|
+
* the tab-hidden guard, and `config.update` is never invoked by
|
|
80
|
+
* wall-clock/RAF timing at all. The caller (a render harness) drives frames
|
|
81
|
+
* itself instead — see `runtime/render-control.ts`, which calls a world's
|
|
82
|
+
* phase hooks directly rather than going through this loop's `update`
|
|
83
|
+
* callback. Default `false` (normal wall-clock RAF playback, unchanged).
|
|
84
|
+
*/
|
|
85
|
+
externalDrive?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Truthful liveness classification for `createGameLoop`'s returned loop
|
|
89
|
+
* (issue #175 — "state must never claim health it cannot observe"). See
|
|
90
|
+
* `GameLoop.liveness`'s doc comment in `game-loop.ts` for the full contract;
|
|
91
|
+
* exported here (rather than only inline on the loop's return type) so
|
|
92
|
+
* callers elsewhere in the engine (`runtime/game.ts`, `runtime/
|
|
93
|
+
* debug-registry.ts`) can name the union without importing `game-loop.ts`
|
|
94
|
+
* as a value.
|
|
95
|
+
*
|
|
96
|
+
* - `'running'` — the rAF chain is armed and `config.update` is being
|
|
97
|
+
* driven by real frames (or, for an `externalDrive` loop, `start()` has
|
|
98
|
+
* been called — see that mode's own liveness note below).
|
|
99
|
+
* - `'hidden-paused'` — the T2.1 idle throttle stopped the loop because
|
|
100
|
+
* `document.hidden` is true; this is deliberate and reversible (resumes
|
|
101
|
+
* automatically on visibility), but ZERO ticks are advancing right now.
|
|
102
|
+
* - `'stopped'` — `stop()` was called, or `start()` was never called.
|
|
103
|
+
*
|
|
104
|
+
* `isRunning` collapses `'hidden-paused'` and `'stopped'` into the same
|
|
105
|
+
* `false` — exactly the ambiguity that let a hidden-paused game report as
|
|
106
|
+
* healthy ("playing") through every consumer that only read `isRunning`/
|
|
107
|
+
* store-level play state. Read `liveness` wherever "is this game actually
|
|
108
|
+
* advancing" matters.
|
|
109
|
+
*/
|
|
110
|
+
export type GameLoopLiveness = 'running' | 'hidden-paused' | 'stopped';
|
|
111
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;;;;CASd,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAE7E,+BAA+B;AAC/B,eAAO,MAAM,WAAW,EAAE,eAAe,EASxC,CAAC;AAEF,wDAAwD;AACxD,MAAM,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACvE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACtE;AAED,yDAAyD;AACzD,MAAM,WAAW,SAAS;IACxB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,8CAA8C;IAC9C,KAAK,EAAE,eAAe,CAAC;IACvB,4EAA4E;IAC5E,IAAI,CAAC,IAAI,IAAI,CAAC;IACd,uBAAuB;IACvB,MAAM,EAAE,QAAQ,CAAC;IACjB,8DAA8D;IAC9D,OAAO,CAAC,IAAI,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;OAUG;IACH,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System execution phases, in order.
|
|
3
|
+
* Each frame, systems run in this exact sequence.
|
|
4
|
+
*/
|
|
5
|
+
export const SystemPhase = {
|
|
6
|
+
INPUT: 'input',
|
|
7
|
+
PRE_PHYSICS: 'prePhysics',
|
|
8
|
+
PHYSICS: 'physics',
|
|
9
|
+
POST_PHYSICS: 'postPhysics',
|
|
10
|
+
GAME_LOGIC: 'gameLogic',
|
|
11
|
+
ANIMATION: 'animation',
|
|
12
|
+
PRE_RENDER: 'preRender',
|
|
13
|
+
RENDER: 'render',
|
|
14
|
+
};
|
|
15
|
+
/** Order of phase execution */
|
|
16
|
+
export const PHASE_ORDER = [
|
|
17
|
+
SystemPhase.INPUT,
|
|
18
|
+
SystemPhase.PRE_PHYSICS,
|
|
19
|
+
SystemPhase.PHYSICS,
|
|
20
|
+
SystemPhase.POST_PHYSICS,
|
|
21
|
+
SystemPhase.GAME_LOGIC,
|
|
22
|
+
SystemPhase.ANIMATION,
|
|
23
|
+
SystemPhase.PRE_RENDER,
|
|
24
|
+
SystemPhase.RENDER,
|
|
25
|
+
];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data assets — W1 (§2.3 consumption API).
|
|
3
|
+
*
|
|
4
|
+
* A data asset is designer-tunable game data: a JSON file in the project's
|
|
5
|
+
* `src/data/`, governed by a Zod schema (`*.schema.ts`, engineer-owned) whose
|
|
6
|
+
* emitted JSON Schema (`*.schema.json`, see {@link toDataJsonSchema}) gives
|
|
7
|
+
* VS Code validation via the data file's `"$schema"` first line. Data assets
|
|
8
|
+
* are immutable at runtime — definitions, not state (§2.1).
|
|
9
|
+
*
|
|
10
|
+
* The blessed consumption shape, scaffolded working-at-birth by the project
|
|
11
|
+
* template (`src/data/` there is the worked example — §6.2):
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import raw from './tuning.data.json';
|
|
15
|
+
* import { TuningSchema } from './tuning.schema';
|
|
16
|
+
* import { defineData } from '@engine/data/data-asset';
|
|
17
|
+
*
|
|
18
|
+
* export const tuning = defineData(TuningSchema, raw, 'src/data/tuning.data.json');
|
|
19
|
+
* // Vite HMR needs the literal dep path in THIS module (static analysis) —
|
|
20
|
+
* // this one line is the entire live-tuning wiring (['default'] not .default:
|
|
21
|
+
* // strict tsconfigs index-signature ModuleNamespace):
|
|
22
|
+
* import.meta.hot?.accept('./tuning.data.json', (m) => tuning.hotSwap(m?.['default']));
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Game code reads `tuning.get()` inside its update loop (never cache fields
|
|
26
|
+
* across frames) or `subscribe()`s; an edit to the `.data.json` — from
|
|
27
|
+
* VS Code, an agent, or the future editor Data tab (W2) — flows through Vite
|
|
28
|
+
* HMR into the running game with no remount. React roots/tools get a
|
|
29
|
+
* `useData` hook with W3's tool-hooks package (deferred with it: the engine
|
|
30
|
+
* core stays React-free).
|
|
31
|
+
*/
|
|
32
|
+
import { z } from 'zod';
|
|
33
|
+
/**
|
|
34
|
+
* A live handle to one data asset (§2.3). `get`/`subscribe` are the whole
|
|
35
|
+
* runtime surface; `hotSwap` exists only for the owning module's
|
|
36
|
+
* `import.meta.hot.accept` callback.
|
|
37
|
+
*/
|
|
38
|
+
export interface DataHandle<T> {
|
|
39
|
+
/** Current parsed values. Read every frame — HMR swaps them under you. */
|
|
40
|
+
get(): T;
|
|
41
|
+
/**
|
|
42
|
+
* Called with the new value after every successful hot swap (NOT with the
|
|
43
|
+
* initial value). Returns an unsubscribe function.
|
|
44
|
+
*/
|
|
45
|
+
subscribe(fn: (value: T) => void): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* HMR entry point — call from the owning module's
|
|
48
|
+
* `import.meta.hot.accept('<file>.data.json', (m) => handle.hotSwap(m?.default))`.
|
|
49
|
+
* Parses like load, but a FAILING edit keeps the last good value and
|
|
50
|
+
* `console.error`s instead of throwing: a typo mid-live-tune must not
|
|
51
|
+
* crash the running game. Fix the file and save again.
|
|
52
|
+
*/
|
|
53
|
+
hotSwap(next: unknown): void;
|
|
54
|
+
/**
|
|
55
|
+
* The project-relative path this handle was defined with (`defineData`'s
|
|
56
|
+
* own `sourcePath` argument, populated automatically below) — OPTIONAL so
|
|
57
|
+
* any hand-rolled structural implementer stays valid. `getRef`
|
|
58
|
+
* (`./data-ref.ts`) reads this to catch a `getRef(wrongHandle, "stem#key")`
|
|
59
|
+
* mismatch with a teaching error instead of silently resolving against the
|
|
60
|
+
* wrong asset; without it, `getRef` just skips that one check.
|
|
61
|
+
*/
|
|
62
|
+
readonly sourcePath?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Define a data asset from its Zod schema, the statically imported JSON, and
|
|
66
|
+
* its project-relative path (used verbatim in error messages, so pass the
|
|
67
|
+
* real one). Parse-on-load: an invalid file fails loud at import time, naming
|
|
68
|
+
* the file, every bad path, and the fix (§2.3, §6.5 "errors teach").
|
|
69
|
+
*
|
|
70
|
+
* Schema fields should carry `.min/.max/.default/.describe` — the same
|
|
71
|
+
* annotations every authored schema uses — so the emitted JSON Schema
|
|
72
|
+
* documents the file and (W2+) the editor renders real widgets.
|
|
73
|
+
*/
|
|
74
|
+
export declare function defineData<S extends z.ZodType>(schema: S, initial: unknown, sourcePath: string): DataHandle<z.output<S>>;
|
|
75
|
+
/**
|
|
76
|
+
* Emit the JSON Schema interchange artifact for a data asset's Zod schema
|
|
77
|
+
* (§2.1: `*.schema.json` is EMITTED, never hand-written; D4: generated and
|
|
78
|
+
* committed by default so VS Code works with no dev server running).
|
|
79
|
+
*
|
|
80
|
+
* Wraps `z.toJSONSchema` with `io: 'input'` — the one non-obvious knob:
|
|
81
|
+
* defaulted fields must be OPTIONAL in the file schema (a data file may omit
|
|
82
|
+
* them), whereas the default output mode would mark every field `required`
|
|
83
|
+
* and make VS Code reject valid files. The template's root `emit-schemas.ts`
|
|
84
|
+
* is the blessed caller (`npm run emit-schemas`).
|
|
85
|
+
*
|
|
86
|
+
* The emitted root schema also explicitly ALLOWS the `"$schema"` string
|
|
87
|
+
* property, mirroring the parse-side strip below: without it, a TABLE
|
|
88
|
+
* asset's emitted schema (`z.record` → `additionalProperties: <rowSchema>`)
|
|
89
|
+
* makes VS Code flag the data file's own `"$schema"` line as an invalid row.
|
|
90
|
+
*/
|
|
91
|
+
export declare function toDataJsonSchema(schema: z.ZodType): Record<string, unknown>;
|
|
92
|
+
/**
|
|
93
|
+
* Parse a raw `.data.json` payload: strips the `"$schema"` interchange line,
|
|
94
|
+
* validates through the Zod schema, throws the teaching error on failure.
|
|
95
|
+
* `defineData` uses this internally on load and hot swap; it is exported for
|
|
96
|
+
* emit/doctor-style scripts (the template's `emit-schemas.ts` validates every
|
|
97
|
+
* data file through it, so file validation and runtime validation can never
|
|
98
|
+
* disagree).
|
|
99
|
+
*/
|
|
100
|
+
export declare function parseDataJson<S extends z.ZodType>(schema: S, data: unknown, sourcePath: string): z.output<S>;
|
|
101
|
+
//# sourceMappingURL=data-asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-asset.d.ts","sourceRoot":"","sources":["../../src/data/data-asset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,0EAA0E;IAC1E,GAAG,IAAI,CAAC,CAAC;IACT;;;OAGG;IACH,SAAS,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC9C;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAC5C,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,GACjB,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAwBzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQ3E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAC/C,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,MAAM,GACjB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAsBb"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data assets — W1 (§2.3 consumption API).
|
|
3
|
+
*
|
|
4
|
+
* A data asset is designer-tunable game data: a JSON file in the project's
|
|
5
|
+
* `src/data/`, governed by a Zod schema (`*.schema.ts`, engineer-owned) whose
|
|
6
|
+
* emitted JSON Schema (`*.schema.json`, see {@link toDataJsonSchema}) gives
|
|
7
|
+
* VS Code validation via the data file's `"$schema"` first line. Data assets
|
|
8
|
+
* are immutable at runtime — definitions, not state (§2.1).
|
|
9
|
+
*
|
|
10
|
+
* The blessed consumption shape, scaffolded working-at-birth by the project
|
|
11
|
+
* template (`src/data/` there is the worked example — §6.2):
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import raw from './tuning.data.json';
|
|
15
|
+
* import { TuningSchema } from './tuning.schema';
|
|
16
|
+
* import { defineData } from '@engine/data/data-asset';
|
|
17
|
+
*
|
|
18
|
+
* export const tuning = defineData(TuningSchema, raw, 'src/data/tuning.data.json');
|
|
19
|
+
* // Vite HMR needs the literal dep path in THIS module (static analysis) —
|
|
20
|
+
* // this one line is the entire live-tuning wiring (['default'] not .default:
|
|
21
|
+
* // strict tsconfigs index-signature ModuleNamespace):
|
|
22
|
+
* import.meta.hot?.accept('./tuning.data.json', (m) => tuning.hotSwap(m?.['default']));
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Game code reads `tuning.get()` inside its update loop (never cache fields
|
|
26
|
+
* across frames) or `subscribe()`s; an edit to the `.data.json` — from
|
|
27
|
+
* VS Code, an agent, or the future editor Data tab (W2) — flows through Vite
|
|
28
|
+
* HMR into the running game with no remount. React roots/tools get a
|
|
29
|
+
* `useData` hook with W3's tool-hooks package (deferred with it: the engine
|
|
30
|
+
* core stays React-free).
|
|
31
|
+
*/
|
|
32
|
+
import { z } from 'zod';
|
|
33
|
+
/**
|
|
34
|
+
* Define a data asset from its Zod schema, the statically imported JSON, and
|
|
35
|
+
* its project-relative path (used verbatim in error messages, so pass the
|
|
36
|
+
* real one). Parse-on-load: an invalid file fails loud at import time, naming
|
|
37
|
+
* the file, every bad path, and the fix (§2.3, §6.5 "errors teach").
|
|
38
|
+
*
|
|
39
|
+
* Schema fields should carry `.min/.max/.default/.describe` — the same
|
|
40
|
+
* annotations every authored schema uses — so the emitted JSON Schema
|
|
41
|
+
* documents the file and (W2+) the editor renders real widgets.
|
|
42
|
+
*/
|
|
43
|
+
export function defineData(schema, initial, sourcePath) {
|
|
44
|
+
let current = parseDataJson(schema, initial, sourcePath);
|
|
45
|
+
const subscribers = new Set();
|
|
46
|
+
return {
|
|
47
|
+
get: () => current,
|
|
48
|
+
sourcePath,
|
|
49
|
+
subscribe(fn) {
|
|
50
|
+
subscribers.add(fn);
|
|
51
|
+
return () => subscribers.delete(fn);
|
|
52
|
+
},
|
|
53
|
+
hotSwap(next) {
|
|
54
|
+
let parsed;
|
|
55
|
+
try {
|
|
56
|
+
parsed = parseDataJson(schema, next, sourcePath);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
// Keep the last good value alive — see the JSDoc on DataHandle.hotSwap.
|
|
60
|
+
// biome-ignore lint/suspicious/noConsole: deliberate, greppable — a rejected live-tune edit must be loud without crashing the running game (mirrors achieved-tier.ts's direct console use)
|
|
61
|
+
console.error(`[data] hot edit rejected, keeping previous values.\n${String(err)}`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
current = parsed;
|
|
65
|
+
for (const fn of subscribers)
|
|
66
|
+
fn(current);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Emit the JSON Schema interchange artifact for a data asset's Zod schema
|
|
72
|
+
* (§2.1: `*.schema.json` is EMITTED, never hand-written; D4: generated and
|
|
73
|
+
* committed by default so VS Code works with no dev server running).
|
|
74
|
+
*
|
|
75
|
+
* Wraps `z.toJSONSchema` with `io: 'input'` — the one non-obvious knob:
|
|
76
|
+
* defaulted fields must be OPTIONAL in the file schema (a data file may omit
|
|
77
|
+
* them), whereas the default output mode would mark every field `required`
|
|
78
|
+
* and make VS Code reject valid files. The template's root `emit-schemas.ts`
|
|
79
|
+
* is the blessed caller (`npm run emit-schemas`).
|
|
80
|
+
*
|
|
81
|
+
* The emitted root schema also explicitly ALLOWS the `"$schema"` string
|
|
82
|
+
* property, mirroring the parse-side strip below: without it, a TABLE
|
|
83
|
+
* asset's emitted schema (`z.record` → `additionalProperties: <rowSchema>`)
|
|
84
|
+
* makes VS Code flag the data file's own `"$schema"` line as an invalid row.
|
|
85
|
+
*/
|
|
86
|
+
export function toDataJsonSchema(schema) {
|
|
87
|
+
const emitted = z.toJSONSchema(schema, { io: 'input' });
|
|
88
|
+
if (emitted['type'] === 'object') {
|
|
89
|
+
const properties = (emitted['properties'] ?? {});
|
|
90
|
+
properties['$schema'] ??= { type: 'string' };
|
|
91
|
+
emitted['properties'] = properties;
|
|
92
|
+
}
|
|
93
|
+
return emitted;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parse a raw `.data.json` payload: strips the `"$schema"` interchange line,
|
|
97
|
+
* validates through the Zod schema, throws the teaching error on failure.
|
|
98
|
+
* `defineData` uses this internally on load and hot swap; it is exported for
|
|
99
|
+
* emit/doctor-style scripts (the template's `emit-schemas.ts` validates every
|
|
100
|
+
* data file through it, so file validation and runtime validation can never
|
|
101
|
+
* disagree).
|
|
102
|
+
*/
|
|
103
|
+
export function parseDataJson(schema, data, sourcePath) {
|
|
104
|
+
// Strip the data file's `"$schema"` interchange line before validating —
|
|
105
|
+
// singleton (z.object, strip-mode) schemas ignored it by luck, but a TABLE
|
|
106
|
+
// asset (z.record) would try to validate it as a row and fail.
|
|
107
|
+
const payload = data !== null && typeof data === 'object' && !Array.isArray(data) && '$schema' in data
|
|
108
|
+
? Object.fromEntries(Object.entries(data).filter(([key]) => key !== '$schema'))
|
|
109
|
+
: data;
|
|
110
|
+
const result = schema.safeParse(payload);
|
|
111
|
+
if (!result.success) {
|
|
112
|
+
const issues = result.error.issues
|
|
113
|
+
.map((issue) => ` - ${issue.path.join('.') || '(root)'}: ${issue.message}`)
|
|
114
|
+
.join('\n');
|
|
115
|
+
throw new Error(`Data asset "${sourcePath}" failed its schema:\n${issues}\n` +
|
|
116
|
+
`Fix the JSON to match the Zod schema (its emitted twin, ` +
|
|
117
|
+
`"${sourcePath.replace(/\.data\.json$/, '.schema.json')}", documents every field — ` +
|
|
118
|
+
`re-emit with \`npm run emit-schemas\` if the schema changed). ` +
|
|
119
|
+
`Worked example: the template's src/data/.`);
|
|
120
|
+
}
|
|
121
|
+
return result.data;
|
|
122
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data-asset integrity core — the PURE half of W5 enforcement ("dangling
|
|
3
|
+
* `file#key` ref" / §6.7 build-path validation). No filesystem, no vite, no
|
|
4
|
+
* zod: plain parsed-JSON in, findings out, so BOTH consumers — `vgai
|
|
5
|
+
* doctor`'s data checks (`packages/editor/src/doctor/data-checks.ts`) and the
|
|
6
|
+
* build-time plugin (`./vite-plugin-data.ts`) — share one definition of "what
|
|
7
|
+
* is a ref" and "what counts as dangling" and can never drift apart.
|
|
8
|
+
*
|
|
9
|
+
* What is a ref (§2.2): a cross-asset reference is a plain string
|
|
10
|
+
* `"file#key"` — optionally with a field path, `"tuning#economy.slotGrowth"`
|
|
11
|
+
* (file `#` key `.` field-path). There is no branded-ref Zod helper shipped
|
|
12
|
+
* yet (W1 deferred it), so ref DETECTION is by convention, tuned against
|
|
13
|
+
* false positives: a string is treated as a ref IFF it matches
|
|
14
|
+
* {@link DATA_REF_PATTERN} AND its `file` prefix names a data asset that
|
|
15
|
+
* actually exists in the project (`src/data/<file>.data.json`). Strings that
|
|
16
|
+
* merely contain `#` — hex colors (`"#ff0000"`, no prefix), URLs with
|
|
17
|
+
* fragments (`/` and `:` never match), musical pitches (`"C#4"` only matches
|
|
18
|
+
* if a `C.data.json` exists) — never fire. The flip side is deliberate and
|
|
19
|
+
* honest: a ref whose file prefix names a NONEXISTENT asset is
|
|
20
|
+
* indistinguishable from an arbitrary string and is NOT flagged ("error if
|
|
21
|
+
* refs exist yet" — the check only bites once the target file exists).
|
|
22
|
+
*
|
|
23
|
+
* `dataRef` (`./data-ref.ts`) now exists, closing that flip side for anyone
|
|
24
|
+
* who adopts it: a `dataRef(target)` field's EMITTED schema carries
|
|
25
|
+
* `"x-vgai-ref": target` — a declared intent, independent of whether the
|
|
26
|
+
* target file currently exists. {@link collectDeclaredRefFields} /
|
|
27
|
+
* {@link findMissingRefTargets} below walk that (zod-free — plain emitted
|
|
28
|
+
* JSON Schema in, findings out, same purity contract as the rest of this
|
|
29
|
+
* module) to catch the §9.4 hole for DECLARED refs: renaming/deleting a
|
|
30
|
+
* target file used to silently un-check every ref into it; now a declared
|
|
31
|
+
* ref's target is checked by NAME, not by "does a string happen to look
|
|
32
|
+
* like one right now." Undeclared conventional-string refs keep the
|
|
33
|
+
* calibrated behavior above, unchanged.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* `file#key(.field)*` — prefix must look like an asset stem (letters,
|
|
37
|
+
* digits, `_`, `-`), key path is dot-separated segments of the same alphabet.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DATA_REF_PATTERN: RegExp;
|
|
40
|
+
/** One ref-shaped string found while walking a data file's parsed JSON. */
|
|
41
|
+
export interface DataRefOccurrence {
|
|
42
|
+
/** Asset stem of the data file the ref string was found IN (e.g. `"tuning"`). */
|
|
43
|
+
readonly inAsset: string;
|
|
44
|
+
/** JSON path of the string inside that file (e.g. `"rows.goblin.drops[2]"`). */
|
|
45
|
+
readonly atPath: string;
|
|
46
|
+
/** The full ref string, verbatim (e.g. `"enemies#goblin"`). */
|
|
47
|
+
readonly ref: string;
|
|
48
|
+
/** Parsed target asset stem (`"enemies"`). */
|
|
49
|
+
readonly targetAsset: string;
|
|
50
|
+
/** Parsed dot-separated key path into the target (`["goblin"]`). */
|
|
51
|
+
readonly targetKeyPath: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/** One dangling ref: the target FILE exists but the key path does not resolve in it. */
|
|
54
|
+
export interface DanglingRefFinding extends DataRefOccurrence {
|
|
55
|
+
/** The first key-path segment that failed to resolve, for the teaching message. */
|
|
56
|
+
readonly missingSegment: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Walk one data file's parsed JSON and collect every ref-shaped string whose
|
|
60
|
+
* file prefix names an asset in `assetNames`. The top-level `"$schema"`
|
|
61
|
+
* interchange line is skipped (it is wiring, not data — same special-casing
|
|
62
|
+
* as `parseDataJson`'s strip).
|
|
63
|
+
*/
|
|
64
|
+
export declare function collectDataRefs(inAsset: string, json: unknown, assetNames: ReadonlySet<string>): DataRefOccurrence[];
|
|
65
|
+
/**
|
|
66
|
+
* Find every dangling `file#key(.field)*` ref across a project's data assets.
|
|
67
|
+
*
|
|
68
|
+
* @param files parsed `.data.json` payloads keyed by asset stem (the
|
|
69
|
+
* filename minus `.data.json` — the same name the ref's prefix uses, §2.2).
|
|
70
|
+
* Pass only files that parsed as JSON; unparseable files are already an
|
|
71
|
+
* error in their own right and can't be resolved against anyway.
|
|
72
|
+
* @returns one finding per ref whose target FILE is in `files` but whose key
|
|
73
|
+
* path does not fully resolve inside it (a table row that doesn't exist, a
|
|
74
|
+
* singleton field path that walks off the object).
|
|
75
|
+
*/
|
|
76
|
+
export declare function findDanglingDataRefs(files: ReadonlyMap<string, unknown>): DanglingRefFinding[];
|
|
77
|
+
/** One `dataRef` field declared in an emitted JSON Schema. */
|
|
78
|
+
export interface DeclaredRefField {
|
|
79
|
+
/** Dot-separated field path within the schema (e.g. `"drop"`, `"loot.dropTable"`). A table's row-schema fields are reported WITHOUT a row-key segment — the declaration applies to every row alike. */
|
|
80
|
+
readonly fieldPath: string;
|
|
81
|
+
/** The asset stem the field's `dataRef(...)` call named. */
|
|
82
|
+
readonly targetStem: string;
|
|
83
|
+
}
|
|
84
|
+
/** One declared ref whose target stem names no asset that currently exists. */
|
|
85
|
+
export interface MissingRefTargetFinding {
|
|
86
|
+
readonly fieldPath: string;
|
|
87
|
+
readonly targetStem: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Walk an emitted data-asset JSON Schema (`toDataJsonSchema`'s output, or the
|
|
91
|
+
* committed `.schema.json` twin — same shape either way) and collect every
|
|
92
|
+
* field stamped `"x-vgai-ref": <target>` by `dataRef` (`./data-ref.ts`).
|
|
93
|
+
* Handles both blessed shapes (spec §2.1): a singleton's `properties`, and a
|
|
94
|
+
* table's `additionalProperties` row schema — walked with the SAME field
|
|
95
|
+
* path (a table's declared ref applies uniformly to every row, there is no
|
|
96
|
+
* per-row schema variation). Nested `properties` inside a ref-declaring
|
|
97
|
+
* field are not walked further (a ref leaf has no children); nested groups
|
|
98
|
+
* elsewhere recurse via their own `properties`.
|
|
99
|
+
*/
|
|
100
|
+
export declare function collectDeclaredRefFields(schema: unknown): DeclaredRefField[];
|
|
101
|
+
/**
|
|
102
|
+
* Every declared ref field whose target stem names no asset in
|
|
103
|
+
* `assetNames` — the §9.4 fix: a `dataRef('items')` field stays flagged if
|
|
104
|
+
* `items.data.json` is renamed or deleted, independent of whether any
|
|
105
|
+
* CURRENT value happens to look like an `items#...` string (the gap the
|
|
106
|
+
* conventional-string calibration above deliberately leaves open).
|
|
107
|
+
*/
|
|
108
|
+
export declare function findMissingRefTargets(declared: readonly DeclaredRefField[], assetNames: ReadonlySet<string>): MissingRefTargetFinding[];
|
|
109
|
+
//# sourceMappingURL=data-check-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-check-core.d.ts","sourceRoot":"","sources":["../../src/data/data-check-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;GAGG;AACH,eAAO,MAAM,gBAAgB,QAA6D,CAAC;AAE3F,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IAChC,iFAAiF;IACjF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,oEAAoE;IACpE,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C;AAED,wFAAwF;AACxF,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,mFAAmF;IACnF,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAMD;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,GAC9B,iBAAiB,EAAE,CAOrB;AA6CD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,kBAAkB,EAAE,CAU9F;AAYD,8DAA8D;AAC9D,MAAM,WAAW,gBAAgB;IAC/B,uMAAuM;IACvM,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,+EAA+E;AAC/E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAI5E;AAwBD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,gBAAgB,EAAE,EACrC,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,GAC9B,uBAAuB,EAAE,CAI3B"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data-asset integrity core — the PURE half of W5 enforcement ("dangling
|
|
3
|
+
* `file#key` ref" / §6.7 build-path validation). No filesystem, no vite, no
|
|
4
|
+
* zod: plain parsed-JSON in, findings out, so BOTH consumers — `vgai
|
|
5
|
+
* doctor`'s data checks (`packages/editor/src/doctor/data-checks.ts`) and the
|
|
6
|
+
* build-time plugin (`./vite-plugin-data.ts`) — share one definition of "what
|
|
7
|
+
* is a ref" and "what counts as dangling" and can never drift apart.
|
|
8
|
+
*
|
|
9
|
+
* What is a ref (§2.2): a cross-asset reference is a plain string
|
|
10
|
+
* `"file#key"` — optionally with a field path, `"tuning#economy.slotGrowth"`
|
|
11
|
+
* (file `#` key `.` field-path). There is no branded-ref Zod helper shipped
|
|
12
|
+
* yet (W1 deferred it), so ref DETECTION is by convention, tuned against
|
|
13
|
+
* false positives: a string is treated as a ref IFF it matches
|
|
14
|
+
* {@link DATA_REF_PATTERN} AND its `file` prefix names a data asset that
|
|
15
|
+
* actually exists in the project (`src/data/<file>.data.json`). Strings that
|
|
16
|
+
* merely contain `#` — hex colors (`"#ff0000"`, no prefix), URLs with
|
|
17
|
+
* fragments (`/` and `:` never match), musical pitches (`"C#4"` only matches
|
|
18
|
+
* if a `C.data.json` exists) — never fire. The flip side is deliberate and
|
|
19
|
+
* honest: a ref whose file prefix names a NONEXISTENT asset is
|
|
20
|
+
* indistinguishable from an arbitrary string and is NOT flagged ("error if
|
|
21
|
+
* refs exist yet" — the check only bites once the target file exists).
|
|
22
|
+
*
|
|
23
|
+
* `dataRef` (`./data-ref.ts`) now exists, closing that flip side for anyone
|
|
24
|
+
* who adopts it: a `dataRef(target)` field's EMITTED schema carries
|
|
25
|
+
* `"x-vgai-ref": target` — a declared intent, independent of whether the
|
|
26
|
+
* target file currently exists. {@link collectDeclaredRefFields} /
|
|
27
|
+
* {@link findMissingRefTargets} below walk that (zod-free — plain emitted
|
|
28
|
+
* JSON Schema in, findings out, same purity contract as the rest of this
|
|
29
|
+
* module) to catch the §9.4 hole for DECLARED refs: renaming/deleting a
|
|
30
|
+
* target file used to silently un-check every ref into it; now a declared
|
|
31
|
+
* ref's target is checked by NAME, not by "does a string happen to look
|
|
32
|
+
* like one right now." Undeclared conventional-string refs keep the
|
|
33
|
+
* calibrated behavior above, unchanged.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* `file#key(.field)*` — prefix must look like an asset stem (letters,
|
|
37
|
+
* digits, `_`, `-`), key path is dot-separated segments of the same alphabet.
|
|
38
|
+
*/
|
|
39
|
+
export const DATA_REF_PATTERN = /^([A-Za-z0-9_-]+)#([A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*)$/;
|
|
40
|
+
function isPlainObject(value) {
|
|
41
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Walk one data file's parsed JSON and collect every ref-shaped string whose
|
|
45
|
+
* file prefix names an asset in `assetNames`. The top-level `"$schema"`
|
|
46
|
+
* interchange line is skipped (it is wiring, not data — same special-casing
|
|
47
|
+
* as `parseDataJson`'s strip).
|
|
48
|
+
*/
|
|
49
|
+
export function collectDataRefs(inAsset, json, assetNames) {
|
|
50
|
+
const out = [];
|
|
51
|
+
visitForRefs(json, '', true, (node, path) => {
|
|
52
|
+
const occurrence = asRefOccurrence(inAsset, node, path, assetNames);
|
|
53
|
+
if (occurrence)
|
|
54
|
+
out.push(occurrence);
|
|
55
|
+
});
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** Depth-first walk over parsed JSON, calling `onString` for every string leaf with its JSON path. */
|
|
59
|
+
function visitForRefs(node, path, topLevel, onString) {
|
|
60
|
+
if (typeof node === 'string') {
|
|
61
|
+
onString(node, path);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(node)) {
|
|
65
|
+
node.forEach((item, i) => {
|
|
66
|
+
visitForRefs(item, `${path}[${i}]`, false, onString);
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (isPlainObject(node)) {
|
|
71
|
+
for (const [key, value] of Object.entries(node)) {
|
|
72
|
+
if (topLevel && key === '$schema')
|
|
73
|
+
continue;
|
|
74
|
+
visitForRefs(value, path ? `${path}.${key}` : key, false, onString);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** The string is a ref iff it matches the pattern AND its file prefix names a real asset. */
|
|
79
|
+
function asRefOccurrence(inAsset, value, path, assetNames) {
|
|
80
|
+
const m = DATA_REF_PATTERN.exec(value);
|
|
81
|
+
if (!m || !assetNames.has(m[1]))
|
|
82
|
+
return null;
|
|
83
|
+
return {
|
|
84
|
+
inAsset,
|
|
85
|
+
atPath: path || '(root)',
|
|
86
|
+
ref: value,
|
|
87
|
+
targetAsset: m[1],
|
|
88
|
+
targetKeyPath: m[2].split('.'),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Find every dangling `file#key(.field)*` ref across a project's data assets.
|
|
93
|
+
*
|
|
94
|
+
* @param files parsed `.data.json` payloads keyed by asset stem (the
|
|
95
|
+
* filename minus `.data.json` — the same name the ref's prefix uses, §2.2).
|
|
96
|
+
* Pass only files that parsed as JSON; unparseable files are already an
|
|
97
|
+
* error in their own right and can't be resolved against anyway.
|
|
98
|
+
* @returns one finding per ref whose target FILE is in `files` but whose key
|
|
99
|
+
* path does not fully resolve inside it (a table row that doesn't exist, a
|
|
100
|
+
* singleton field path that walks off the object).
|
|
101
|
+
*/
|
|
102
|
+
export function findDanglingDataRefs(files) {
|
|
103
|
+
const assetNames = new Set(files.keys());
|
|
104
|
+
const findings = [];
|
|
105
|
+
for (const [name, json] of files) {
|
|
106
|
+
for (const occurrence of collectDataRefs(name, json, assetNames)) {
|
|
107
|
+
const missing = firstUnresolvedSegment(files.get(occurrence.targetAsset), occurrence);
|
|
108
|
+
if (missing !== null)
|
|
109
|
+
findings.push({ ...occurrence, missingSegment: missing });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return findings;
|
|
113
|
+
}
|
|
114
|
+
/** The first key-path segment that fails to resolve in the target payload, or `null` if the whole path resolves. */
|
|
115
|
+
function firstUnresolvedSegment(target, ref) {
|
|
116
|
+
let node = target;
|
|
117
|
+
for (const segment of ref.targetKeyPath) {
|
|
118
|
+
if (!isPlainObject(node) || !(segment in node))
|
|
119
|
+
return segment;
|
|
120
|
+
node = node[segment];
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
function asSchemaNode(value) {
|
|
125
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
126
|
+
? value
|
|
127
|
+
: null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Walk an emitted data-asset JSON Schema (`toDataJsonSchema`'s output, or the
|
|
131
|
+
* committed `.schema.json` twin — same shape either way) and collect every
|
|
132
|
+
* field stamped `"x-vgai-ref": <target>` by `dataRef` (`./data-ref.ts`).
|
|
133
|
+
* Handles both blessed shapes (spec §2.1): a singleton's `properties`, and a
|
|
134
|
+
* table's `additionalProperties` row schema — walked with the SAME field
|
|
135
|
+
* path (a table's declared ref applies uniformly to every row, there is no
|
|
136
|
+
* per-row schema variation). Nested `properties` inside a ref-declaring
|
|
137
|
+
* field are not walked further (a ref leaf has no children); nested groups
|
|
138
|
+
* elsewhere recurse via their own `properties`.
|
|
139
|
+
*/
|
|
140
|
+
export function collectDeclaredRefFields(schema) {
|
|
141
|
+
const out = [];
|
|
142
|
+
walkForDeclaredRefs(schema, '', out);
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
function walkForDeclaredRefs(raw, path, out) {
|
|
146
|
+
const node = asSchemaNode(raw);
|
|
147
|
+
if (!node)
|
|
148
|
+
return;
|
|
149
|
+
if (typeof node['x-vgai-ref'] === 'string') {
|
|
150
|
+
out.push({ fieldPath: path || '(root)', targetStem: node['x-vgai-ref'] });
|
|
151
|
+
return; // a ref leaf — nothing further to walk under it
|
|
152
|
+
}
|
|
153
|
+
if (isPlainObject(node.properties)) {
|
|
154
|
+
for (const [key, child] of Object.entries(node.properties)) {
|
|
155
|
+
if (key === '$schema')
|
|
156
|
+
continue;
|
|
157
|
+
walkForDeclaredRefs(child, path ? `${path}.${key}` : key, out);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// A table's row schema (`z.record(rowSchema)` emits an object-valued
|
|
161
|
+
// `additionalProperties`) — same field-path grammar, no row-key segment.
|
|
162
|
+
if (isPlainObject(node.additionalProperties)) {
|
|
163
|
+
walkForDeclaredRefs(node.additionalProperties, path, out);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Every declared ref field whose target stem names no asset in
|
|
168
|
+
* `assetNames` — the §9.4 fix: a `dataRef('items')` field stays flagged if
|
|
169
|
+
* `items.data.json` is renamed or deleted, independent of whether any
|
|
170
|
+
* CURRENT value happens to look like an `items#...` string (the gap the
|
|
171
|
+
* conventional-string calibration above deliberately leaves open).
|
|
172
|
+
*/
|
|
173
|
+
export function findMissingRefTargets(declared, assetNames) {
|
|
174
|
+
return declared
|
|
175
|
+
.filter((d) => !assetNames.has(d.targetStem))
|
|
176
|
+
.map((d) => ({ fieldPath: d.fieldPath, targetStem: d.targetStem }));
|
|
177
|
+
}
|