tspace-spear 1.2.7 → 1.2.9
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 +299 -146
- package/dist/cli/generators/app/index.d.ts +1 -0
- package/dist/cli/generators/app/index.js +124 -0
- package/dist/cli/generators/app/index.js.map +1 -0
- package/dist/cli/generators/app/template.d.ts +1 -0
- package/dist/cli/{app.js → generators/app/template.js} +22 -8
- package/dist/cli/generators/app/template.js.map +1 -0
- package/dist/cli/generators/client/template.d.ts +1 -0
- package/dist/cli/generators/client/template.js +30 -0
- package/dist/cli/generators/client/template.js.map +1 -0
- package/dist/cli/generators/controller/index.d.ts +1 -0
- package/dist/cli/generators/controller/index.js +78 -0
- package/dist/cli/generators/controller/index.js.map +1 -0
- package/dist/cli/generators/controller/template.d.ts +1 -0
- package/dist/cli/generators/controller/template.js +106 -0
- package/dist/cli/generators/controller/template.js.map +1 -0
- package/dist/cli/generators/dto/index.d.ts +1 -0
- package/dist/cli/generators/dto/index.js +57 -0
- package/dist/cli/generators/dto/index.js.map +1 -0
- package/dist/cli/generators/dto/template.d.ts +1 -0
- package/dist/cli/generators/dto/template.js +32 -0
- package/dist/cli/generators/dto/template.js.map +1 -0
- package/dist/cli/generators/middleware/index.d.ts +1 -0
- package/dist/cli/generators/middleware/index.js +38 -0
- package/dist/cli/generators/middleware/index.js.map +1 -0
- package/dist/cli/generators/middleware/template.d.ts +1 -0
- package/dist/cli/generators/middleware/template.js +16 -0
- package/dist/cli/generators/middleware/template.js.map +1 -0
- package/dist/cli/generators/module/index.d.ts +1 -0
- package/dist/cli/generators/module/index.js +173 -0
- package/dist/cli/generators/module/index.js.map +1 -0
- package/dist/cli/generators/service/index.d.ts +1 -0
- package/dist/cli/generators/service/index.js +53 -0
- package/dist/cli/generators/service/index.js.map +1 -0
- package/dist/cli/generators/service/template.d.ts +1 -0
- package/dist/cli/generators/service/template.js +74 -0
- package/dist/cli/generators/service/template.js.map +1 -0
- package/dist/cli/generators/shared/index.d.ts +3 -0
- package/dist/cli/generators/shared/index.js +22 -0
- package/dist/cli/generators/shared/index.js.map +1 -0
- package/dist/cli/index.js +53 -96
- 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 +47 -26
- package/dist/lib/core/client/index.js.map +1 -1
- package/dist/lib/core/{compiler → client}/types.d.ts +29 -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 +186 -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 +170 -34
- package/dist/lib/core/compiler/pre-routes.js +45 -25
- package/dist/lib/core/compiler/pre-routes.js.map +1 -1
- package/dist/lib/core/decorators/context.d.ts +78 -8
- package/dist/lib/core/decorators/context.js +84 -9
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/statusCode.js +3 -1
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/package/index.d.ts +11 -0
- package/dist/lib/core/package/index.js +42 -0
- package/dist/lib/core/package/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.js +2 -2
- package/dist/lib/core/server/index.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 +32 -27
- package/package.json +7 -4
- package/dist/cli/app.d.ts +0 -1
- package/dist/cli/app.js.map +0 -1
- package/dist/cli/controller.d.ts +0 -1
- package/dist/cli/controller.js +0 -158
- package/dist/cli/controller.js.map +0 -1
- package/dist/lib/core/compiler/types.js.map +0 -1
- /package/dist/lib/core/{compiler → client}/types.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tspace-spear",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "tspace-spear is a lightweight, high-performance API framework for Node.js that leverages the native HTTP server and supports uWebSockets.js (C++) for maximum speed and efficiency.",
|
|
5
5
|
"main": "./dist/lib/index.js",
|
|
6
6
|
"types": "./dist/lib/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"bin": {
|
|
11
|
-
"
|
|
11
|
+
"spear": "./dist/cli/index.js"
|
|
12
12
|
},
|
|
13
13
|
"type": "commonjs",
|
|
14
14
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"benchmark:node": "npm run build && node benchmarks/tests/benchmark.node.js",
|
|
46
46
|
"benchmark:bun": "npm run build && bun run benchmarks/tests/benchmark.bun.js",
|
|
47
47
|
"load": "autocannon -c 100 -d 30 -p 10 localhost:5000",
|
|
48
|
-
"test": "ts-mocha ./__tests__/**/*.test.ts --reporter spec --no-timeouts --recursive --reporter mochawesome --reporter-options reportDir=__tests-report__,reportFilename=errors.html,reportTitle=Unit-test --exit",
|
|
48
|
+
"test": "ts-mocha ./__tests__/**/*.test.ts --reporter spec --slow 0 --no-timeouts --recursive --reporter mochawesome --reporter-options reportDir=__tests-report__,reportFilename=errors.html,reportTitle=Unit-test --exit",
|
|
49
49
|
"docs": "npx docsify-cli serve docs"
|
|
50
50
|
},
|
|
51
51
|
"exports": {
|
|
@@ -67,7 +67,6 @@
|
|
|
67
67
|
"busboy": "1.6.0",
|
|
68
68
|
"fast-querystring": "1.1.2",
|
|
69
69
|
"mime-types": "2.1.35",
|
|
70
|
-
"node-fetch": "2.7.0",
|
|
71
70
|
"on-finished": "2.4.1",
|
|
72
71
|
"reflect-metadata": "0.2.2",
|
|
73
72
|
"swagger-ui-dist": "5.32.0",
|
|
@@ -101,9 +100,13 @@
|
|
|
101
100
|
"elysia": "1.4.28",
|
|
102
101
|
"express": "4.19.2",
|
|
103
102
|
"fastify": "4.28.1",
|
|
103
|
+
"form-data": "4.0.5",
|
|
104
|
+
"graphql": "16.14.0",
|
|
105
|
+
"graphql-http": "1.22.4",
|
|
104
106
|
"hono": "4.12.9",
|
|
105
107
|
"mocha": "10.2.0",
|
|
106
108
|
"mochawesome": "7.1.3",
|
|
109
|
+
"node-fetch": "2.7.0",
|
|
107
110
|
"ts-mocha": "10.0.0",
|
|
108
111
|
"ts-node": "10.9.2",
|
|
109
112
|
"typescript": "5.6.2",
|
package/dist/cli/app.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CatController = void 0;
|
|
4
|
-
exports.CatController = `
|
|
5
|
-
import {
|
|
6
|
-
type T,
|
|
7
|
-
Controller,
|
|
8
|
-
Get,
|
|
9
|
-
Post,
|
|
10
|
-
Put,
|
|
11
|
-
Delete
|
|
12
|
-
} from "tspace-spear";
|
|
13
|
-
|
|
14
|
-
type Cat = {
|
|
15
|
-
id: number;
|
|
16
|
-
name: string;
|
|
17
|
-
age: number;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
let cats: Cat[] = [
|
|
21
|
-
{
|
|
22
|
-
id: 1,
|
|
23
|
-
name: "cat 1",
|
|
24
|
-
age: 2
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
id: 2,
|
|
28
|
-
name: "cat 2",
|
|
29
|
-
age: 4
|
|
30
|
-
}
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
@Controller("/cats")
|
|
34
|
-
export default class CatController {
|
|
35
|
-
|
|
36
|
-
@Get("/")
|
|
37
|
-
async index() {
|
|
38
|
-
return {
|
|
39
|
-
cats
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Get("/:id")
|
|
44
|
-
async show({
|
|
45
|
-
res,
|
|
46
|
-
params
|
|
47
|
-
}: T.Context<{
|
|
48
|
-
params: {
|
|
49
|
-
id: number;
|
|
50
|
-
};
|
|
51
|
-
}>) {
|
|
52
|
-
|
|
53
|
-
const cat = cats.find(
|
|
54
|
-
d => d.id === Number(params.id)
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
if (!cat) {
|
|
58
|
-
throw res.notFound(
|
|
59
|
-
"Cat not found"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
cat
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@Post("/")
|
|
69
|
-
async create({
|
|
70
|
-
body
|
|
71
|
-
}: T.Context<{
|
|
72
|
-
body: {
|
|
73
|
-
name: string;
|
|
74
|
-
age: number;
|
|
75
|
-
};
|
|
76
|
-
}>) {
|
|
77
|
-
|
|
78
|
-
const cat: Cat = {
|
|
79
|
-
id: cats.length + 1,
|
|
80
|
-
name: body.name,
|
|
81
|
-
age: body.age
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
cats.push(cat);
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
message: "Created",
|
|
88
|
-
cat
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@Put("/:id")
|
|
93
|
-
async update({
|
|
94
|
-
res,
|
|
95
|
-
params,
|
|
96
|
-
body
|
|
97
|
-
}: T.Context<{
|
|
98
|
-
params: {
|
|
99
|
-
id: number;
|
|
100
|
-
};
|
|
101
|
-
body: Partial<{
|
|
102
|
-
name: string;
|
|
103
|
-
age: number;
|
|
104
|
-
}>;
|
|
105
|
-
}>) {
|
|
106
|
-
|
|
107
|
-
const index = cats.findIndex(
|
|
108
|
-
d => d.id === Number(params.id)
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
if (index === -1) {
|
|
112
|
-
throw res.notFound(
|
|
113
|
-
"Cat not found"
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
cats[index] = {
|
|
118
|
-
...cats[index],
|
|
119
|
-
...body
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
message: "Updated",
|
|
124
|
-
cat: cats[index]
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
@Delete("/:id")
|
|
129
|
-
async remove({
|
|
130
|
-
res,
|
|
131
|
-
params
|
|
132
|
-
}: T.Context<{
|
|
133
|
-
params: {
|
|
134
|
-
id: number;
|
|
135
|
-
};
|
|
136
|
-
}>) {
|
|
137
|
-
|
|
138
|
-
const index = cats.findIndex(
|
|
139
|
-
d => d.id === Number(params.id)
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
if (index === -1) {
|
|
143
|
-
throw res.notFound(
|
|
144
|
-
"Cat not found"
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
cats = cats.filter(
|
|
149
|
-
d => d.id !== Number(params.id)
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
message: "Deleted"
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
`;
|
|
158
|
-
//# sourceMappingURL=controller.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/cli/controller.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyJ5B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/types.ts"],"names":[],"mappings":""}
|
|
File without changes
|