fastnode-cli 0.2.0 → 0.4.0
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/README.md +42 -5
- package/dist/index.js +35 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img
|
|
3
|
+
src="https://res.cloudinary.com/dlvcthd0a/image/upload/v1773121010/fast_cgma5m.png"
|
|
4
|
+
alt="FastNode logo"
|
|
5
|
+
width="220"
|
|
6
|
+
/>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
1
9
|
# fastnode-cli
|
|
2
10
|
|
|
3
11
|
`fastnode-cli` scaffolds FastNode applications and works with `fastnode-core`.
|
|
@@ -47,24 +55,33 @@ src/items/items.controller.ts
|
|
|
47
55
|
|
|
48
56
|
## What the Scaffold Includes
|
|
49
57
|
|
|
50
|
-
The generated app now includes a
|
|
58
|
+
The generated app now includes a minimal HTTP + Socket.IO setup:
|
|
51
59
|
|
|
52
60
|
- app-level default execution policy in `createApp(...)`
|
|
53
61
|
- controller-level policy with `@ExecutionPolicy(...)`
|
|
62
|
+
- request-scoped execution helpers with `@Context()`
|
|
54
63
|
- FastAPI-style path placeholders like `/{item_id}`
|
|
55
64
|
- parameter decorators like `@Param()` and `@Query()`
|
|
65
|
+
- one Socket.IO namespace controller with `@Subscribe()` and `@EmitToClient()`
|
|
66
|
+
- Swagger docs available automatically at `/docs`
|
|
67
|
+
- Socket.IO attached automatically at the default `/socket.io` path
|
|
56
68
|
|
|
57
69
|
Example generated shape:
|
|
58
70
|
|
|
59
71
|
```ts
|
|
60
72
|
import "reflect-metadata";
|
|
61
73
|
import {
|
|
74
|
+
Body,
|
|
75
|
+
Context,
|
|
62
76
|
Controller,
|
|
77
|
+
EmitToClient,
|
|
63
78
|
ExecutionPolicy,
|
|
64
79
|
Get,
|
|
65
80
|
Module,
|
|
66
81
|
Param,
|
|
67
82
|
Query,
|
|
83
|
+
SocketController,
|
|
84
|
+
Subscribe,
|
|
68
85
|
createApp,
|
|
69
86
|
} from "fastnode-core";
|
|
70
87
|
|
|
@@ -72,9 +89,12 @@ import {
|
|
|
72
89
|
@ExecutionPolicy({ timeout: 5000 })
|
|
73
90
|
class HelloController {
|
|
74
91
|
@Get("/")
|
|
75
|
-
hello(@Query("name") name?: string) {
|
|
92
|
+
async hello(@Query("name") name?: string, @Context() ctx?: any) {
|
|
93
|
+
await ctx?.sleep(25);
|
|
94
|
+
|
|
76
95
|
return {
|
|
77
96
|
message: `Hello from hello${name ? `, ${name}` : ""}`,
|
|
97
|
+
deadline: ctx?.snapshot?.().deadline,
|
|
78
98
|
};
|
|
79
99
|
}
|
|
80
100
|
|
|
@@ -84,7 +104,16 @@ class HelloController {
|
|
|
84
104
|
}
|
|
85
105
|
}
|
|
86
106
|
|
|
87
|
-
@
|
|
107
|
+
@SocketController("/chat")
|
|
108
|
+
class HelloSocketController {
|
|
109
|
+
@Subscribe("ping")
|
|
110
|
+
@EmitToClient()
|
|
111
|
+
ping(@Body("message") message?: string) {
|
|
112
|
+
return { message: message ?? "pong" };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@Module({ controllers: [HelloController, HelloSocketController] })
|
|
88
117
|
class HelloModule {}
|
|
89
118
|
|
|
90
119
|
createApp([HelloModule], {
|
|
@@ -99,15 +128,23 @@ Generated controller files also include request-data examples for:
|
|
|
99
128
|
|
|
100
129
|
- `@Param("id")`
|
|
101
130
|
- `@Query("page")`
|
|
131
|
+
- `@Post("/")`
|
|
102
132
|
- `@Body()`
|
|
103
133
|
- `@Body("name")`
|
|
104
134
|
|
|
105
135
|
## Related Docs
|
|
106
136
|
|
|
107
|
-
See `packages/core/README.md` for the full
|
|
137
|
+
See `packages/core/README.md` for the full framework guide, including:
|
|
108
138
|
|
|
109
139
|
- `@ExecutionPolicy()`
|
|
110
140
|
- `@UseExecutionPolicy()`
|
|
141
|
+
- `@Context()`
|
|
142
|
+
- `@IsolatedInput()`
|
|
111
143
|
- `@IsolatedHandler()`
|
|
144
|
+
- `@SocketController()`
|
|
145
|
+
- `@Subscribe()`
|
|
146
|
+
- `@UseGuard()`
|
|
147
|
+
- `@UseRateLimit()`
|
|
148
|
+
- `@UseValidation()`
|
|
112
149
|
- inline vs isolated execution
|
|
113
|
-
-
|
|
150
|
+
- socket event handling and room broadcasts
|
package/dist/index.js
CHANGED
|
@@ -89,12 +89,18 @@ function buildMainTemplate(projectName) {
|
|
|
89
89
|
const moduleName = `${toPascalCase(projectName)}Module`;
|
|
90
90
|
return `import "reflect-metadata";
|
|
91
91
|
import {
|
|
92
|
+
Body,
|
|
93
|
+
Context,
|
|
92
94
|
Controller,
|
|
95
|
+
EmitToClient,
|
|
93
96
|
ExecutionPolicy,
|
|
94
97
|
Get,
|
|
95
98
|
Module,
|
|
96
99
|
Param,
|
|
100
|
+
Post,
|
|
97
101
|
Query,
|
|
102
|
+
SocketController,
|
|
103
|
+
Subscribe,
|
|
98
104
|
createApp,
|
|
99
105
|
} from "fastnode-core";
|
|
100
106
|
|
|
@@ -102,9 +108,15 @@ import {
|
|
|
102
108
|
@ExecutionPolicy({ timeout: 5000 })
|
|
103
109
|
class ${className} {
|
|
104
110
|
@Get("/")
|
|
105
|
-
hello(
|
|
111
|
+
async hello(
|
|
112
|
+
@Query("name") name?: string,
|
|
113
|
+
@Context() ctx?: any
|
|
114
|
+
) {
|
|
115
|
+
await ctx?.sleep(25);
|
|
116
|
+
|
|
106
117
|
return {
|
|
107
118
|
message: \`Hello from ${projectName}\${name ? \`, \${name}\` : ""}\`,
|
|
119
|
+
deadline: ctx?.snapshot?.().deadline,
|
|
108
120
|
};
|
|
109
121
|
}
|
|
110
122
|
|
|
@@ -118,9 +130,27 @@ class ${className} {
|
|
|
118
130
|
include,
|
|
119
131
|
};
|
|
120
132
|
}
|
|
133
|
+
|
|
134
|
+
@Post("/")
|
|
135
|
+
create() {
|
|
136
|
+
return {
|
|
137
|
+
created: true,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@SocketController("/chat")
|
|
143
|
+
class ${toPascalCase(projectName)}SocketController {
|
|
144
|
+
@Subscribe("ping")
|
|
145
|
+
@EmitToClient()
|
|
146
|
+
ping(@Body("message") message?: string) {
|
|
147
|
+
return {
|
|
148
|
+
message: message ?? "pong",
|
|
149
|
+
};
|
|
150
|
+
}
|
|
121
151
|
}
|
|
122
152
|
|
|
123
|
-
@Module({ controllers: [${className}] })
|
|
153
|
+
@Module({ controllers: [${className}, ${toPascalCase(projectName)}SocketController] })
|
|
124
154
|
class ${moduleName} {}
|
|
125
155
|
|
|
126
156
|
createApp([${moduleName}], {
|
|
@@ -137,6 +167,7 @@ function buildControllerTemplate(controllerName) {
|
|
|
137
167
|
Body,
|
|
138
168
|
Controller,
|
|
139
169
|
Get,
|
|
170
|
+
Post,
|
|
140
171
|
Param,
|
|
141
172
|
Query,
|
|
142
173
|
} from "fastnode-core";
|
|
@@ -166,8 +197,8 @@ export class ${className} {
|
|
|
166
197
|
};
|
|
167
198
|
}
|
|
168
199
|
|
|
169
|
-
@
|
|
170
|
-
|
|
200
|
+
@Post("/")
|
|
201
|
+
create(
|
|
171
202
|
@Body() payload?: Record<string, unknown>,
|
|
172
203
|
@Body("name") name?: string
|
|
173
204
|
) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastnode-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The official CLI for scaffolding and serving FastNode applications.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"fastnode": "dist/index.js"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"chalk": "^5.3.0",
|
|
27
27
|
"commander": "^11.0.0",
|
|
28
|
-
"fastnode-core": "^0.
|
|
28
|
+
"fastnode-core": "^0.4.0",
|
|
29
29
|
"reflect-metadata": "^0.1.13"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|