Skip to content

Commit 658eab0

Browse files
committed
docs: enhance documentation: summary new version
1 parent 9de5a98 commit 658eab0

File tree

5 files changed

+70
-64
lines changed

5 files changed

+70
-64
lines changed

README.md

+48-30
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
Why `fast-maker`?
1616

17-
fastify.js already have auto route mechanics using [fastify-autoload](https://github.com/fastify/fastify-autoload). But why you have to use `fast-maker`?
17+
fastify.js already have excellent auto route mechanics using [fastify-autoload](https://github.com/fastify/fastify-autoload). But why you have to use `fast-maker`?
1818

19+
1. Zero cost in Run-Time.
1920
1. [Static analysis](https://en.wikipedia.org/wiki/Static_program_analysis): `fast-maker` generate TypeScript source code. Because it help to find error in compile-time, not runtime
20-
2. Complex Variable: You can use like that: `/person/[kind]-[id]/`. It help to get id and kind of id, for example serial-number and id or db-pk and id
21-
3. Next.js: `fast-maker` use the same mechanics as [Next.js](https://nextjs.org/docs/routing/introduction)
22-
4. `fast-maker` support a beautiful cli-interface
21+
1. Flexable Routing: You can use like that: `/person/[kind]-[id]/`. It help to get id and kind of id, for example serial-number and id or db-pk and id, even if you can use regular expression.
22+
1. Unifying how route paths are built: `fast-maker` use the same mechanics as [Next.js](https://nextjs.org/docs/routing/introduction). Route paths using file-system cannot be developer-specific
23+
1. `fast-maker` support a beautiful cli-interface
2324

2425
## Table of Contents <!-- omit in toc -->
2526

@@ -88,9 +89,6 @@ npx fast-maker --help
8889
# display help for route commands
8990
npx fast-maker route --help
9091

91-
# display help for watch commands
92-
npx fast-maker watch --help
93-
9492
# display help for init commands
9593
npx fast-maker init --help
9694
```
@@ -107,26 +105,29 @@ use file-system.
107105

108106
```text
109107
handlers/
110-
├─ get/
111-
│ ├─ hero/
112-
│ │ ├─ [name].ts
113-
├─ post/
114-
│ ├─ hero.ts
115-
├─ put/
116-
│ ├─ hero/
117-
│ │ ├─ [name].ts
118-
├─ delete/
119-
│ ├─ hero/
120-
│ │ ├─ [name].ts
108+
├─ superheros/
109+
│ ├─ [id]/
110+
│ │ ├─ powers/
111+
│ │ │ ├─ [id]/
112+
│ │ │ │ ├─ delete.ts
113+
│ │ │ │ ├─ get.ts
114+
│ │ │ │ ├─ put.ts
115+
│ │ │ ├─ post.ts
116+
│ │ ├─ delete.ts
117+
│ │ ├─ get.ts
118+
│ │ ├─ put.ts
119+
│ ├─ get.ts
120+
│ ├─ post.ts
121121
```
122122

123-
`get`, `post`, `put`, `delete` directory represent _HTTP Method_. Also you can use `options`, `patch`, `head`, `all` directory.
123+
`get`, `post`, `put`, `delete` filename represent _HTTP Method_. Also you can use `options`, `patch`, `head`, `all` filename.
124124

125125
### Route options
126126

127127
You can pass `RouteShorthandOptions` option like that,
128128

129129
```ts
130+
// When not using a `fastify` instance, you can declare it as a variable like this
130131
export const option: RouteShorthandOptions = {
131132
schema: {
132133
querystring: schema.properties?.Querystring,
@@ -135,6 +136,22 @@ export const option: RouteShorthandOptions = {
135136
};
136137
```
137138

139+
```ts
140+
// When using the `fastify` instance, you can declare it as a function like this
141+
export const option = (fastify: FastifyInstance): RouteShorthandOptions => {
142+
return {
143+
schema: {
144+
querystring: schema.properties?.Querystring,
145+
body: schema.properties?.Body,
146+
},
147+
preHandler: fastify.auth([
148+
fastify.allowAnonymous,
149+
fastify.verifyBearerAuth
150+
]),
151+
};
152+
};
153+
```
154+
138155
You have to `named export` and variable name must be a `option`.
139156

140157
### Route handler
@@ -145,7 +162,7 @@ You can pass route handler function like that,
145162
import { FastifyRequest } from 'fastify';
146163
import type { IReqSearchPokemonQuerystring, IReqSearchPokemonParams } from '../../interface/IReqSearchPokemon';
147164

148-
export default async function (
165+
export async function handler(
149166
req: FastifyRequest<{ Querystring: IReqSearchPokemonQuerystring; Params: IReqSearchPokemonParams }>,
150167
) {
151168
console.debug(req.query);
@@ -155,26 +172,27 @@ export default async function (
155172
}
156173
```
157174

158-
You have to `non-named export` (aka default export). Also you can use arrow function and you can use any name under TypeScript function name rule, as well as type arguments perfectly applied on route configuration
175+
You have to `named export` and variable name must be a `handler`. Also you can use arrow function and you can use any name under TypeScript function name rule, as well as type arguments perfectly applied on route configuration
159176

160177
### Variable in Route Path
161178

162179
File or Directory name surrounded square bracket like that,
163180

164181
```text
165182
handlers/
166-
├─ get/
167-
│ ├─ hero/
168-
│ │ ├─ [name].ts
183+
├─ superheros/
184+
│ ├─ [id]/
185+
│ │ ├─ get.ts
186+
│ │ ├─ put.ts
169187
```
170188

171-
Complex variable, No problem.
189+
Multiple variable, No problem.
172190

173191
```text
174192
handlers/
175-
├─ get/
176-
│ ├─ hero/
177-
│ │ ├─ [affiliation]-[name].ts
193+
├─ superheros/
194+
│ ├─ [kind]-[id]/
195+
│ │ ├─ get.ts
178196
```
179197

180198
This route path access like that: `curl http://localhost:8080/hero/marvel-ironman`
@@ -192,10 +210,10 @@ A complete example of using `fast-maker` can be found at [Ma-eum](https://github
192210

193211
## Roadmaps
194212

195-
- [ ] display each route path in cli-table
213+
- [x] display each route path in cli-table
196214
- [ ] add new option silent
197215
- [ ] documentation site
198-
- [ ] add more test
216+
- [x] add more test
199217

200218
## License
201219

docs/advance.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Hash create by resolved full-directory. And hash use crypto.createHmac function.
4747
fast-maker support FastifyRequest type argument. see below.
4848

4949
```ts
50-
// get/poke/world.ts
51-
const world = async (
50+
// poke/world/get.ts
51+
export const handler = async (
5252
req: FastifyRequest<
5353
{
5454
Querystring: IReqPokeHello['Querystring'];
@@ -77,11 +77,9 @@ const world = async (
7777
};
7878

7979
// generated code
80-
fastify.get<{
81-
// if IReqPokeHello interface in your typescript project, fast-maker append postfix hash.
82-
// Because error prevent raise by same name interface import
83-
Querystring: IReqPokeHello_052A3A1D6C6D4FFC835C4EB7F39FE90E['Querystring'];
84-
Body: IReqPokeHello_052A3A1D6C6D4FFC835C4EB7F39FE90E['Body'];
80+
fastify.route<{
81+
Querystring: IReqPokeHello['Querystring'];
82+
Body: IReqPokeHello['Body'];
8583
Headers: {
8684
'access-token': string;
8785
'refresh-token': string;
@@ -94,14 +92,18 @@ fastify.get<{
9492
};
9593
};
9694
};
97-
}>('/po-ke/world', option_nPZHxkE1fH4b3EascyCyIFc8UqLca2bc, world_nPZHxkE1fH4b3EascyCyIFc8UqLca2bc);
95+
}>({
96+
...option_nPZHxkE1fH4b3EascyCyIFc8UqLca2bc,
97+
url: '/po-ke/world',
98+
handler: world_nPZHxkE1fH4b3EascyCyIFc8UqLca2bc,
99+
});
98100
```
99101

100102
Don't worry about request type arguments, detail type declare and error prevent!
101103

102104
## RouteShorthandOptions
103105

104-
Named export `option` variable use to RouteShorthandOptions. I recommand using [simple-tjscli](https://www.npmjs.com/package/simple-tjscli). or [crate-ts-json-schema](https://github.com/imjuni/create-ts-json-schema). simple-tjscli, create-ts-json-schema can transfile TypeScript interface to JSONSchema. So you can pass like that.
106+
Named export `option` variable use to RouteShorthandOptions. I recommand using [simple-tjscli](https://www.npmjs.com/package/simple-tjscli). or [schema-nozzle](https://github.com/imjuni/schema-nozzle). simple-tjscli, schema-nozzle can transfile TypeScript interface to JSONSchema. So you can pass like that.
105107

106108
```ts
107109
// simple-tjscli

docs/options.md

+3-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
- [command list](#command-list)
66
- [`route`, `r` Option](#route-r-option)
7-
- [`watch`, `w` Option](#watch-w-option)
87

98
## command list
109

@@ -23,26 +22,11 @@
2322
| --config | | -c | configuration file path |
2423
| --output | | -o | route.ts file generate on output directory. Default value is route handler directory(--handler option passed) |
2524
| --skip-error | | | skip compile error on project source file |
25+
| --templates | | | path of the template files |
26+
| --ext-kind | | | module, route file extensions processing style in route.ts |
2627
| --cli-logo | | | display cli logo |
2728
| --route-map | | | create route-map source file |
28-
| --max-workers | | | max worker count |
29-
| --worker-timeout | | | route code generation worker timeout: default 90 seconds |
3029
| --use-default-export | | | route function in output file that use default export |
3130
| --route-function-name | | | rotue function name |
3231

33-
## `watch`, `w` Option
34-
35-
| name | required | alias | desc. |
36-
| :-------------------- | :------: | :---: | :------------------------------------------------------------------------------------------------------------ |
37-
| --handler | required | -a | API handler path |
38-
| --project | required | -p | tsconfig path |
39-
| --config | | -c | configuration file path |
40-
| --output | | -o | route.ts file generate on output directory. Default value is route handler directory(--handler option passed) |
41-
| --skip-error | | | skip compile error on project source file |
42-
| --cli-logo | | | display cli logo |
43-
| --route-map | | | create route-map source file |
44-
| --max-workers | | | max worker count |
45-
| --worker-timeout | | | route code generation worker timeout: default 90 seconds |
46-
| --use-default-export | | | route function in output file that use default export |
47-
| --route-function-name | | | rotue function name |
48-
| --debounce-time | | | watch file debounceTime. unit use milliseconds |
32+
---

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fast-maker",
3-
"version": "4.0.0-beta01",
3+
"version": "4.0.0",
44
"description": "create route file on specific directory",
55
"engines": {
66
"node": ">=18"

src/configs/interfaces/IBaseOption.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface IBaseOption {
1313
/** path of the tsconfig file. Because fast-maker use typescript compiler api. */
1414
project: string;
1515

16-
/** path of the tsconfig file. Because fast-maker use typescript compiler api. */
16+
/** path of the template files. */
1717
templates: string;
1818

1919
/** module, route file extensions processing style in route.ts */
@@ -29,14 +29,16 @@ export interface IBaseOption {
2929
routeMap: boolean;
3030

3131
/**
32-
* index.ts 파일을 생성할 때 사용할 파일의 목록입니다. 만약 아무런 값을 설정하지 않는다면
33-
* tsconfig.json 파일에 설정된 include 설정 값을 사용합니다
32+
* A list of files to use when generating the index.ts file.
33+
* If no value is set, the value of the include setting
34+
* set in the tsconfig.json file will be used
3435
*/
3536
include: string[];
3637

3738
/**
38-
* index.ts 파일을 생성할 때 제외할 파일의 목록입니다. 만약 아무런 값을 설정하지 않는다면
39-
* tsconfig.json 파일에 설정된 exclude 설정 값을 사용합니다
39+
* A list of files to exclude when generating the index.ts file.
40+
* If no value is set, the Use the value of the exclude setting
41+
* set in the tsconfig.json file
4042
*/
4143
exclude: string[];
4244

0 commit comments

Comments
 (0)