Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add biome and formatbot workflow #107

Merged
merged 7 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/formatbot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Format PR

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
format:
name: Format code
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Get @biomejs/biome version
id: get-biome-version
run: echo "BIOME_VERSION=$(node -p "require('./package.json').devDependencies['@biomejs/biome']")" >> $GITHUB_OUTPUT

- name: Install @biomejs/biome
run: npm install @biomejs/biome@${{ steps.get-biome-version.outputs.BIOME_VERSION }}

- name: Run formatter
run: npx @biomejs/biome format .

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "formatbot: Automatically format code"
branch: ${{ github.head_ref }}
commit_user_name: tscircuitbot
commit_user_email: [email protected]
commit_author: tscircuitbot <[email protected]>
44 changes: 44 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"indentStyle": "space"
},
"files": {
"ignore": ["cosmos-export", "dist", "package.json"]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off"
},
"style": {
"noNonNullAssertion": "off",
"useFilenamingConvention": {
"level": "error",
"options": {
"strictCase": true,
"requireAscii": true,
"filenameCases": ["kebab-case", "export"]
}
}
}
}
}
}
Binary file modified bun.lockb
Binary file not shown.
Binary file modified dev-server-api/bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions dev-server-api/routes/api/db/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export default withWinterSpec({
dev_server_database_dump: await ctx.db.dump(),
},
null,
" "
" ",
),
{
headers: {
"content-type": "application/json",
},
}
},
)
})
2 changes: 1 addition & 1 deletion dev-server-api/routes/api/dev_package_examples/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default withWinterSpec({
})(async (req, ctx) => {
const dev_package_example = await ctx.db.get(
"dev_package_example",
req.commonParams.dev_package_example_id
req.commonParams.dev_package_example_id,
)

if (!dev_package_example) {
Expand Down
4 changes: 2 additions & 2 deletions dev-server-api/routes/api/dev_package_examples/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default withWinterSpec({
edit_events_last_updated_at: z.string().datetime().nullable(),
soup_last_updated_at: z.string().datetime().nullable(),
last_updated_at: z.string().datetime().nullable(),
})
}),
),
}),
auth: "none",
Expand All @@ -27,7 +27,7 @@ export default withWinterSpec({
edit_events_last_updated_at: dpe.edit_events_last_updated_at,
soup_last_updated_at: dpe.soup_last_updated_at,
last_updated_at: dpe.last_updated_at,
})
}),
)

return ctx.json({
Expand Down
2 changes: 1 addition & 1 deletion dev-server-api/routes/api/dev_package_examples/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default withWinterSpec({
})(async (req, ctx) => {
const dev_package_example = await ctx.db.get(
"dev_package_example",
req.jsonBody.dev_package_example_id
req.jsonBody.dev_package_example_id,
)

if (!dev_package_example) {
Expand Down
4 changes: 2 additions & 2 deletions dev-server-api/routes/api/export_requests/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default withWinterSpec({
jsonResponse: z.object({
export_request: ExportRequestSchema.extend({
file_summary: z.array(
z.object({ file_name: z.string(), export_file_id: z.coerce.number() })
z.object({ file_name: z.string(), export_file_id: z.coerce.number() }),
),
}),
}),
Expand All @@ -33,7 +33,7 @@ export default withWinterSpec({
}

const export_files = (await ctx.db.list("export_file")).filter(
(ef) => ef.export_request_id === export_request_id
(ef) => ef.export_request_id === export_request_id,
)
ext_export_request.file_summary = export_files.map((ef) => ({
file_name: ef.file_name!,
Expand Down
2 changes: 1 addition & 1 deletion dev-server-api/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export default withWinterSpec({
headers: {
"content-type": "text/html",
},
}
},
)
})
2 changes: 1 addition & 1 deletion dev-server-api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Request as EdgeRuntimeRequest } from "@edge-runtime/primitives"
import { join } from "node:path"

const serverFetch = await createFetchHandlerFromDir(
join(import.meta.dir, "./routes")
join(import.meta.dir, "./routes"),
)

console.log("starting dev-server-api on http://127.0.0.1:3021")
Expand Down
8 changes: 4 additions & 4 deletions dev-server-api/src/db/create-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const createSchema = async (db: DbClient) => {
await db.schema
.createTable("dev_package_example")
.addColumn("dev_package_example_id", "integer", (col) =>
col.primaryKey().autoIncrement()
col.primaryKey().autoIncrement(),
)
.addColumn("file_path", "text", (col) => col.unique())
.addColumn("export_name", "text")
Expand All @@ -27,7 +27,7 @@ export const createSchema = async (db: DbClient) => {
await db.schema
.createTable("export_request")
.addColumn("export_request_id", "integer", (col) =>
col.primaryKey().autoIncrement()
col.primaryKey().autoIncrement(),
)
.addColumn("example_file_path", "text")
.addColumn("export_parameters", "json")
Expand All @@ -41,13 +41,13 @@ export const createSchema = async (db: DbClient) => {
await db.schema
.createTable("export_file")
.addColumn("export_file_id", "integer", (col) =>
col.primaryKey().autoIncrement()
col.primaryKey().autoIncrement(),
)
.addColumn("file_name", "text")
.addColumn("file_content", "blob")
.addColumn("is_complete", "boolean", (col) => col.defaultTo(0).notNull())
.addColumn("export_request_id", "integer", (col) =>
col.references("export_request.export_request_id")
col.references("export_request.export_request_id"),
)
.addColumn("created_at", "text")
.execute()
Expand Down
4 changes: 2 additions & 2 deletions dev-server-api/src/db/generic-json-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class GenericJsonLevel extends AbstractLevel<string, any> {
}

async _batch(
operations: Array<{ type: "put" | "del"; key: string; value?: any }>
operations: Array<{ type: "put" | "del"; key: string; value?: any }>,
): Promise<void> {
for (const op of operations) {
if (op.type === "put") {
Expand Down Expand Up @@ -99,7 +99,7 @@ class GenericJsonLevel extends AbstractLevel<string, any> {
async next() {
if (files.length === 0) {
files = (await fs.readdir(this.db.location)).filter((file) =>
file.endsWith(".json")
file.endsWith(".json"),
)
}

Expand Down
18 changes: 9 additions & 9 deletions dev-server-api/src/db/zod-level-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ZodLevelDatabase {

async get<K extends keyof DBSchemaType>(
collection: K,
id: string | number
id: string | number,
): Promise<DBSchemaType[K] | null> {
const key = `${collection}:${id}`
const data = await this.db.get(key).catch((e) => null)
Expand All @@ -32,7 +32,7 @@ export class ZodLevelDatabase {

async put<K extends keyof DBSchemaType>(
collection: K,
value: DBInputSchemaType[K]
value: DBInputSchemaType[K],
): Promise<DBSchemaType[K]> {
const idkey = `${collection}_id`
const valueLoose: any = value
Expand All @@ -51,15 +51,15 @@ export class ZodLevelDatabase {

async del<K extends keyof DBSchemaType>(
collection: K,
id: string
id: string,
): Promise<void> {
const key = `${collection}:${id}`
await this.db.del(key)
}

async find<K extends keyof DBSchemaType>(
collection: K,
partialObject: Partial<DBSchemaType[K]>
partialObject: Partial<DBSchemaType[K]>,
): Promise<DBSchemaType[K] | null> {
const schema = DBSchema.shape[collection]

Expand All @@ -82,22 +82,22 @@ export class ZodLevelDatabase {

async findOrThrow<K extends keyof DBSchemaType>(
collection: K,
partialObject: Partial<DBSchemaType[K]>
partialObject: Partial<DBSchemaType[K]>,
): Promise<DBSchemaType[K]> {
const result = await this.find(collection, partialObject)
if (!result) {
throw new Error(
`No record in "${collection}" matches query ${JSON.stringify(
partialObject
)}`
partialObject,
)}`,
)
}
return result
}

private matchesPartialObject<T>(
fullObject: T,
partialObject: Partial<T>
partialObject: Partial<T>,
): boolean {
for (const [key, value] of Object.entries(partialObject)) {
if (fullObject[key as keyof T] !== value) {
Expand All @@ -121,7 +121,7 @@ export class ZodLevelDatabase {
}

async list<K extends keyof DBSchemaType>(
collection: K
collection: K,
): Promise<DBSchemaType[K][]> {
const schema = DBSchema.shape[collection]
const results: DBSchemaType[K][] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const debug = Debug("tscircuit:cli:api")
export const withDebugRequestLogging: Middleware<{}, {}> = async (
req,
ctx,
next
next,
) => {
debug(`[REQ] ${req.method?.toUpperCase()} ${req.url}`)
return next(req, ctx)
Expand Down
4 changes: 2 additions & 2 deletions dev-server-api/src/middlewares/with-error-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const withErrorResponse: Middleware<{}, {}> = async (req, ctx, next) => {
error_code: "not_found",
},
},
{ status: error?.status || 404 }
{ status: error?.status || 404 },
)
}

Expand All @@ -31,7 +31,7 @@ export const withErrorResponse: Middleware<{}, {}> = async (req, ctx, next) => {
error_code: error?.error_code ?? "internal_server_error",
},
},
{ status: error?.status || 500 }
{ status: error?.status || 500 },
)
}
}
59 changes: 41 additions & 18 deletions dev-server-api/static-routes.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@

// import { WinterSpecRouteMap } from "@winterspec/types"

const routeMap = {
"/api/db/download": (await import('routes/api/db/download.ts')).default,
"/api/dev_package_examples/create": (await import('routes/api/dev_package_examples/create.ts')).default,
"/api/dev_package_examples/get": (await import('routes/api/dev_package_examples/get.ts')).default,
"/api/dev_package_examples/list": (await import('routes/api/dev_package_examples/list.ts')).default,
"/api/dev_package_examples/update": (await import('routes/api/dev_package_examples/update.ts')).default,
"/api/dev_server/reset": (await import('routes/api/dev_server/reset.ts')).default,
"/api/export_files/create": (await import('routes/api/export_files/create.ts')).default,
"/api/export_files/download": (await import('routes/api/export_files/download.ts')).default,
"/api/export_requests/create": (await import('routes/api/export_requests/create.ts')).default,
"/api/export_requests/get": (await import('routes/api/export_requests/get.ts')).default,
"/api/export_requests/list": (await import('routes/api/export_requests/list.ts')).default,
"/api/export_requests/update": (await import('routes/api/export_requests/update.ts')).default,
"/api/health": (await import('routes/api/health.ts')).default,
"/api/package_info/create": (await import('routes/api/package_info/create.ts')).default,
"/api/package_info/get": (await import('routes/api/package_info/get.ts')).default,
"/health": (await import('routes/health.ts')).default,
"/": (await import('routes/index.ts')).default
"/api/db/download": (await import("routes/api/db/download.ts")).default,
"/api/dev_package_examples/create": (
await import("routes/api/dev_package_examples/create.ts")
).default,
"/api/dev_package_examples/get": (
await import("routes/api/dev_package_examples/get.ts")
).default,
"/api/dev_package_examples/list": (
await import("routes/api/dev_package_examples/list.ts")
).default,
"/api/dev_package_examples/update": (
await import("routes/api/dev_package_examples/update.ts")
).default,
"/api/dev_server/reset": (await import("routes/api/dev_server/reset.ts"))
.default,
"/api/export_files/create": (
await import("routes/api/export_files/create.ts")
).default,
"/api/export_files/download": (
await import("routes/api/export_files/download.ts")
).default,
"/api/export_requests/create": (
await import("routes/api/export_requests/create.ts")
).default,
"/api/export_requests/get": (
await import("routes/api/export_requests/get.ts")
).default,
"/api/export_requests/list": (
await import("routes/api/export_requests/list.ts")
).default,
"/api/export_requests/update": (
await import("routes/api/export_requests/update.ts")
).default,
"/api/health": (await import("routes/api/health.ts")).default,
"/api/package_info/create": (
await import("routes/api/package_info/create.ts")
).default,
"/api/package_info/get": (await import("routes/api/package_info/get.ts"))
.default,
"/health": (await import("routes/health.ts")).default,
"/": (await import("routes/index.ts")).default,
}

export default routeMap
2 changes: 1 addition & 1 deletion dev-server-api/tests/fixtures/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Request as EdgeRuntimeRequest } from "@edge-runtime/primitives"
import { join } from "node:path"

const serverFetch = await createFetchHandlerFromDir(
join(import.meta.dir, "../../routes")
join(import.meta.dir, "../../routes"),
)

export const startServer = ({ port }: { port: number }) =>
Expand Down
Loading
Loading