From 91880fdb057eefab6b19469da6fc40796bff155b Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Fri, 23 Dec 2022 17:39:04 -0800 Subject: [PATCH 01/94] begin fresh refactor --- .devcontainer/devcontainer.json | 8 +++----- .vscode/extensions.json | 1 + .vscode/settings.json | 7 ++----- components/Button.tsx | 12 ++++++++++++ components/Meta.tsx | 11 +++++++++++ deno.jsonc => deno.json | 5 ++++- dev.ts | 3 +++ dprint.json | 2 +- fresh.gen.ts | 30 ++++++++++++++++++++++++++++++ import_map.json | 10 ++++++++++ islands/Counter.tsx | 17 +++++++++++++++++ main.ts | 19 +++++++++++++++++++ routes/[...path].tsx | 12 ++++++++++++ routes/_404.tsx | 5 +++++ routes/_500.tsx | 11 +++++++++++ routes/_app.tsx | 9 +++++++++ routes/docs/[...path].tsx | 6 ++++++ routes/index.tsx | 12 ++++++++++++ serve.ts | 1 + static/favicon.ico | Bin 0 -> 1150 bytes static/logo.svg | 1 + twind.config.ts | 5 +++++ words.txt | 4 ++++ 23 files changed, 179 insertions(+), 12 deletions(-) create mode 100644 components/Button.tsx create mode 100644 components/Meta.tsx rename deno.jsonc => deno.json (90%) create mode 100644 dev.ts create mode 100644 fresh.gen.ts create mode 100644 islands/Counter.tsx create mode 100644 main.ts create mode 100644 routes/[...path].tsx create mode 100644 routes/_404.tsx create mode 100644 routes/_500.tsx create mode 100644 routes/_app.tsx create mode 100644 routes/docs/[...path].tsx create mode 100644 routes/index.tsx create mode 100644 static/favicon.ico create mode 100644 static/logo.svg create mode 100644 twind.config.ts diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 318336b0c..719c64754 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,17 +10,14 @@ "**/.git/subtree-cache/**": true, "target/**": true }, - "[jsonc]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, "[yaml]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[typescript]": { "editor.defaultFormatter": "dprint.dprint" }, - "deno.codeLens.testArgs": ["--no-check=remote", "-A", "-L=info"], - "deno.config": "./deno.jsonc", + "deno.codeLens.testArgs": ["-A", "-L=info"], + "deno.config": "./deno.json", "deno.enable": true, "deno.lint": true, "editor.defaultFormatter": "dprint.dprint", @@ -34,6 +31,7 @@ "dprint.dprint", "esbenp.prettier-vscode", "ms-azuretools.vscode-docker", + "sastan.twind-intellisense", "streetsidesoftware.code-spell-checker", "vadimcn.vscode-lldb", "bungcip.better-toml" diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 9757ed490..2b2bfca54 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -5,6 +5,7 @@ "dprint.dprint", "esbenp.prettier-vscode", "ms-azuretools.vscode-docker", + "sastan.twind-intellisense", "streetsidesoftware.code-spell-checker", "vadimcn.vscode-lldb" ] diff --git a/.vscode/settings.json b/.vscode/settings.json index 736116339..d6be1939d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,15 +1,12 @@ { - "[jsonc]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, "[yaml]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[typescript]": { "editor.defaultFormatter": "dprint.dprint" }, - "deno.codeLens.testArgs": ["--no-check=remote", "-A", "-L=info"], - "deno.config": "./deno.jsonc", + "deno.codeLens.testArgs": ["-A", "-L=info"], + "deno.config": "./deno.json", "deno.importMap": "./import_map.json", "deno.suggest.imports.hosts": { "https://deno.land": true, diff --git a/components/Button.tsx b/components/Button.tsx new file mode 100644 index 000000000..909d38078 --- /dev/null +++ b/components/Button.tsx @@ -0,0 +1,12 @@ +import { JSX } from "preact"; +import { IS_BROWSER } from "$fresh/runtime.ts"; + +export function Button(props: JSX.HTMLAttributes) { + return ( + + + + ); +} diff --git a/main.ts b/main.ts new file mode 100644 index 000000000..e0c64697c --- /dev/null +++ b/main.ts @@ -0,0 +1,19 @@ +/// +/// +/// +/// +/// + +import twindPlugin from "$fresh/plugins/twind.ts" +import { start } from "$fresh/server.ts" +import manifest from "./fresh.gen.ts" +import twindConfig from "./twind.config.ts" + +const abortController = new AbortController() + +await start(manifest, { + signal: abortController.signal, + plugins: [ + twindPlugin(twindConfig), + ], +}) diff --git a/routes/[...path].tsx b/routes/[...path].tsx new file mode 100644 index 000000000..a60ae7e15 --- /dev/null +++ b/routes/[...path].tsx @@ -0,0 +1,12 @@ +import { Handlers } from "$fresh/server.ts" + +export const handler: Handlers = { + GET(_req, ctx) { + const path = ctx.params.path! + try { + return new Response(Deno.readFileSync(path)) + } catch (_e) { + return ctx.renderNotFound() + } + }, +} diff --git a/routes/_404.tsx b/routes/_404.tsx new file mode 100644 index 000000000..a59e8dec4 --- /dev/null +++ b/routes/_404.tsx @@ -0,0 +1,5 @@ +import { UnknownPageProps } from "$fresh/server.ts" + +export default function NotFoundPage({ url }: UnknownPageProps) { + return

404 not found: {url.pathname}

+} diff --git a/routes/_500.tsx b/routes/_500.tsx new file mode 100644 index 000000000..a4b68a423 --- /dev/null +++ b/routes/_500.tsx @@ -0,0 +1,11 @@ +import { ErrorPageProps } from "$fresh/server.ts" + +export default function ErrorPage({ error }: ErrorPageProps) { + return ( +

+ 500 internal error: {error instanceof Error + ? error.message + : `the following data was thrown: ${JSON.stringify(error)}`} +

+ ) +} diff --git a/routes/_app.tsx b/routes/_app.tsx new file mode 100644 index 000000000..d68af7cd5 --- /dev/null +++ b/routes/_app.tsx @@ -0,0 +1,9 @@ +import { AppProps } from "$fresh/server.ts" + +export default function App({ Component }: AppProps) { + return ( + + + + ) +} diff --git a/routes/docs/[...path].tsx b/routes/docs/[...path].tsx new file mode 100644 index 000000000..433c51ef1 --- /dev/null +++ b/routes/docs/[...path].tsx @@ -0,0 +1,6 @@ +import { PageProps } from "$fresh/server.ts" + +export default function DocsPage({ params }: PageProps) { + const path = params.path! + return

Docs –– {path}

+} diff --git a/routes/index.tsx b/routes/index.tsx new file mode 100644 index 000000000..08be6d09e --- /dev/null +++ b/routes/index.tsx @@ -0,0 +1,12 @@ +import { Meta } from "../components/Meta.tsx" + +export default function LandingPage() { + return ( + <> + , +
+ Welcome to the Capi Console +
, + + ) +} diff --git a/serve.ts b/serve.ts index 11e7a4ac9..1e9fc2c1e 100644 --- a/serve.ts +++ b/serve.ts @@ -1,4 +1,5 @@ import { LocalCapiCodegenServer } from "./server/local.ts" console.log("Listening on http://localhost:5646/") + new LocalCapiCodegenServer().listen(5646) diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..70fab93d18a8a1cb07fdb1fcdcb64848d62c20a7 GIT binary patch literal 1150 zcmZQzU<5(|0R|wcz>vYhz#zuJz@P!dKp~(AL>x#lFaYI*xFHzKhY&adO>oe>L;WgT^`wfbU9-9!%06e;f)?9$o|L1MpuuGk4+y;44ZmvVlegS OG&Z#ZEC#fmd;kDpmbuaZ literal 0 HcmV?d00001 diff --git a/static/logo.svg b/static/logo.svg new file mode 100644 index 000000000..38f7b7e7d --- /dev/null +++ b/static/logo.svg @@ -0,0 +1 @@ + diff --git a/twind.config.ts b/twind.config.ts new file mode 100644 index 000000000..6bc290e28 --- /dev/null +++ b/twind.config.ts @@ -0,0 +1,5 @@ +import { Options } from "$fresh/plugins/twind.ts" + +export default ((): Options => ({ + selfURL: import.meta.url, +}))() diff --git a/words.txt b/words.txt index 099185b0c..56beb3233 100644 --- a/words.txt +++ b/words.txt @@ -210,3 +210,7 @@ lparachain unioned rustc procps +twind +preact +asynciterable +sastan From 23886ecd18daf5ee55456434de914e352ac1c6f8 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Fri, 23 Dec 2022 21:16:35 -0800 Subject: [PATCH 02/94] continued --- fresh.gen.ts | 15 +++++----- islands/Counter.tsx | 17 ----------- routes/autocomplete/[...path].ts | 11 +++++++ .../.well-known/deno-import-intellisense.json | 29 +++++++++++++++++++ 4 files changed, 47 insertions(+), 25 deletions(-) delete mode 100644 islands/Counter.tsx create mode 100644 routes/autocomplete/[...path].ts create mode 100644 static/.well-known/deno-import-intellisense.json diff --git a/fresh.gen.ts b/fresh.gen.ts index 35df6dd9d..9ee32c907 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -7,9 +7,9 @@ import * as $0 from "./routes/[...path].tsx"; import * as $1 from "./routes/_404.tsx"; import * as $2 from "./routes/_500.tsx"; import * as $3 from "./routes/_app.tsx"; -import * as $4 from "./routes/docs/[...path].tsx"; -import * as $5 from "./routes/index.tsx"; -import * as $$0 from "./islands/Counter.tsx"; +import * as $4 from "./routes/autocomplete/[...path].ts"; +import * as $5 from "./routes/docs/[...path].tsx"; +import * as $6 from "./routes/index.tsx"; const manifest = { routes: { @@ -17,12 +17,11 @@ const manifest = { "./routes/_404.tsx": $1, "./routes/_500.tsx": $2, "./routes/_app.tsx": $3, - "./routes/docs/[...path].tsx": $4, - "./routes/index.tsx": $5, - }, - islands: { - "./islands/Counter.tsx": $$0, + "./routes/autocomplete/[...path].ts": $4, + "./routes/docs/[...path].tsx": $5, + "./routes/index.tsx": $6, }, + islands: {}, baseUrl: import.meta.url, config, }; diff --git a/islands/Counter.tsx b/islands/Counter.tsx deleted file mode 100644 index 1b437bf2f..000000000 --- a/islands/Counter.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { useState } from "preact/hooks"; -import { Button } from "../components/Button.tsx"; - -interface CounterProps { - start: number; -} - -export default function Counter(props: CounterProps) { - const [count, setCount] = useState(props.start); - return ( -
-

{count}

- - -
- ); -} diff --git a/routes/autocomplete/[...path].ts b/routes/autocomplete/[...path].ts new file mode 100644 index 000000000..8fea06edf --- /dev/null +++ b/routes/autocomplete/[...path].ts @@ -0,0 +1,11 @@ +import { Handlers } from "$fresh/server.ts" + +export const handler: Handlers = { + GET(_req) { + try { + return new Response("TODO") + } catch (_e) { + throw new Error() + } + }, +} diff --git a/static/.well-known/deno-import-intellisense.json b/static/.well-known/deno-import-intellisense.json new file mode 100644 index 000000000..f1f0fa1ff --- /dev/null +++ b/static/.well-known/deno-import-intellisense.json @@ -0,0 +1,29 @@ +{ + "$schema": "https://deno.land/x/deno@v1.29.1/cli/schemas/registry-completions.v2.json", + "version": 2, + "registries": [ + { + "schema": "/:version(@[^/]*)?/:file*", + "variables": [ + { "key": "version", "url": "/autocomplete/version" }, + { "key": "file", "url": "/${version}/autocomplete/moduleFile/${file}" } + ] + }, + { + "schema": "/:version(@[^/]*)/:_proxy(proxy)/:chainUrl(dev:\\w*|wss?:[^/]*)/:chainVersion(@[^/]+)/:file*", + "variables": [ + { "key": "version", "url": "/autocomplete/version" }, + { "key": "_proxy", "url": "/autocomplete/null" }, + { "key": "chainUrl", "url": "/${version}/autocomplete/chainUrl/${chainUrl}" }, + { + "key": "chainVersion", + "url": "/${version}/autocomplete/chainVersion/${chainUrl}/${chainVersion}" + }, + { + "key": "file", + "url": "/${version}/autocomplete/chainFile/${chainUrl}/${chainVersion}/${file}" + } + ] + } + ] +} From 3238deeb0d704c0e39854e308676b687ee010649 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Thu, 5 Jan 2023 05:57:53 -0500 Subject: [PATCH 03/94] continued --- .vscode/extensions.json | 1 - .vscode/settings.json | 5 +- _tasks/gen_deploy.ts | 32 ++--- cache.ts | 18 --- components/Button.tsx | 12 -- components/Meta.tsx | 11 -- deno.json => deno.jsonc | 7 +- deps/preact.ts | 1 + deps/preact_render_to_string.ts | 1 + deps/std/encoding/toml.ts | 1 + deps/std/http/http_status.ts | 1 + deps/std/http/negotiation.ts | 1 + dev.ts | 3 - effects/extrinsic.test.ts | 78 +++++++++-- examples/batch.ts | 40 +++--- fresh.gen.ts | 29 ----- help.txt | 1 + import_map.json | 10 -- main.ts | 53 ++++++-- mod.ts | 17 ++- routes/[...path].tsx | 12 -- routes/_404.tsx | 5 - routes/_500.tsx | 11 -- routes/_app.tsx | 9 -- routes/autocomplete/[...path].ts | 11 -- routes/docs/[...path].tsx | 6 - routes/index.tsx | 12 -- serve.ts | 5 - server/Ctx.ts | 12 ++ server/Readme.md | 45 +++++++ server/blah/LocalCompasses.ts | 49 +++++++ server/local/RouteInfo.test.ts | 63 +++++++++ server/local/RouteInfo.ts | 122 ++++++++++++++++++ server/local/pages/404.tsx | 5 + server/local/pages/500.tsx | 5 + server/local/pages/Code.tsx | 5 + server/local/pages/Landing.tsx | 5 + server/local/pages/mod.ts | 4 + server/local/serve.ts | 61 +++++++++ .../.well-known/deno-import-intellisense.json | 0 {static => server/local/static}/favicon.ico | Bin server/mod.ts | 6 +- server/provider/Bin.ts | 2 + server/provider/PolkadotDev.test.ts | 10 ++ server/provider/PolkadotDev.ts | 103 +++++++++++++++ server/provider/Smoldot.ts | 2 + server/provider/Workspace.ts | 2 + server/provider/Ws.test.ts | 10 ++ server/provider/Ws.ts | 31 +++++ server/provider/Zombienet.ts | 92 +++++++++++++ server/provider/common.ts | 16 +++ server/provider/mod.ts | 2 + {server => server_prev}/capi_repo.ts | 0 {server => server_prev}/codecs.test.ts | 0 {server => server_prev}/completions.json | 0 {server => server_prev}/deploy.ts | 0 {server => server_prev}/git_utils.ts | 0 {server => server_prev}/local.ts | 0 server_prev/mod.ts | 3 + {server => server_prev}/server.ts | 0 static/logo.svg | 1 - test_util/clients/kusama.ts | 3 - test_util/clients/mod.ts | 4 - test_util/clients/polkadot.ts | 3 - test_util/clients/rococo.ts | 3 - test_util/clients/westend.ts | 3 - test_util/common.ts | 83 ------------ test_util/ctx.ts | 66 ---------- test_util/extrinsic.ts | 59 --------- test_util/local.ts | 83 ------------ test_util/mod.ts | 12 -- test_util/zombienet.ts | 88 ------------- twind.config.ts | 5 - {server => util}/cache/base.ts | 2 +- {server => util}/cache/fs.ts | 0 {server => util}/cache/memory.ts | 2 +- {server => util}/cache/mod.ts | 0 {server => util}/cache/s3.ts | 0 util/mod.ts | 1 + util/port.ts | 23 ++++ test_util/pairs.ts => util/test_pairs.ts | 9 +- words.txt | 2 + 82 files changed, 857 insertions(+), 643 deletions(-) delete mode 100644 cache.ts delete mode 100644 components/Button.tsx delete mode 100644 components/Meta.tsx rename deno.json => deno.jsonc (90%) create mode 100644 deps/preact.ts create mode 100644 deps/preact_render_to_string.ts create mode 100644 deps/std/encoding/toml.ts create mode 100644 deps/std/http/http_status.ts create mode 100644 deps/std/http/negotiation.ts delete mode 100644 dev.ts delete mode 100644 fresh.gen.ts create mode 100644 help.txt delete mode 100644 routes/[...path].tsx delete mode 100644 routes/_404.tsx delete mode 100644 routes/_500.tsx delete mode 100644 routes/_app.tsx delete mode 100644 routes/autocomplete/[...path].ts delete mode 100644 routes/docs/[...path].tsx delete mode 100644 routes/index.tsx delete mode 100644 serve.ts create mode 100644 server/Ctx.ts create mode 100644 server/Readme.md create mode 100644 server/blah/LocalCompasses.ts create mode 100644 server/local/RouteInfo.test.ts create mode 100644 server/local/RouteInfo.ts create mode 100644 server/local/pages/404.tsx create mode 100644 server/local/pages/500.tsx create mode 100644 server/local/pages/Code.tsx create mode 100644 server/local/pages/Landing.tsx create mode 100644 server/local/pages/mod.ts create mode 100644 server/local/serve.ts rename {static => server/local/static}/.well-known/deno-import-intellisense.json (100%) rename {static => server/local/static}/favicon.ico (100%) create mode 100644 server/provider/Bin.ts create mode 100644 server/provider/PolkadotDev.test.ts create mode 100644 server/provider/PolkadotDev.ts create mode 100644 server/provider/Smoldot.ts create mode 100644 server/provider/Workspace.ts create mode 100644 server/provider/Ws.test.ts create mode 100644 server/provider/Ws.ts create mode 100644 server/provider/Zombienet.ts create mode 100644 server/provider/common.ts create mode 100644 server/provider/mod.ts rename {server => server_prev}/capi_repo.ts (100%) rename {server => server_prev}/codecs.test.ts (100%) rename {server => server_prev}/completions.json (100%) rename {server => server_prev}/deploy.ts (100%) rename {server => server_prev}/git_utils.ts (100%) rename {server => server_prev}/local.ts (100%) create mode 100644 server_prev/mod.ts rename {server => server_prev}/server.ts (100%) delete mode 100644 static/logo.svg delete mode 100644 test_util/clients/kusama.ts delete mode 100644 test_util/clients/mod.ts delete mode 100644 test_util/clients/polkadot.ts delete mode 100644 test_util/clients/rococo.ts delete mode 100644 test_util/clients/westend.ts delete mode 100644 test_util/common.ts delete mode 100644 test_util/ctx.ts delete mode 100644 test_util/extrinsic.ts delete mode 100644 test_util/local.ts delete mode 100644 test_util/mod.ts delete mode 100644 test_util/zombienet.ts delete mode 100644 twind.config.ts rename {server => util}/cache/base.ts (95%) rename {server => util}/cache/fs.ts (100%) rename {server => util}/cache/memory.ts (87%) rename {server => util}/cache/mod.ts (100%) rename {server => util}/cache/s3.ts (100%) create mode 100644 util/port.ts rename test_util/pairs.ts => util/test_pairs.ts (87%) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 2b2bfca54..9757ed490 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -5,7 +5,6 @@ "dprint.dprint", "esbenp.prettier-vscode", "ms-azuretools.vscode-docker", - "sastan.twind-intellisense", "streetsidesoftware.code-spell-checker", "vadimcn.vscode-lldb" ] diff --git a/.vscode/settings.json b/.vscode/settings.json index d6be1939d..83f5c0b9b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,14 +6,15 @@ "editor.defaultFormatter": "dprint.dprint" }, "deno.codeLens.testArgs": ["-A", "-L=info"], - "deno.config": "./deno.json", + "deno.config": "./deno.jsonc", "deno.importMap": "./import_map.json", "deno.suggest.imports.hosts": { "https://deno.land": true, "https://x.nest.land": true, "https://crux.land": true, "http://localhost:5646": true, - "https://capi.dev": true + "https://capi.dev": true, + "http://localhost:8000": false }, "deno.enable": true, "deno.lint": true, diff --git a/_tasks/gen_deploy.ts b/_tasks/gen_deploy.ts index 34ca280e1..9c29c2e3e 100644 --- a/_tasks/gen_deploy.ts +++ b/_tasks/gen_deploy.ts @@ -1,18 +1,20 @@ -import { ensureDir } from "../deps/std/fs.ts" -import { getModuleIndex, getSha } from "../server/git_utils.ts" +export {} -const sha = await getSha() -const index = await getModuleIndex() +// import { ensureDir } from "../deps/std/fs.ts" +// import { getModuleIndex, getSha } from "../server/git_utils.ts" -await ensureDir("target") -await Deno.writeTextFile( - "target/deploy.ts", - ` -import { DenoDeployCodegenServer } from "../server/deploy.ts" +// const sha = await getSha() +// const index = await getModuleIndex() -new DenoDeployCodegenServer( - "sha:${sha}", - ${JSON.stringify(index)}, -).listen(80) -`, -) +// await ensureDir("target") +// await Deno.writeTextFile( +// "target/deploy.ts", +// ` +// import { DenoDeployCodegenServer } from "../server/deploy.ts" + +// new DenoDeployCodegenServer( +// "sha:${sha}", +// ${JSON.stringify(index)}, +// ).listen(80) +// `, +// ) diff --git a/cache.ts b/cache.ts deleted file mode 100644 index d48e71a4c..000000000 --- a/cache.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as fs from "./deps/std/fs.ts" -import { LocalCapiCodegenServer } from "./server/local.ts" - -await fs.emptyDir("target/codegen/generated") -const port = 5646 -const server = new LocalCapiCodegenServer() -server.listen(port) - -await Deno.run({ - cmd: [ - "deno", - "cache", - `--reload=http://localhost:${port}/`, - ...Deno.args, - ], -}).status() - -server.abortController.abort() diff --git a/components/Button.tsx b/components/Button.tsx deleted file mode 100644 index 909d38078..000000000 --- a/components/Button.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { JSX } from "preact"; -import { IS_BROWSER } from "$fresh/runtime.ts"; - -export function Button(props: JSX.HTMLAttributes) { - return ( -