Skip to content

Commit

Permalink
feat: support egg >= 4.0
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257
  • Loading branch information
fengmk2 committed Feb 4, 2025
1 parent 674ed79 commit ea1bf7e
Show file tree
Hide file tree
Showing 26 changed files with 270 additions and 211 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
coverage
test/fixtures
coverage
__snapshots__
40 changes: 2 additions & 38 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
{
"root": true,
"extends": [
"eslint-config-egg/typescript",
"plugin:compat/recommended", // https://www.npmjs.com/package/eslint-plugin-compat
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended"
],
"env": {
"browser": true,
"node": true
},
"settings": {
"polyfills": ["Promise"]
},
"rules": {
"prefer-arrow-callback": "error",
"space-before-function-paren": [
"error",
{
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}
],
"jsdoc/require-param-description": "off",
"jsdoc/require-returns-type": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": "off",
"import/default": "off",
"import/order": [
"error",
{
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
"groups": ["builtin", "external", "internal", ["parent", "sibling", "index"], "object"],
"newlines-between": "never"
}
]
}
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
15 changes: 15 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, windows-latest, macos-latest'
version: '18, 20, 22'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ dist
.idea
*.js
typings

.tshy*
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .tshy/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"module": "nodenext",
"moduleResolution": "nodenext"
}
}
16 changes: 16 additions & 0 deletions .tshy/commonjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.cts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../src/**/*.mts",
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/commonjs"
}
}
15 changes: 15 additions & 0 deletions .tshy/esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/esm"
}
}
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# egg-typebox-validate

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-typebox-validate.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-typebox-validate
[travis-image]: https://img.shields.io/travis/xiekw2010/egg-typebox-validate.svg?style=flat-square
[travis-url]: https://travis-ci.org/xiekw2010/egg-typebox-validate
[codecov-image]: https://img.shields.io/codecov/c/github/xiekw2010/egg-typebox-validate.svg?style=flat-square
[codecov-url]: https://codecov.io/github/xiekw2010/egg-typebox-validate?branch=master
[david-image]: https://img.shields.io/david/xiekw2010/egg-typebox-validate.svg?style=flat-square
[david-url]: https://david-dm.org/xiekw2010/egg-typebox-validate
[snyk-image]: https://snyk.io/test/npm/egg-typebox-validate/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-typebox-validate
[download-image]: https://img.shields.io/npm/dm/egg-typebox-validate.svg?style=flat-square
Expand Down Expand Up @@ -106,16 +101,23 @@ export default HomeController;

![tpian](https://gw.alipayobjects.com/zos/antfincdn/XjH2W7lEB/ad5b628c-9ff9-456d-bb7b-2fb0ac418f1c.png)


## 怎么使用

1. 安装

针对 `egg@4.x` 及以上版本,使用

```js
npm i egg-typebox-validate -S
```

2. 在项目中配置
针对 `egg@3.x` 版本,使用

```js
npm i egg-typebox-validate@3 -S
```

1. 在项目中配置

```js
// config/plugin.ts
Expand Down Expand Up @@ -452,3 +454,9 @@ async someFunc() {
## License

[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=xiekw2010/egg-typebox-validate)](https://github.com/xiekw2010/egg-typebox-validate/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
13 changes: 12 additions & 1 deletion benchmark/ajv-vs-parameter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Benchmark from 'benchmark';
import addFormats from 'ajv-formats';
import Ajv from 'ajv';
import Parameter from 'parameter';
import { Type } from '../typebox';
import { Type } from '../dist/esm/typebox.js';

const getAjvInstance = () =>
addFormats(new Ajv({}), [
Expand Down Expand Up @@ -88,11 +88,22 @@ suite
.run({ async: true });

/*
MacBook Pro(2.2 GHz 六核Intel Core i7)
#ajv x 941 ops/sec ±3.97% (73 runs sampled)
#ajv define once x 17,188,370 ops/sec ±11.53% (73 runs sampled)
#parameter x 2,544,118 ops/sec ±4.68% (79 runs sampled)
#parameter define once x 2,541,590 ops/sec ±5.34% (77 runs sampled)
Fastest is #ajv define once
MacBook Pro(13-inch, M1, 2020)
#ajv x 2,822 ops/sec ±6.24% (82 runs sampled)
#ajv define once x 27,165,953 ops/sec ±7.68% (88 runs sampled)
#parameter x 4,464,409 ops/sec ±1.45% (98 runs sampled)
#parameter define once x 4,515,932 ops/sec ±5.30% (92 runs sampled)
Fastest is #ajv define once
*/

8 changes: 0 additions & 8 deletions decorator.d.ts

This file was deleted.

18 changes: 0 additions & 18 deletions index.d.ts

This file was deleted.

Loading

0 comments on commit ea1bf7e

Please sign in to comment.