-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathkatas.ts
More file actions
98 lines (81 loc) · 2.11 KB
/
Copy pathkatas.ts
File metadata and controls
98 lines (81 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { default as katasContent } from "./katas-content.generated.js";
export type Example = {
type: "example";
id: string;
code: string;
};
export type TextContent = {
type: "text-content";
content: string;
};
export type ContentItem = Example | TextContent;
export type Solution = {
type: "solution";
id: string;
code: string;
};
export type ExplainedSolutionItem = ContentItem | Solution;
export type ExplainedSolution = {
type: "explained-solution";
items: ExplainedSolutionItem[];
};
export type Exercise = {
type: "exercise";
id: string;
title: string;
description: TextContent;
sourceIds: string[];
placeholderCode: string;
explainedSolution: ExplainedSolution;
/**
* Hints extracted from index.md <details> blocks.
* Only populated in the Markdown bundle (used by VS Code); undefined in the HTML bundle (playground).
*/
hints?: string[];
};
export type Answer = {
type: "answer";
items: ContentItem[];
};
export type Question = {
type: "question";
description: TextContent;
answer: Answer;
};
export type LessonItem = ContentItem | Question;
export type Lesson = {
type: "lesson";
id: string;
title: string;
items: LessonItem[];
};
export type KataSection = Exercise | Lesson;
export type Kata = {
id: string;
title: string;
sections: KataSection[];
published: boolean;
};
export async function getAllKatas(
options: { includeUnpublished?: boolean } = { includeUnpublished: false },
): Promise<Kata[]> {
return katasContent.katas.filter(
(k) => options.includeUnpublished || k.published,
) as Kata[];
}
export async function getKata(id: string): Promise<Kata> {
const katas = await getAllKatas({ includeUnpublished: true });
return (
katas.find((k) => k.id === id) ||
Promise.reject(`Failed to get kata with id: ${id}`)
);
}
export async function getExerciseSources(
exercise: Exercise,
): Promise<string[]> {
return katasContent.globalCodeSources
.filter((source) => exercise.sourceIds.indexOf(source.id) > -1)
.map((source) => source.code);
}