Skip to content
Draft
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
6 changes: 2 additions & 4 deletions packages/ts/.oxfmtrc.jsonc → .oxfmtrc.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@
"printWidth": 80,
/**
* JSDoc formatting applies to TypeScript/JavaScript only (wrap to
* printWidth, tag layout). Oxfmt does not reflow `/**` blocks in JSONCkeep
* printWidth, tag layout). Oxfmt does not reflow `/**` blocks in JSONC; keep
* lines within printWidth here by breaking them yourself.
*/
"jsdoc": {
"lineWrappingStyle": "greedy"
},
/**
* Closest built-in replacement for prettier-plugin-organize-imports.
* Oxfmt sorts imports and specifiers, but it does not remove unused imports.
*/
"sortImports": {
"newlinesBetween": false,
"partitionByNewline": true
},
/**
* Closest built-in replacement for prettier-plugin-packagejson.
* Oxfmt's package.json ordering is opinionated, not byte-for-byte identical.
* Oxfmt's package.json ordering is opinionated.
*/
"sortPackageJson": {
"sortScripts": true
Expand Down
11 changes: 0 additions & 11 deletions .prettierrc.json

This file was deleted.

28 changes: 26 additions & 2 deletions Taskfile.common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,34 @@ tasks:
- tsconfig.tsbuildinfo

lint:
cmd: bun eslint src/ --fix
cmd: bun --cwd ../.. oxlint {{.PACKAGE_DIR}}/src --fix
sources:
- "{{.LOCKFILE}}"
- ../../eslint.config.js
- ../../oxlint.config.ts
- src/**/*

fmt:
cmd: >-
bun --cwd ../.. oxfmt
{{.PACKAGE_DIR}}/src
{{.PACKAGE_DIR}}/package.json
{{.PACKAGE_DIR}}/Taskfile.yaml
{{.PACKAGE_DIR}}/tsconfig.json
sources:
- "{{.LOCKFILE}}"
- ../../.oxfmtrc.jsonc
- src/**/*

fmt:check:
cmd: >-
bun --cwd ../.. oxfmt --check
{{.PACKAGE_DIR}}/src
{{.PACKAGE_DIR}}/package.json
{{.PACKAGE_DIR}}/Taskfile.yaml
{{.PACKAGE_DIR}}/tsconfig.json
sources:
- "{{.LOCKFILE}}"
- ../../.oxfmtrc.jsonc
- src/**/*

test:
Expand Down
577 changes: 84 additions & 493 deletions bun.lock

Large diffs are not rendered by default.

110 changes: 0 additions & 110 deletions eslint.config.js

This file was deleted.

16 changes: 12 additions & 4 deletions packages/ts/oxlint.config.ts → oxlint.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { defineConfig } from "oxlint"

const maintainedTypeScriptFiles = [
"packages/ts/src/**/*.ts",
"packages/ts/scripts/**/*.ts",
"packages/hono/src/**/*.ts",
"src/**/*.ts",
"scripts/**/*.ts",
]

export default defineConfig({
plugins: ["typescript", "jsdoc"],
categories: {
Expand All @@ -25,10 +33,10 @@ export default defineConfig({
},
},
},
// jsPlugins: ["./scripts/oxlint-prefer-schema-examples.ts"],
// jsPlugins: ["./packages/ts/scripts/oxlint-prefer-schema-examples.ts"],
overrides: [
{
files: ["src/**/*.ts", "scripts/**/*.ts"],
files: maintainedTypeScriptFiles,
rules: {
// "local/prefer-schema-examples": "warn",
"typescript/consistent-type-imports": [
Expand Down Expand Up @@ -63,13 +71,13 @@ export default defineConfig({
},
},
{
files: ["scripts/**/*.ts"],
files: ["packages/ts/scripts/**/*.ts", "scripts/**/*.ts"],
rules: {
"no-console": "off",
},
},
{
files: ["src/**/*.test.ts"],
files: ["packages/ts/src/**/*.test.ts", "src/**/*.test.ts"],
rules: {
/**
* `no-unsafe-type-assertion` has no Oxlint options (cannot allow only
Expand Down
13 changes: 3 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@
"packages/*"
],
"devDependencies": {
"@bgotink/prettier-plugin-kdl": "^0.2.0-next.0",
"@typescript-eslint/eslint-plugin": "^8.59.1",
"@typescript-eslint/parser": "^8.59.1",
"eslint": "^10.2.1",
"eslint-plugin-ban": "^2.0.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"openapi3-ts": "^4.5.0",
"prettier": "^3.8.3",
"prettier-plugin-organize-imports": "^4.3.0",
"prettier-plugin-packagejson": "^3.0.2",
"prettier-plugin-tailwindcss": "^0.8.0",
"oxfmt": "^0.48.0",
"oxlint": "^1.63.0",
"oxlint-tsgolint": "^0.22.1",
"typescript": "^6.0.3",
"vitest": "^4.1.5"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: 3
includes:
common:
taskfile: ../../Taskfile.common.yaml
vars:
PACKAGE_DIR: packages/cli
flatten: true

tasks:
Expand Down
2 changes: 2 additions & 0 deletions packages/generator/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ version: 3
includes:
common:
taskfile: ../../Taskfile.common.yaml
vars:
PACKAGE_DIR: packages/generator
flatten: true
2 changes: 1 addition & 1 deletion packages/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"typings": "dist/index.d.ts",
"scripts": {
"bld": "bun build src/kdl.ts --outdir=dist/ --external kdljs --external deepmerge --target=node --sourcemap=external --format=esm",
"lint": "eslint src --fix"
"lint": "bun --cwd ../.. oxlint packages/generator/src --fix"
},
"dependencies": {
"deepmerge": "^4.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function respectOptionality(

export const parseSecurity = (parent: kdljs.Node): ParsedSecurity => {
const [node] = parent.children
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
// oxlint-disable-next-line typescript/no-unnecessary-condition
if (!node) return { securitySchemes: {}, security: [] }

switch (node.name.toUpperCase()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const isAbsent = (
export const removeAbsent = <T extends object>(t: T): T => {
for (const k in t) {
if (isAbsent(t[k])) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
// oxlint-disable-next-line typescript/no-dynamic-delete
delete t[k]
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/hono/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: 3
includes:
common:
taskfile: ../../Taskfile.common.yaml
vars:
PACKAGE_DIR: packages/hono

tasks:
check:
Expand Down
12 changes: 6 additions & 6 deletions packages/hono/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"version": "1.1.2",
"description": "OpenAPI router and testing helpers for Hono",
"license": "MIT",
"type": "module",
"main": "./dist/hono/src/index.js",
"types": "./dist/hono/src/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"hono": "^4.12.16"
},
"type": "module",
"main": "./dist/hono/src/index.js",
"types": "./dist/hono/src/index.d.ts",
"publishConfig": {
"access": "public"
},
"dependencies": {
"hono": "^4.12.18"
}
}
27 changes: 17 additions & 10 deletions packages/hono/src/req.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { lowerCaseKeys, memoize, mkAjv } from "../../http-jsonschema/src/common"
import { JsonResolver } from "../../http-jsonschema/src/jsonresolver"
import {
type FullOperation,
type HttpMethod,
isHttpMethod,
operationLookup,
} from "../../http-jsonschema/src/operations"
import {
Expand Down Expand Up @@ -61,27 +61,32 @@ function getOp(
ctx: Context,
): oas31.OperationObject | undefined {
const openApiPath = openApiPaths[routePath(ctx)]
const method = ctx.req.method.toLowerCase() as HttpMethod
return doc.paths?.[openApiPath][method]
const method = ctx.req.method.toLowerCase()
if (!isHttpMethod(method)) return undefined

return doc.paths?.[openApiPath]?.[method]
}

function validateMiddleware<OpID extends string>({
function validateMiddleware({
doc,
openApiPaths,
ops,
onErrors,
}: {
doc: oas31.OpenAPIObject
openApiPaths: Record<string, string>
ops: Record<OpID, FullOperation>
ops: Readonly<Partial<Record<string, FullOperation>>>
onErrors: (ctx: Context, errors: ErrorObject[]) => Response
}): MiddlewareHandler {
const refs = new JsonResolver(doc)
const ajv = mkAjv(doc)

const getReqValidator = memoize((opID: OpID) =>
ajv.compile<ReqBuf>(requestToSchema(refs, ops[opID])),
)
const getReqValidator = memoize((opID: string) => {
const op = ops[opID]
if (!op) throw new Error(`missing operation ${opID}`)

return ajv.compile<ReqBuf>(requestToSchema(refs, op))
})

return async (ctx, next) => {
const op = getOp(refs.root, openApiPaths, ctx)
Expand All @@ -92,15 +97,17 @@ function validateMiddleware<OpID extends string>({

const body = await getBody(ctx.req)

const validate = getReqValidator(op.operationId as OpID)
if (!op.operationId) return next()

const validate = getReqValidator(op.operationId)
validate(inMemReq(ctx, body))
const errors = validate.errors

if (errors?.length) {
return onErrors(ctx, errors)
}

await next()
return next()
}
}

Expand Down
Loading