This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e066c9c
commit 6a9dbb5
Showing
23 changed files
with
116 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { contentType } from "https://deno.land/x/[email protected]/mod.ts" | ||
import { Application, send } from "https://deno.land/x/[email protected]/mod.ts" | ||
import { babel, babelPresetTypeScript } from "https://escad.dev/deps/babel.ts" | ||
import { babel, babelPresetTypeScript } from "../deps/babel.ts" | ||
import { contentType } from "../deps/media_types.ts" | ||
import { Application, send } from "../deps/oak.ts" | ||
import * as path from "../deps/std/path.ts" | ||
|
||
const dirname = path.dirname(path.fromFileUrl(import.meta.url)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://escad.dev/deps/babel.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/x/[email protected]/mod.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/x/[email protected]/mod.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/x/[email protected]/mod.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/x/[email protected]/mod.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/x/[email protected]/mod.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://esm.sh/[email protected]?bundle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/[email protected]/http/file_server.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/[email protected]/http/server.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as fs from "../../deps/std/fs.ts" | ||
import * as path from "../../deps/std/path.ts" | ||
import { CacheBase } from "./base.ts" | ||
|
||
export class FsCache extends CacheBase { | ||
constructor(readonly location: string, signal: AbortSignal) { | ||
super(signal) | ||
} | ||
|
||
async _getRaw(key: string, init: () => Promise<Uint8Array>) { | ||
const file = path.join(this.location, key) | ||
try { | ||
return await Deno.readFile(file) | ||
} catch (e) { | ||
if (!(e instanceof Deno.errors.NotFound)) throw e | ||
const content = await init() | ||
await fs.ensureDir(path.dirname(file)) | ||
await Deno.writeFile(file, content) | ||
return content | ||
} | ||
} | ||
|
||
async _list(prefix: string): Promise<string[]> { | ||
try { | ||
const result = [] | ||
for await (const entry of Deno.readDir(path.join(this.location, prefix))) { | ||
result.push(entry.name) | ||
} | ||
return result | ||
} catch (e) { | ||
if (e instanceof Deno.errors.NotFound) { | ||
return [] | ||
} | ||
throw e | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PermanentMemo } from "../../util/mod.ts" | ||
import { CacheBase } from "./base.ts" | ||
|
||
export class InMemoryCache extends CacheBase { | ||
memo = new PermanentMemo<string, Uint8Array>() | ||
_getRaw(key: string, init: () => Promise<Uint8Array>): Promise<Uint8Array> { | ||
return Promise.resolve(this.memo.run(key, init)) | ||
} | ||
_list(): Promise<string[]> { | ||
throw new Error("unimplemented") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./base.ts" | ||
export * from "./fs.ts" | ||
export * from "./memory.ts" | ||
export * from "./s3.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { S3Bucket, S3BucketConfig } from "https://deno.land/x/[email protected]/mod.ts" | ||
import { Cache } from "./cache.ts" | ||
import { S3Bucket, S3BucketConfig } from "../../deps/s3.ts" | ||
import { CacheBase } from "./base.ts" | ||
|
||
export class S3Cache extends Cache { | ||
export class S3Cache extends CacheBase { | ||
bucket | ||
|
||
constructor(config: S3BucketConfig, signal: AbortSignal) { | ||
super(signal) | ||
this.bucket = new S3Bucket(config) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "https://deno.land/x/[email protected]/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}" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from "./cache.ts" | ||
export * from "./cache/mod.ts" | ||
export * from "./local.ts" | ||
export * from "./server.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts" | ||
import { escapeHtml } from "https://deno.land/x/[email protected]/mod.ts" | ||
import * as shiki from "https://esm.sh/[email protected]?bundle" | ||
import { Files } from "../codegen/Files.ts" | ||
import { codegen } from "../codegen/mod.ts" | ||
import { escapeHtml } from "../deps/escape.ts" | ||
import * as $ from "../deps/scale.ts" | ||
import * as shiki from "../deps/shiki.ts" | ||
import { serve } from "../deps/std/http/server.ts" | ||
import * as C from "../mod.ts" | ||
import * as T from "../test_util/mod.ts" | ||
import * as U from "../util/mod.ts" | ||
import { TimedMemo } from "../util/mod.ts" | ||
import { Cache } from "./cache.ts" | ||
import { CacheBase } from "./cache/mod.ts" | ||
|
||
shiki.setCDN("https://unpkg.com/shiki/") | ||
export const highlighterPromise = shiki.getHighlighter({ theme: "github-dark", langs: ["ts"] }) | ||
|
@@ -40,8 +40,8 @@ const R_WITH_CHAIN_URL = /^\/proxy\/(dev:\w+|wss?:[^\/]+)\/(?:@([^\/]+)\/)?(.*)$ | |
|
||
const $index = $.array($.str) | ||
|
||
export abstract class CodegenServer { | ||
abstract cache: Cache | ||
export abstract class Server { | ||
abstract cache: CacheBase | ||
abstract local: boolean | ||
abstract mainVersion: string | ||
abstract canHandleVersion(version: string): Promise<boolean> | ||
|
@@ -71,7 +71,7 @@ export abstract class CodegenServer { | |
async root(request: Request): Promise<Response> { | ||
const fullPath = new URL(request.url).pathname | ||
if (fullPath === "/.well-known/deno-import-intellisense.json") { | ||
return this.autocompleteSchema() | ||
return await fetch(new URL("completions.json", import.meta.url)) | ||
} | ||
const versionMatch = R_WITH_CAPI_VERSION.exec(fullPath) | ||
if (!versionMatch) { | ||
|
@@ -170,38 +170,6 @@ export const client = C.rpcClient(C.rpc.proxyProvider, ${JSON.stringify(chainUrl | |
) | ||
} | ||
|
||
autocompleteSchema() { | ||
return this.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}", | ||
}, | ||
], | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
async autocompleteApi(path: string, version: string) { | ||
const parts = path.slice(1).split("/") | ||
if (parts[0] !== "autocomplete") return this.e404() | ||
|