tspace-spear 1.2.8 → 1.2.9-beta.1
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 +303 -82
- package/dist/cli/app.d.ts +1 -1
- package/dist/cli/app.js +3 -7
- package/dist/cli/app.js.map +1 -1
- package/dist/cli/controller.d.ts +1 -1
- package/dist/cli/controller.js +1 -12
- package/dist/cli/controller.js.map +1 -1
- package/dist/cli/generators/app/index.js +1 -1
- package/dist/cli/generators/app/index.js.map +1 -1
- package/dist/cli/generators/controller/template.d.ts +1 -1
- package/dist/cli/generators/controller/template.js +16 -7
- package/dist/cli/generators/controller/template.js.map +1 -1
- package/dist/cli/generators/dto/index.js +5 -3
- package/dist/cli/generators/dto/index.js.map +1 -1
- package/dist/cli/generators/module/index.js +3 -3
- package/dist/cli/generators/service/template.d.ts +1 -1
- package/dist/cli/generators/service/template.js +17 -17
- package/dist/cli/index.js +10 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/core/client/index.d.ts +13 -43
- package/dist/lib/core/client/index.js +70 -33
- package/dist/lib/core/client/index.js.map +1 -1
- package/dist/lib/core/client/types.d.ts +43 -0
- package/dist/lib/core/client/types.js +3 -0
- package/dist/lib/core/client/types.js.map +1 -0
- package/dist/lib/core/compiler/generator.d.ts +4 -6
- package/dist/lib/core/compiler/generator.js +172 -39
- package/dist/lib/core/compiler/generator.js.map +1 -1
- package/dist/lib/core/compiler/index.d.ts +2 -2
- package/dist/lib/core/compiler/index.js +2 -2
- package/dist/lib/core/compiler/index.js.map +1 -1
- package/dist/lib/core/compiler/pre-routes.d.ts +12 -130
- package/dist/lib/core/compiler/pre-routes.js +13 -35
- package/dist/lib/core/compiler/pre-routes.js.map +1 -1
- package/dist/lib/core/compiler/types.d.ts +25 -0
- package/dist/lib/core/decorators/context.js +23 -15
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/controller.js +2 -1
- package/dist/lib/core/decorators/controller.js.map +1 -1
- package/dist/lib/core/decorators/index.d.ts +1 -0
- package/dist/lib/core/decorators/index.js +1 -0
- package/dist/lib/core/decorators/index.js.map +1 -1
- package/dist/lib/core/decorators/methods.js +4 -3
- package/dist/lib/core/decorators/methods.js.map +1 -1
- package/dist/lib/core/decorators/middleware.d.ts +40 -2
- package/dist/lib/core/decorators/middleware.js +54 -9
- package/dist/lib/core/decorators/middleware.js.map +1 -1
- package/dist/lib/core/decorators/service.d.ts +28 -0
- package/dist/lib/core/decorators/service.js +36 -0
- package/dist/lib/core/decorators/service.js.map +1 -0
- package/dist/lib/core/decorators/statusCode.js +3 -1
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/decorators/swagger.js +4 -3
- package/dist/lib/core/decorators/swagger.js.map +1 -1
- package/dist/lib/core/exception/index.d.ts +68 -0
- package/dist/lib/core/exception/index.js +123 -0
- package/dist/lib/core/exception/index.js.map +1 -0
- package/dist/lib/core/metadata/index.d.ts +6 -0
- package/dist/lib/core/metadata/index.js +13 -0
- package/dist/lib/core/metadata/index.js.map +1 -0
- package/dist/lib/core/server/fast-router.d.ts +2 -2
- package/dist/lib/core/server/fast-router.js +17 -3
- package/dist/lib/core/server/fast-router.js.map +1 -1
- package/dist/lib/core/server/index.d.ts +32 -5
- package/dist/lib/core/server/index.js +188 -45
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/parser-factory.js +59 -10
- package/dist/lib/core/server/parser-factory.js.map +1 -1
- package/dist/lib/core/server/response.js +21 -1
- package/dist/lib/core/server/response.js.map +1 -1
- package/dist/lib/core/types/index.d.ts +42 -29
- package/package.json +14 -5
- package/dist/cli/client.d.ts +0 -1
- package/dist/cli/client.js +0 -30
- package/dist/cli/client.js.map +0 -1
- package/dist/cli/middleware.d.ts +0 -1
- package/dist/cli/middleware.js +0 -16
- package/dist/cli/middleware.js.map +0 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.js +0 -17
- package/dist/client.js.map +0 -1
- package/dist/common/middlewares/log.middleware.d.ts +0 -2
- package/dist/common/middlewares/log.middleware.js +0 -12
- package/dist/common/middlewares/log.middleware.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -32
- package/dist/index.js.map +0 -1
- package/dist/modules/cats/cat.controller.d.ts +0 -58
- package/dist/modules/cats/cat.controller.js +0 -90
- package/dist/modules/cats/cat.controller.js.map +0 -1
- package/dist/modules/cats/cat.dto.d.ts +0 -8
- package/dist/modules/cats/cat.dto.js +0 -44
- package/dist/modules/cats/cat.dto.js.map +0 -1
- package/dist/modules/cats/cat.service.d.ts +0 -23
- package/dist/modules/cats/cat.service.js +0 -56
- package/dist/modules/cats/cat.service.js.map +0 -1
- package/dist/tests/e2e..test.d.ts +0 -1
- package/dist/tests/e2e..test.js +0 -16
- package/dist/tests/e2e..test.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,12 +12,20 @@ It is designed with a strong focus on developer experience and provides end-to-e
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
14
|
- ⚡ High-performance core built on native Node.js HTTP
|
|
15
|
-
- 🚀 Optional uWebSockets.js support
|
|
16
|
-
- 🧠 End-to-end (
|
|
17
|
-
-
|
|
15
|
+
- 🚀 Optional [uWebSockets.js](#adapter) adapter support for ultra-low latency and maximum throughput
|
|
16
|
+
- 🧠 End-to-end [E2E](#e2e) type safety across the entire request → response lifecycle
|
|
17
|
+
- 🎮 Built-in support for [Controllers](#controller) and route-based architecture
|
|
18
|
+
- 🏷️ Powerful Decorator system for [routes](#router), [middleware](#middleware), validation, and metadata
|
|
19
|
+
- 💉 Built-in constructor-based dependency injection (DI) for [Services](#service)
|
|
20
|
+
- 📦 [DTO](#dto) (Data Transfer Object) support for structured and type-safe request handling
|
|
21
|
+
- 📂 Built-in [File Upload](#file-upload) support via `useFileUpload()` with zero configuration required
|
|
22
|
+
- 🔌 Native [WebSocket](#web-socket) support for real-time applications and event-driven systems
|
|
23
|
+
- ⚛️ [GraphQL](#graphql) support with flexible schema integration and HTTP adapters
|
|
24
|
+
- 🖥️ Built-in [Cluster mode](#cluster) support for multi-core scalability and higher throughput
|
|
25
|
+
- 🧪 Built-in testing utilities for [E2E](#e2e) validation
|
|
18
26
|
- 🧩 Simple and intuitive developer experience
|
|
19
|
-
-
|
|
20
|
-
-
|
|
27
|
+
- 📘 Auto-generated [Swagger](#swagger) documentation via `app.useSwagger()` with zero manual configuration
|
|
28
|
+
- 🔥 Lightweight and optimized for high-performance APIs and microservices
|
|
21
29
|
|
|
22
30
|
---
|
|
23
31
|
|
|
@@ -36,7 +44,7 @@ See the [`docs`](https://thanathip41.github.io/tspace-spear) directory for full
|
|
|
36
44
|
|
|
37
45
|
## Basic Usage
|
|
38
46
|
- [Getting Started](#getting-started)
|
|
39
|
-
- [
|
|
47
|
+
- [Quick Started](#quick-started)
|
|
40
48
|
- [Adapter](#adapter)
|
|
41
49
|
- [Cluster](#cluster)
|
|
42
50
|
- [Global Prefix](#global-prefix)
|
|
@@ -51,12 +59,13 @@ See the [`docs`](https://thanathip41.github.io/tspace-spear) directory for full
|
|
|
51
59
|
- [Cookie](#cookie)
|
|
52
60
|
- [Middleware](#middleware)
|
|
53
61
|
- [Controller](#controller)
|
|
62
|
+
- [Service](#service)
|
|
54
63
|
- [Dto](#dto)
|
|
55
64
|
- [Router](#router)
|
|
56
65
|
- [Swagger](#swagger)
|
|
57
66
|
- [WebSocket](#websocket)
|
|
67
|
+
- [Graphql](#graphql)
|
|
58
68
|
- [E2E](#e2e)
|
|
59
|
-
- [Example CRUD](#example-crud)
|
|
60
69
|
|
|
61
70
|
## Getting Started
|
|
62
71
|
```js
|
|
@@ -72,7 +81,7 @@ new Spear()
|
|
|
72
81
|
.listen(8000 , () => console.log(`Server is now listening http://localhost:8000`))
|
|
73
82
|
```
|
|
74
83
|
|
|
75
|
-
##
|
|
84
|
+
## Quick Started
|
|
76
85
|
Generate applications, modules, controllers, services, and middleware with the Spear CLI.
|
|
77
86
|
```sh
|
|
78
87
|
# Install CLI globally
|
|
@@ -113,8 +122,6 @@ npm run dev
|
|
|
113
122
|
|
|
114
123
|
✔ Run E2E client:
|
|
115
124
|
ts-node src/client.ts
|
|
116
|
-
|
|
117
|
-
ts-node src/client.ts // for E2E
|
|
118
125
|
```
|
|
119
126
|
|
|
120
127
|
## Adapter
|
|
@@ -169,12 +176,31 @@ Global Prefix allows you to define a base path for all routes in your applicatio
|
|
|
169
176
|
It helps keep your API structured and consistent (e.g. /api, /v1, /app).
|
|
170
177
|
```js
|
|
171
178
|
const app = new Spear({
|
|
172
|
-
globalPrefix : '/api' // prefix all routes
|
|
179
|
+
globalPrefix : '/api', // prefix all routes
|
|
173
180
|
})
|
|
174
|
-
.get('/' , () => 'Hello world!')
|
|
181
|
+
.get('/' , () => 'Hello world!') // http://localhost:8000/api
|
|
182
|
+
.get('/cats' , () => `Hello all cats`) // http://localhost:8000/api/cats
|
|
183
|
+
.get('/cats/:id' , ({ params }) => `Hello cat: ${params.id}`) // http://localhost:8000/api/cats/1
|
|
175
184
|
.listen(8000 , () => console.log(`Server is now listening http://localhost:8000`))
|
|
176
185
|
|
|
177
186
|
// http://localhost:8000/api => 'Hello world!'
|
|
187
|
+
|
|
188
|
+
// Or this
|
|
189
|
+
|
|
190
|
+
const app = new Spear()
|
|
191
|
+
.useGlobalPrefix('api', {
|
|
192
|
+
exclude : [
|
|
193
|
+
{
|
|
194
|
+
path : '/cats/*',
|
|
195
|
+
// methods : '*'
|
|
196
|
+
// methods : ['GET','POST']
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
})
|
|
200
|
+
.get('/' , () => 'Hello world!') // http://localhost:8000/api
|
|
201
|
+
.get('/cats' , () => `Hello all cats`) // http://localhost:8000/cats
|
|
202
|
+
.get('/cats/:id' , ({ params }) => `Hello cat: ${params.id}`) // http://localhost:8000/cats/1
|
|
203
|
+
.listen(8000 , () => console.log(`Server is now listening http://localhost:8000`))
|
|
178
204
|
```
|
|
179
205
|
|
|
180
206
|
## Logger
|
|
@@ -594,6 +620,68 @@ import CatController from './cat-controller.ts'
|
|
|
594
620
|
})()
|
|
595
621
|
```
|
|
596
622
|
|
|
623
|
+
## Service
|
|
624
|
+
Registers one or more service classes for Dependency Injection.
|
|
625
|
+
|
|
626
|
+
All registered services will be available in the controller constructor
|
|
627
|
+
without manual instantiation.
|
|
628
|
+
```js
|
|
629
|
+
// cat-service.ts
|
|
630
|
+
class CatService {
|
|
631
|
+
public index () {
|
|
632
|
+
return [
|
|
633
|
+
{
|
|
634
|
+
id: 1,
|
|
635
|
+
name: 'cat1'
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
id: 2,
|
|
639
|
+
name: 'cat2'
|
|
640
|
+
}
|
|
641
|
+
]
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// cat-controller.ts
|
|
646
|
+
import {
|
|
647
|
+
Controller,
|
|
648
|
+
Get
|
|
649
|
+
} from 'tspace-spear';
|
|
650
|
+
import CatService from './cat-service.ts'
|
|
651
|
+
|
|
652
|
+
@Service([CatService]) // don't forgot this to send CatService for Dependency Injection(DI)
|
|
653
|
+
@Controller('/cats')
|
|
654
|
+
class CatController {
|
|
655
|
+
|
|
656
|
+
constructor(
|
|
657
|
+
private catService: CatService
|
|
658
|
+
) {}
|
|
659
|
+
|
|
660
|
+
@Get('/')
|
|
661
|
+
public index() {
|
|
662
|
+
return this.catService.index();
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// app.ts
|
|
667
|
+
import { Spear } from "tspace-spear";
|
|
668
|
+
|
|
669
|
+
(async () => {
|
|
670
|
+
|
|
671
|
+
const app = new Spear({
|
|
672
|
+
controllers : {
|
|
673
|
+
folder : `${__dirname}/controllers`,
|
|
674
|
+
name : /controller\.(ts|js)$/i,
|
|
675
|
+
preRouteTypes : true
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
app.useSwagger();
|
|
680
|
+
|
|
681
|
+
app.listen(8000 , () => console.log(`Server is now listening http://localhost:8000`));
|
|
682
|
+
})()
|
|
683
|
+
```
|
|
684
|
+
|
|
597
685
|
## Dto
|
|
598
686
|
DTO (Data Transfer Object) is used to validate and transform incoming request data before it reaches your controller logic.
|
|
599
687
|
```js
|
|
@@ -1083,6 +1171,163 @@ new Spear()
|
|
|
1083
1171
|
|
|
1084
1172
|
```
|
|
1085
1173
|
|
|
1174
|
+
## Graphql
|
|
1175
|
+
GraphQL CRUD Example with graphql-yoga + tspace-spear
|
|
1176
|
+
|
|
1177
|
+
This example shows how to build a simple GraphQL CRUD API using graphql-yoga and tspace-spear.
|
|
1178
|
+
|
|
1179
|
+
It includes:
|
|
1180
|
+
|
|
1181
|
+
- GraphQL schema setup
|
|
1182
|
+
- Query and Mutation examples
|
|
1183
|
+
- Create / Read / Update / Delete operations
|
|
1184
|
+
- HTTP integration with graphql-yoga
|
|
1185
|
+
|
|
1186
|
+
The server uses an in-memory array as a fake database for simplicity.
|
|
1187
|
+
|
|
1188
|
+
Features
|
|
1189
|
+
- High performance HTTP server with tspace-spear
|
|
1190
|
+
- Native GraphQL schema definitions
|
|
1191
|
+
- Full CRUD operations
|
|
1192
|
+
- Simple and dependency-light setup
|
|
1193
|
+
- Works with standard GraphQL clients and tools
|
|
1194
|
+
|
|
1195
|
+
```sh
|
|
1196
|
+
npm install graphql graphql-yoga
|
|
1197
|
+
```
|
|
1198
|
+
|
|
1199
|
+
```js
|
|
1200
|
+
import { type T, Spear } from "tspace-spear";
|
|
1201
|
+
|
|
1202
|
+
import {
|
|
1203
|
+
createYoga,
|
|
1204
|
+
createSchema,
|
|
1205
|
+
} from 'graphql-yoga';
|
|
1206
|
+
|
|
1207
|
+
type User = {
|
|
1208
|
+
id: number;
|
|
1209
|
+
name: string;
|
|
1210
|
+
email: string;
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
const users: User[] = [
|
|
1214
|
+
{
|
|
1215
|
+
id: 1,
|
|
1216
|
+
name: 'John',
|
|
1217
|
+
email: 'john@gmail.com',
|
|
1218
|
+
},
|
|
1219
|
+
];
|
|
1220
|
+
|
|
1221
|
+
const yoga = createYoga({
|
|
1222
|
+
graphqlEndpoint: '/graphql',
|
|
1223
|
+
|
|
1224
|
+
schema: createSchema({
|
|
1225
|
+
typeDefs: /* GraphQL */ `
|
|
1226
|
+
type User {
|
|
1227
|
+
id: Int!
|
|
1228
|
+
name: String!
|
|
1229
|
+
email: String!
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
input CreateUserInput {
|
|
1233
|
+
name: String!
|
|
1234
|
+
email: String!
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
input UpdateUserInput {
|
|
1238
|
+
id: Int!
|
|
1239
|
+
name: String
|
|
1240
|
+
email: String
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
type Query {
|
|
1244
|
+
users: [User!]!
|
|
1245
|
+
user(id: Int!): User
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
type Mutation {
|
|
1249
|
+
createUser(input: CreateUserInput!): User!
|
|
1250
|
+
updateUser(input: UpdateUserInput!): User!
|
|
1251
|
+
removeUser(id: Int!): User!
|
|
1252
|
+
}
|
|
1253
|
+
`,
|
|
1254
|
+
|
|
1255
|
+
resolvers: {
|
|
1256
|
+
Query: {
|
|
1257
|
+
users: () => users,
|
|
1258
|
+
|
|
1259
|
+
user: (_root, args) => {
|
|
1260
|
+
return users.find(
|
|
1261
|
+
(u) => u.id === args.id,
|
|
1262
|
+
);
|
|
1263
|
+
},
|
|
1264
|
+
},
|
|
1265
|
+
|
|
1266
|
+
Mutation: {
|
|
1267
|
+
createUser: (_root, args) => {
|
|
1268
|
+
const user = {
|
|
1269
|
+
id: Date.now(),
|
|
1270
|
+
name: args.input.name,
|
|
1271
|
+
email: args.input.email,
|
|
1272
|
+
};
|
|
1273
|
+
|
|
1274
|
+
users.push(user);
|
|
1275
|
+
|
|
1276
|
+
return user;
|
|
1277
|
+
},
|
|
1278
|
+
|
|
1279
|
+
updateUser: (_root, args) => {
|
|
1280
|
+
const user = users.find(
|
|
1281
|
+
(u) => u.id === args.input.id,
|
|
1282
|
+
);
|
|
1283
|
+
|
|
1284
|
+
if (!user) {
|
|
1285
|
+
throw new Error(
|
|
1286
|
+
'User not found',
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
if (args.input.name !== undefined) {
|
|
1291
|
+
user.name = args.input.name;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
if (args.input.email !== undefined) {
|
|
1295
|
+
user.email = args.input.email;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
return user;
|
|
1299
|
+
},
|
|
1300
|
+
|
|
1301
|
+
removeUser: (_root, args) => {
|
|
1302
|
+
const index = users.findIndex(
|
|
1303
|
+
(u) => u.id === args.id,
|
|
1304
|
+
);
|
|
1305
|
+
|
|
1306
|
+
if (index === -1) {
|
|
1307
|
+
throw new Error(
|
|
1308
|
+
'User not found',
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
const deleted = users[index];
|
|
1313
|
+
|
|
1314
|
+
users.splice(index, 1);
|
|
1315
|
+
|
|
1316
|
+
return deleted;
|
|
1317
|
+
},
|
|
1318
|
+
},
|
|
1319
|
+
},
|
|
1320
|
+
}),
|
|
1321
|
+
});
|
|
1322
|
+
|
|
1323
|
+
const app = new Spear()
|
|
1324
|
+
.get('/graphql',({ req , res }) => yoga(req , res))
|
|
1325
|
+
.post('/graphql',({ req , res }) => yoga(req , res))
|
|
1326
|
+
.listen(4000 , ({ port , server }) => {
|
|
1327
|
+
console.log(`server listening on : http://localhost:${port}/graphql`)
|
|
1328
|
+
})
|
|
1329
|
+
```
|
|
1330
|
+
|
|
1086
1331
|
## E2E
|
|
1087
1332
|
Provides end-to-end type safety and testing support across the full request lifecycle, from request input to
|
|
1088
1333
|
response output. It allows you to:
|
|
@@ -1142,7 +1387,7 @@ class CatController {
|
|
|
1142
1387
|
const cat = cats.find((d) => d.id === Number(params.id));
|
|
1143
1388
|
|
|
1144
1389
|
if(cat == null) {
|
|
1145
|
-
|
|
1390
|
+
throw res.notFound('not found cat')
|
|
1146
1391
|
}
|
|
1147
1392
|
|
|
1148
1393
|
return {
|
|
@@ -1184,7 +1429,7 @@ class CatController {
|
|
|
1184
1429
|
const index = cats.findIndex((d) => d.id === id);
|
|
1185
1430
|
|
|
1186
1431
|
if (index === -1) {
|
|
1187
|
-
|
|
1432
|
+
throw res.notFound('not found cat')
|
|
1188
1433
|
}
|
|
1189
1434
|
|
|
1190
1435
|
cats[index] = {
|
|
@@ -1227,7 +1472,7 @@ import Spear from "tspace-spear";
|
|
|
1227
1472
|
const app = new Spear({
|
|
1228
1473
|
logger : true,
|
|
1229
1474
|
controllers: {
|
|
1230
|
-
folder : `${__dirname}/controllers
|
|
1475
|
+
folder : `${__dirname}/controllers/*`,
|
|
1231
1476
|
name:/controller\.(ts|js)$/i,
|
|
1232
1477
|
// don't forget to set this option for auto-generate route metadata for type-safe E2E usage,
|
|
1233
1478
|
// and swagger documentation. By default if use .useSwagger() in app no need to set any description
|
|
@@ -1251,79 +1496,55 @@ const client: ApiClient<AppRouter> = new ApiClient(
|
|
|
1251
1496
|
`http://localhost:8000/api`
|
|
1252
1497
|
);
|
|
1253
1498
|
|
|
1254
|
-
|
|
1499
|
+
await client.get("/catsq"); ❌ // Type error: Argument of type '"/catsq"' is not assignable to parameter of type '"/cats" | "/cats/:id" | ... 3 more
|
|
1255
1500
|
const res = await client.get("/cats");
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
## Example CRUD
|
|
1268
|
-
```js
|
|
1269
|
-
import { Spear } from "tspace-spear";
|
|
1270
|
-
|
|
1271
|
-
const spears = [
|
|
1272
|
-
{
|
|
1273
|
-
id : 1,
|
|
1274
|
-
damage : 100
|
|
1275
|
-
},
|
|
1276
|
-
{
|
|
1277
|
-
id : 2,
|
|
1278
|
-
damage : 75
|
|
1279
|
-
},
|
|
1280
|
-
{
|
|
1281
|
-
id : 3,
|
|
1282
|
-
damage : 50
|
|
1283
|
-
}
|
|
1284
|
-
]
|
|
1285
|
-
|
|
1286
|
-
new Spear()
|
|
1287
|
-
// enable body payload
|
|
1288
|
-
.useBodyParser()
|
|
1289
|
-
.get('/' , () => spears)
|
|
1290
|
-
.get('/:id' , ({ params }) => spears.find(spear => spear.id === Number(params.id ?? 0)))
|
|
1291
|
-
.post('/' , ({ body }) => {
|
|
1292
|
-
// please validation the your body
|
|
1293
|
-
const damage = Number(body.damage ?? (Math.random() * 100).toFixed(0))
|
|
1294
|
-
|
|
1295
|
-
const id = spears.reduce((max, spear) => spear.id > max ? spear.id : max, 0) + 1
|
|
1296
|
-
|
|
1297
|
-
spears.push({ id , damage })
|
|
1298
|
-
|
|
1299
|
-
return spears.find(spear => spear.id === id)
|
|
1300
|
-
})
|
|
1301
|
-
.patch('/:id' , ({ params , body , res }) => {
|
|
1302
|
-
|
|
1303
|
-
const damage = Number(body.damage ?? (Math.random() * 100).toFixed(0))
|
|
1304
|
-
|
|
1305
|
-
const id = Number(params.id)
|
|
1306
|
-
|
|
1307
|
-
const spear = spears.find(spear => spear.id === id)
|
|
1308
|
-
|
|
1309
|
-
if (spear == null) return res.status(404).json({ message : 'Spear not found'})
|
|
1501
|
+
// res.ok -> true or false
|
|
1502
|
+
// res.status -> number
|
|
1503
|
+
// res.headers -> Hearders
|
|
1504
|
+
// res.data -> { cats: [{ id: 1, name: 'cat1', age: 1.6 },{ id: 2, name: 'cat2', age: 1.8 }] }
|
|
1505
|
+
|
|
1506
|
+
// Without checking `res.ok`, `res.data` is always typed as `any`.
|
|
1507
|
+
if(res.ok) {
|
|
1508
|
+
res.data.cats = 1 ❌ // Type error: Type 'number' is not assignable to type '{ id: number; name: string; age: number; }[]'
|
|
1509
|
+
res.data.cats[0].name = 1 ❌ // Type error: Type 'number' is not assignable to type 'string'
|
|
1510
|
+
res.data.cats[0].age = "1.6" ❌ // Type error: Type 'string' is not assignable to type 'number'
|
|
1511
|
+
}
|
|
1310
1512
|
|
|
1311
|
-
|
|
1513
|
+
await client.get("/cats/:id") ❌ // Expected 2 arguments, but got 1.
|
|
1514
|
+
await client.get("/cats/:id", { params : { id : "1" }}) ❌
|
|
1515
|
+
// The expected type comes from property 'id' which is declared here on type '{ id: number; }'
|
|
1516
|
+
await client.get("/cats/:id", { params : { id : 1 }}) ✅
|
|
1312
1517
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1518
|
+
await client.post("/cats") ❌ // Expected 2 arguments, but got 1.
|
|
1519
|
+
await client.post("/cats",{
|
|
1520
|
+
body : {} ❌ // Type '{}' is missing the following properties from type '{ name: string; age: number; }'
|
|
1521
|
+
});
|
|
1522
|
+
await client.post("/cats",{
|
|
1523
|
+
body : { name : "super cat" } ❌
|
|
1524
|
+
// Property 'age' is missing in type '{ name: string; }'
|
|
1525
|
+
// but required in type '{ name: string; age: number; }'.
|
|
1526
|
+
});
|
|
1527
|
+
await client.post("/cats",{
|
|
1528
|
+
body : { name : "super cat" , age : 5 } ✅
|
|
1529
|
+
});
|
|
1316
1530
|
|
|
1317
|
-
|
|
1531
|
+
await client.put("/cats") ✅
|
|
1318
1532
|
|
|
1319
|
-
|
|
1533
|
+
await client.put("/cats",{
|
|
1534
|
+
body : {} ✅
|
|
1535
|
+
});
|
|
1320
1536
|
|
|
1321
|
-
|
|
1537
|
+
await client.put("/cats",{
|
|
1538
|
+
body : { name : 1 } ❌ // Type 'number' is not assignable to type 'string'.
|
|
1539
|
+
});
|
|
1322
1540
|
|
|
1323
|
-
|
|
1541
|
+
await client.put("/cats",{
|
|
1542
|
+
body : { name : "super cat" } ✅
|
|
1543
|
+
});
|
|
1324
1544
|
|
|
1325
|
-
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1545
|
+
await client.put("/cats",{
|
|
1546
|
+
body : { name : "super cat" , age : 5 } ✅
|
|
1547
|
+
});
|
|
1548
|
+
|
|
1549
|
+
```
|
|
1328
1550
|
|
|
1329
|
-
```
|
package/dist/cli/app.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const app = "\nimport Spear from \"tspace-spear\";\n\
|
|
1
|
+
export declare const app = "\nimport Spear from \"tspace-spear\";\n\nexport const app = new Spear({\n logger: true,\n controllers: {\n folder: `${__dirname}/controllers`,\n name: /controller\\\\.(ts|js)$/i,\n\n // don't forget to set this option for auto-generate route metadata for type-safe E2E usage, \n // and swagger documentation. By default if use .useSwagger() in app no need to set any description\n preRouteTypes: true\n }\n})\n\napp.useGlobalPrefix(\"api\");\napp.useSwagger();\napp.useBodyParser();\n\napp.listen(8000 , ({ port , server }) => {\n console.log(`Server listening on : http://localhost:${port}`)\n console.log(\n`Docs listening on : http://localhost:${port}`/api/docs)\n})\n";
|
package/dist/cli/app.js
CHANGED
|
@@ -4,11 +4,11 @@ exports.app = void 0;
|
|
|
4
4
|
exports.app = `
|
|
5
5
|
import Spear from "tspace-spear";
|
|
6
6
|
|
|
7
|
-
const app = new Spear({
|
|
7
|
+
export const app = new Spear({
|
|
8
8
|
logger: true,
|
|
9
9
|
controllers: {
|
|
10
10
|
folder: \`\${__dirname}/controllers\`,
|
|
11
|
-
name: /controller
|
|
11
|
+
name: /controller\\\\.(ts|js)$/i,
|
|
12
12
|
|
|
13
13
|
// don't forget to set this option for auto-generate route metadata for type-safe E2E usage,
|
|
14
14
|
// and swagger documentation. By default if use .useSwagger() in app no need to set any description
|
|
@@ -22,11 +22,7 @@ app.useBodyParser();
|
|
|
22
22
|
|
|
23
23
|
app.listen(8000 , ({ port , server }) => {
|
|
24
24
|
console.log(\`Server listening on : http://localhost:\${port}\`)
|
|
25
|
-
console.log(\`Docs listening on : http://localhost:\${port}
|
|
25
|
+
console.log(\n\`Docs listening on : http://localhost:\${port}\`/api/docs)
|
|
26
26
|
})
|
|
27
|
-
|
|
28
|
-
type AppRouter = typeof app.contract;
|
|
29
|
-
export { AppRouter };
|
|
30
|
-
export { app };
|
|
31
27
|
`;
|
|
32
28
|
//# sourceMappingURL=app.js.map
|
package/dist/cli/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/cli/app.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/cli/app.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBlB,CAAC"}
|
package/dist/cli/controller.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CatController = "\nimport {\n type T,\n Controller,\n
|
|
1
|
+
export declare const CatController = "\nimport {\n type T,\n Controller,\n Get,\n Post,\n Put,\n Delete\n} from \"tspace-spear\";\n\ntype Cat = {\n id: number;\n name: string;\n age: number;\n};\n\nlet cats: Cat[] = [\n {\n id: 1,\n name: \"cat 1\",\n age: 2\n },\n {\n id: 2,\n name: \"cat 2\",\n age: 4\n }\n];\n\n@Controller(\"/cats\")\nexport default class CatController {\n\n @Get(\"/\")\n async index() {\n return {\n cats\n };\n }\n\n @Get(\"/:id\")\n async show({\n res,\n params\n }: T.Context<{\n params: {\n id: number;\n };\n }>) {\n\n const cat = cats.find(\n d => d.id === Number(params.id)\n );\n\n if (!cat) {\n throw res.notFound(\n \"Cat not found\"\n );\n }\n\n return {\n cat\n };\n }\n\n @Post(\"/\")\n async create({\n body\n }: T.Context<{\n body: {\n name: string;\n age: number;\n };\n }>) {\n\n const cat: Cat = {\n id: cats.length + 1,\n name: body.name,\n age: body.age\n };\n\n cats.push(cat);\n\n return {\n message: \"Created\",\n cat\n };\n }\n\n @Put(\"/:id\")\n async update({\n res,\n params,\n body\n }: T.Context<{\n params: {\n id: number;\n };\n body: Partial<{\n name: string;\n age: number;\n }>;\n }>) {\n\n const index = cats.findIndex(\n d => d.id === Number(params.id)\n );\n\n if (index === -1) {\n throw res.notFound(\n \"Cat not found\"\n );\n }\n\n cats[index] = {\n ...cats[index],\n ...body\n };\n\n return {\n message: \"Updated\",\n cat: cats[index]\n };\n }\n\n @Delete(\"/:id\")\n async remove({\n res,\n params\n }: T.Context<{\n params: {\n id: number;\n };\n }>) {\n\n const index = cats.findIndex(\n d => d.id === Number(params.id)\n );\n\n if (index === -1) {\n throw res.notFound(\n \"Cat not found\"\n );\n }\n\n cats = cats.filter(\n d => d.id !== Number(params.id)\n );\n\n return {\n message: \"Deleted\"\n };\n }\n}\n";
|
package/dist/cli/controller.js
CHANGED
|
@@ -5,15 +5,12 @@ exports.CatController = `
|
|
|
5
5
|
import {
|
|
6
6
|
type T,
|
|
7
7
|
Controller,
|
|
8
|
-
Middleware,
|
|
9
8
|
Get,
|
|
10
9
|
Post,
|
|
11
10
|
Put,
|
|
12
11
|
Delete
|
|
13
12
|
} from "tspace-spear";
|
|
14
13
|
|
|
15
|
-
import { CatMiddleware } from "../middlewares/cat.middleware";
|
|
16
|
-
|
|
17
14
|
type Cat = {
|
|
18
15
|
id: number;
|
|
19
16
|
name: string;
|
|
@@ -34,10 +31,9 @@ let cats: Cat[] = [
|
|
|
34
31
|
];
|
|
35
32
|
|
|
36
33
|
@Controller("/cats")
|
|
37
|
-
class CatController {
|
|
34
|
+
export default class CatController {
|
|
38
35
|
|
|
39
36
|
@Get("/")
|
|
40
|
-
@Middleware(CatMiddleware)
|
|
41
37
|
async index() {
|
|
42
38
|
return {
|
|
43
39
|
cats
|
|
@@ -45,7 +41,6 @@ class CatController {
|
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
@Get("/:id")
|
|
48
|
-
@Middleware(CatMiddleware)
|
|
49
44
|
async show({
|
|
50
45
|
res,
|
|
51
46
|
params
|
|
@@ -71,7 +66,6 @@ class CatController {
|
|
|
71
66
|
}
|
|
72
67
|
|
|
73
68
|
@Post("/")
|
|
74
|
-
@Middleware(CatMiddleware)
|
|
75
69
|
async create({
|
|
76
70
|
body
|
|
77
71
|
}: T.Context<{
|
|
@@ -96,7 +90,6 @@ class CatController {
|
|
|
96
90
|
}
|
|
97
91
|
|
|
98
92
|
@Put("/:id")
|
|
99
|
-
@Middleware(CatMiddleware)
|
|
100
93
|
async update({
|
|
101
94
|
res,
|
|
102
95
|
params,
|
|
@@ -133,7 +126,6 @@ class CatController {
|
|
|
133
126
|
}
|
|
134
127
|
|
|
135
128
|
@Delete("/:id")
|
|
136
|
-
@Middleware(CatMiddleware)
|
|
137
129
|
async remove({
|
|
138
130
|
res,
|
|
139
131
|
params
|
|
@@ -162,8 +154,5 @@ class CatController {
|
|
|
162
154
|
};
|
|
163
155
|
}
|
|
164
156
|
}
|
|
165
|
-
|
|
166
|
-
export { CatController };
|
|
167
|
-
export default CatController;
|
|
168
157
|
`;
|
|
169
158
|
//# sourceMappingURL=controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/cli/controller.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/cli/controller.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyJ5B,CAAC"}
|
|
@@ -24,7 +24,7 @@ const c = {
|
|
|
24
24
|
};
|
|
25
25
|
async function createApp(inputPath) {
|
|
26
26
|
if (!inputPath) {
|
|
27
|
-
console.log("Missing target path, try: spear
|
|
27
|
+
console.log("Missing target path, try: spear create new app");
|
|
28
28
|
process.exit(1);
|
|
29
29
|
}
|
|
30
30
|
const root = path_1.default.resolve(process.cwd(), inputPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/generators/app/index.ts"],"names":[],"mappings":";;;;;AAsBA,8BAsJC;AA5KD,4CAAoB;AACpB,gDAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/generators/app/index.ts"],"names":[],"mappings":";;;;;AAsBA,8BAsJC;AA5KD,4CAAoB;AACpB,gDAAwB;AACxB,iDAAqC;AACrC,yCAAyC;AACzC,iDAAoD;AACpD,qDAA4D;AAC5D,qDAA4D;AAC5D,kDAAsD;AACtD,8CAA8C;AAG9C,MAAM,CAAC,GAAG;IACR,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,IAAI,SAAS;IAC/C,GAAG,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,IAAI,SAAS;IAC9C,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,IAAI,SAAS;IACjD,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,IAAI,SAAS;IAChD,SAAS,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,IAAI,SAAS;IACpD,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,IAAI,SAAS;IAChD,KAAK,EAAE,SAAS;CACjB,CAAC;AAGK,KAAK,UAAU,SAAS,CAAC,SAAkB;IAChD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;QAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;IAEpD,YAAE,CAAC,SAAS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,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,oCAAoC,CAAC,IAAI,CAAC,CAAC;IAElE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,UAAU,SAAS,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ControllerTemplate = "\nimport {\n type T,\n Controller,\n Middleware,\n Get,\n Post,\n Put,\n Delete,\n ValidateDto\n} from \"tspace-spear\";\nimport { CatService } from \"./cat.service\";\nimport { CreateCatDto , UpdateCatDto } from \"./cat.dto\";\nimport { LogMiddleware } from \"../../common/middlewares/log.middleware\";\n\n@Controller(\"/cats\")\nclass CatController {\n\n constructor(\n private catService: CatService
|
|
1
|
+
export declare const ControllerTemplate = "\nimport {\n type T,\n Controller,\n Service,\n Middleware,\n Get,\n Post,\n Put,\n Delete,\n ValidateDto\n} from \"tspace-spear\";\nimport { CatService } from \"./cat.service\";\nimport { CreateCatDto , UpdateCatDto } from \"./cat.dto\";\nimport { LogMiddleware } from \"../../common/middlewares/log.middleware\";\n\n@Service([CatService])\n@Controller(\"/cats\")\nclass CatController {\n\n constructor(\n private catService: CatService\n ) {}\n\n @Get(\"/\")\n @Middleware(LogMiddleware)\n async index() {\n const cats = await this.catService.index();\n return { cats };\n }\n\n @Get(\"/:id\")\n @Middleware(LogMiddleware)\n async show({\n params\n }: T.Context<{\n params: {\n id: number;\n };\n }>) {\n const cat = await this.catService.show(params.id);\n return { cat }\n }\n\n @Post(\"/\")\n @ValidateDto(CreateCatDto)\n @Middleware(LogMiddleware)\n async create({\n body\n }: T.Context<{\n body: CreateCatDto;\n }>) {\n\n const cat = await this.catService\n .create({ \n name: body.name, \n age: body.age \n });\n\n return { cat };\n }\n\n @Put(\"/:id\")\n @ValidateDto(UpdateCatDto)\n @Middleware(LogMiddleware)\n async update({\n params,\n body\n }: T.Context<{\n params: {\n id: number;\n };\n body: UpdateCatDto;\n }>) {\n\n const cat = await this.catService\n .update(params.id, { \n name: body.name, \n age: body.age \n });\n\n return { cat }\n }\n\n @Delete(\"/:id\")\n @Middleware(LogMiddleware)\n async remove({\n params\n }: T.Context<{\n params: {\n id: number;\n };\n }>) {\n\n const deleted = await this.catService\n .remove(params.id);\n\n return deleted;\n }\n}\n\nexport { CatController };\nexport default CatController;\n";
|