barehttp 0.6.0 → 2.0.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/lib/context/execution.js +3 -10
- package/lib/context/index.d.ts +2 -3
- package/lib/context/index.js +6 -14
- package/lib/env.js +1 -4
- package/lib/index.d.ts +5 -5
- package/lib/index.js +3 -9
- package/lib/logger/index.d.ts +3 -5
- package/lib/logger/index.js +16 -43
- package/lib/logger/serializers.d.ts +2 -3
- package/lib/logger/serializers.js +12 -22
- package/lib/middlewares/cookies/cookie-manager.d.ts +7 -6
- package/lib/middlewares/cookies/cookie-manager.js +14 -18
- package/lib/middlewares/cookies/signer.js +4 -11
- package/lib/middlewares/cors/cors.d.ts +3 -3
- package/lib/middlewares/cors/cors.js +1 -4
- package/lib/request.d.ts +7 -8
- package/lib/request.js +22 -29
- package/lib/schemas/custom-schema.d.ts +7 -7
- package/lib/schemas/custom-schema.js +13 -20
- package/lib/schemas/dirty-tsm.js +18 -20
- package/lib/schemas/generator.d.ts +3 -3
- package/lib/schemas/generator.js +25 -32
- package/lib/schemas/helpers.d.ts +1 -1
- package/lib/schemas/helpers.js +26 -36
- package/lib/schemas/json-schema.d.ts +1 -1
- package/lib/schemas/json-schema.js +4 -8
- package/lib/schemas/openami-schema.d.ts +2 -2
- package/lib/schemas/openami-schema.js +4 -8
- package/lib/schemas/project.d.ts +1 -0
- package/lib/schemas/project.js +1 -1
- package/lib/server.d.ts +17 -18
- package/lib/server.js +35 -42
- package/lib/utils/content-type.js +2 -5
- package/lib/utils/http-methods.d.ts +2 -2
- package/lib/utils/http-methods.js +1 -4
- package/lib/utils/index.d.ts +4 -4
- package/lib/utils/index.js +4 -12
- package/lib/utils/safe-json.js +2 -7
- package/lib/utils/status-codes.d.ts +1 -1
- package/lib/utils/status-codes.js +1 -4
- package/lib/utils/status-phrases.js +1 -4
- package/lib/websocket.d.ts +6 -7
- package/lib/websocket.js +24 -27
- package/package.json +48 -37
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.generateCustomSchema = void 0;
|
|
7
|
-
const find_1 = __importDefault(require("lodash/find"));
|
|
8
|
-
const helpers_1 = require("./helpers");
|
|
9
|
-
const generateCustomSchema = (t) => {
|
|
10
|
-
if ((0, helpers_1.isFinalType)(t)) {
|
|
11
|
-
return { type: (0, helpers_1.getTypeGenericText)(t), nullable: false };
|
|
1
|
+
import find from 'lodash/find.js';
|
|
2
|
+
import { getApparentTypeName, getTypeGenericText, helpers, isFinalType, isNullType, } from './helpers.js';
|
|
3
|
+
export const generateCustomSchema = (t) => {
|
|
4
|
+
if (isFinalType(t)) {
|
|
5
|
+
return { type: getTypeGenericText(t), nullable: false };
|
|
12
6
|
}
|
|
13
7
|
if (t.isUnion()) {
|
|
14
|
-
const nulled = t.getUnionTypes().some((nt) =>
|
|
15
|
-
const cleanTypes =
|
|
8
|
+
const nulled = t.getUnionTypes().some((nt) => isNullType(nt));
|
|
9
|
+
const cleanTypes = helpers.cleanNullableTypes(t.getUnionTypes());
|
|
16
10
|
let returning = {
|
|
17
11
|
nullable: false,
|
|
18
12
|
type: 'union',
|
|
19
13
|
};
|
|
20
14
|
const transformed = cleanTypes.reduce((acc, ut) => {
|
|
21
|
-
const regenerated =
|
|
22
|
-
if ((
|
|
15
|
+
const regenerated = generateCustomSchema(ut);
|
|
16
|
+
if (find(acc, regenerated))
|
|
23
17
|
return acc;
|
|
24
18
|
return acc.concat(regenerated);
|
|
25
19
|
}, []);
|
|
@@ -36,7 +30,7 @@ const generateCustomSchema = (t) => {
|
|
|
36
30
|
}
|
|
37
31
|
if (t.isIntersection()) {
|
|
38
32
|
return t.getIntersectionTypes().reduce((acc, it) => {
|
|
39
|
-
const generatedSchema =
|
|
33
|
+
const generatedSchema = generateCustomSchema(it);
|
|
40
34
|
if (Object.keys(acc).length === 0) {
|
|
41
35
|
acc = generatedSchema;
|
|
42
36
|
return acc;
|
|
@@ -50,20 +44,19 @@ const generateCustomSchema = (t) => {
|
|
|
50
44
|
if (t.isArray()) {
|
|
51
45
|
return {
|
|
52
46
|
type: 'array',
|
|
53
|
-
items:
|
|
47
|
+
items: generateCustomSchema(t.getArrayElementType()),
|
|
54
48
|
};
|
|
55
49
|
}
|
|
56
50
|
if (t.isInterface() || t.isObject()) {
|
|
57
51
|
const result = t.getProperties().reduce((acc, ci) => {
|
|
58
52
|
const val = ci.getValueDeclaration();
|
|
59
|
-
acc.properties = { ...acc.properties, [ci.getName()]:
|
|
53
|
+
acc.properties = { ...acc.properties, [ci.getName()]: generateCustomSchema(val.getType()) };
|
|
60
54
|
return acc;
|
|
61
55
|
}, { type: 'object', properties: {} });
|
|
62
56
|
return result;
|
|
63
57
|
}
|
|
64
58
|
return {
|
|
65
|
-
type:
|
|
59
|
+
type: getApparentTypeName(t),
|
|
66
60
|
nullable: false,
|
|
67
61
|
};
|
|
68
62
|
};
|
|
69
|
-
exports.generateCustomSchema = generateCustomSchema;
|
package/lib/schemas/dirty-tsm.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const helpers_1 = require("./helpers");
|
|
6
|
-
const project = new ts_morph_1.Project({ tsConfigFilePath: 'tsconfig.json' });
|
|
1
|
+
import { Project, ts } from 'ts-morph';
|
|
2
|
+
import { generateCustomSchema } from './custom-schema.js';
|
|
3
|
+
import { isFinalType, logInternals } from './helpers.js';
|
|
4
|
+
const project = new Project({ tsConfigFilePath: 'tsconfig.json' });
|
|
7
5
|
project.enableLogging();
|
|
8
6
|
const sourceFile = project.getSourceFile('server.ts');
|
|
9
7
|
const tp = sourceFile?.getClass('BareServer')?.getMember('route');
|
|
@@ -14,7 +12,7 @@ function returnFinder(route, base) {
|
|
|
14
12
|
throw new Error('No project been allocated, theres some issue');
|
|
15
13
|
}
|
|
16
14
|
const refsAcrossProject = base
|
|
17
|
-
.getChildrenOfKind(
|
|
15
|
+
.getChildrenOfKind(ts.SyntaxKind.Identifier)[0]
|
|
18
16
|
.findReferences()[0]
|
|
19
17
|
.getReferences()
|
|
20
18
|
?.filter((re) => re.compilerObject.fileName.includes(route));
|
|
@@ -26,14 +24,14 @@ function returnFinder(route, base) {
|
|
|
26
24
|
return ref
|
|
27
25
|
.getNode()
|
|
28
26
|
.getAncestors()
|
|
29
|
-
.find((n) => n.getKind() ===
|
|
27
|
+
.find((n) => n.getKind() === ts.SyntaxKind.CallExpression)
|
|
30
28
|
?.getChildren()
|
|
31
|
-
.find((n) => n.getKind() ===
|
|
29
|
+
.find((n) => n.getKind() === ts.SyntaxKind.SyntaxList)
|
|
32
30
|
?.getFirstChild()
|
|
33
31
|
?.getChildSyntaxList()
|
|
34
32
|
?.getChildren()
|
|
35
33
|
.filter((c) => {
|
|
36
|
-
return c.getKind() ===
|
|
34
|
+
return c.getKind() === ts.SyntaxKind.PropertyAssignment && (isHandler(c) || isRoute(c));
|
|
37
35
|
})
|
|
38
36
|
.map((c) => {
|
|
39
37
|
if (isHandler(c)) {
|
|
@@ -41,8 +39,8 @@ function returnFinder(route, base) {
|
|
|
41
39
|
type: 'handler',
|
|
42
40
|
syntaxList: c
|
|
43
41
|
.getChildren()
|
|
44
|
-
.find((n) => n.getKind() ===
|
|
45
|
-
n.getKind() ===
|
|
42
|
+
.find((n) => n.getKind() === ts.SyntaxKind.ArrowFunction ||
|
|
43
|
+
n.getKind() === ts.SyntaxKind.FunctionExpression)
|
|
46
44
|
?.getLastChild()
|
|
47
45
|
?.getChildSyntaxList(),
|
|
48
46
|
};
|
|
@@ -78,7 +76,7 @@ function returnFinder(route, base) {
|
|
|
78
76
|
handler: getReturnStatements(routeCombination.handler),
|
|
79
77
|
}));
|
|
80
78
|
const schemas = perRoute.map(({ handler, route }) => {
|
|
81
|
-
const schemas = handler.map((t) =>
|
|
79
|
+
const schemas = handler.map((t) => generateCustomSchema(t));
|
|
82
80
|
let finalSchema = schemas[0];
|
|
83
81
|
if (schemas.length > 1) {
|
|
84
82
|
finalSchema = {
|
|
@@ -130,7 +128,7 @@ function returnFinder(route, base) {
|
|
|
130
128
|
const extractReturnStatements = (accumulator, n) => {
|
|
131
129
|
if (!n)
|
|
132
130
|
return;
|
|
133
|
-
if (
|
|
131
|
+
if (ts.SyntaxKind.IfStatement === n.getKind()) {
|
|
134
132
|
const thenProp = n.getNodeProperty('thenStatement');
|
|
135
133
|
const elseProp = n.getNodeProperty('elseStatement');
|
|
136
134
|
const thenSyntax = thenProp?.getChildSyntaxList();
|
|
@@ -141,10 +139,10 @@ const extractReturnStatements = (accumulator, n) => {
|
|
|
141
139
|
}
|
|
142
140
|
if (n.getChildren().length) {
|
|
143
141
|
const cleanChildren = n.getChildren().filter((c) => typeof c.getKind === 'function');
|
|
144
|
-
const findReturn = cleanChildren.find((c) => c.getKind() ===
|
|
145
|
-
const thereIf = cleanChildren.find((c) => c.getKind() ===
|
|
146
|
-
const thereWhile = cleanChildren.find((c) => c.getKind() ===
|
|
147
|
-
const thereFor = cleanChildren.find((c) => c.getKind() ===
|
|
142
|
+
const findReturn = cleanChildren.find((c) => c.getKind() === ts.SyntaxKind.ReturnStatement);
|
|
143
|
+
const thereIf = cleanChildren.find((c) => c.getKind() === ts.SyntaxKind.IfStatement);
|
|
144
|
+
const thereWhile = cleanChildren.find((c) => c.getKind() === ts.SyntaxKind.WhileKeyword);
|
|
145
|
+
const thereFor = cleanChildren.find((c) => c.getKind() === ts.SyntaxKind.ForStatement);
|
|
148
146
|
const syntaxList = n.getChildSyntaxList();
|
|
149
147
|
if (findReturn) {
|
|
150
148
|
accumulator.push(findReturn);
|
|
@@ -163,7 +161,7 @@ const getReturnStatements = (n) => {
|
|
|
163
161
|
return accumulator
|
|
164
162
|
.map((r) => r.getChildren().find((c) => {
|
|
165
163
|
const type = c.getType();
|
|
166
|
-
return type.isObject() ||
|
|
164
|
+
return type.isObject() || isFinalType(type);
|
|
167
165
|
}))
|
|
168
166
|
.filter((n) => n)
|
|
169
167
|
.map((acc) => acc.getType());
|
|
@@ -192,7 +190,7 @@ const getReturnStatements = (n) => {
|
|
|
192
190
|
// .map((v) => v!.getType());
|
|
193
191
|
};
|
|
194
192
|
// returnFinder('examples', tp);
|
|
195
|
-
|
|
193
|
+
logInternals(returnFinder('examples', tp));
|
|
196
194
|
// logInternals(returnFinder('examples', tp).map((s) => convertToJsonSchema(s)));
|
|
197
195
|
// console.log(tp);
|
|
198
196
|
// logInternals(getReturnStatements(res!)?.map((t) => regenerateTypeSchema(t!)));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const generateRouteSchema: (fileRouteToDeclarations: string) => {
|
|
2
2
|
route: string;
|
|
3
|
-
methodName: "get" | "
|
|
4
|
-
schemas: import("./custom-schema").CustomSchema[];
|
|
5
|
-
finalSchema: import("./custom-schema").CustomSchema;
|
|
3
|
+
methodName: "get" | "options" | "post" | "put" | "delete" | "patch" | "head";
|
|
4
|
+
schemas: import("./custom-schema.js").CustomSchema[];
|
|
5
|
+
finalSchema: import("./custom-schema.js").CustomSchema;
|
|
6
6
|
jsonSchema: any;
|
|
7
7
|
}[];
|
package/lib/schemas/generator.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const json_schema_1 = require("./json-schema");
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const fs_1 = require("fs");
|
|
13
|
-
const project = new ts_morph_1.Project({ tsConfigFilePath: path_1.default.join(process.cwd(), '/tsconfig.json') });
|
|
14
|
-
const nodeModulesFile = path_1.default.join(process.cwd(), 'node_modules', 'barehttp');
|
|
15
|
-
const isInstalledPackage = (0, fs_1.existsSync)(nodeModulesFile);
|
|
1
|
+
import { Project, ts } from 'ts-morph';
|
|
2
|
+
import { generateCustomSchema } from './custom-schema.js';
|
|
3
|
+
import { isFinalType, isHandler, isRoute } from './helpers.js';
|
|
4
|
+
import { convertToJsonSchema } from './json-schema.js';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { existsSync } from 'fs';
|
|
7
|
+
const project = new Project({ tsConfigFilePath: path.join(process.cwd(), '/tsconfig.json') });
|
|
8
|
+
const nodeModulesFile = path.join(process.cwd(), 'node_modules', 'barehttp');
|
|
9
|
+
const isInstalledPackage = existsSync(nodeModulesFile);
|
|
16
10
|
if (isInstalledPackage)
|
|
17
11
|
project.addSourceFileAtPath(nodeModulesFile + '/lib/server.d.ts');
|
|
18
12
|
const serverSourceFile = project.getSourceFile('server.d.ts');
|
|
@@ -26,7 +20,7 @@ const getReferences = (fileRoute, target) => {
|
|
|
26
20
|
if (!target)
|
|
27
21
|
return [];
|
|
28
22
|
return target
|
|
29
|
-
?.getChildrenOfKind(
|
|
23
|
+
?.getChildrenOfKind(ts.SyntaxKind.Identifier)[0]
|
|
30
24
|
.findReferences()[0]
|
|
31
25
|
.getReferences()
|
|
32
26
|
?.filter((re) => {
|
|
@@ -44,7 +38,7 @@ const getReferences = (fileRoute, target) => {
|
|
|
44
38
|
// .filter((p) => p?.getKind() === ts.SyntaxKind.CallExpression)
|
|
45
39
|
// .map((p) => p?.getNodeProperty('arguments' as any));
|
|
46
40
|
// };
|
|
47
|
-
const generateRouteSchema = (fileRouteToDeclarations) => {
|
|
41
|
+
export const generateRouteSchema = (fileRouteToDeclarations) => {
|
|
48
42
|
if (!routes && !runtimeRoutes) {
|
|
49
43
|
throw new Error('No project been allocated, theres some issue');
|
|
50
44
|
}
|
|
@@ -65,24 +59,24 @@ const generateRouteSchema = (fileRouteToDeclarations) => {
|
|
|
65
59
|
return ref
|
|
66
60
|
.getNode()
|
|
67
61
|
.getAncestors()
|
|
68
|
-
.find((n) => n.getKind() ===
|
|
62
|
+
.find((n) => n.getKind() === ts.SyntaxKind.CallExpression)
|
|
69
63
|
?.getChildren()
|
|
70
|
-
.find((n) => n.getKind() ===
|
|
64
|
+
.find((n) => n.getKind() === ts.SyntaxKind.SyntaxList)
|
|
71
65
|
?.getFirstChild()
|
|
72
66
|
?.getChildSyntaxList()
|
|
73
67
|
?.getChildren()
|
|
74
68
|
.filter((c) => {
|
|
75
|
-
return c.getKind() ===
|
|
69
|
+
return c.getKind() === ts.SyntaxKind.PropertyAssignment && (isHandler(c) || isRoute(c));
|
|
76
70
|
})
|
|
77
71
|
.map((c) => {
|
|
78
|
-
if (
|
|
72
|
+
if (isHandler(c)) {
|
|
79
73
|
return {
|
|
80
74
|
type: 'handler',
|
|
81
75
|
methodName,
|
|
82
76
|
syntaxList: c
|
|
83
77
|
.getChildren()
|
|
84
|
-
.find((n) => n.getKind() ===
|
|
85
|
-
n.getKind() ===
|
|
78
|
+
.find((n) => n.getKind() === ts.SyntaxKind.ArrowFunction ||
|
|
79
|
+
n.getKind() === ts.SyntaxKind.FunctionExpression)
|
|
86
80
|
?.getLastChild()
|
|
87
81
|
?.getChildSyntaxList(),
|
|
88
82
|
};
|
|
@@ -122,7 +116,7 @@ const generateRouteSchema = (fileRouteToDeclarations) => {
|
|
|
122
116
|
const schemas = perRoute
|
|
123
117
|
.filter((pr) => pr.route && pr.handler.length)
|
|
124
118
|
.map(({ handler, route, methodName }) => {
|
|
125
|
-
const schemas = handler.map((t) =>
|
|
119
|
+
const schemas = handler.map((t) => generateCustomSchema(t));
|
|
126
120
|
let finalSchema = schemas[0];
|
|
127
121
|
if (schemas.length > 1) {
|
|
128
122
|
finalSchema = {
|
|
@@ -136,16 +130,15 @@ const generateRouteSchema = (fileRouteToDeclarations) => {
|
|
|
136
130
|
methodName,
|
|
137
131
|
schemas,
|
|
138
132
|
finalSchema,
|
|
139
|
-
jsonSchema:
|
|
133
|
+
jsonSchema: convertToJsonSchema(finalSchema),
|
|
140
134
|
};
|
|
141
135
|
});
|
|
142
136
|
return [...schemas];
|
|
143
137
|
};
|
|
144
|
-
exports.generateRouteSchema = generateRouteSchema;
|
|
145
138
|
const extractReturnStatements = (accumulator, n) => {
|
|
146
139
|
if (!n)
|
|
147
140
|
return;
|
|
148
|
-
if (
|
|
141
|
+
if (ts.SyntaxKind.IfStatement === n.getKind()) {
|
|
149
142
|
const thenProp = n.getNodeProperty('thenStatement');
|
|
150
143
|
const elseProp = n.getNodeProperty('elseStatement');
|
|
151
144
|
const thenSyntax = thenProp?.getChildSyntaxList();
|
|
@@ -156,10 +149,10 @@ const extractReturnStatements = (accumulator, n) => {
|
|
|
156
149
|
}
|
|
157
150
|
if (n.getChildren().length) {
|
|
158
151
|
const cleanChildren = n.getChildren().filter((c) => typeof c.getKind === 'function');
|
|
159
|
-
const findReturn = cleanChildren.find((c) => c.getKind() ===
|
|
160
|
-
const thereIf = cleanChildren.find((c) => c.getKind() ===
|
|
161
|
-
const thereWhile = cleanChildren.find((c) => c.getKind() ===
|
|
162
|
-
const thereFor = cleanChildren.find((c) => c.getKind() ===
|
|
152
|
+
const findReturn = cleanChildren.find((c) => c.getKind() === ts.SyntaxKind.ReturnStatement);
|
|
153
|
+
const thereIf = cleanChildren.find((c) => c.getKind() === ts.SyntaxKind.IfStatement);
|
|
154
|
+
const thereWhile = cleanChildren.find((c) => c.getKind() === ts.SyntaxKind.WhileKeyword);
|
|
155
|
+
const thereFor = cleanChildren.find((c) => c.getKind() === ts.SyntaxKind.ForStatement);
|
|
163
156
|
const syntaxList = n.getChildSyntaxList();
|
|
164
157
|
if (findReturn) {
|
|
165
158
|
accumulator.push(findReturn);
|
|
@@ -173,7 +166,7 @@ const extractReturnStatements = (accumulator, n) => {
|
|
|
173
166
|
const getTypes = (nodes) => nodes
|
|
174
167
|
.map((r) => r.getChildren().find((c) => {
|
|
175
168
|
const type = c.getType();
|
|
176
|
-
return type.isObject() ||
|
|
169
|
+
return type.isObject() || isFinalType(type);
|
|
177
170
|
}))
|
|
178
171
|
.filter((n) => n && typeof n.getType === 'function')
|
|
179
172
|
.map((acc) => acc.getType());
|
package/lib/schemas/helpers.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const helpers: {
|
|
|
18
18
|
};
|
|
19
19
|
export declare const isFinalType: (t: Type<ts.Type>) => boolean;
|
|
20
20
|
export declare const isNullType: (t: Type<ts.Type>) => boolean;
|
|
21
|
-
|
|
21
|
+
type ResolvedBasicTypes = 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
22
22
|
export declare const isHandler: (c: Node<ts.Node>) => boolean;
|
|
23
23
|
export declare const isRoute: (c: Node<ts.Node>) => boolean;
|
|
24
24
|
export declare const getTypeGenericText: (t: Type<ts.Type>) => ResolvedBasicTypes;
|
package/lib/schemas/helpers.js
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const ts_morph_1 = require("ts-morph");
|
|
5
|
-
const util_1 = require("util");
|
|
6
|
-
exports.helpers = {
|
|
1
|
+
import { ts } from 'ts-morph';
|
|
2
|
+
import { inspect } from 'util';
|
|
3
|
+
export const helpers = {
|
|
7
4
|
findCallExpressionFromChildren: (property) => property.getChildren(),
|
|
8
|
-
findCallExpression: (n) => n.find((x) => x.getKind() ===
|
|
9
|
-
findSyntaxList: (property) => property.getChildren().find((x) => x.getKind() ===
|
|
5
|
+
findCallExpression: (n) => n.find((x) => x.getKind() === ts.SyntaxKind.CallExpression),
|
|
6
|
+
findSyntaxList: (property) => property.getChildren().find((x) => x.getKind() === ts.SyntaxKind.SyntaxList),
|
|
10
7
|
findFunction: (property) => property
|
|
11
8
|
.getChildren()
|
|
12
|
-
.find((x) => x.getKind() ===
|
|
13
|
-
x.getKind() ===
|
|
14
|
-
findReturnStatement: (property) => property.getChildren().find((x) => x.getKind() ===
|
|
15
|
-
findIdentifier: (property) => property.getChildren().find((x) => x.getKind() ===
|
|
16
|
-
findObjectLiteralExpressionFromChildren: (property) => property.getChildren().find((x) => x.getKind() ===
|
|
17
|
-
findObjectLiteralExpression: (n) => n.find((x) => x.getKind() ===
|
|
18
|
-
filterPropertyAssignmentFromChildren: (property) => property.getChildren().filter((x) => x.getKind() ===
|
|
19
|
-
findPropertyAssignmentFromChildren: (property) => property.getChildren().find((x) => x.getKind() ===
|
|
20
|
-
findPropertyAssignment: (n) => n.find((x) => x.getKind() ===
|
|
21
|
-
findUnionTypeNodeFromChildren: (n) => n.getChildren().find((x) => x.getKind() ===
|
|
22
|
-
findNullableTypeFromChildren: (n) => n.getChildren().find((x) =>
|
|
23
|
-
filterNullableTypeFromChildren: (n) => n.getChildren().filter((x) => !
|
|
24
|
-
cleanNullableTypes: (t) => t.filter((x) => !
|
|
9
|
+
.find((x) => x.getKind() === ts.SyntaxKind.ArrowFunction ||
|
|
10
|
+
x.getKind() === ts.SyntaxKind.FunctionExpression),
|
|
11
|
+
findReturnStatement: (property) => property.getChildren().find((x) => x.getKind() === ts.SyntaxKind.ReturnStatement),
|
|
12
|
+
findIdentifier: (property) => property.getChildren().find((x) => x.getKind() === ts.SyntaxKind.ReturnStatement),
|
|
13
|
+
findObjectLiteralExpressionFromChildren: (property) => property.getChildren().find((x) => x.getKind() === ts.SyntaxKind.ObjectLiteralExpression),
|
|
14
|
+
findObjectLiteralExpression: (n) => n.find((x) => x.getKind() === ts.SyntaxKind.ObjectLiteralExpression),
|
|
15
|
+
filterPropertyAssignmentFromChildren: (property) => property.getChildren().filter((x) => x.getKind() === ts.SyntaxKind.PropertyAssignment),
|
|
16
|
+
findPropertyAssignmentFromChildren: (property) => property.getChildren().find((x) => x.getKind() === ts.SyntaxKind.PropertyAssignment),
|
|
17
|
+
findPropertyAssignment: (n) => n.find((x) => x.getKind() === ts.SyntaxKind.PropertyAssignment),
|
|
18
|
+
findUnionTypeNodeFromChildren: (n) => n.getChildren().find((x) => x.getKind() === ts.SyntaxKind.UnionType),
|
|
19
|
+
findNullableTypeFromChildren: (n) => n.getChildren().find((x) => isNullType(x.getType())),
|
|
20
|
+
filterNullableTypeFromChildren: (n) => n.getChildren().filter((x) => !isNullType(x.getType())),
|
|
21
|
+
cleanNullableTypes: (t) => t.filter((x) => !isNullType(x)),
|
|
25
22
|
}; //Prop
|
|
26
|
-
const isFinalType = (t) => t.isNumber() || t.isString() || t.isBoolean() || t.isLiteral();
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
exports.isHandler = isHandler;
|
|
32
|
-
const isRoute = (c) => c.getSymbol()?.getName() === 'route';
|
|
33
|
-
exports.isRoute = isRoute;
|
|
34
|
-
const getTypeGenericText = (t) => {
|
|
23
|
+
export const isFinalType = (t) => t.isNumber() || t.isString() || t.isBoolean() || t.isLiteral();
|
|
24
|
+
export const isNullType = (t) => t.isNull() || t.isUndefined();
|
|
25
|
+
export const isHandler = (c) => c.getSymbol()?.getName() === 'handler';
|
|
26
|
+
export const isRoute = (c) => c.getSymbol()?.getName() === 'route';
|
|
27
|
+
export const getTypeGenericText = (t) => {
|
|
35
28
|
if (t.isStringLiteral() || t.isNumberLiteral() || t.isBooleanLiteral()) {
|
|
36
29
|
return t.getBaseTypeOfLiteralType().getText();
|
|
37
30
|
}
|
|
@@ -39,12 +32,9 @@ const getTypeGenericText = (t) => {
|
|
|
39
32
|
return t.getText();
|
|
40
33
|
}
|
|
41
34
|
};
|
|
42
|
-
|
|
43
|
-
const getApparentTypeName = (t) => {
|
|
35
|
+
export const getApparentTypeName = (t) => {
|
|
44
36
|
return t.getApparentType().getText().toLowerCase();
|
|
45
37
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
console.log((0, util_1.inspect)(data, false, null, true));
|
|
38
|
+
export function logInternals(data) {
|
|
39
|
+
console.log(inspect(data, false, null, true));
|
|
49
40
|
}
|
|
50
|
-
exports.logInternals = logInternals;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CustomSchema } from './custom-schema';
|
|
1
|
+
import { CustomSchema } from './custom-schema.js';
|
|
2
2
|
export declare const convertToJsonSchema: (schema: CustomSchema) => any;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertToJsonSchema = void 0;
|
|
4
|
-
const convertToJsonSchema = (schema) => {
|
|
1
|
+
export const convertToJsonSchema = (schema) => {
|
|
5
2
|
if (schema.type === 'string') {
|
|
6
3
|
return {
|
|
7
4
|
type: 'string',
|
|
@@ -21,13 +18,13 @@ const convertToJsonSchema = (schema) => {
|
|
|
21
18
|
const reSchema = schema;
|
|
22
19
|
return {
|
|
23
20
|
type: 'array',
|
|
24
|
-
items:
|
|
21
|
+
items: convertToJsonSchema(reSchema.items),
|
|
25
22
|
};
|
|
26
23
|
}
|
|
27
24
|
if (schema.type === 'object') {
|
|
28
25
|
const reSchema = schema;
|
|
29
26
|
const objectJsonedProperties = Object.keys(reSchema.properties).reduce((acc, key) => {
|
|
30
|
-
acc[key] =
|
|
27
|
+
acc[key] = convertToJsonSchema(reSchema.properties[key]);
|
|
31
28
|
return acc;
|
|
32
29
|
}, {});
|
|
33
30
|
const required = Object.entries(reSchema.properties).reduce((acc, [key, value]) => {
|
|
@@ -45,8 +42,7 @@ const convertToJsonSchema = (schema) => {
|
|
|
45
42
|
if (schema.type === 'union') {
|
|
46
43
|
const reSchema = schema;
|
|
47
44
|
return {
|
|
48
|
-
anyOf: reSchema.anyOf.map((item) =>
|
|
45
|
+
anyOf: reSchema.anyOf.map((item) => convertToJsonSchema(item)),
|
|
49
46
|
};
|
|
50
47
|
}
|
|
51
48
|
};
|
|
52
|
-
exports.convertToJsonSchema = convertToJsonSchema;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CustomSchema } from './custom-schema';
|
|
2
|
-
export declare const convertToOpenApiSchema: (schema: CustomSchema, route?: string
|
|
1
|
+
import { CustomSchema } from './custom-schema.js';
|
|
2
|
+
export declare const convertToOpenApiSchema: (schema: CustomSchema, route?: string, method?: string) => any;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertToOpenApiSchema = void 0;
|
|
4
1
|
const createRouteSchema = (route, method, openApiSchema) => ({
|
|
5
2
|
[route]: {
|
|
6
3
|
[method]: {
|
|
@@ -11,7 +8,7 @@ const createRouteSchema = (route, method, openApiSchema) => ({
|
|
|
11
8
|
},
|
|
12
9
|
},
|
|
13
10
|
});
|
|
14
|
-
const convertToOpenApiSchema = (schema, route, method) => {
|
|
11
|
+
export const convertToOpenApiSchema = (schema, route, method) => {
|
|
15
12
|
if (schema.type === 'string') {
|
|
16
13
|
return {
|
|
17
14
|
type: 'string',
|
|
@@ -31,13 +28,13 @@ const convertToOpenApiSchema = (schema, route, method) => {
|
|
|
31
28
|
const reSchema = schema;
|
|
32
29
|
return {
|
|
33
30
|
type: 'array',
|
|
34
|
-
items:
|
|
31
|
+
items: convertToOpenApiSchema(reSchema.items),
|
|
35
32
|
};
|
|
36
33
|
}
|
|
37
34
|
if (schema.type === 'object') {
|
|
38
35
|
const reSchema = schema;
|
|
39
36
|
const objectJsonedProperties = Object.keys(reSchema.properties).reduce((acc, key) => {
|
|
40
|
-
acc[key] =
|
|
37
|
+
acc[key] = convertToOpenApiSchema(reSchema.properties[key]);
|
|
41
38
|
return acc;
|
|
42
39
|
}, {});
|
|
43
40
|
const required = Object.entries(reSchema.properties).reduce((acc, [key, value]) => {
|
|
@@ -55,9 +52,8 @@ const convertToOpenApiSchema = (schema, route, method) => {
|
|
|
55
52
|
if (schema.type === 'union') {
|
|
56
53
|
const reSchema = schema;
|
|
57
54
|
return {
|
|
58
|
-
anyOf: reSchema.anyOf.map((item) =>
|
|
55
|
+
anyOf: reSchema.anyOf.map((item) => convertToOpenApiSchema(item)),
|
|
59
56
|
};
|
|
60
57
|
}
|
|
61
58
|
return createRouteSchema(route, method, schema);
|
|
62
59
|
};
|
|
63
|
-
exports.convertToOpenApiSchema = convertToOpenApiSchema;
|
package/lib/schemas/project.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/schemas/project.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/lib/server.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { ServerOptions } from 'ws';
|
|
3
|
-
import Ajv from 'ajv';
|
|
4
|
-
import { BareRequest, CacheOpts } from './request';
|
|
5
|
-
import { CookiesManagerOptions } from './middlewares/cookies/cookie-manager';
|
|
6
|
-
import { HttpMethodsUnion, StatusCodesUnion } from './utils';
|
|
7
|
-
import { CorsOptions } from './middlewares/cors/cors';
|
|
8
|
-
import { WebSocketServer } from './websocket';
|
|
2
|
+
import { Ajv } from 'ajv';
|
|
3
|
+
import { BareRequest, CacheOpts } from './request.js';
|
|
4
|
+
import { CookiesManagerOptions } from './middlewares/cookies/cookie-manager.js';
|
|
5
|
+
import { HttpMethodsUnion, StatusCodesUnion } from './utils/index.js';
|
|
6
|
+
import { CorsOptions } from './middlewares/cors/cors.js';
|
|
7
|
+
import { WebSocketServer } from './websocket.js';
|
|
9
8
|
import { Server } from 'http';
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
type Middleware = (flow: BareRequest) => Promise<void> | void;
|
|
10
|
+
type Handler<H extends {
|
|
12
11
|
[key: string]: string | undefined;
|
|
13
12
|
}> = (flow: BareRequest<H>) => any;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
type ErrorHandler = (err: any, flow: BareRequest, status?: StatusCodesUnion) => void;
|
|
14
|
+
type IP = `${number}.${number}.${number}.${number}`;
|
|
15
|
+
type RouteOpts<C> = {
|
|
17
16
|
disableCache?: C extends true ? C : undefined;
|
|
18
17
|
cache?: C extends true ? undefined : CacheOpts;
|
|
19
18
|
/**
|
|
@@ -25,7 +24,7 @@ declare type RouteOpts<C> = {
|
|
|
25
24
|
};
|
|
26
25
|
middlewares?: Array<Middleware>;
|
|
27
26
|
};
|
|
28
|
-
|
|
27
|
+
type BareOptions<A extends IP> = {
|
|
29
28
|
/**
|
|
30
29
|
* Declare a global middlewares array
|
|
31
30
|
* Default: []
|
|
@@ -91,9 +90,9 @@ declare type BareOptions<A extends IP> = {
|
|
|
91
90
|
*/
|
|
92
91
|
cors?: boolean | CorsOptions;
|
|
93
92
|
};
|
|
94
|
-
|
|
93
|
+
type ExtractRouteParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
95
94
|
[K in Param | keyof ExtractRouteParams<Rest>]: string;
|
|
96
|
-
} : T extends `${
|
|
95
|
+
} : T extends `${string}:${infer Param}` ? {
|
|
97
96
|
[K in Param]: string;
|
|
98
97
|
} : {
|
|
99
98
|
[k: string]: string;
|
|
@@ -110,15 +109,15 @@ interface HandlerExposed<K> {
|
|
|
110
109
|
handler: Handler<ExtractRouteParams<R>>;
|
|
111
110
|
}): BareServer<any> & Routes;
|
|
112
111
|
}
|
|
113
|
-
export
|
|
112
|
+
export type RouteReport = {
|
|
114
113
|
hits: number;
|
|
115
114
|
success: number;
|
|
116
115
|
fails: number;
|
|
117
116
|
};
|
|
118
|
-
export
|
|
117
|
+
export type Routes = {
|
|
119
118
|
[K in HttpMethodsUnion | 'declare']: HandlerExposed<K>;
|
|
120
119
|
};
|
|
121
|
-
export
|
|
120
|
+
export type BareHttpType<A extends IP = any> = BareServer<A> & Routes;
|
|
122
121
|
export declare class BareServer<A extends IP> {
|
|
123
122
|
#private;
|
|
124
123
|
private bareOptions;
|