te.js 2.1.0 → 2.1.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.
Files changed (70) hide show
  1. package/README.md +197 -196
  2. package/auto-docs/analysis/handler-analyzer.js +58 -58
  3. package/auto-docs/analysis/source-resolver.js +101 -101
  4. package/auto-docs/constants.js +37 -37
  5. package/auto-docs/docs-llm/index.js +7 -7
  6. package/auto-docs/docs-llm/prompts.js +222 -222
  7. package/auto-docs/docs-llm/provider.js +132 -132
  8. package/auto-docs/index.js +146 -146
  9. package/auto-docs/openapi/endpoint-processor.js +277 -277
  10. package/auto-docs/openapi/generator.js +107 -107
  11. package/auto-docs/openapi/level3.js +131 -131
  12. package/auto-docs/openapi/spec-builders.js +244 -244
  13. package/auto-docs/ui/docs-ui.js +186 -186
  14. package/auto-docs/utils/logger.js +17 -17
  15. package/auto-docs/utils/strip-usage.js +10 -10
  16. package/cli/docs-command.js +315 -315
  17. package/cli/fly-command.js +71 -71
  18. package/cli/index.js +56 -56
  19. package/cors/index.js +71 -0
  20. package/database/index.js +165 -165
  21. package/database/mongodb.js +146 -146
  22. package/database/redis.js +201 -201
  23. package/docs/README.md +36 -36
  24. package/docs/ammo.md +362 -362
  25. package/docs/api-reference.md +490 -490
  26. package/docs/auto-docs.md +216 -216
  27. package/docs/cli.md +152 -152
  28. package/docs/configuration.md +275 -275
  29. package/docs/database.md +390 -390
  30. package/docs/error-handling.md +438 -438
  31. package/docs/file-uploads.md +333 -333
  32. package/docs/getting-started.md +214 -214
  33. package/docs/middleware.md +355 -355
  34. package/docs/rate-limiting.md +393 -393
  35. package/docs/routing.md +302 -302
  36. package/lib/llm/client.js +73 -0
  37. package/lib/llm/index.js +7 -0
  38. package/lib/llm/parse.js +89 -0
  39. package/package.json +64 -62
  40. package/rate-limit/algorithms/fixed-window.js +141 -141
  41. package/rate-limit/algorithms/sliding-window.js +147 -147
  42. package/rate-limit/algorithms/token-bucket.js +115 -115
  43. package/rate-limit/base.js +165 -165
  44. package/rate-limit/index.js +147 -147
  45. package/rate-limit/storage/base.js +104 -104
  46. package/rate-limit/storage/memory.js +101 -101
  47. package/rate-limit/storage/redis.js +88 -88
  48. package/server/ammo/body-parser.js +220 -220
  49. package/server/ammo/dispatch-helper.js +103 -103
  50. package/server/ammo/enhancer.js +57 -57
  51. package/server/ammo.js +454 -415
  52. package/server/endpoint.js +97 -74
  53. package/server/error.js +9 -9
  54. package/server/errors/code-context.js +125 -125
  55. package/server/errors/llm-error-service.js +140 -140
  56. package/server/files/helper.js +33 -33
  57. package/server/files/uploader.js +143 -143
  58. package/server/handler.js +158 -119
  59. package/server/target.js +185 -175
  60. package/server/targets/middleware-validator.js +22 -22
  61. package/server/targets/path-validator.js +21 -21
  62. package/server/targets/registry.js +160 -160
  63. package/server/targets/shoot-validator.js +21 -21
  64. package/te.js +428 -402
  65. package/utils/auto-register.js +17 -17
  66. package/utils/configuration.js +64 -64
  67. package/utils/errors-llm-config.js +84 -84
  68. package/utils/request-logger.js +43 -43
  69. package/utils/status-codes.js +82 -82
  70. package/utils/tejas-entrypoint-html.js +18 -18
@@ -1,146 +1,146 @@
1
- import { spawn } from 'child_process';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import { fileURLToPath } from 'url';
5
- import TejLogger from 'tej-logger';
6
- import TejError from '../server/error.js';
7
-
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
10
-
11
- const logger = new TejLogger('MongoDBConnectionManager');
12
-
13
- function checkMongooseInstallation() {
14
- const packageJsonPath = path.join(__dirname, '..', 'package.json');
15
- const nodeModulesPath = path.join(
16
- __dirname,
17
- '..',
18
- 'node_modules',
19
- 'mongoose',
20
- );
21
-
22
- try {
23
- // Check if mongoose exists in package.json
24
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
25
- const inPackageJson = !!packageJson.dependencies?.mongoose;
26
-
27
- // Check if mongoose exists in node_modules
28
- const inNodeModules = fs.existsSync(nodeModulesPath);
29
-
30
- return {
31
- needsInstall: !inPackageJson || !inNodeModules,
32
- reason: !inPackageJson
33
- ? 'not in package.json'
34
- : !inNodeModules
35
- ? 'not in node_modules'
36
- : null,
37
- };
38
- } catch (error) {
39
- return { needsInstall: true, reason: 'error checking installation' };
40
- }
41
- }
42
-
43
- function installMongooseSync() {
44
- const spinner = ['|', '/', '-', '\\'];
45
- let current = 0;
46
- let intervalId;
47
-
48
- try {
49
- const { needsInstall, reason } = checkMongooseInstallation();
50
-
51
- if (!needsInstall) {
52
- return true;
53
- }
54
-
55
- // Start the spinner
56
- intervalId = setInterval(() => {
57
- process.stdout.write(`\r${spinner[current]} Installing mongoose...`);
58
- current = (current + 1) % spinner.length;
59
- }, 100);
60
-
61
- logger.info(`Tejas will install mongoose (${reason})...`);
62
-
63
- const command = process.platform === 'win32' ? 'npm.cmd' : 'npm';
64
- const result = spawn.sync(command, ['install', 'mongoose'], {
65
- stdio: 'inherit',
66
- shell: true,
67
- });
68
-
69
- process.stdout.write('\r');
70
- clearInterval(intervalId);
71
-
72
- if (result.status === 0) {
73
- logger.info('Mongoose installed successfully');
74
- return true;
75
- } else {
76
- logger.error('Mongoose installation failed');
77
- return false;
78
- }
79
- } catch (error) {
80
- if (intervalId) {
81
- process.stdout.write('\r');
82
- clearInterval(intervalId);
83
- }
84
- logger.error('Error installing mongoose:', error);
85
- return false;
86
- }
87
- }
88
-
89
- /**
90
- * Create a new MongoDB connection
91
- * @param {Object} config - MongoDB configuration
92
- * @param {string} config.uri - MongoDB connection URI
93
- * @param {Object} [config.options={}] - Additional Mongoose options
94
- * @returns {Promise<mongoose.Connection>} Mongoose connection instance
95
- */
96
- async function createConnection(config) {
97
- const { needsInstall } = checkMongooseInstallation();
98
-
99
- if (needsInstall) {
100
- const installed = installMongooseSync();
101
- if (!installed) {
102
- throw new TejError(500, 'Failed to install required mongoose package');
103
- }
104
- }
105
-
106
- const { uri, options = {} } = config;
107
-
108
- try {
109
- const mongoose = await import('mongoose').then((mod) => mod.default);
110
- const connection = await mongoose.createConnection(uri, options);
111
-
112
- connection.on('error', (err) =>
113
- logger.error(`MongoDB connection error:`, err),
114
- );
115
- connection.on('connected', () => {
116
- logger.info(`MongoDB connected to ${uri}`);
117
- });
118
- connection.on('disconnected', () => {
119
- logger.info(`MongoDB disconnected from ${uri}`);
120
- });
121
-
122
- return connection;
123
- } catch (error) {
124
- logger.error(`Failed to create MongoDB connection:`, error);
125
- throw new TejError(
126
- 500,
127
- `Failed to create MongoDB connection: ${error.message}`,
128
- );
129
- }
130
- }
131
-
132
- /**
133
- * Close a MongoDB connection
134
- * @param {mongoose.Connection} connection - Mongoose connection to close
135
- * @returns {Promise<void>}
136
- */
137
- async function closeConnection(connection) {
138
- if (connection) {
139
- await connection.close();
140
- }
141
- }
142
-
143
- export default {
144
- createConnection,
145
- closeConnection,
146
- };
1
+ import { spawn } from 'child_process';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import TejLogger from 'tej-logger';
6
+ import TejError from '../server/error.js';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ const logger = new TejLogger('MongoDBConnectionManager');
12
+
13
+ function checkMongooseInstallation() {
14
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
15
+ const nodeModulesPath = path.join(
16
+ __dirname,
17
+ '..',
18
+ 'node_modules',
19
+ 'mongoose',
20
+ );
21
+
22
+ try {
23
+ // Check if mongoose exists in package.json
24
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
25
+ const inPackageJson = !!packageJson.dependencies?.mongoose;
26
+
27
+ // Check if mongoose exists in node_modules
28
+ const inNodeModules = fs.existsSync(nodeModulesPath);
29
+
30
+ return {
31
+ needsInstall: !inPackageJson || !inNodeModules,
32
+ reason: !inPackageJson
33
+ ? 'not in package.json'
34
+ : !inNodeModules
35
+ ? 'not in node_modules'
36
+ : null,
37
+ };
38
+ } catch (error) {
39
+ return { needsInstall: true, reason: 'error checking installation' };
40
+ }
41
+ }
42
+
43
+ function installMongooseSync() {
44
+ const spinner = ['|', '/', '-', '\\'];
45
+ let current = 0;
46
+ let intervalId;
47
+
48
+ try {
49
+ const { needsInstall, reason } = checkMongooseInstallation();
50
+
51
+ if (!needsInstall) {
52
+ return true;
53
+ }
54
+
55
+ // Start the spinner
56
+ intervalId = setInterval(() => {
57
+ process.stdout.write(`\r${spinner[current]} Installing mongoose...`);
58
+ current = (current + 1) % spinner.length;
59
+ }, 100);
60
+
61
+ logger.info(`Tejas will install mongoose (${reason})...`);
62
+
63
+ const command = process.platform === 'win32' ? 'npm.cmd' : 'npm';
64
+ const result = spawn.sync(command, ['install', 'mongoose'], {
65
+ stdio: 'inherit',
66
+ shell: true,
67
+ });
68
+
69
+ process.stdout.write('\r');
70
+ clearInterval(intervalId);
71
+
72
+ if (result.status === 0) {
73
+ logger.info('Mongoose installed successfully');
74
+ return true;
75
+ } else {
76
+ logger.error('Mongoose installation failed');
77
+ return false;
78
+ }
79
+ } catch (error) {
80
+ if (intervalId) {
81
+ process.stdout.write('\r');
82
+ clearInterval(intervalId);
83
+ }
84
+ logger.error('Error installing mongoose:', error);
85
+ return false;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Create a new MongoDB connection
91
+ * @param {Object} config - MongoDB configuration
92
+ * @param {string} config.uri - MongoDB connection URI
93
+ * @param {Object} [config.options={}] - Additional Mongoose options
94
+ * @returns {Promise<mongoose.Connection>} Mongoose connection instance
95
+ */
96
+ async function createConnection(config) {
97
+ const { needsInstall } = checkMongooseInstallation();
98
+
99
+ if (needsInstall) {
100
+ const installed = installMongooseSync();
101
+ if (!installed) {
102
+ throw new TejError(500, 'Failed to install required mongoose package');
103
+ }
104
+ }
105
+
106
+ const { uri, options = {} } = config;
107
+
108
+ try {
109
+ const mongoose = await import('mongoose').then((mod) => mod.default);
110
+ const connection = await mongoose.createConnection(uri, options);
111
+
112
+ connection.on('error', (err) =>
113
+ logger.error(`MongoDB connection error:`, err),
114
+ );
115
+ connection.on('connected', () => {
116
+ logger.info(`MongoDB connected to ${uri}`);
117
+ });
118
+ connection.on('disconnected', () => {
119
+ logger.info(`MongoDB disconnected from ${uri}`);
120
+ });
121
+
122
+ return connection;
123
+ } catch (error) {
124
+ logger.error(`Failed to create MongoDB connection:`, error);
125
+ throw new TejError(
126
+ 500,
127
+ `Failed to create MongoDB connection: ${error.message}`,
128
+ );
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Close a MongoDB connection
134
+ * @param {mongoose.Connection} connection - Mongoose connection to close
135
+ * @returns {Promise<void>}
136
+ */
137
+ async function closeConnection(connection) {
138
+ if (connection) {
139
+ await connection.close();
140
+ }
141
+ }
142
+
143
+ export default {
144
+ createConnection,
145
+ closeConnection,
146
+ };