Skip to content

Commit bbd5a30

Browse files
authored
Add backwards compatibility for course lookup by dependency name (#952)
The PR #950 changed the provider to store courses by courseId (extracted from manifest), which broke the docs site that passes dependency names like '@skuilder/hero-course' to getCourseDB(). This adds a mapping from dependency name to courseId, allowing getCourseDB() to accept either format: - Direct courseId lookup (e.g., '2aeb8315...') for scaffolded apps - Dependency name lookup (e.g., '@skuilder/hero-course') for docs site The provider now maintains both maps and falls back to dependency name lookup if direct courseId lookup fails, ensuring backwards compatibility.
2 parents 65c5eb7 + 478c4fb commit bbd5a30

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

packages/db/src/impl/static/StaticDataLayerProvider.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export class StaticDataLayerProvider implements DataLayerProvider {
3737
private initialized: boolean = false;
3838
private courseUnpackers: Map<string, StaticDataUnpacker> = new Map();
3939
private manifests: Record<string, StaticCourseManifest> = {};
40+
// Mapping from dependency name to actual courseId for backwards compatibility
41+
private dependencyNameToCourseId: Map<string, string> = new Map();
4042

4143
constructor(config: Partial<StaticDataLayerConfig>) {
4244
this.config = {
@@ -81,6 +83,10 @@ export class StaticDataLayerProvider implements DataLayerProvider {
8183
const unpacker = new StaticDataUnpacker(finalManifest, baseUrl);
8284
this.courseUnpackers.set(courseId, unpacker);
8385

86+
// Also store mapping from dependency name to courseId for backwards compatibility
87+
// This allows lookup by either dependency name or courseId
88+
this.dependencyNameToCourseId.set(courseName, courseId);
89+
8490
logger.info(`[StaticDataLayerProvider] Successfully resolved and prepared course: ${courseName} (courseId: ${courseId})`);
8591
}
8692
} catch (e) {
@@ -111,12 +117,24 @@ export class StaticDataLayerProvider implements DataLayerProvider {
111117
}
112118

113119
getCourseDB(courseId: string): CourseDBInterface {
114-
const unpacker = this.courseUnpackers.get(courseId);
120+
// Try direct lookup by courseId first
121+
let unpacker = this.courseUnpackers.get(courseId);
122+
let actualCourseId = courseId;
123+
124+
// If not found, try lookup by dependency name (backwards compatibility)
125+
if (!unpacker) {
126+
const mappedCourseId = this.dependencyNameToCourseId.get(courseId);
127+
if (mappedCourseId) {
128+
unpacker = this.courseUnpackers.get(mappedCourseId);
129+
actualCourseId = mappedCourseId;
130+
}
131+
}
132+
115133
if (!unpacker) {
116134
throw new Error(`Course ${courseId} not found or failed to initialize in static data layer.`);
117135
}
118-
const manifest = this.manifests[courseId];
119-
return new StaticCourseDB(courseId, unpacker, this.getUserDB(), manifest);
136+
const manifest = this.manifests[actualCourseId];
137+
return new StaticCourseDB(actualCourseId, unpacker, this.getUserDB(), manifest);
120138
}
121139

122140
getCoursesDB(): CoursesDBInterface {

0 commit comments

Comments
 (0)