From 252e4256a2eec18709f74110d3eb1f968e00e7c2 Mon Sep 17 00:00:00 2001 From: gcanti Date: Mon, 17 Jul 2023 18:20:15 +0200 Subject: [PATCH] remove outdated examples (tracing + tsplus) --- deno/.vscode/settings.json | 8 - deno/.vscode/snippets.code-snippets | 12 - deno/deno.json | 35 - deno/deno.lock | 27 - deno/import_map.json | 8 - deno/scripts/check.sh | 2 - deno/scripts/debug.sh | 2 - deno/scripts/start.sh | 2 - deno/src/debug.init.ts | 4 - deno/src/debug.ts | 2 - deno/src/lib.ts | 72 - deno/src/main.ts | 40 - starter-remix-tsc/.eslintrc.js | 4 - starter-remix-tsc/.gitignore | 7 - starter-remix-tsc/.npmrc | 1 - starter-remix-tsc/.pnpmfile.cjs | 17 - starter-remix-tsc/.prettierrc | 3 - starter-remix-tsc/.vscode/settings.json | 8 - starter-remix-tsc/README.md | 7 - starter-remix-tsc/app/entry.client.tsx | 26 - starter-remix-tsc/app/entry.server.tsx | 101 - starter-remix-tsc/app/layer/main.ts | 3 - starter-remix-tsc/app/lib/remix.server.ts | 24 - starter-remix-tsc/app/lib/remix.ts | 11 - starter-remix-tsc/app/lib/runtime.server.tsx | 43 - starter-remix-tsc/app/root.tsx | 48 - starter-remix-tsc/app/routes/index.tsx | 31 - starter-remix-tsc/app/utils.ts | 7 - starter-remix-tsc/babel.config.js | 8 - starter-remix-tsc/package.json | 44 - starter-remix-tsc/pnpm-lock.yaml | 8330 ------------------ starter-remix-tsc/public/favicon.ico | Bin 16958 -> 0 bytes starter-remix-tsc/remix.config.js | 8 - starter-remix-tsc/remix.env.d.ts | 2 - starter-remix-tsc/server.js | 101 - starter-remix-tsc/tsconfig.json | 21 - starter-traced/.gitignore | 1 - starter-traced/.prettierrc | 3 - starter-traced/.vscode/settings.json | 5 - starter-traced/README.md | 14 - starter-traced/package.json | 24 - starter-traced/pnpm-lock.yaml | 242 - starter-traced/src/main.debug.ts | 6 - starter-traced/src/main.ts | 28 - starter-traced/tsconfig.json | 12 - tsconfig.json | 4 +- 46 files changed, 1 insertion(+), 9407 deletions(-) delete mode 100644 deno/.vscode/settings.json delete mode 100644 deno/.vscode/snippets.code-snippets delete mode 100644 deno/deno.json delete mode 100644 deno/deno.lock delete mode 100644 deno/import_map.json delete mode 100755 deno/scripts/check.sh delete mode 100755 deno/scripts/debug.sh delete mode 100755 deno/scripts/start.sh delete mode 100644 deno/src/debug.init.ts delete mode 100644 deno/src/debug.ts delete mode 100644 deno/src/lib.ts delete mode 100644 deno/src/main.ts delete mode 100644 starter-remix-tsc/.eslintrc.js delete mode 100644 starter-remix-tsc/.gitignore delete mode 100644 starter-remix-tsc/.npmrc delete mode 100644 starter-remix-tsc/.pnpmfile.cjs delete mode 100644 starter-remix-tsc/.prettierrc delete mode 100644 starter-remix-tsc/.vscode/settings.json delete mode 100644 starter-remix-tsc/README.md delete mode 100644 starter-remix-tsc/app/entry.client.tsx delete mode 100644 starter-remix-tsc/app/entry.server.tsx delete mode 100644 starter-remix-tsc/app/layer/main.ts delete mode 100644 starter-remix-tsc/app/lib/remix.server.ts delete mode 100644 starter-remix-tsc/app/lib/remix.ts delete mode 100644 starter-remix-tsc/app/lib/runtime.server.tsx delete mode 100644 starter-remix-tsc/app/root.tsx delete mode 100644 starter-remix-tsc/app/routes/index.tsx delete mode 100644 starter-remix-tsc/app/utils.ts delete mode 100644 starter-remix-tsc/babel.config.js delete mode 100644 starter-remix-tsc/package.json delete mode 100644 starter-remix-tsc/pnpm-lock.yaml delete mode 100644 starter-remix-tsc/public/favicon.ico delete mode 100644 starter-remix-tsc/remix.config.js delete mode 100644 starter-remix-tsc/remix.env.d.ts delete mode 100644 starter-remix-tsc/server.js delete mode 100644 starter-remix-tsc/tsconfig.json delete mode 100644 starter-traced/.gitignore delete mode 100644 starter-traced/.prettierrc delete mode 100644 starter-traced/.vscode/settings.json delete mode 100644 starter-traced/README.md delete mode 100644 starter-traced/package.json delete mode 100644 starter-traced/pnpm-lock.yaml delete mode 100644 starter-traced/src/main.debug.ts delete mode 100644 starter-traced/src/main.ts delete mode 100644 starter-traced/tsconfig.json diff --git a/deno/.vscode/settings.json b/deno/.vscode/settings.json deleted file mode 100644 index c1b03f9..0000000 --- a/deno/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "editor.formatOnSave": true, - "deno.enable": true, - "[typescript]": { - "editor.defaultFormatter": "denoland.vscode-deno", - "editor.inlayHints.enabled": "off" - } -} diff --git a/deno/.vscode/snippets.code-snippets b/deno/.vscode/snippets.code-snippets deleted file mode 100644 index 491fddc..0000000 --- a/deno/.vscode/snippets.code-snippets +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Gen Function $": { - "prefix": "gg", - "body": ["function* ($) {}"], - "description": "Generator FUnction with _ input" - }, - "Gen Yield $": { - "prefix": "yy", - "body": ["yield* $($0)"], - "description": "Yield generator calling $()" - } -} diff --git a/deno/deno.json b/deno/deno.json deleted file mode 100644 index 8ee4f7c..0000000 --- a/deno/deno.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "compilerOptions": { - "allowJs": true, - "lib": ["deno.window"], - "strict": true - }, - "importMap": "import_map.json", - "lint": { - "files": { - "include": ["src/"] - }, - "rules": { - "tags": ["recommended"], - "include": ["ban-untagged-todo"], - "exclude": ["no-unused-vars"] - } - }, - "fmt": { - "files": { - "include": ["src/"] - }, - "options": { - "useTabs": false, - "lineWidth": 80, - "indentWidth": 2, - "singleQuote": true, - "proseWrap": "preserve" - } - }, - "test": { - "files": { - "include": ["src/"] - } - } -} diff --git a/deno/deno.lock b/deno/deno.lock deleted file mode 100644 index 5eca3d5..0000000 --- a/deno/deno.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "version": "2", - "remote": {}, - "npm": { - "specifiers": { - "@effect/io": "@effect/io@0.0.63", - "@fp-ts/data": "@fp-ts/data@0.0.39" - }, - "packages": { - "@effect/io@0.0.63": { - "integrity": "sha512-Xsa0KTuJOkJ8u5ePdaNaA21a5dTrQI8prAMXqnMabcxpDCRbDxmoXHmtPx0ZueF+jBoSxCWCKUHZzgTQa/sZhg==", - "dependencies": { - "@fp-ts/core": "@fp-ts/core@0.0.11", - "@fp-ts/data": "@fp-ts/data@0.0.39" - } - }, - "@fp-ts/core@0.0.11": { - "integrity": "sha512-BCAJBYzghwoJpcUOARJ1tui50HoYJFlV2pJlVMlsEkDFhD8MTtq8xQVpZCRF66RmtkxtGBYINCQ+5H1lRaL35Q==", - "dependencies": {} - }, - "@fp-ts/data@0.0.39": { - "integrity": "sha512-dNw1LWjQmChmdenrDuxPct+ycucgKQQboVtWqov8rkAGY3DULznoSDJZam6l2kaLdq1ScPv810N4mzLLT+cBBw==", - "dependencies": { "@fp-ts/core": "@fp-ts/core@0.0.11" } - } - } - } -} diff --git a/deno/import_map.json b/deno/import_map.json deleted file mode 100644 index 69f820e..0000000 --- a/deno/import_map.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "imports": { - "@/lib": "./src/lib.ts", - "@/debug.init": "./src/debug.init.ts", - "@/debug": "./src/debug.ts", - "@/main": "./src/main.ts" - } -} diff --git a/deno/scripts/check.sh b/deno/scripts/check.sh deleted file mode 100755 index e4c3bfa..0000000 --- a/deno/scripts/check.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -deno check src/main.ts \ No newline at end of file diff --git a/deno/scripts/debug.sh b/deno/scripts/debug.sh deleted file mode 100755 index e064fc6..0000000 --- a/deno/scripts/debug.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -deno run -A src/debug.ts \ No newline at end of file diff --git a/deno/scripts/start.sh b/deno/scripts/start.sh deleted file mode 100755 index a783685..0000000 --- a/deno/scripts/start.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -deno run -A src/main.ts \ No newline at end of file diff --git a/deno/src/debug.init.ts b/deno/src/debug.init.ts deleted file mode 100644 index eb3c94a..0000000 --- a/deno/src/debug.init.ts +++ /dev/null @@ -1,4 +0,0 @@ -import * as Debug from 'npm:@effect/io/Debug'; - -Debug.runtimeDebug.getCallTrace = Debug.getCallTraceFromNewError; -Debug.runtimeDebug.traceFilter = (trace) => !trace.includes('.cache'); diff --git a/deno/src/debug.ts b/deno/src/debug.ts deleted file mode 100644 index ccf0091..0000000 --- a/deno/src/debug.ts +++ /dev/null @@ -1,2 +0,0 @@ -import {} from '@/debug.init'; -import {} from '@/main'; diff --git a/deno/src/lib.ts b/deno/src/lib.ts deleted file mode 100644 index 7afddc6..0000000 --- a/deno/src/lib.ts +++ /dev/null @@ -1,72 +0,0 @@ -import * as Cause from 'npm:@effect/io/Cause'; -import * as Effect from 'npm:@effect/io/Effect'; -import * as Fiber from 'npm:@effect/io/Fiber'; -import * as Exit from 'npm:@effect/io/Exit'; -import * as Logger from 'npm:@effect/io/Logger'; -import * as Layer from 'npm:@effect/io/Layer'; -import { pipe } from 'npm:@fp-ts/data/Function'; - -export const runMain = (effect: Effect.Effect) => { - let interrupt = false; - - const fiber = pipe( - effect, - Effect.matchCauseEffect( - (cause) => - Cause.isInterruptedOnly(cause) - ? Effect.unit() - : Effect.logErrorCause(cause), - () => Effect.unit(), - ), - Effect.traced(void 0), - Effect.provideSomeLayer( - Deno.env.get('LOGGER') === 'LOGFMT' - ? Logger.logFmt - : Layer.environment(), - ), - Effect.unsafeFork, - ); - - fiber.unsafeAddObserver((exit) => { - if (!interrupt) { - if (Exit.isFailure(exit) && !Cause.isInterruptedOnly(exit.cause)) { - Deno.exit(1); - } else { - Deno.exit(0); - } - } - }); - - Deno.addSignalListener( - 'SIGINT', - () => { - interrupt = true; - pipe( - Fiber.interrupt(fiber), - Effect.flatMap( - (exit) => - Exit.isFailure(exit) - ? (Cause.isInterruptedOnly(exit.cause) ? Effect.unit() : pipe( - Effect.logErrorCause(exit.cause), - Effect.flatMap(() => Effect.failCause(exit.cause)), - )) - : Exit.succeed(exit.value), - ), - Effect.provideSomeLayer(Logger.logFmt), - Effect.unsafeFork, - ).unsafeAddObserver((exit) => { - if (Exit.isFailure(exit) && !Cause.isInterruptedOnly(exit.cause)) { - Deno.exit(1); - } else { - Deno.exit(0); - } - }); - }, - ); -}; - -export * as Exit from 'npm:@effect/io/Exit'; -export * as Queue from 'npm:@effect/io/Queue'; -export * as Duration from 'npm:@fp-ts/data/Duration'; -export * as Effect from 'npm:@effect/io/Effect'; -export { pipe } from 'npm:@fp-ts/data/Function'; diff --git a/deno/src/main.ts b/deno/src/main.ts deleted file mode 100644 index 9d8874b..0000000 --- a/deno/src/main.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Duration, Effect, pipe, Queue, runMain } from '@/lib'; - -const pull = (queue: Queue.Queue) => - pipe( - Effect.gen(function* ($) { - while (true) { - const n = yield* $(Queue.take(queue)); - yield* $(Effect.log(`got: ${n}`)); - } - }), - Effect.onInterrupt(() => Effect.log(`interrupted pull`)), - ); - -const push = (queue: Queue.Queue) => - pipe( - Effect.gen(function* ($) { - let n = 0; - while (true) { - yield* $(Effect.sleep(Duration.millis(500))); - yield* $(Queue.offer(n++)(queue)); - - if (n > 6) { - yield* $(Effect.die('boom')); - } - } - }), - Effect.onInterrupt(() => Effect.log(`interrupted push`)), - ); - -const main = Effect.gen(function* ($) { - const queue = yield* $(Queue.unbounded()); - - for (let i = 0; i < 3; i++) { - yield* $(Effect.fork(pull(queue))); - } - - return yield* $(push(queue)); -}); - -runMain(main); diff --git a/starter-remix-tsc/.eslintrc.js b/starter-remix-tsc/.eslintrc.js deleted file mode 100644 index 2061cd2..0000000 --- a/starter-remix-tsc/.eslintrc.js +++ /dev/null @@ -1,4 +0,0 @@ -/** @type {import('eslint').Linter.Config} */ -module.exports = { - extends: ["@remix-run/eslint-config", "@remix-run/eslint-config/node"], -}; diff --git a/starter-remix-tsc/.gitignore b/starter-remix-tsc/.gitignore deleted file mode 100644 index 6a598bd..0000000 --- a/starter-remix-tsc/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -node_modules - -/.cache -/build -/public/build -.env -./plugins/*.js \ No newline at end of file diff --git a/starter-remix-tsc/.npmrc b/starter-remix-tsc/.npmrc deleted file mode 100644 index c483022..0000000 --- a/starter-remix-tsc/.npmrc +++ /dev/null @@ -1 +0,0 @@ -shamefully-hoist=true \ No newline at end of file diff --git a/starter-remix-tsc/.pnpmfile.cjs b/starter-remix-tsc/.pnpmfile.cjs deleted file mode 100644 index bd408bd..0000000 --- a/starter-remix-tsc/.pnpmfile.cjs +++ /dev/null @@ -1,17 +0,0 @@ -function readPackage(pkg, context) { - if (pkg.dependencies["typescript"]) { - delete pkg.dependencies["typescript"] - } - - if (pkg.peerDependencies["typescript"]) { - delete pkg.peerDependencies["typescript"] - } - - return pkg; -} - -module.exports = { - hooks: { - readPackage, - }, -}; diff --git a/starter-remix-tsc/.prettierrc b/starter-remix-tsc/.prettierrc deleted file mode 100644 index de753c5..0000000 --- a/starter-remix-tsc/.prettierrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "printWidth": 100 -} diff --git a/starter-remix-tsc/.vscode/settings.json b/starter-remix-tsc/.vscode/settings.json deleted file mode 100644 index 7196d21..0000000 --- a/starter-remix-tsc/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "typescript.tsdk": "node_modules/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true, - "editor.formatOnSave": true, - "[typescriptreact]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - } -} diff --git a/starter-remix-tsc/README.md b/starter-remix-tsc/README.md deleted file mode 100644 index a4d53ef..0000000 --- a/starter-remix-tsc/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Effect Starter Remix - -This project is a quick-start that uses remix with express and integrates effect for loaders. - -## Install & Run - -Run `yarn install` and `yarn run dev` to start. diff --git a/starter-remix-tsc/app/entry.client.tsx b/starter-remix-tsc/app/entry.client.tsx deleted file mode 100644 index 8ff7a75..0000000 --- a/starter-remix-tsc/app/entry.client.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { RemixBrowser } from "@remix-run/react"; -import { startTransition, StrictMode } from "react"; -import { hydrateRoot } from "react-dom/client"; - -function hydrate() { - startTransition(() => { - hydrateRoot( - document, - process.env["NODE_ENV"] === "development" ? ( - - - - ) : ( - - ) - ); - }); -} - -if (window.requestIdleCallback) { - window.requestIdleCallback(hydrate); -} else { - // Safari doesn't support requestIdleCallback - // https://caniuse.com/requestidlecallback - window.setTimeout(hydrate, 1); -} diff --git a/starter-remix-tsc/app/entry.server.tsx b/starter-remix-tsc/app/entry.server.tsx deleted file mode 100644 index 43831bb..0000000 --- a/starter-remix-tsc/app/entry.server.tsx +++ /dev/null @@ -1,101 +0,0 @@ -import { PassThrough } from "stream"; -import type { EntryContext } from "@remix-run/node"; -import { Response } from "@remix-run/node"; -import { RemixServer } from "@remix-run/react"; -import isbot from "isbot"; -import { renderToPipeableStream } from "react-dom/server"; - -const ABORT_DELAY = 5000; - -export default function handleRequest( - request: Request, - responseStatusCode: number, - responseHeaders: Headers, - remixContext: EntryContext -) { - return isbot(request.headers.get("user-agent")) - ? handleBotRequest(request, responseStatusCode, responseHeaders, remixContext) - : handleBrowserRequest(request, responseStatusCode, responseHeaders, remixContext); -} - -function handleBotRequest( - request: Request, - responseStatusCode: number, - responseHeaders: Headers, - remixContext: EntryContext -) { - return new Promise((resolve, reject) => { - let didError = false; - - const { pipe, abort } = renderToPipeableStream( - , - { - onAllReady() { - const body = new PassThrough(); - - responseHeaders.set("Content-Type", "text/html"); - - resolve( - new Response(body, { - headers: responseHeaders, - status: didError ? 500 : responseStatusCode, - }) - ); - - pipe(body); - }, - onShellError(error: unknown) { - reject(error); - }, - onError(error: unknown) { - didError = true; - - console.error(error); - }, - } - ); - - setTimeout(abort, ABORT_DELAY); - }); -} - -function handleBrowserRequest( - request: Request, - responseStatusCode: number, - responseHeaders: Headers, - remixContext: EntryContext -) { - return new Promise((resolve, reject) => { - let didError = false; - - const { pipe, abort } = renderToPipeableStream( - , - { - onShellReady() { - const body = new PassThrough(); - - responseHeaders.set("Content-Type", "text/html"); - - resolve( - new Response(body, { - headers: responseHeaders, - status: didError ? 500 : responseStatusCode, - }) - ); - - pipe(body); - }, - onShellError(err: unknown) { - reject(err); - }, - onError(error: unknown) { - didError = true; - - console.error(error); - }, - } - ); - - setTimeout(abort, ABORT_DELAY); - }); -} diff --git a/starter-remix-tsc/app/layer/main.ts b/starter-remix-tsc/app/layer/main.ts deleted file mode 100644 index 42aef6d..0000000 --- a/starter-remix-tsc/app/layer/main.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Layer } from "~/utils"; - -export const appLayer = Layer.environment(); diff --git a/starter-remix-tsc/app/lib/remix.server.ts b/starter-remix-tsc/app/lib/remix.server.ts deleted file mode 100644 index e1b090c..0000000 --- a/starter-remix-tsc/app/lib/remix.server.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { DataFunctionArgs, LoaderFunction } from "@remix-run/node"; -import { Context, pipe } from "effect/data"; -import { Effect } from "effect/io"; -import type { Codec } from "effect/schema"; - -export const LoaderArgs = Context.Tag(); - -export const makeLoader: ( - type: Codec.Codec -) => (self: Effect.Effect) => LoaderFunction = - (type) => (self) => (data) => - import("~/lib/runtime.server") - .then((_) => _.deferredRuntime) - .then(({ runtime }) => - runtime.unsafeRunPromise( - pipe( - self, - Effect.map((a) => type.encode(a)), - Effect.provideService(LoaderArgs)(data) - ) - ) - ); - -export const requestURL = Effect.serviceWith(LoaderArgs)((_) => new URL(_.request.url)); diff --git a/starter-remix-tsc/app/lib/remix.ts b/starter-remix-tsc/app/lib/remix.ts deleted file mode 100644 index 75c3bfb..0000000 --- a/starter-remix-tsc/app/lib/remix.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useLoaderData as useLoaderDataRemix } from "@remix-run/react"; -import type { Codec } from "effect/schema"; - -export const useLoaderData = (type: Codec.Codec) => { - const data = useLoaderDataRemix(); - const parsed = type.decode(data); - if (parsed._tag === "Left") { - throw new Error(JSON.stringify(parsed.left)); - } - return parsed.right; -}; diff --git a/starter-remix-tsc/app/lib/runtime.server.tsx b/starter-remix-tsc/app/lib/runtime.server.tsx deleted file mode 100644 index 1be4f73..0000000 --- a/starter-remix-tsc/app/lib/runtime.server.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { pipe } from "effect/data"; -import { Effect, Exit, Layer, Scope } from "effect/io"; -import { appLayer } from "~/layer/main"; - -const appRuntime = (layer: Layer.Layer) => - Effect.gen(function* ($) { - const scope = yield* $(Scope.make()); - const env = yield* $(Layer.buildWithScope(scope)(layer)); - const runtime = yield* $(pipe(Effect.runtime(), Effect.provideEnvironment(env))); - - return { - runtime, - clean: Scope.close(Exit.unit())(scope), - }; - }); - -const runtimeSymbol = Symbol.for("@effect/examples/starter-remix-tsc/runtime"); - -const existing = process.listeners("beforeExit").find((listener) => runtimeSymbol in listener); - -if (existing) { - process.removeListener("beforeExit", existing); -} - -export const deferredRuntime = ( - existing ? (existing as () => Promise)() : Promise.resolve() -).then(() => Effect.unsafeRunPromise(appRuntime(appLayer))); - -const cleanup = Object.assign( - () => - Effect.unsafeRunPromise( - pipe( - Effect.promise(() => deferredRuntime), - Effect.flatMap((_) => _.clean) - ) - ), - { [runtimeSymbol]: true } -); - -// @ts-expect-error -globalThis[runtimeSymbol] = deferredRuntime; - -process.on("beforeExit", cleanup); diff --git a/starter-remix-tsc/app/root.tsx b/starter-remix-tsc/app/root.tsx deleted file mode 100644 index f0a3f3e..0000000 --- a/starter-remix-tsc/app/root.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import type { MetaFunction } from "@remix-run/node"; -import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration } from "@remix-run/react"; - -export const meta: MetaFunction = () => ({ - charset: "utf-8", - title: "New Remix App", - viewport: "width=device-width,initial-scale=1", -}); - -export default function App() { - return ( - - - - - {process.env["NODE_ENV"] !== "production" ? ( -