Connect, collaborate, and grow with a community of TypeScript developers
Move all the seed files to a md (#56)
Sean Boult8b133603f4ed
diff --git a/__seed__/beginner/desc.md b/__seed__/beginner/desc.mdnew file mode 100644index 00000000..d9365684--- /dev/null+++ b/__seed__/beginner/desc.md@@ -0,0 +1,20 @@+Implement the built-in `Pick<T, K>` generic without using it.++Constructs a type by picking the set of properties `K` from `T`++For example:++```ts+interface Todo {+ title: string+ description: string+ completed: boolean+}++type TodoPreview = MyPick<Todo, 'title' | 'completed'>++const todo: TodoPreview = {+ title: 'Clean room',+ completed: false,+}+```diff --git a/__seed__/beginner/prompt.md b/__seed__/beginner/prompt.mdnew file mode 100644index 00000000..51f7591f--- /dev/null+++ b/__seed__/beginner/prompt.md@@ -0,0 +1,7 @@+/* _____________ Test Cases _____________ */+Extends<HelloWorld, `Hello, ${string}`>()++Extends<HelloWorld, `${string}!`>()++/* _____________ Your Code Here _____________ */+type HelloWorld = ""diff --git a/__seed__/easy/desc.md b/__seed__/easy/desc.mdnew file mode 100644index 00000000..d9365684--- /dev/null+++ b/__seed__/easy/desc.md@@ -0,0 +1,20 @@+Implement the built-in `Pick<T, K>` generic without using it.++Constructs a type by picking the set of properties `K` from `T`++For example:++```ts+interface Todo {+ title: string+ description: string+ completed: boolean+}++type TodoPreview = MyPick<Todo, 'title' | 'completed'>++const todo: TodoPreview = {+ title: 'Clean room',+ completed: false,+}+```diff --git a/__seed__/easy/prompt.md b/__seed__/easy/prompt.mdnew file mode 100644index 00000000..cef2cc13--- /dev/null+++ b/__seed__/easy/prompt.md@@ -0,0 +1,8 @@+/* _____________ Test Cases _____________ */+Extends<HelloWorld, `Hello, \${string}`>()++Extends<HelloWorld, `${string}!`>()++/* _____________ Your Code Here _____________ */+type HelloWorld = ""+diff --git a/__seed__/extreme/desc.md b/__seed__/extreme/desc.mdnew file mode 100644index 00000000..722a1021--- /dev/null+++ b/__seed__/extreme/desc.md@@ -0,0 +1,13 @@+Implement a generic `GetReadonlyKeys<T>` that returns a union of the readonly keys of an Object.+# THIS IS A TEST+For example++```ts+interface Todo {+ readonly title: string+ readonly description: string+ completed: boolean+}++type Keys = GetReadonlyKeys<Todo> // expected to be "title" | "description"+```diff --git a/__seed__/extreme/prompt.md b/__seed__/extreme/prompt.mdnew file mode 100644index 00000000..b48fffa4--- /dev/null+++ b/__seed__/extreme/prompt.md@@ -0,0 +1,7 @@+/* _____________ Test Cases _____________ */+Extends<HelloWorld, `Hello, \${string}\`>()++Extends<HelloWorld, `\${string}!\`>()++/* _____________ Your Code Here _____________ */+type HelloWorld = ""diff --git a/__seed__/hard/desc.md b/__seed__/hard/desc.mdnew file mode 100644index 00000000..5cf52573--- /dev/null+++ b/__seed__/hard/desc.md@@ -0,0 +1,35 @@+Implement a simpiled version of a Vue-like typing support.++By providing a function name `SimpleVue` (similar to `Vue.extend` or `defineComponent`), it should properly infer the `this` type inside computed and methods.++In this challenge, we assume that SimpleVue take an Object with `data`, `computed` and `methods` fields as it's only argument,++- `data` is a simple function that returns an object that exposes the context `this`, but you won't be accessible to other computed values or methods.++- `computed` is an Object of functions that take the context as `this`, doing some calculation and returns the result. The computed results should be exposed to the context as the plain return values instead of functions.++- `methods` is an Object of functions that take the context as `this` as well. Methods can access the fields exposed by `data`, `computed` as well as other `methods`. The different between `computed` is that `methods` exposed as functions as-is.++The type of `SimpleVue's return value can be arbitrary.++```ts+const instance = SimpleVue({+ data() {+ return {+ firstname: 'Type',+ lastname: 'Challenges',+ amount: 10,+ }+ },+ computed: {+ fullname() {+ return this.firstname + ' ' + this.lastname+ }+ },+ methods: {+ hi() {+ alert(this.fullname.toLowerCase())+ }+ }+})+```diff --git a/__seed__/hard/prompt.md b/__seed__/hard/prompt.mdnew file mode 100644index 00000000..b48fffa4--- /dev/null+++ b/__seed__/hard/prompt.md@@ -0,0 +1,7 @@+/* _____________ Test Cases _____________ */+Extends<HelloWorld, `Hello, \${string}\`>()++Extends<HelloWorld, `\${string}!\`>()++/* _____________ Your Code Here _____________ */+type HelloWorld = ""diff --git a/__seed__/medium/desc.md b/__seed__/medium/desc.mdnew file mode 100644index 00000000..522b5a3e--- /dev/null+++ b/__seed__/medium/desc.md@@ -0,0 +1,19 @@+Implement the built-in `Omit<T, K>` generic without using it.++Constructs a type by picking the set of properties `K` from `T`++For example:++```ts+interface Todo {+ title: string+ description: string+ completed: boolean+}++type TodoPreview = MyOmit<Todo, 'description' | 'title'>++const todo: TodoPreview = {+ completed: false,+}+```diff --git a/__seed__/medium/prompt.md b/__seed__/medium/prompt.mdnew file mode 100644index 00000000..b48fffa4--- /dev/null+++ b/__seed__/medium/prompt.md@@ -0,0 +1,7 @@+/* _____________ Test Cases _____________ */+Extends<HelloWorld, `Hello, \${string}\`>()++Extends<HelloWorld, `\${string}!\`>()++/* _____________ Your Code Here _____________ */+type HelloWorld = ""diff --git a/package.json b/package.jsonindex c817c930..3337da97 100644--- a/package.json+++ b/package.json@@ -9,6 +9,7 @@"lint": "next lint","reset": "prisma db push --force-reset --preview-feature","start": "next start",+ "refresh": "pnpm reset && pnpm prisma db seed","typecheck": "tsc --noEmit"},"dependencies": {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 4abec4db..fefa90cc 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1,5 +1,9 @@lockfileVersion: '6.0'+settings:+ autoInstallPeers: true+ excludeLinksFromLockfile: false+dependencies:'@clerk/nextjs':specifier: ^4.19.0diff --git a/prisma/challenges.mock.ts b/prisma/challenges.mock.tsindex 95619678..45e78a4c 100644--- a/prisma/challenges.mock.ts+++ b/prisma/challenges.mock.ts@@ -1,8 +1,23 @@import type { Difficulty, Prisma } from '@prisma/client';import { gId, trashId } from './seed';++import fs from 'fs';+import path from 'path';+function randomTrueOrFalse() {return Math.random() > 0.5;}++/**+ * Load markdown file synchronously from the __seed__+ */+function loadChallenegeSync(challengeSlug: string) {+ // read from the __seed__ folder all the markdown files+ //+ const filePath = path.join(__dirname, `../__seed__/${challengeSlug}.md`);+ return fs.readFileSync(filePath, 'utf8');+}+export const CHALLENGE_MAP: Record<Difficulty,(v: number) => Prisma.ChallengeCreateWithoutUserInput@@ -13,182 +28,45 @@ export const CHALLENGE_MAP: Record<updatedAt: new Date(),Bookmark: randomTrueOrFalse()? {- create: {- userId: randomTrueOrFalse() ? trashId : gId,- },- }+ create: {+ userId: randomTrueOrFalse() ? trashId : gId,+ },+ }: undefined,- description: `Implement the built-in \`Pick<T, K>\` generic without using it.--Constructs a type by picking the set of properties \`K\` from \`T\`--For example:--\`\`\`ts-interface Todo {- title: string- description: string- completed: boolean-}--type TodoPreview = MyPick<Todo, 'title' | 'completed'>--const todo: TodoPreview = {- title: 'Clean room',- completed: false,-}-\`\`\`- `,- prompt: `/* _____________ Test Cases _____________ */-Extends<HelloWorld, \`Hello, \${string}\`>()--Extends<HelloWorld, \`\${string}!\`>()--/* _____________ Your Code Here _____________ */-type HelloWorld =`,+ description: loadChallenegeSync('beginner/desc'),+ prompt: loadChallenegeSync('beginner/prompt'),difficulty: 'BEGINNER',}),EASY: (challengeIndex: number) => ({name: `Easy Challenge ${challengeIndex + 1}`,createdAt: new Date(),updatedAt: new Date(),- description: `Implement the built-in \`Pick<T, K>\` generic without using it.--Constructs a type by picking the set of properties \`K\` from \`T\`--For example:--\`\`\`ts-interface Todo {- title: string- description: string- completed: boolean-}--type TodoPreview = MyPick<Todo, 'title' | 'completed'>--const todo: TodoPreview = {- title: 'Clean room',- completed: false,-}-\`\`\`- `,- prompt: `/* _____________ Test Cases _____________ */-Extends<HelloWorld, \`Hello, \${string}\`>()--Extends<HelloWorld, \`\${string}!\`>()--/* _____________ Your Code Here _____________ */-type HelloWorld =`,+ description: loadChallenegeSync('easy/desc'),+ prompt: loadChallenegeSync('easy/prompt'),difficulty: 'EASY',}),MEDIUM: (challengeIndex: number) => ({name: `Medium Challenge ${challengeIndex + 1}`,createdAt: new Date(),updatedAt: new Date(),- description: `Implement the built-in \`Omit<T, K>\` generic without using it.--Constructs a type by picking the set of properties \`K\` from \`T\`--For example:--\`\`\`ts-interface Todo {- title: string- description: string- completed: boolean-}--type TodoPreview = MyOmit<Todo, 'description' | 'title'>--const todo: TodoPreview = {- completed: false,-}-\`\`\`- `,- prompt: `/* _____________ Test Cases _____________ */-Extends<HelloWorld, \`Hello, \${string}\`>()--Extends<HelloWorld, \`\${string}!\`>()--/* _____________ Your Code Here _____________ */-type HelloWorld =`,+ description: loadChallenegeSync('medium/desc'),+ prompt: loadChallenegeSync('medium/prompt'),difficulty: 'MEDIUM',}),HARD: (challengeIndex: number) => ({name: `Hard Challenge ${challengeIndex + 1}`,createdAt: new Date(),updatedAt: new Date(),- description: `Implement a simpiled version of a Vue-like typing support.--By providing a function name \`SimpleVue\` (similar to \`Vue.extend\` or \`defineComponent\`), it should properly infer the \`this\` type inside computed and methods.--In this challenge, we assume that SimpleVue take an Object with \`data\`, \`computed\` and \`methods\` fields as it's only argument,--- \`data\` is a simple function that returns an object that exposes the context \`this\`, but you won't be accessible to other computed values or methods.--- \`computed\` is an Object of functions that take the context as \`this\`, doing some calculation and returns the result. The computed results should be exposed to the context as the plain return values instead of functions.--- \`methods\` is an Object of functions that take the context as \`this\` as well. Methods can access the fields exposed by \`data\`, \`computed\` as well as other \`methods\`. The different between \`computed\` is that \`methods\` exposed as functions as-is.--The type of \`SimpleVue's return value can be arbitrary\.--\`\`\`ts-const instance = SimpleVue({- data() {- return {- firstname: 'Type',- lastname: 'Challenges',- amount: 10,- }- },- computed: {- fullname() {- return this.firstname + ' ' + this.lastname- }- },- methods: {- hi() {- alert(this.fullname.toLowerCase())- }- }-})-\`\`\`-`,- prompt: `/* _____________ Test Cases _____________ */-Extends<HelloWorld, \`Hello, \${string}\`>()--Extends<HelloWorld, \`\${string}!\`>()--/* _____________ Your Code Here _____________ */-type HelloWorld =`,+ description: loadChallenegeSync('hard/desc'),+ prompt: loadChallenegeSync('hard/prompt'),difficulty: 'HARD',}),EXTREME: (challengeIndex: number) => ({name: `Extreme Challenge ${challengeIndex + 1}`,createdAt: new Date(),updatedAt: new Date(),- description: `Implement a generic \`GetReadonlyKeys<T>\` that returns a union of the readonly keys of an Object.--For example--\`\`\`ts-interface Todo {- readonly title: string- readonly description: string- completed: boolean-}--type Keys = GetReadonlyKeys<Todo> // expected to be "title" | "description"-\`\`\`-`,- prompt: `/* _____________ Test Cases _____________ */-Extends<HelloWorld, \`Hello, \${string}\`>()--Extends<HelloWorld, \`\${string}!\`>()--/* _____________ Your Code Here _____________ */-type HelloWorld =`,+ description: loadChallenegeSync('extreme/desc'),+ prompt: loadChallenegeSync('extreme/prompt'),difficulty: 'EXTREME',}),};