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.
Files changed (44) hide show
  1. package/lib/context/execution.js +3 -10
  2. package/lib/context/index.d.ts +2 -3
  3. package/lib/context/index.js +6 -14
  4. package/lib/env.js +1 -4
  5. package/lib/index.d.ts +5 -5
  6. package/lib/index.js +3 -9
  7. package/lib/logger/index.d.ts +3 -5
  8. package/lib/logger/index.js +16 -43
  9. package/lib/logger/serializers.d.ts +2 -3
  10. package/lib/logger/serializers.js +12 -22
  11. package/lib/middlewares/cookies/cookie-manager.d.ts +7 -6
  12. package/lib/middlewares/cookies/cookie-manager.js +14 -18
  13. package/lib/middlewares/cookies/signer.js +4 -11
  14. package/lib/middlewares/cors/cors.d.ts +3 -3
  15. package/lib/middlewares/cors/cors.js +1 -4
  16. package/lib/request.d.ts +7 -8
  17. package/lib/request.js +22 -29
  18. package/lib/schemas/custom-schema.d.ts +7 -7
  19. package/lib/schemas/custom-schema.js +13 -20
  20. package/lib/schemas/dirty-tsm.js +18 -20
  21. package/lib/schemas/generator.d.ts +3 -3
  22. package/lib/schemas/generator.js +25 -32
  23. package/lib/schemas/helpers.d.ts +1 -1
  24. package/lib/schemas/helpers.js +26 -36
  25. package/lib/schemas/json-schema.d.ts +1 -1
  26. package/lib/schemas/json-schema.js +4 -8
  27. package/lib/schemas/openami-schema.d.ts +2 -2
  28. package/lib/schemas/openami-schema.js +4 -8
  29. package/lib/schemas/project.d.ts +1 -0
  30. package/lib/schemas/project.js +1 -1
  31. package/lib/server.d.ts +17 -18
  32. package/lib/server.js +35 -42
  33. package/lib/utils/content-type.js +2 -5
  34. package/lib/utils/http-methods.d.ts +2 -2
  35. package/lib/utils/http-methods.js +1 -4
  36. package/lib/utils/index.d.ts +4 -4
  37. package/lib/utils/index.js +4 -12
  38. package/lib/utils/safe-json.js +2 -7
  39. package/lib/utils/status-codes.d.ts +1 -1
  40. package/lib/utils/status-codes.js +1 -4
  41. package/lib/utils/status-phrases.js +1 -4
  42. package/lib/websocket.d.ts +6 -7
  43. package/lib/websocket.js +24 -27
  44. package/package.json +48 -37
@@ -1,25 +1,19 @@
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.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) => (0, helpers_1.isNullType)(nt));
15
- const cleanTypes = helpers_1.helpers.cleanNullableTypes(t.getUnionTypes());
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 = (0, exports.generateCustomSchema)(ut);
22
- if ((0, find_1.default)(acc, regenerated))
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 = (0, exports.generateCustomSchema)(it);
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: (0, exports.generateCustomSchema)(t.getArrayElementType()),
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()]: (0, exports.generateCustomSchema)(val.getType()) };
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: (0, helpers_1.getApparentTypeName)(t),
59
+ type: getApparentTypeName(t),
66
60
  nullable: false,
67
61
  };
68
62
  };
69
- exports.generateCustomSchema = generateCustomSchema;
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ts_morph_1 = require("ts-morph");
4
- const custom_schema_1 = require("./custom-schema");
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(ts_morph_1.ts.SyntaxKind.Identifier)[0]
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() === ts_morph_1.ts.SyntaxKind.CallExpression)
27
+ .find((n) => n.getKind() === ts.SyntaxKind.CallExpression)
30
28
  ?.getChildren()
31
- .find((n) => n.getKind() === ts_morph_1.ts.SyntaxKind.SyntaxList)
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() === ts_morph_1.ts.SyntaxKind.PropertyAssignment && (isHandler(c) || isRoute(c));
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() === ts_morph_1.ts.SyntaxKind.ArrowFunction ||
45
- n.getKind() === ts_morph_1.ts.SyntaxKind.FunctionExpression)
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) => (0, custom_schema_1.generateCustomSchema)(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 (ts_morph_1.ts.SyntaxKind.IfStatement === n.getKind()) {
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() === ts_morph_1.ts.SyntaxKind.ReturnStatement);
145
- const thereIf = cleanChildren.find((c) => c.getKind() === ts_morph_1.ts.SyntaxKind.IfStatement);
146
- const thereWhile = cleanChildren.find((c) => c.getKind() === ts_morph_1.ts.SyntaxKind.WhileKeyword);
147
- const thereFor = cleanChildren.find((c) => c.getKind() === ts_morph_1.ts.SyntaxKind.ForStatement);
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() || (0, helpers_1.isFinalType)(type);
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
- (0, helpers_1.logInternals)(returnFinder('examples', tp));
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" | "post" | "put" | "delete" | "patch" | "options" | "head";
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
  }[];
@@ -1,18 +1,12 @@
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.generateRouteSchema = void 0;
7
- const ts_morph_1 = require("ts-morph");
8
- const custom_schema_1 = require("./custom-schema");
9
- const helpers_1 = require("./helpers");
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(ts_morph_1.ts.SyntaxKind.Identifier)[0]
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() === ts_morph_1.ts.SyntaxKind.CallExpression)
62
+ .find((n) => n.getKind() === ts.SyntaxKind.CallExpression)
69
63
  ?.getChildren()
70
- .find((n) => n.getKind() === ts_morph_1.ts.SyntaxKind.SyntaxList)
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() === ts_morph_1.ts.SyntaxKind.PropertyAssignment && ((0, helpers_1.isHandler)(c) || (0, helpers_1.isRoute)(c));
69
+ return c.getKind() === ts.SyntaxKind.PropertyAssignment && (isHandler(c) || isRoute(c));
76
70
  })
77
71
  .map((c) => {
78
- if ((0, helpers_1.isHandler)(c)) {
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() === ts_morph_1.ts.SyntaxKind.ArrowFunction ||
85
- n.getKind() === ts_morph_1.ts.SyntaxKind.FunctionExpression)
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) => (0, custom_schema_1.generateCustomSchema)(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: (0, json_schema_1.convertToJsonSchema)(finalSchema),
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 (ts_morph_1.ts.SyntaxKind.IfStatement === n.getKind()) {
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() === ts_morph_1.ts.SyntaxKind.ReturnStatement);
160
- const thereIf = cleanChildren.find((c) => c.getKind() === ts_morph_1.ts.SyntaxKind.IfStatement);
161
- const thereWhile = cleanChildren.find((c) => c.getKind() === ts_morph_1.ts.SyntaxKind.WhileKeyword);
162
- const thereFor = cleanChildren.find((c) => c.getKind() === ts_morph_1.ts.SyntaxKind.ForStatement);
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() || (0, helpers_1.isFinalType)(type);
169
+ return type.isObject() || isFinalType(type);
177
170
  }))
178
171
  .filter((n) => n && typeof n.getType === 'function')
179
172
  .map((acc) => acc.getType());
@@ -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
- declare type ResolvedBasicTypes = 'string' | 'number' | 'boolean' | 'array' | 'object';
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;
@@ -1,37 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logInternals = exports.getApparentTypeName = exports.getTypeGenericText = exports.isRoute = exports.isHandler = exports.isNullType = exports.isFinalType = exports.helpers = void 0;
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() === ts_morph_1.ts.SyntaxKind.CallExpression),
9
- findSyntaxList: (property) => property.getChildren().find((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.SyntaxList),
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() === ts_morph_1.ts.SyntaxKind.ArrowFunction ||
13
- x.getKind() === ts_morph_1.ts.SyntaxKind.FunctionExpression),
14
- findReturnStatement: (property) => property.getChildren().find((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.ReturnStatement),
15
- findIdentifier: (property) => property.getChildren().find((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.ReturnStatement),
16
- findObjectLiteralExpressionFromChildren: (property) => property.getChildren().find((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.ObjectLiteralExpression),
17
- findObjectLiteralExpression: (n) => n.find((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.ObjectLiteralExpression),
18
- filterPropertyAssignmentFromChildren: (property) => property.getChildren().filter((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.PropertyAssignment),
19
- findPropertyAssignmentFromChildren: (property) => property.getChildren().find((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.PropertyAssignment),
20
- findPropertyAssignment: (n) => n.find((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.PropertyAssignment),
21
- findUnionTypeNodeFromChildren: (n) => n.getChildren().find((x) => x.getKind() === ts_morph_1.ts.SyntaxKind.UnionType),
22
- findNullableTypeFromChildren: (n) => n.getChildren().find((x) => (0, exports.isNullType)(x.getType())),
23
- filterNullableTypeFromChildren: (n) => n.getChildren().filter((x) => !(0, exports.isNullType)(x.getType())),
24
- cleanNullableTypes: (t) => t.filter((x) => !(0, exports.isNullType)(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
- exports.isFinalType = isFinalType;
28
- const isNullType = (t) => t.isNull() || t.isUndefined();
29
- exports.isNullType = isNullType;
30
- const isHandler = (c) => c.getSymbol()?.getName() === 'handler';
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
- exports.getTypeGenericText = getTypeGenericText;
43
- const getApparentTypeName = (t) => {
35
+ export const getApparentTypeName = (t) => {
44
36
  return t.getApparentType().getText().toLowerCase();
45
37
  };
46
- exports.getApparentTypeName = getApparentTypeName;
47
- function logInternals(data) {
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
- "use strict";
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: (0, exports.convertToJsonSchema)(reSchema.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] = (0, exports.convertToJsonSchema)(reSchema.properties[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) => (0, exports.convertToJsonSchema)(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 | undefined, method?: string | undefined) => any;
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: (0, exports.convertToOpenApiSchema)(reSchema.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] = (0, exports.convertToOpenApiSchema)(reSchema.properties[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) => (0, exports.convertToOpenApiSchema)(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;
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- "use strict";
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
- declare type Middleware = (flow: BareRequest) => Promise<void> | void;
11
- declare type Handler<H extends {
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
- declare type ErrorHandler = (err: any, flow: BareRequest, status?: StatusCodesUnion) => void;
15
- declare type IP = `${number}.${number}.${number}.${number}`;
16
- declare type RouteOpts<C> = {
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
- declare type BareOptions<A extends IP> = {
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
- declare type ExtractRouteParams<T extends string> = T extends `${infer Start}:${infer Param}/${infer Rest}` ? {
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 `${infer Start}:${infer Param}` ? {
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 declare type RouteReport = {
112
+ export type RouteReport = {
114
113
  hits: number;
115
114
  success: number;
116
115
  fails: number;
117
116
  };
118
- export declare type Routes = {
117
+ export type Routes = {
119
118
  [K in HttpMethodsUnion | 'declare']: HandlerExposed<K>;
120
119
  };
121
- export declare type BareHttpType<A extends IP = any> = BareServer<A> & Routes;
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;