Skip to content
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
16 changes: 10 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ updates:
schedule:
interval: "monthly"
open-pull-requests-limit: 1
labels: ["dependencies", "automated"]
commit-message:
prefix: "chore"
groups:
all-npm-dependencies:
patterns:
- "*"
npm-all:
patterns: ["*"]

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
open-pull-requests-limit: 1
labels: ["dependencies", "automated"]
commit-message:
prefix: "chore"
groups:
all-github-actions-dependencies:
patterns:
- "*"
github-actions-all:
patterns: ["*"]
40 changes: 40 additions & 0 deletions .github/workflows/nodeci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Node CI

# На каждое событие ровно один workflow: здесь нет release-please, поэтому
# main проверяет Node CI.
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [26.x]

steps:
- uses: actions/checkout@v7

# pnpm ставится до setup-node: тот с cache: pnpm ищет уже существующий
# бинарь, чтобы вычислить путь к store, и иначе падает с
# «Unable to locate executable file: pnpm».
- uses: pnpm/action-setup@v6

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node-version }}
cache: pnpm

- name: Install
run: make install
- name: Run linter
run: make lint
- name: Run tests
run: make test
23 changes: 23 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PR Title

# Заголовок PR обязан быть conventional commit: при squash-мерже он становится
# сообщением коммита, а по нему release-please определяет разряд версии.
# Отдельные коммиты ветки намеренно не проверяются.
on:
pull_request_target:
types:
- opened
- edited
- synchronize
- reopened

permissions:
pull-requests: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 0 additions & 24 deletions .github/workflows/push.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .oxfmtignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Что oxfmt не форматирует. Файл нужен потому, что без --ignore-path oxfmt читает
# .gitignore текущего каталога, а в ките в .gitignore лежат exercises/, courses/ и
# projects/ целиком: запущенный из корня oxfmt тогда молча пропускает весь контент,
# и это неотличимо от «всё уже отформатировано».
#
# Список повторяет ignorePatterns из .oxlintrc.json: линт и формат должны видеть
# одни и те же файлы.
node_modules/
# oxfmt форматирует не только js/ts: на spec.yml упражнения он снимает пустую
# строку, а package.json переписывает в свой вид. YAML и JSON в ките ведут другие
# инструменты (yamlfmt через mdsf, npm сам), поэтому здесь только js/ts.
*.yml
*.yaml
*.json
*.jsonc
*.css
*.md
npm-cache/
vendor/
dist/
build/
coverage/
.venv/
__snapshots__/
36 changes: 36 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
"plugins": [
"typescript",
"unicorn",
"oxc",
"import",
"promise",
"node",
"jsdoc",
"vitest",
"react",
"react-perf",
"jsx-a11y",
"vue"
],
"categories": {
"correctness": "error"
},
"rules": {},
"env": {
"builtin": true,
"browser": true,
"node": true
},
"ignorePatterns": [
"**/node_modules/**",
"**/npm-cache/**",
"**/vendor/**",
"**/dist/**",
"**/build/**",
"**/coverage/**",
"**/.venv/**",
"**/__snapshots__/**"
]
}
30 changes: 17 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
test:
npm test
pnpm test

dev:
npm run dev
pnpm run dev

check-types:
npx tsc
pnpm exec tsc

routes:
npx fastify print-routes routes/api/users.js
pnpm exec fastify print-routes routes/api/users.js

migration-generate:
npx drizzle-kit generate
pnpm exec drizzle-kit generate

lint:
npx @biomejs/biome check
npx tsc
pnpm --silent run lint
pnpm exec tsc
pnpm --silent run format:check

lint-fix:
npx @biomejs/biome check --fix
pnpm --silent run lint:fix

generate-openapi:
npx tsp compile .
pnpm exec tsp compile .

generate-openapi-ts-types:
# # npx openapi-box ./tsp-output/@typespec/openapi3/openapi.v1.json
# npx openapi-typescript ./tsp-output/@typespec/openapi3/openapi.v1.json -o types/openapi.ts
npx openapi-ts
# # pnpm exec openapi-box ./tsp-output/@typespec/openapi3/openapi.v1.json
# pnpm exec openapi-typescript ./tsp-output/@typespec/openapi3/openapi.v1.json -o types/openapi.ts
pnpm exec openapi-ts

generate-types: generate-openapi generate-openapi-ts-types

mock:
npx prism mock ./tsp-output/@typespec/openapi3/openapi.v1.json
pnpm exec prism mock ./tsp-output/@typespec/openapi3/openapi.v1.json

tsp-build:

.PHONY: test routes

install:
pnpm install
51 changes: 22 additions & 29 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,62 @@
import path from 'node:path';
import type { AutoloadPluginOptions } from '@fastify/autoload';
import AutoLoad from '@fastify/autoload';
import type { FastifyPluginAsync, FastifyServerOptions } from 'fastify';
import glue from 'fastify-openapi-glue';
import { ValiError } from 'valibot';
import serviceHandlers from './routes/index.ts';
import path from "node:path";
import type { AutoloadPluginOptions } from "@fastify/autoload";
import AutoLoad from "@fastify/autoload";
import type { FastifyPluginAsync, FastifyServerOptions } from "fastify";
import glue from "fastify-openapi-glue";
import { ValiError } from "valibot";
import serviceHandlers from "./routes/index.ts";

export interface AppOptions
extends FastifyServerOptions,
Partial<AutoloadPluginOptions> {}
export interface AppOptions extends FastifyServerOptions, Partial<AutoloadPluginOptions> {}

// Pass --options via CLI arguments in command to enable these options.
const options: AppOptions = {};

const app: FastifyPluginAsync<AppOptions> = async (
fastify,
opts,
): Promise<void> => {
const app: FastifyPluginAsync<AppOptions> = async (fastify, opts): Promise<void> => {
fastify.setErrorHandler((error, _request, reply) => {
if (error instanceof ValiError) {
const errors = error.issues.map((issue) => {
const lastPathItem =
issue.path && issue.path.length > 0
? issue.path[issue.path.length - 1]
: undefined;
issue.path && issue.path.length > 0 ? issue.path[issue.path.length - 1] : undefined;
const field =
lastPathItem && 'key' in lastPathItem && lastPathItem.key != null
lastPathItem && "key" in lastPathItem && lastPathItem.key != null
? String(lastPathItem.key)
: '';
: "";
return {
message: issue.message ?? 'Validation error',
rule: String(issue.type ?? 'validation'),
message: issue.message ?? "Validation error",
rule: String(issue.type ?? "validation"),
field,
};
});
const errorDetail = {
status: 422,
title: 'Validation Error',
detail: 'Errors related to business logic such as uniqueness',
title: "Validation Error",
detail: "Errors related to business logic such as uniqueness",
errors,
};
reply.type('application/problem+json').code(422).send(errorDetail);
reply.type("application/problem+json").code(422).send(errorDetail);
} else {
reply.send(error);
}
});

fastify.addContentTypeParser(
'application/problem+json',
{ parseAs: 'string' },
fastify.getDefaultJsonParser('ignore', 'ignore'),
"application/problem+json",
{ parseAs: "string" },
fastify.getDefaultJsonParser("ignore", "ignore"),
);

// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(AutoLoad, {
dir: path.join(import.meta.dirname, 'plugins'),
dir: path.join(import.meta.dirname, "plugins"),
options: opts,
});

fastify.register(glue, {
// prefix: 'v1',
serviceHandlers,
specification: './tsp-output/@typespec/openapi3/openapi.v1.json',
specification: "./tsp-output/@typespec/openapi3/openapi.v1.json",
});

// This loads all plugins defined in routes
Expand Down
46 changes: 0 additions & 46 deletions biome.json

This file was deleted.

Loading