Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
rename capn to devnets (harry hates fun)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi committed Apr 7, 2023
1 parent f4a8348 commit 1b7aef4
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion _tasks/generate_artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { testUser } from "../capn/mod.ts"
import { hex } from "../crypto/mod.ts"
import * as $ from "../deps/scale.ts"
import { emptyDir } from "../deps/std/fs.ts"
import * as path from "../deps/std/path.ts"
import { testUser } from "../devnets/mod.ts"
import dprintConfig from "../dprint.json" assert { type: "json" }
import { compress } from "../util/compression.ts"

Expand Down
11 changes: 0 additions & 11 deletions capn/CapnConnection.ts

This file was deleted.

2 changes: 1 addition & 1 deletion cli/resolveConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CapiConfig } from "../capn/mod.ts"
import * as flags from "../deps/std/flags.ts"
import * as path from "../deps/std/path.ts"
import { CapiConfig } from "../devnets/mod.ts"

export async function resolveConfig(...args: string[]) {
const { config: rawConfigPath } = flags.parse(args, {
Expand Down
12 changes: 6 additions & 6 deletions cli/serve.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTempDir } from "../capn/createTempDir.ts"
import { createCapnHandler } from "../capn/mod.ts"
import * as flags from "../deps/std/flags.ts"
import { serve } from "../deps/std/http.ts"
import { createTempDir } from "../devnets/createTempDir.ts"
import { createDevnetsHandler } from "../devnets/mod.ts"
import { createCorsHandler } from "../server/corsHandler.ts"
import { createErrorHandler } from "../server/errorHandler.ts"
import { createCodegenHandler } from "../server/mod.ts"
Expand Down Expand Up @@ -37,15 +37,15 @@ export default async function(...args: string[]) {
.catch(() => false)

if (!running) {
const capnHandler = createCapnHandler(tempDir, config, signal)
const devnetsHandler = createDevnetsHandler(tempDir, config, signal)
const codegenHandler = createCodegenHandler(dataCache, tempCache)
const handler = createCorsHandler(createErrorHandler(async (request) => {
const { pathname } = new URL(request.url)
if (pathname === "/capi_cwd") {
return new Response(Deno.cwd())
}
if (pathname.startsWith("/capn/")) {
return await capnHandler(request)
if (pathname.startsWith("/devnets/")) {
return await devnetsHandler(request)
}
return await codegenHandler(request)
}))
Expand Down Expand Up @@ -73,7 +73,7 @@ export default async function(...args: string[]) {
args,
signal,
env: {
CAPN_SERVER: `http://localhost:${port}/capn/`,
DEVNETS_SERVER: `http://localhost:${port}/devnets/`,
},
})
const status = await command.spawn().status
Expand Down
4 changes: 2 additions & 2 deletions cli/sync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTempDir } from "../capn/createTempDir.ts"
import { syncConfig } from "../capn/mod.ts"
import * as flags from "../deps/std/flags.ts"
import { assertEquals } from "../deps/std/testing/asserts.ts"
import { createTempDir } from "../devnets/createTempDir.ts"
import { syncConfig } from "../devnets/mod.ts"
import { resolveConfig } from "./resolveConfig.ts"

export default async function(...args: string[]) {
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions devnets/CapnConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { WsConnection } from "../rpc/mod.ts"

export class DevnetsConnection extends WsConnection {
constructor(path: string) {
const server = Deno.env.get("DEVNETS_SERVER")
if (!server) throw new Error("Must be run with a devnets server")
const url = new URL(path, server)
url.protocol = "ws"
super(url.toString())
}
}
File renamed without changes.
6 changes: 3 additions & 3 deletions capn/capnHandler.ts → devnets/capnHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { CapiConfig } from "./CapiConfig.ts"
import { Network, startNetwork } from "./startNetwork.ts"
import { testUserPublicKeys } from "./testUsers.ts"

const rCapnApi = /^\/capn\/([\w-]+)(?:\/([\w-]+))?$/
const rDevnetsApi = /^\/devnets\/([\w-]+)(?:\/([\w-]+))?$/

export function createCapnHandler(tempDir: string, config: CapiConfig, signal: AbortSignal) {
export function createDevnetsHandler(tempDir: string, config: CapiConfig, signal: AbortSignal) {
const networkMemo = new PermanentMemo<string, Network>()
return async (request: Request) => {
const { pathname, searchParams } = new URL(request.url)
const match = rCapnApi.exec(pathname)
const match = rDevnetsApi.exec(pathname)
if (!match) return f.notFound()
const name = match[1]!
const paraName = match[2]
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions capn/createTempDir.ts → devnets/createTempDir.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as path from "../deps/std/path.ts"

export async function createTempDir() {
const dir = path.resolve("target/capn")
const dir = path.resolve("target/devnets")
await Deno.mkdir(dir, { recursive: true })
return await Deno.makeTempDir({
dir,
prefix: `capn-${new Date().toISOString()}-`,
prefix: `devnets-${new Date().toISOString()}-`,
})
}
4 changes: 2 additions & 2 deletions capn/mod.ts → devnets/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

export * from "./binary.ts"
export * from "./CapiConfig.ts"
export * from "./CapnConnection.ts"
export * from "./capnHandler.ts"
export * from "./chainSpec.ts"
export * from "./createTempDir.ts"
export * from "./DevnetsConnection.ts"
export * from "./devnetsHandler.ts"
export * from "./startNetwork.ts"
export * from "./syncConfig.ts"
export * from "./testUsers.ts"
File renamed without changes.
2 changes: 1 addition & 1 deletion capn/syncConfig.ts → devnets/syncConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function syncConfig(tempDir: string, config: CapiConfig) {
metadata: metadata,
chainName: normalizeTypeName(name),
connection: {
type: "CapnConnection",
type: "DevnetsConnection",
discovery: name + (paraName ? `/${paraName}` : ""),
},
},
Expand Down
4 changes: 2 additions & 2 deletions capn/testUsers.ts → devnets/testUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function testUserFactory(endpoint: string) {
function createUsers(): Promise<Record<typeof testUserNames[number], Sr25519>>
function createUsers<N extends number>(count: N): Promise<ArrayOfLength<Sr25519, N>>
async function createUsers(count?: number): Promise<Record<string, Sr25519> | Sr25519[]> {
const server = Deno.env.get("CAPN_SERVER")
if (!server) throw new Error("Must be run with a capn server")
const server = Deno.env.get("DEVNETS_SERVER")
if (!server) throw new Error("Must be run with a devnets server")
const response = await fetch(
new URL(`${endpoint}?users=${count ?? testUserNames.length}`, server),
{
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export { BitSequence } from "./deps/scale.ts"
// moderate --exclude main.ts server util capi.config.ts

export * from "./capi.config.ts"
export * from "./capn/mod.ts"
export * from "./crypto/mod.ts"
export * from "./devnets/mod.ts"
export * from "./fluent/mod.ts"
export * from "./frame_metadata/mod.ts"
export * from "./rpc/mod.ts"
Expand Down
4 changes: 2 additions & 2 deletions server/codegenHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const connect = C.${entry.connection.type}.bind(${
})
${
entry.connection.type === "CapnConnection"
entry.connection.type === "DevnetsConnection"
? `export const createUsers = C.testUserFactory(${
JSON.stringify(entry.connection.discovery)
})`
Expand All @@ -147,7 +147,7 @@ import * as C from "./capi.js"
export const connect: (signal: AbortSignal) => C.Connection
${
entry.connection.type === "CapnConnection"
entry.connection.type === "DevnetsConnection"
? `export const createUsers: ReturnType<typeof C.testUserFactory>`
: ""
}
Expand Down
2 changes: 1 addition & 1 deletion server/codegenSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const $codegenEntry = $.taggedUnion("type", [
"connection",
$.taggedUnion("type", [
$.variant("WsConnection", $.field("discovery", $.str)),
$.variant("CapnConnection", $.field("discovery", $.str)),
$.variant("DevnetsConnection", $.field("discovery", $.str)),
]),
),
),
Expand Down
2 changes: 1 addition & 1 deletion words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ bootnode
bootnodes
callables
capi
capn
chainspec
chelios
chev
childstate
codegen
concat
deno
devnets
dispatchable
dprint
egdoc
Expand Down

0 comments on commit 1b7aef4

Please sign in to comment.