Skip to content

Commit 552f1d4

Browse files
committed
check existing entries for schemaSerialization
1 parent 7c11a82 commit 552f1d4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/studio-ui/src/utils/courseConfigRegistration.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface ProcessedDataShape {
4242
}
4343

4444
/**
45-
* Check if a data shape is already registered in the course config
45+
* Check if a data shape is already registered in the course config with valid schema
4646
*/
4747
export function isDataShapeRegistered(
4848
dataShape: ProcessedDataShape,
@@ -53,7 +53,10 @@ export function isDataShapeRegistered(
5353
course: dataShape.course,
5454
});
5555

56-
return courseConfig.dataShapes.some((ds) => ds.name === namespacedName);
56+
const existingDataShape = courseConfig.dataShapes.find((ds) => ds.name === namespacedName);
57+
58+
// Must exist AND have serialized schema to be considered "registered"
59+
return existingDataShape !== undefined && existingDataShape.serializedZodSchema !== undefined;
5760
}
5861

5962
/**
@@ -122,7 +125,7 @@ export function registerDataShape(
122125
): boolean {
123126
if (isDataShapeRegistered(dataShape, courseConfig)) {
124127
console.log(
125-
` ℹ️ DataShape '${dataShape.name}' from '${dataShape.course}' already registered`
128+
` ℹ️ DataShape '${dataShape.name}' from '${dataShape.course}' already registered with schema`
126129
);
127130
return false;
128131
}
@@ -141,6 +144,13 @@ export function registerDataShape(
141144
serializedZodSchema = undefined;
142145
}
143146

147+
// Check if entry exists but without schema (legacy entry) - remove it
148+
const existingIndex = courseConfig.dataShapes.findIndex((ds) => ds.name === namespacedName);
149+
if (existingIndex !== -1) {
150+
console.log(` 🔧 Replacing legacy DataShape entry: ${namespacedName}`);
151+
courseConfig.dataShapes.splice(existingIndex, 1);
152+
}
153+
144154
courseConfig.dataShapes.push({
145155
name: namespacedName,
146156
questionTypes: [],

0 commit comments

Comments
 (0)