From 4326ba9d54bbd55286a9fe53fa07039f3389094a Mon Sep 17 00:00:00 2001 From: quinm0 Date: Fri, 17 Apr 2026 17:50:16 -0400 Subject: [PATCH] soupclown core --- bun/core/.gitignore | 34 ++++++++++++++++++ bun/core/Dockerfile | 38 ++++++++++++++++++++ bun/core/README.md | 15 ++++++++ bun/core/bun.lock | 26 ++++++++++++++ bun/core/index.ts | 8 +++++ bun/core/package.json | 12 +++++++ bun/core/tsconfig.json | 29 +++++++++++++++ bun/core/types/ClientOptions.ts | 5 +++ bun/core/types/Node.ts | 64 +++++++++++++++++++++++++++++++++ bun/core/types/ServerOptions.ts | 5 +++ 10 files changed, 236 insertions(+) create mode 100644 bun/core/.gitignore create mode 100644 bun/core/Dockerfile create mode 100644 bun/core/README.md create mode 100644 bun/core/bun.lock create mode 100644 bun/core/index.ts create mode 100644 bun/core/package.json create mode 100644 bun/core/tsconfig.json create mode 100644 bun/core/types/ClientOptions.ts create mode 100644 bun/core/types/Node.ts create mode 100644 bun/core/types/ServerOptions.ts diff --git a/bun/core/.gitignore b/bun/core/.gitignore new file mode 100644 index 0000000..a14702c --- /dev/null +++ b/bun/core/.gitignore @@ -0,0 +1,34 @@ +# dependencies (bun install) +node_modules + +# output +out +dist +*.tgz + +# code coverage +coverage +*.lcov + +# logs +logs +_.log +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# caches +.eslintcache +.cache +*.tsbuildinfo + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/bun/core/Dockerfile b/bun/core/Dockerfile new file mode 100644 index 0000000..745af55 --- /dev/null +++ b/bun/core/Dockerfile @@ -0,0 +1,38 @@ +# use the official Bun image +# see all versions at https://hub.docker.com/r/oven/bun/tags +FROM oven/bun:1 AS base +WORKDIR /usr/src/app + +# install dependencies into temp directory +# this will cache them and speed up future builds +FROM base AS install +RUN mkdir -p /temp/dev +COPY package.json bun.lock /temp/dev/ +RUN cd /temp/dev && bun install --frozen-lockfile + +# install with --production (exclude devDependencies) +RUN mkdir -p /temp/prod +COPY package.json bun.lock /temp/prod/ +RUN cd /temp/prod && bun install --frozen-lockfile --production + +# copy node_modules from temp directory +# then copy all (non-ignored) project files into the image +FROM base AS prerelease +COPY --from=install /temp/dev/node_modules node_modules +COPY . . + +# [optional] tests & build +ENV NODE_ENV=production +RUN bun test +RUN bun run build + +# copy production dependencies and source code into final image +FROM base AS release +# COPY --from=install /temp/prod/node_modules node_modules +# COPY --from=prerelease /usr/src/app/index.ts . +# COPY --from=prerelease /usr/src/app/package.json . + +# run the app +USER bun +EXPOSE 3000/tcp +ENTRYPOINT [ "bun", "run", "index.ts" ] \ No newline at end of file diff --git a/bun/core/README.md b/bun/core/README.md new file mode 100644 index 0000000..418f1b2 --- /dev/null +++ b/bun/core/README.md @@ -0,0 +1,15 @@ +# core + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.3.3. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. diff --git a/bun/core/bun.lock b/bun/core/bun.lock new file mode 100644 index 0000000..2023301 --- /dev/null +++ b/bun/core/bun.lock @@ -0,0 +1,26 @@ +{ + "lockfileVersion": 1, + "configVersion": 1, + "workspaces": { + "": { + "name": "core", + "devDependencies": { + "@types/bun": "latest", + }, + "peerDependencies": { + "typescript": "^5", + }, + }, + }, + "packages": { + "@types/bun": ["@types/bun@1.3.12", "", { "dependencies": { "bun-types": "1.3.12" } }, "sha512-DBv81elK+/VSwXHDlnH3Qduw+KxkTIWi7TXkAeh24zpi5l0B2kUg9Ga3tb4nJaPcOFswflgi/yAvMVBPrxMB+A=="], + + "@types/node": ["@types/node@25.6.0", "", { "dependencies": { "undici-types": "~7.19.0" } }, "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ=="], + + "bun-types": ["bun-types@1.3.12", "", { "dependencies": { "@types/node": "*" } }, "sha512-HqOLj5PoFajAQciOMRiIZGNoKxDJSr6qigAttOX40vJuSp6DN/CxWp9s3C1Xwm4oH7ybueITwiaOcWXoYVoRkA=="], + + "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], + + "undici-types": ["undici-types@7.19.2", "", {}, "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg=="], + } +} diff --git a/bun/core/index.ts b/bun/core/index.ts new file mode 100644 index 0000000..b5189fa --- /dev/null +++ b/bun/core/index.ts @@ -0,0 +1,8 @@ +import { Node } from "./types/Node"; + +const server = new Node({ + runServer: true, +}) + + +const client = new Node({runServer: false}) \ No newline at end of file diff --git a/bun/core/package.json b/bun/core/package.json new file mode 100644 index 0000000..ef951f2 --- /dev/null +++ b/bun/core/package.json @@ -0,0 +1,12 @@ +{ + "name": "core", + "module": "index.ts", + "type": "module", + "private": true, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5" + } +} diff --git a/bun/core/tsconfig.json b/bun/core/tsconfig.json new file mode 100644 index 0000000..bfa0fea --- /dev/null +++ b/bun/core/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + // Environment setup & latest features + "lib": ["ESNext"], + "target": "ESNext", + "module": "Preserve", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/bun/core/types/ClientOptions.ts b/bun/core/types/ClientOptions.ts new file mode 100644 index 0000000..03d0b55 --- /dev/null +++ b/bun/core/types/ClientOptions.ts @@ -0,0 +1,5 @@ +export type NodeClientOptions = { + serverHost?: string; + serverPort?: number; + runServer: false; +}; \ No newline at end of file diff --git a/bun/core/types/Node.ts b/bun/core/types/Node.ts new file mode 100644 index 0000000..eca3a44 --- /dev/null +++ b/bun/core/types/Node.ts @@ -0,0 +1,64 @@ +import type { NodeClientOptions } from "./ClientOptions"; +import type { NodeServerOptions } from "./ServerOptions"; + +export class Node { + private server: Bun.Server | null = null; + private client: WebSocket | null = null; + + constructor(opts?: NodeClientOptions | NodeServerOptions ){ + if(opts?.runServer){ + this.initServer(opts) + }else{ + this.initClient({ + runServer: false, + serverHost: 'localhost', + serverPort: 3000, + ...opts + }); + } + } + + public initServer(opts: NodeServerOptions){ + this.server = Bun.serve({ + fetch(req, server) { + // upgrade the request to a WebSocket + if (server.upgrade(req)) { + return; // do not return a Response + } + return new Response("Upgrade failed", { status: 500 }); + }, + websocket: { + ping: (ws) => { + console.log(`ws://${ws.remoteAddress} sent ping, responding pong!`) + ws.pong() + ws.sendText('pong') + }, + message: (ws, message) => { + }, + open: (ws) => { + console.log('client connected', ws.remoteAddress) + }, + close: (ws, code, reason) => { + + } + }, + port: opts.serverPort, + }); + + console.log('server running on', this.server.port) + } + + public initClient(opts: NodeClientOptions){ + const newClient = new WebSocket(`ws://${opts.serverHost}:${opts.serverPort}`) + if(newClient !== null){ + newClient.onopen = (ev) => { + console.log('opened client!') + console.log('client: ping') + newClient.ping(); + } + newClient.onmessage = (ev) => { + console.log('message from server', JSON.stringify(ev.data, null, 2)) + } + } + } +} \ No newline at end of file diff --git a/bun/core/types/ServerOptions.ts b/bun/core/types/ServerOptions.ts new file mode 100644 index 0000000..a1da958 --- /dev/null +++ b/bun/core/types/ServerOptions.ts @@ -0,0 +1,5 @@ +export type NodeServerOptions = { + serverHost?: string; + serverPort?: number; + runServer: true; +}; \ No newline at end of file