MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / validatePrefab

Function validatePrefab

src/world/validate.ts:72–98  ·  view source on GitHub ↗
(p: PrefabData)

Source from the content-addressed store, hash-verified

70}
71
72export function validatePrefab(p: PrefabData): ValidationResult {
73 const errors: string[] = [];
74
75 if (typeof p.schemaVersion !== 'number') {
76 errors.push('prefab.schemaVersion is missing or not a number');
77 } else if (p.schemaVersion > WORLD_SCHEMA_VERSION) {
78 errors.push('prefab.schemaVersion ' + p.schemaVersion + ' is newer than engine');
79 }
80
81 if (typeof p.id !== 'string' || p.id.length === 0) {
82 errors.push('prefab.id must be a non-empty string');
83 }
84 if (typeof p.name !== 'string') {
85 errors.push('prefab.name must be a string');
86 }
87
88 if (!Array.isArray(p.children)) {
89 errors.push('prefab.children must be an array');
90 } else {
91 const seenIds = new Set<string>();
92 for (let i = 0; i < p.children.length; i++) {
93 validatePrefabChild(errors, 'prefab.children[' + i + ']', p.children[i], seenIds);
94 }
95 }
96
97 return { ok: errors.length === 0, errors };
98}
99
100// ---- helpers ---------------------------------------------------------------
101

Callers 2

savePrefabFunction · 0.90
loadPrefabFunction · 0.90

Calls 2

validatePrefabChildFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected