microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
iadavis/spike-3310

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/npm/qsharp/src/katas.ts

98lines · modecode

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