create-aomex 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/templates/.eslintrc.yml +7 -3
- package/templates/.gitignore +9 -0
- package/templates/.vscode/extensions.json +6 -1
- package/templates/src/cli.ts +1 -1
- package/templates/src/commanders/schedule.cmd.ts +4 -0
- package/templates/src/routers/{index.router.ts → hello.router.ts} +9 -2
- package/templates/src/routers/user.router.ts +28 -3
- package/templates/src/services/{db.ts → prisma.ts} +1 -1
- package/templates/src/services/user.service.ts +4 -4
- package/templates/src/web.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-aomex",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"repository": "git@github.com:aomex/create-aomex.git",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
25
|
"templates",
|
|
26
|
+
"templates/.gitignore",
|
|
26
27
|
"LICENSE",
|
|
27
28
|
"package.json",
|
|
28
29
|
"README.md"
|
package/templates/.eslintrc.yml
CHANGED
|
@@ -14,9 +14,13 @@ rules:
|
|
|
14
14
|
'@typescript-eslint/no-unsafe-return': 'error'
|
|
15
15
|
|
|
16
16
|
'@typescript-eslint/await-thenable': 'error'
|
|
17
|
-
# Number String Object
|
|
18
|
-
'@typescript-eslint/
|
|
19
|
-
|
|
17
|
+
# Number String Object Boolean BigInt Symbol
|
|
18
|
+
'@typescript-eslint/no-wrapper-object-types': 'error'
|
|
19
|
+
# Function
|
|
20
|
+
'@typescript-eslint/no-unsafe-function-type': 'error'
|
|
21
|
+
# no @ts-ignore @ts-nocheck @ts-check
|
|
22
|
+
# yes @ts-expect-error: WITH_YOUR_DESCRIPTION
|
|
23
|
+
'@typescript-eslint/ban-ts-comments': ['error', { 'ts-expect-error': 'allow-with-description' }]
|
|
20
24
|
'@typescript-eslint/no-duplicate-type-constituents': 'error'
|
|
21
25
|
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error'
|
|
22
26
|
# foo?.bar!
|
package/templates/src/cli.ts
CHANGED
|
@@ -5,6 +5,10 @@ import { schedule } from '@aomex/cron';
|
|
|
5
5
|
export const commander = new Commander();
|
|
6
6
|
|
|
7
7
|
commander.create('schedule', {
|
|
8
|
+
docs: {
|
|
9
|
+
summary: '执行 npx aomex -h 可以看到我',
|
|
10
|
+
description: '执行 npx aomex schedule -h 可以看到我',
|
|
11
|
+
},
|
|
8
12
|
mount: [
|
|
9
13
|
// schedule({
|
|
10
14
|
// second: '*/15',
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rule } from '@aomex/core';
|
|
2
|
+
import { response, Router } from '@aomex/web';
|
|
2
3
|
import { hello } from '@middleware/hello.middleware';
|
|
3
4
|
|
|
4
5
|
export const router = new Router();
|
|
5
6
|
|
|
6
7
|
router.get('/', {
|
|
7
|
-
mount: [
|
|
8
|
+
mount: [
|
|
9
|
+
hello,
|
|
10
|
+
response({
|
|
11
|
+
statusCode: 200,
|
|
12
|
+
content: rule.string(),
|
|
13
|
+
}),
|
|
14
|
+
],
|
|
8
15
|
action: (ctx) => {
|
|
9
16
|
ctx.send(`hello world, ${ctx.visitCount}`);
|
|
10
17
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { services } from '@services';
|
|
2
|
-
import { body, params, Router } from '@aomex/web';
|
|
2
|
+
import { body, params, response, Router } from '@aomex/web';
|
|
3
3
|
import { rule } from '@aomex/core';
|
|
4
4
|
|
|
5
5
|
export const router = new Router({
|
|
@@ -7,6 +7,16 @@ export const router = new Router({
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
router.get('/', {
|
|
10
|
+
mount: [
|
|
11
|
+
response({
|
|
12
|
+
statusCode: 200,
|
|
13
|
+
content: rule.array({
|
|
14
|
+
id: rule.int(),
|
|
15
|
+
name: rule.string(),
|
|
16
|
+
age: rule.int(),
|
|
17
|
+
}),
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
10
20
|
action: async (ctx) => {
|
|
11
21
|
const users = await services.user.findAll();
|
|
12
22
|
ctx.send(200, users);
|
|
@@ -18,12 +28,24 @@ router.get('/:id', {
|
|
|
18
28
|
params({
|
|
19
29
|
id: rule.int().min(1),
|
|
20
30
|
}),
|
|
31
|
+
response({
|
|
32
|
+
statusCode: 200,
|
|
33
|
+
content: {
|
|
34
|
+
id: rule.int(),
|
|
35
|
+
name: rule.string(),
|
|
36
|
+
age: rule.int(),
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
response({
|
|
40
|
+
statusCode: 404,
|
|
41
|
+
description: '用户不存在',
|
|
42
|
+
}),
|
|
21
43
|
],
|
|
22
44
|
action: async (ctx) => {
|
|
23
45
|
const { id } = ctx.params;
|
|
24
46
|
const user = await services.user.findById(id);
|
|
25
47
|
if (!user) {
|
|
26
|
-
return
|
|
48
|
+
return ctx.throw(404, '用户不存在');
|
|
27
49
|
}
|
|
28
50
|
ctx.send(user);
|
|
29
51
|
},
|
|
@@ -35,10 +57,13 @@ router.post('/', {
|
|
|
35
57
|
name: rule.string(),
|
|
36
58
|
age: rule.number(),
|
|
37
59
|
}),
|
|
60
|
+
response({
|
|
61
|
+
statusCode: 201,
|
|
62
|
+
}),
|
|
38
63
|
],
|
|
39
64
|
action: async (ctx) => {
|
|
40
65
|
const { name, age } = ctx.body;
|
|
41
66
|
await services.user.createUser(name, age);
|
|
42
|
-
ctx.send(201);
|
|
67
|
+
ctx.send(201, null);
|
|
43
68
|
},
|
|
44
69
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Service } from '@aomex/core';
|
|
2
|
-
import {
|
|
2
|
+
import { prisma } from './prisma';
|
|
3
3
|
import { Prisma } from '@prisma/client';
|
|
4
4
|
import { traceMethod } from '@aomex/async-trace';
|
|
5
5
|
|
|
6
6
|
export class UserService extends Service {
|
|
7
7
|
@traceMethod('User.findAll')
|
|
8
8
|
async findAll() {
|
|
9
|
-
return
|
|
9
|
+
return prisma.user.findMany({
|
|
10
10
|
orderBy: [
|
|
11
11
|
{
|
|
12
12
|
id: Prisma.SortOrder.desc,
|
|
@@ -17,11 +17,11 @@ export class UserService extends Service {
|
|
|
17
17
|
|
|
18
18
|
@traceMethod((userId) => `User.find(${userId})`)
|
|
19
19
|
async findById(userId: number) {
|
|
20
|
-
return
|
|
20
|
+
return prisma.user.findUnique({ where: { id: userId } });
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async createUser(name: string, age: number) {
|
|
24
|
-
await
|
|
24
|
+
await prisma.user.create({
|
|
25
25
|
data: {
|
|
26
26
|
name,
|
|
27
27
|
age,
|
package/templates/src/web.ts
CHANGED
|
@@ -12,8 +12,9 @@ import { generateOpenapi } from '@aomex/openapi';
|
|
|
12
12
|
export const app = new WebApp({
|
|
13
13
|
locale: 'zh_CN',
|
|
14
14
|
mount: [
|
|
15
|
+
httpLogger(),
|
|
15
16
|
responseTime,
|
|
16
|
-
traceMiddleware('生命周期', async (
|
|
17
|
+
traceMiddleware('生命周期', async (_record) => {
|
|
17
18
|
// 根据 record.delta 上报慢日志
|
|
18
19
|
// console.log(record);
|
|
19
20
|
}),
|
|
@@ -32,7 +33,6 @@ export const app = new WebApp({
|
|
|
32
33
|
},
|
|
33
34
|
}),
|
|
34
35
|
helmet(),
|
|
35
|
-
httpLogger(),
|
|
36
36
|
routers('./src/routers'),
|
|
37
37
|
],
|
|
38
38
|
});
|