diff --git a/compiled_starters/typescript/.codecrafters/compile.sh b/compiled_starters/typescript/.codecrafters/compile.sh new file mode 100755 index 0000000..d8b7a95 --- /dev/null +++ b/compiled_starters/typescript/.codecrafters/compile.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +# (This file is empty since TypeScript programs don't use a compile step) diff --git a/compiled_starters/typescript/.codecrafters/run.sh b/compiled_starters/typescript/.codecrafters/run.sh new file mode 100755 index 0000000..c3c6b1e --- /dev/null +++ b/compiled_starters/typescript/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec bun run app/main.ts "$@" diff --git a/compiled_starters/typescript/.gitattributes b/compiled_starters/typescript/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/typescript/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/typescript/.gitignore b/compiled_starters/typescript/.gitignore new file mode 100644 index 0000000..a338e5c --- /dev/null +++ b/compiled_starters/typescript/.gitignore @@ -0,0 +1,2 @@ +# Dependency directories +node_modules/ \ No newline at end of file diff --git a/compiled_starters/typescript/README.md b/compiled_starters/typescript/README.md new file mode 100644 index 0000000..2a3172a --- /dev/null +++ b/compiled_starters/typescript/README.md @@ -0,0 +1,34 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/kafka.png) + +This is a starting point for TypeScript solutions to the +["Build Your Own Kafka" Challenge](https://codecrafters.io/challenges/kafka). + +In this challenge, you'll build a toy Kafka clone that's capable of accepting +and responding to APIVersions & Fetch API requests. You'll also learn about +encoding and decoding messages using the Kafka wire protocol. You'll also learn +about handling the network protocol, event loops, TCP sockets and more. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your Kafka implementation is in `app/main.ts`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git commit -am "pass 1st stage" # any msg +git push origin master +``` + +That's all! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `bun (1.1)` installed locally +1. Run `./your_program.sh` to run your Kafka broker, which is implemented in + `app/main.ts`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/compiled_starters/typescript/app/main.ts b/compiled_starters/typescript/app/main.ts new file mode 100644 index 0000000..03cd7b6 --- /dev/null +++ b/compiled_starters/typescript/app/main.ts @@ -0,0 +1,11 @@ +import net from "net"; + +// You can use print statements as follows for debugging, they'll be visible when running tests. +console.log("Logs from your program will appear here!"); + +// Uncomment this block to pass the first stage +// const server = net.createServer((connection) => { +// // Handle connection +// }); +// +// server.listen(9092, "127.0.0.1"); diff --git a/compiled_starters/typescript/codecrafters.yml b/compiled_starters/typescript/codecrafters.yml new file mode 100644 index 0000000..a263216 --- /dev/null +++ b/compiled_starters/typescript/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the TypeScript version used to run your code +# on Codecrafters. +# +# Available versions: bun-1.1 +language_pack: bun-1.1 diff --git a/compiled_starters/typescript/package.json b/compiled_starters/typescript/package.json new file mode 100644 index 0000000..e86856d --- /dev/null +++ b/compiled_starters/typescript/package.json @@ -0,0 +1,6 @@ +{ + "name": "@codecrafters/kafka", + "version": "1.0.0", + "type": "module", + "dependencies": {} +} diff --git a/compiled_starters/typescript/your_program.sh b/compiled_starters/typescript/your_program.sh new file mode 100755 index 0000000..45031bb --- /dev/null +++ b/compiled_starters/typescript/your_program.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Use this script to run your program LOCALLY. +# +# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit early if any commands fail + +# Copied from .codecrafters/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +exec bun run app/main.ts "$@" diff --git a/course-definition.yml b/course-definition.yml index 152e5f0..fd4f8ca 100644 --- a/course-definition.yml +++ b/course-definition.yml @@ -20,6 +20,7 @@ languages: - slug: "javascript" - slug: "python" - slug: "rust" + - slug: "typescript" marketing: difficulty: medium diff --git a/dockerfiles/bun-1.1.Dockerfile b/dockerfiles/bun-1.1.Dockerfile new file mode 100644 index 0000000..1247325 --- /dev/null +++ b/dockerfiles/bun-1.1.Dockerfile @@ -0,0 +1,18 @@ +# syntax=docker/dockerfile:1.7-labs +FROM oven/bun:1.1.27-alpine + +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb" + +WORKDIR /app + +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app + +# For reproducible builds. +# This will install the exact versions of each package specified in the lockfile. +# If package.json disagrees with bun.lockb, Bun will exit with an error. The lockfile will not be updated. +RUN bun install --frozen-lockfile + +RUN mkdir -p /app-cached +# If the node_modules directory exists, move it to /app-cached +RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi diff --git a/solutions/typescript/01-vi6/code/.codecrafters/compile.sh b/solutions/typescript/01-vi6/code/.codecrafters/compile.sh new file mode 100755 index 0000000..d8b7a95 --- /dev/null +++ b/solutions/typescript/01-vi6/code/.codecrafters/compile.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +# (This file is empty since TypeScript programs don't use a compile step) diff --git a/solutions/typescript/01-vi6/code/.codecrafters/run.sh b/solutions/typescript/01-vi6/code/.codecrafters/run.sh new file mode 100755 index 0000000..c3c6b1e --- /dev/null +++ b/solutions/typescript/01-vi6/code/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec bun run app/main.ts "$@" diff --git a/solutions/typescript/01-vi6/code/.gitattributes b/solutions/typescript/01-vi6/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/typescript/01-vi6/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/typescript/01-vi6/code/.gitignore b/solutions/typescript/01-vi6/code/.gitignore new file mode 100644 index 0000000..a338e5c --- /dev/null +++ b/solutions/typescript/01-vi6/code/.gitignore @@ -0,0 +1,2 @@ +# Dependency directories +node_modules/ \ No newline at end of file diff --git a/solutions/typescript/01-vi6/code/README.md b/solutions/typescript/01-vi6/code/README.md new file mode 100644 index 0000000..2a3172a --- /dev/null +++ b/solutions/typescript/01-vi6/code/README.md @@ -0,0 +1,34 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/kafka.png) + +This is a starting point for TypeScript solutions to the +["Build Your Own Kafka" Challenge](https://codecrafters.io/challenges/kafka). + +In this challenge, you'll build a toy Kafka clone that's capable of accepting +and responding to APIVersions & Fetch API requests. You'll also learn about +encoding and decoding messages using the Kafka wire protocol. You'll also learn +about handling the network protocol, event loops, TCP sockets and more. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your Kafka implementation is in `app/main.ts`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git commit -am "pass 1st stage" # any msg +git push origin master +``` + +That's all! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `bun (1.1)` installed locally +1. Run `./your_program.sh` to run your Kafka broker, which is implemented in + `app/main.ts`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/solutions/typescript/01-vi6/code/app/main.ts b/solutions/typescript/01-vi6/code/app/main.ts new file mode 100644 index 0000000..fe535c7 --- /dev/null +++ b/solutions/typescript/01-vi6/code/app/main.ts @@ -0,0 +1,7 @@ +import net from "net"; + +const server = net.createServer((connection) => { + // Handle connection +}); + +server.listen(9092, "127.0.0.1"); diff --git a/solutions/typescript/01-vi6/code/codecrafters.yml b/solutions/typescript/01-vi6/code/codecrafters.yml new file mode 100644 index 0000000..a263216 --- /dev/null +++ b/solutions/typescript/01-vi6/code/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the TypeScript version used to run your code +# on Codecrafters. +# +# Available versions: bun-1.1 +language_pack: bun-1.1 diff --git a/solutions/typescript/01-vi6/code/package.json b/solutions/typescript/01-vi6/code/package.json new file mode 100644 index 0000000..e86856d --- /dev/null +++ b/solutions/typescript/01-vi6/code/package.json @@ -0,0 +1,6 @@ +{ + "name": "@codecrafters/kafka", + "version": "1.0.0", + "type": "module", + "dependencies": {} +} diff --git a/solutions/typescript/01-vi6/code/your_program.sh b/solutions/typescript/01-vi6/code/your_program.sh new file mode 100755 index 0000000..45031bb --- /dev/null +++ b/solutions/typescript/01-vi6/code/your_program.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Use this script to run your program LOCALLY. +# +# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit early if any commands fail + +# Copied from .codecrafters/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +exec bun run app/main.ts "$@" diff --git a/solutions/typescript/01-vi6/diff/app/main.ts.diff b/solutions/typescript/01-vi6/diff/app/main.ts.diff new file mode 100644 index 0000000..c2b9865 --- /dev/null +++ b/solutions/typescript/01-vi6/diff/app/main.ts.diff @@ -0,0 +1,16 @@ +@@ -1,11 +1,7 @@ + import net from "net"; + +-// You can use print statements as follows for debugging, they'll be visible when running tests. +-console.log("Logs from your program will appear here!"); ++const server = net.createServer((connection) => { ++ // Handle connection ++}); + +-// Uncomment this block to pass the first stage +-// const server = net.createServer((connection) => { +-// // Handle connection +-// }); +-// +-// server.listen(9092, "127.0.0.1"); ++server.listen(9092, "127.0.0.1"); diff --git a/solutions/typescript/01-vi6/explanation.md b/solutions/typescript/01-vi6/explanation.md new file mode 100644 index 0000000..27b0c46 --- /dev/null +++ b/solutions/typescript/01-vi6/explanation.md @@ -0,0 +1,20 @@ +The entry point for your Kafka implementation is in `app/main.ts`. + +Study and uncomment the relevant code: + +```typescript +// Uncomment this block to pass the first stage +const server = net.createServer((connection) => { + // Handle connection +}); + +server.listen(9092, "127.0.0.1"); +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` diff --git a/starter_templates/typescript/code/.codecrafters/compile.sh b/starter_templates/typescript/code/.codecrafters/compile.sh new file mode 100755 index 0000000..d8b7a95 --- /dev/null +++ b/starter_templates/typescript/code/.codecrafters/compile.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +# (This file is empty since TypeScript programs don't use a compile step) diff --git a/starter_templates/typescript/code/.codecrafters/run.sh b/starter_templates/typescript/code/.codecrafters/run.sh new file mode 100755 index 0000000..c3c6b1e --- /dev/null +++ b/starter_templates/typescript/code/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +exec bun run app/main.ts "$@" diff --git a/starter_templates/typescript/code/.gitignore b/starter_templates/typescript/code/.gitignore new file mode 100644 index 0000000..a338e5c --- /dev/null +++ b/starter_templates/typescript/code/.gitignore @@ -0,0 +1,2 @@ +# Dependency directories +node_modules/ \ No newline at end of file diff --git a/starter_templates/typescript/code/app/main.ts b/starter_templates/typescript/code/app/main.ts new file mode 100644 index 0000000..03cd7b6 --- /dev/null +++ b/starter_templates/typescript/code/app/main.ts @@ -0,0 +1,11 @@ +import net from "net"; + +// You can use print statements as follows for debugging, they'll be visible when running tests. +console.log("Logs from your program will appear here!"); + +// Uncomment this block to pass the first stage +// const server = net.createServer((connection) => { +// // Handle connection +// }); +// +// server.listen(9092, "127.0.0.1"); diff --git a/starter_templates/typescript/code/package.json b/starter_templates/typescript/code/package.json new file mode 100644 index 0000000..e86856d --- /dev/null +++ b/starter_templates/typescript/code/package.json @@ -0,0 +1,6 @@ +{ + "name": "@codecrafters/kafka", + "version": "1.0.0", + "type": "module", + "dependencies": {} +} diff --git a/starter_templates/typescript/config.yml b/starter_templates/typescript/config.yml new file mode 100644 index 0000000..9abb315 --- /dev/null +++ b/starter_templates/typescript/config.yml @@ -0,0 +1,3 @@ +attributes: + required_executable: bun (1.1) + user_editable_file: app/main.ts