tspace-spear 1.2.4 → 1.2.5-beta.2
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/dist/lib/core/client/index.d.ts +23 -0
- package/dist/lib/core/client/index.js +51 -0
- package/dist/lib/core/client/index.js.map +1 -0
- package/dist/lib/core/compiler/generator.d.ts +18 -0
- package/dist/lib/core/compiler/generator.js +142 -0
- package/dist/lib/core/compiler/generator.js.map +1 -0
- package/dist/lib/core/compiler/index.d.ts +14 -0
- package/dist/lib/core/compiler/index.js +11 -0
- package/dist/lib/core/compiler/index.js.map +1 -0
- package/dist/lib/core/compiler/pre-routes.d.ts +144 -0
- package/dist/lib/core/compiler/pre-routes.js +5 -0
- package/dist/lib/core/compiler/pre-routes.js.map +1 -0
- package/dist/lib/core/compiler/types.d.ts +14 -0
- package/dist/lib/core/compiler/types.js +3 -0
- package/dist/lib/core/compiler/types.js.map +1 -0
- package/dist/lib/core/server/fast-router.js +11 -2
- package/dist/lib/core/server/fast-router.js.map +1 -1
- package/dist/lib/core/server/index.d.ts +7 -0
- package/dist/lib/core/server/index.js +13 -1
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/types/index.d.ts +6 -5
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/package.json +18 -2
- package/dist/lib/core/server/express.d.ts +0 -295
- package/dist/lib/core/server/express.js +0 -1356
- package/dist/lib/core/server/express.js.map +0 -1
- package/dist/lib/core/server/request.d.ts +0 -2
- package/dist/lib/core/server/request.js +0 -7
- package/dist/lib/core/server/request.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AppRoutes } from "../compiler/pre-routes";
|
|
2
|
+
import type { AnyRoutes, RoutesWithMethod, RequestBody, RequestQuery, RequestParams, RequestFiles, ResponseType } from "../compiler/types";
|
|
3
|
+
type RequestInput<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = RequestParams<TRoutes, TPath, TMethod> extends never ? {
|
|
4
|
+
body?: RequestBody<TRoutes, TPath, TMethod>;
|
|
5
|
+
query?: RequestQuery<TRoutes, TPath, TMethod>;
|
|
6
|
+
files?: RequestFiles<TRoutes, TPath, TMethod>;
|
|
7
|
+
} : {
|
|
8
|
+
params: RequestParams<TRoutes, TPath, TMethod>;
|
|
9
|
+
body?: RequestBody<TRoutes, TPath, TMethod>;
|
|
10
|
+
query?: RequestQuery<TRoutes, TPath, TMethod>;
|
|
11
|
+
files?: RequestFiles<TRoutes, TPath, TMethod>;
|
|
12
|
+
};
|
|
13
|
+
export declare class ApiClient<TRoutes extends AnyRoutes = AppRoutes> {
|
|
14
|
+
private baseURL;
|
|
15
|
+
constructor(baseURL: string);
|
|
16
|
+
protected request<TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]>(method: TMethod, path: TPath, input?: RequestInput<TRoutes, TPath, TMethod>): Promise<ResponseType<TRoutes, TPath, TMethod>>;
|
|
17
|
+
get<TPath extends RoutesWithMethod<TRoutes, "GET">>(path: TPath, input?: RequestInput<TRoutes, TPath, "GET">): Promise<ResponseType<TRoutes, TPath, "GET">>;
|
|
18
|
+
post<TPath extends RoutesWithMethod<TRoutes, "POST">>(path: TPath, input: RequestInput<TRoutes, TPath, "POST">): Promise<ResponseType<TRoutes, TPath, "POST">>;
|
|
19
|
+
put<TPath extends RoutesWithMethod<TRoutes, "PUT">>(path: TPath, input: RequestInput<TRoutes, TPath, "PUT">): Promise<ResponseType<TRoutes, TPath, "PUT">>;
|
|
20
|
+
patch<TPath extends RoutesWithMethod<TRoutes, "PATCH">>(path: TPath, input: RequestInput<TRoutes, TPath, "PATCH">): Promise<ResponseType<TRoutes, TPath, "PATCH">>;
|
|
21
|
+
delete<TPath extends RoutesWithMethod<TRoutes, "DELETE">>(path: TPath, input?: RequestInput<TRoutes, TPath, "DELETE">): Promise<ResponseType<TRoutes, TPath, "DELETE">>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiClient = void 0;
|
|
4
|
+
class ApiClient {
|
|
5
|
+
baseURL;
|
|
6
|
+
constructor(baseURL) {
|
|
7
|
+
this.baseURL = baseURL;
|
|
8
|
+
}
|
|
9
|
+
async request(method, path, input) {
|
|
10
|
+
const url = this.baseURL + String(path);
|
|
11
|
+
const res = await fetch(url, {
|
|
12
|
+
method: method,
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
},
|
|
16
|
+
body: input?.body
|
|
17
|
+
? JSON.stringify(input.body)
|
|
18
|
+
: undefined,
|
|
19
|
+
});
|
|
20
|
+
const contentType = res.headers.get("content-type");
|
|
21
|
+
const isJson = contentType?.includes("application/json");
|
|
22
|
+
const data = isJson
|
|
23
|
+
? await res.json()
|
|
24
|
+
: await res.text();
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
throw new Error(data?.message ||
|
|
27
|
+
data?.error ||
|
|
28
|
+
(typeof data === "string"
|
|
29
|
+
? data
|
|
30
|
+
: `HTTP ${res.status}`));
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
async get(path, input) {
|
|
35
|
+
return this.request("GET", path, input);
|
|
36
|
+
}
|
|
37
|
+
async post(path, input) {
|
|
38
|
+
return this.request("POST", path, input);
|
|
39
|
+
}
|
|
40
|
+
async put(path, input) {
|
|
41
|
+
return this.request("PUT", path, input);
|
|
42
|
+
}
|
|
43
|
+
async patch(path, input) {
|
|
44
|
+
return this.request("PATCH", path, input);
|
|
45
|
+
}
|
|
46
|
+
async delete(path, input) {
|
|
47
|
+
return this.request("DELETE", path, input);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ApiClient = ApiClient;
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -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ACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,KAAK,EACL,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,IAAI,CAMf,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,MAAM,EACN,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,GAAG,CAMd,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,KAAK,EACL,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,KAAK,CAMhB,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,OAAO,EACP,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,MAAM,CAMjB,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,QAAQ,EACR,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;CACF;AAxKD,8BAwKC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Route = {
|
|
2
|
+
method: string;
|
|
3
|
+
path: string;
|
|
4
|
+
response: string;
|
|
5
|
+
body: string;
|
|
6
|
+
params: string;
|
|
7
|
+
query: string;
|
|
8
|
+
files: string;
|
|
9
|
+
};
|
|
10
|
+
type Options = {
|
|
11
|
+
controllers: {
|
|
12
|
+
folder: string;
|
|
13
|
+
name: RegExp;
|
|
14
|
+
};
|
|
15
|
+
output?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function generateRoutes(options: Options): Promise<Route[]>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateRoutes = generateRoutes;
|
|
7
|
+
const ts_morph_1 = require("ts-morph");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const HTTP_METHODS = {
|
|
11
|
+
Get: "GET",
|
|
12
|
+
Post: "POST",
|
|
13
|
+
Put: "PUT",
|
|
14
|
+
Patch: "PATCH",
|
|
15
|
+
Delete: "DELETE",
|
|
16
|
+
Options: "OPTIONS",
|
|
17
|
+
Head: "HEAD",
|
|
18
|
+
};
|
|
19
|
+
function normalizePath(p) {
|
|
20
|
+
return ("/" +
|
|
21
|
+
p
|
|
22
|
+
.replace(/['"`]/g, "")
|
|
23
|
+
.replace(/\/+/g, "/")
|
|
24
|
+
.replace(/\/$/, "")
|
|
25
|
+
.replace(/^\//, ""));
|
|
26
|
+
}
|
|
27
|
+
function extractPropertyType(type, key, node) {
|
|
28
|
+
const prop = type.getProperty(key);
|
|
29
|
+
if (!prop)
|
|
30
|
+
return "never";
|
|
31
|
+
const t = prop.getTypeAtLocation(node);
|
|
32
|
+
const text = t.getText(node);
|
|
33
|
+
if (!text || text.includes("undefined"))
|
|
34
|
+
return "never";
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
async function generateRoutes(options) {
|
|
38
|
+
const project = new ts_morph_1.Project({
|
|
39
|
+
tsConfigFilePath: path_1.default.resolve(process.cwd(), "tsconfig.json"),
|
|
40
|
+
});
|
|
41
|
+
project.addSourceFilesAtPaths(path_1.default.join(options.controllers.folder, "**/*"));
|
|
42
|
+
const files = project.getSourceFiles();
|
|
43
|
+
if (!files.length) {
|
|
44
|
+
throw new Error("No controller files found");
|
|
45
|
+
}
|
|
46
|
+
const routes = [];
|
|
47
|
+
for (const file of files) {
|
|
48
|
+
const filename = file.getBaseName();
|
|
49
|
+
if (!options.controllers.name.test(filename))
|
|
50
|
+
continue;
|
|
51
|
+
for (const cls of file.getClasses()) {
|
|
52
|
+
const controller = cls.getDecorator("Controller");
|
|
53
|
+
if (!controller)
|
|
54
|
+
continue;
|
|
55
|
+
const basePath = controller.getArguments()[0]
|
|
56
|
+
?.getText()
|
|
57
|
+
.replace(/['"`]/g, "") || "";
|
|
58
|
+
for (const method of cls.getMethods()) {
|
|
59
|
+
for (const [decName, http] of Object.entries(HTTP_METHODS)) {
|
|
60
|
+
const decorator = method.getDecorator(decName);
|
|
61
|
+
if (!decorator)
|
|
62
|
+
continue;
|
|
63
|
+
const methodPath = decorator
|
|
64
|
+
.getArguments()[0]
|
|
65
|
+
?.getText()
|
|
66
|
+
.replace(/['"`]/g, "") || "";
|
|
67
|
+
const fullPath = normalizePath(`${basePath}/${methodPath}`);
|
|
68
|
+
const response = method.getReturnType().getText(method);
|
|
69
|
+
let body = "never";
|
|
70
|
+
let params = "never";
|
|
71
|
+
let query = "never";
|
|
72
|
+
let files = "never";
|
|
73
|
+
const firstParam = method.getParameters()[0];
|
|
74
|
+
if (firstParam) {
|
|
75
|
+
const type = firstParam.getType();
|
|
76
|
+
body = extractPropertyType(type, "body", firstParam);
|
|
77
|
+
params = extractPropertyType(type, "params", firstParam);
|
|
78
|
+
query = extractPropertyType(type, "query", firstParam);
|
|
79
|
+
files = extractPropertyType(type, "files", firstParam);
|
|
80
|
+
}
|
|
81
|
+
routes.push({
|
|
82
|
+
method: http,
|
|
83
|
+
path: fullPath,
|
|
84
|
+
response,
|
|
85
|
+
body,
|
|
86
|
+
params,
|
|
87
|
+
query,
|
|
88
|
+
files,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const grouped = {};
|
|
95
|
+
for (const r of routes) {
|
|
96
|
+
grouped[r.path] ??= {};
|
|
97
|
+
grouped[r.path][r.method] = {
|
|
98
|
+
response: r.response,
|
|
99
|
+
body: r.body,
|
|
100
|
+
params: r.params,
|
|
101
|
+
query: r.query,
|
|
102
|
+
files: r.files,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const routeMap = Object.entries(grouped)
|
|
106
|
+
.map(([path, methods]) => {
|
|
107
|
+
const methodBlock = Object.entries(methods)
|
|
108
|
+
.map(([method, c]) => `
|
|
109
|
+
${method}: {
|
|
110
|
+
params: ${c.params}
|
|
111
|
+
query: ${c.query}
|
|
112
|
+
body: ${c.body}
|
|
113
|
+
files: ${c.files}
|
|
114
|
+
response: ${c.response}
|
|
115
|
+
}`)
|
|
116
|
+
.join("\n");
|
|
117
|
+
return `
|
|
118
|
+
"${path}": {
|
|
119
|
+
${methodBlock}
|
|
120
|
+
}`;
|
|
121
|
+
})
|
|
122
|
+
.join("\n");
|
|
123
|
+
const output = `
|
|
124
|
+
// AUTO GENERATED FILE
|
|
125
|
+
// DO NOT EDIT
|
|
126
|
+
|
|
127
|
+
export interface AppRoutes {
|
|
128
|
+
${routeMap}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type AppRoute = keyof AppRoutes
|
|
132
|
+
`;
|
|
133
|
+
const outPath = options.output
|
|
134
|
+
? `${__dirname}/${options.output}/pre-routes.ts`
|
|
135
|
+
: `${__dirname}/pre-routes.ts`;
|
|
136
|
+
await fs_1.default.promises.mkdir(path_1.default.dirname(outPath), {
|
|
137
|
+
recursive: true,
|
|
138
|
+
});
|
|
139
|
+
await fs_1.default.promises.writeFile(outPath, output);
|
|
140
|
+
return routes;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/generator.ts"],"names":[],"mappings":";;;;;AA4DA,wCAqIC;AAjMD,uCAAkC;AAClC,4CAAmB;AACnB,gDAAuB;AAEvB,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAA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rC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE;QACvB,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;aACxC,GAAG,CACF,CAAC,CAAC,MAAM,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC;MAC1B,MAAM;gBACI,CAAC,CAAC,MAAM;eACT,CAAC,CAAC,KAAK;cACR,CAAC,CAAC,IAAI;eACL,CAAC,CAAC,KAAK;kBACJ,CAAC,CAAC,QAAQ;MACtB,CACG;aACA,IAAI,CAAC,IAAI,CAAC,CAAA;QAEb,OAAO;KACR,IAAI;EACP,WAAW;IACT,CAAA;IACA,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,MAAM,GAAG;;;;;EAKf,QAAQ;;;;CAIT,CAAA;IAEC,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM;QAC5B,CAAC,CAAC,GAAG,SAAS,IAAI,OAAO,CAAC,MAAM,gBAAgB;QAChD,CAAC,CAAC,GAAG,SAAS,gBAAgB,CAAA;IAEhC,MAAM,YAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC7C,SAAS,EAAE,IAAI;KAChB,CAAC,CAAA;IAEF,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAE5C,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Compiler = void 0;
|
|
4
|
+
const generator_1 = require("./generator");
|
|
5
|
+
class Compiler {
|
|
6
|
+
async generateRoutes(options) {
|
|
7
|
+
return await (0, generator_1.generateRoutes)({ controllers: options });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.Compiler = Compiler;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/index.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,MAAa,QAAQ;IACV,KAAK,CAAC,cAAc,CAAE,OAG5B;QACG,OAAO,MAAM,IAAA,0BAAc,EAAC,EAAE,WAAW,EAAG,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;CACJ;AAPD,4BAOC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export interface AppRoutes {
|
|
2
|
+
"/cats": {
|
|
3
|
+
GET: {
|
|
4
|
+
params: never;
|
|
5
|
+
query: never;
|
|
6
|
+
body: Record<string, any>;
|
|
7
|
+
files: never;
|
|
8
|
+
response: Promise<{
|
|
9
|
+
query: Record<string, string | undefined>;
|
|
10
|
+
user: any;
|
|
11
|
+
userx: any;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
POST: {
|
|
15
|
+
params: never;
|
|
16
|
+
query: never;
|
|
17
|
+
body: Record<string, any>;
|
|
18
|
+
files: never;
|
|
19
|
+
response: Promise<{
|
|
20
|
+
body: Record<string, any>;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
"/cats/:id": {
|
|
25
|
+
GET: {
|
|
26
|
+
params: {
|
|
27
|
+
id: string;
|
|
28
|
+
};
|
|
29
|
+
query: never;
|
|
30
|
+
body: Record<string, any>;
|
|
31
|
+
files: never;
|
|
32
|
+
response: Promise<{
|
|
33
|
+
params: {
|
|
34
|
+
id: string;
|
|
35
|
+
};
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
"/cats/:uuid": {
|
|
40
|
+
PUT: {
|
|
41
|
+
params: never;
|
|
42
|
+
query: never;
|
|
43
|
+
body: Record<string, any>;
|
|
44
|
+
files: never;
|
|
45
|
+
response: Promise<{
|
|
46
|
+
body: Record<string, any>;
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
PATCH: {
|
|
50
|
+
params: never;
|
|
51
|
+
query: never;
|
|
52
|
+
body: Record<string, any>;
|
|
53
|
+
files: never;
|
|
54
|
+
response: Promise<{
|
|
55
|
+
body: Record<string, any>;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
DELETE: {
|
|
59
|
+
params: never;
|
|
60
|
+
query: never;
|
|
61
|
+
body: Record<string, any>;
|
|
62
|
+
files: never;
|
|
63
|
+
response: Promise<{
|
|
64
|
+
params: Record<string, string | undefined>;
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
"/cats/upload": {
|
|
69
|
+
POST: {
|
|
70
|
+
params: never;
|
|
71
|
+
query: never;
|
|
72
|
+
body: Record<string, any>;
|
|
73
|
+
files: never;
|
|
74
|
+
response: Promise<{
|
|
75
|
+
body: Record<string, any>;
|
|
76
|
+
files: {
|
|
77
|
+
[x: string]: {
|
|
78
|
+
size: number;
|
|
79
|
+
sizes: {
|
|
80
|
+
bytes: number;
|
|
81
|
+
kb: number;
|
|
82
|
+
mb: number;
|
|
83
|
+
gb: number;
|
|
84
|
+
};
|
|
85
|
+
tempFilePath: string;
|
|
86
|
+
tempFileName: string;
|
|
87
|
+
mimetype: string;
|
|
88
|
+
extension: string;
|
|
89
|
+
name: string;
|
|
90
|
+
write: (to: string) => Promise<void>;
|
|
91
|
+
remove: () => Promise<void>;
|
|
92
|
+
}[] | undefined;
|
|
93
|
+
};
|
|
94
|
+
}>;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
"/dogs": {
|
|
98
|
+
GET: {
|
|
99
|
+
params: never;
|
|
100
|
+
query: {
|
|
101
|
+
id: string;
|
|
102
|
+
name?: string;
|
|
103
|
+
};
|
|
104
|
+
body: Record<string, any>;
|
|
105
|
+
files: never;
|
|
106
|
+
response: Promise<{
|
|
107
|
+
dogs: {
|
|
108
|
+
name: string;
|
|
109
|
+
age1: number;
|
|
110
|
+
}[];
|
|
111
|
+
}>;
|
|
112
|
+
};
|
|
113
|
+
POST: {
|
|
114
|
+
params: never;
|
|
115
|
+
query: never;
|
|
116
|
+
body: {
|
|
117
|
+
name: string;
|
|
118
|
+
id: number;
|
|
119
|
+
};
|
|
120
|
+
files: never;
|
|
121
|
+
response: Promise<{
|
|
122
|
+
message: string;
|
|
123
|
+
name: string;
|
|
124
|
+
id: number;
|
|
125
|
+
}>;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
"/dogs/:id": {
|
|
129
|
+
GET: {
|
|
130
|
+
params: {
|
|
131
|
+
id: string;
|
|
132
|
+
};
|
|
133
|
+
query: never;
|
|
134
|
+
body: Record<string, any>;
|
|
135
|
+
files: never;
|
|
136
|
+
response: Promise<{
|
|
137
|
+
params: {
|
|
138
|
+
id: string;
|
|
139
|
+
};
|
|
140
|
+
}>;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export type AppRoute = keyof AppRoutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pre-routes.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/pre-routes.ts"],"names":[],"mappings":";AACA,sBAAsB;AACtB,cAAc"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type AnyRoutes = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export type RoutesWithMethod<TRoutes extends AnyRoutes, TMethod extends string> = {
|
|
5
|
+
[K in keyof TRoutes]: TMethod extends keyof TRoutes[K] ? K : never;
|
|
6
|
+
}[keyof TRoutes];
|
|
7
|
+
export type ExtractFrom<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath], Key extends string> = TRoutes[TPath][TMethod] extends Record<Key, infer R> ? R : never;
|
|
8
|
+
export type RequestBody<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = ExtractFrom<TRoutes, TPath, TMethod, "body">;
|
|
9
|
+
export type RequestQuery<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = ExtractFrom<TRoutes, TPath, TMethod, "query">;
|
|
10
|
+
export type RequestParams<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = ExtractFrom<TRoutes, TPath, TMethod, "params">;
|
|
11
|
+
export type RequestFiles<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = ExtractFrom<TRoutes, TPath, TMethod, "files">;
|
|
12
|
+
export type ResponseType<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = TRoutes[TPath][TMethod] extends {
|
|
13
|
+
response: infer R;
|
|
14
|
+
} ? Awaited<R> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/types.ts"],"names":[],"mappings":""}
|
|
@@ -162,8 +162,10 @@ class FastRouter {
|
|
|
162
162
|
const method = req.method;
|
|
163
163
|
let node = this.trees[method];
|
|
164
164
|
if (!node) {
|
|
165
|
+
if (res.writableEnded) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
165
168
|
res.statusCode = 405;
|
|
166
|
-
console.log({ method });
|
|
167
169
|
return res.end("Method Not Allowed");
|
|
168
170
|
}
|
|
169
171
|
let url = req.url || "/";
|
|
@@ -200,6 +202,9 @@ class FastRouter {
|
|
|
200
202
|
if (rootWildcard?.handler) {
|
|
201
203
|
return rootWildcard.handler(req, res, params);
|
|
202
204
|
}
|
|
205
|
+
if (res.writableEnded) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
203
208
|
res.statusCode = 404;
|
|
204
209
|
res.end("Not Found");
|
|
205
210
|
return;
|
|
@@ -209,8 +214,12 @@ class FastRouter {
|
|
|
209
214
|
if (rootWildcard?.handler) {
|
|
210
215
|
return rootWildcard.handler(req, res, params);
|
|
211
216
|
}
|
|
217
|
+
if (res.writableEnded) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
212
220
|
res.statusCode = 404;
|
|
213
|
-
|
|
221
|
+
res.end("Not Found");
|
|
222
|
+
return;
|
|
214
223
|
}
|
|
215
224
|
return node.handler(req, res, params);
|
|
216
225
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fast-router.js","sourceRoot":"","sources":["../../../../src/lib/core/server/fast-router.ts"],"names":[],"mappings":";;;AAiBA,MAAM,OAAO,GAAG;IACd,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;IAC7B,QAAQ,EAAE,SAAS,EAAE,MAAM;CACnB,CAAA;AAGV,MAAa,UAAU;IACb,KAAK,GAAyB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,GAAc,EAAE,CAAA;IAE/B;QACE,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACrC,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;OAWG;IACI,GAAG,CAAC,IAAY,EAAE,OAAgB;QACvC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACI,IAAI,CAAC,IAAY,EAAE,OAAgB;QACxC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACI,GAAG,CAAC,IAAY,EAAE,OAAgB;QACvC,IAAI,CAAC,IAAI,CAAC,KAAK,EA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,OAAO;IACT,CAAC;IAEO,cAAc,CAAC,IAAY;QACjC,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBAElC,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,CAAC;gBAED,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1UD,gCA0UC"}
|
|
@@ -3,6 +3,7 @@ import WebSocket from 'ws';
|
|
|
3
3
|
import { FastRouter } from './fast-router';
|
|
4
4
|
import { Router } from './router';
|
|
5
5
|
import type { T } from '../types';
|
|
6
|
+
import { AppRoutes } from '../compiler/pre-routes';
|
|
6
7
|
/**
|
|
7
8
|
*
|
|
8
9
|
* The 'Spear' class is used to create a server and handle HTTP requests.
|
|
@@ -36,6 +37,7 @@ declare class Spear {
|
|
|
36
37
|
private _formatResponse;
|
|
37
38
|
private _onListeners;
|
|
38
39
|
private _fileUploadOptions;
|
|
40
|
+
private _generateRoutes;
|
|
39
41
|
constructor({ controllers, middlewares, globalPrefix, logger, cluster, adapter }?: T.Application);
|
|
40
42
|
/**
|
|
41
43
|
* The get 'instance' method is used to get the instance of Spear.
|
|
@@ -49,6 +51,11 @@ declare class Spear {
|
|
|
49
51
|
* @returns {FastRouter}
|
|
50
52
|
*/
|
|
51
53
|
get routers(): FastRouter;
|
|
54
|
+
get contract(): AppRoutes;
|
|
55
|
+
useGenerateRouteType(options: {
|
|
56
|
+
folder: string;
|
|
57
|
+
name: RegExp;
|
|
58
|
+
}): this;
|
|
52
59
|
/**
|
|
53
60
|
* The 'ws' method is used to creates the WebSocket server.
|
|
54
61
|
*
|
|
@@ -50,6 +50,7 @@ const net_1 = __importDefault(require("net"));
|
|
|
50
50
|
const parser_factory_1 = require("./parser-factory");
|
|
51
51
|
const fast_router_1 = require("./fast-router");
|
|
52
52
|
const response_1 = require("./response");
|
|
53
|
+
const compiler_1 = require("../compiler");
|
|
53
54
|
const uWS_1 = require("./uWS");
|
|
54
55
|
const net_2 = require("./net");
|
|
55
56
|
/**
|
|
@@ -110,6 +111,7 @@ class Spear {
|
|
|
110
111
|
ms: 1000 * 60 * 10
|
|
111
112
|
}
|
|
112
113
|
};
|
|
114
|
+
_generateRoutes;
|
|
113
115
|
constructor({ controllers, middlewares, globalPrefix, logger, cluster, adapter } = {}) {
|
|
114
116
|
this._controllers = controllers;
|
|
115
117
|
this._middlewares = middlewares;
|
|
@@ -138,6 +140,13 @@ class Spear {
|
|
|
138
140
|
get routers() {
|
|
139
141
|
return this._router;
|
|
140
142
|
}
|
|
143
|
+
get contract() {
|
|
144
|
+
return {};
|
|
145
|
+
}
|
|
146
|
+
useGenerateRouteType(options) {
|
|
147
|
+
this._generateRoutes = options;
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
141
150
|
/**
|
|
142
151
|
* The 'ws' method is used to creates the WebSocket server.
|
|
143
152
|
*
|
|
@@ -391,6 +400,9 @@ class Spear {
|
|
|
391
400
|
callback = hostname;
|
|
392
401
|
}
|
|
393
402
|
const server = await this._createServer();
|
|
403
|
+
if (this._generateRoutes) {
|
|
404
|
+
await new compiler_1.Compiler().generateRoutes(this._generateRoutes);
|
|
405
|
+
}
|
|
394
406
|
if (this._cluster != null &&
|
|
395
407
|
this._cluster || typeof this._cluster === 'number') {
|
|
396
408
|
this._clusterMode({
|
|
@@ -790,7 +802,7 @@ class Spear {
|
|
|
790
802
|
return (err) => {
|
|
791
803
|
const errorMessage = err?.message || NEXT_MESSAGE;
|
|
792
804
|
if (this._errorHandler != null) {
|
|
793
|
-
return this._errorHandler(
|
|
805
|
+
return this._errorHandler(err, ctx);
|
|
794
806
|
}
|
|
795
807
|
if (!ctx.res.headersSent) {
|
|
796
808
|
ctx.res.writeHead(500, const_1.HEADER_CONTENT_TYPES['json']);
|