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.
- package/README.md +197 -196
- package/auto-docs/analysis/handler-analyzer.js +58 -58
- package/auto-docs/analysis/source-resolver.js +101 -101
- package/auto-docs/constants.js +37 -37
- package/auto-docs/docs-llm/index.js +7 -7
- package/auto-docs/docs-llm/prompts.js +222 -222
- package/auto-docs/docs-llm/provider.js +132 -132
- package/auto-docs/index.js +146 -146
- package/auto-docs/openapi/endpoint-processor.js +277 -277
- package/auto-docs/openapi/generator.js +107 -107
- package/auto-docs/openapi/level3.js +131 -131
- package/auto-docs/openapi/spec-builders.js +244 -244
- package/auto-docs/ui/docs-ui.js +186 -186
- package/auto-docs/utils/logger.js +17 -17
- package/auto-docs/utils/strip-usage.js +10 -10
- package/cli/docs-command.js +315 -315
- package/cli/fly-command.js +71 -71
- package/cli/index.js +56 -56
- package/cors/index.js +71 -0
- package/database/index.js +165 -165
- package/database/mongodb.js +146 -146
- package/database/redis.js +201 -201
- package/docs/README.md +36 -36
- package/docs/ammo.md +362 -362
- package/docs/api-reference.md +490 -490
- package/docs/auto-docs.md +216 -216
- package/docs/cli.md +152 -152
- package/docs/configuration.md +275 -275
- package/docs/database.md +390 -390
- package/docs/error-handling.md +438 -438
- package/docs/file-uploads.md +333 -333
- package/docs/getting-started.md +214 -214
- package/docs/middleware.md +355 -355
- package/docs/rate-limiting.md +393 -393
- package/docs/routing.md +302 -302
- package/lib/llm/client.js +73 -0
- package/lib/llm/index.js +7 -0
- package/lib/llm/parse.js +89 -0
- package/package.json +64 -62
- package/rate-limit/algorithms/fixed-window.js +141 -141
- package/rate-limit/algorithms/sliding-window.js +147 -147
- package/rate-limit/algorithms/token-bucket.js +115 -115
- package/rate-limit/base.js +165 -165
- package/rate-limit/index.js +147 -147
- package/rate-limit/storage/base.js +104 -104
- package/rate-limit/storage/memory.js +101 -101
- package/rate-limit/storage/redis.js +88 -88
- package/server/ammo/body-parser.js +220 -220
- package/server/ammo/dispatch-helper.js +103 -103
- package/server/ammo/enhancer.js +57 -57
- package/server/ammo.js +454 -415
- package/server/endpoint.js +97 -74
- package/server/error.js +9 -9
- package/server/errors/code-context.js +125 -125
- package/server/errors/llm-error-service.js +140 -140
- package/server/files/helper.js +33 -33
- package/server/files/uploader.js +143 -143
- package/server/handler.js +158 -119
- package/server/target.js +185 -175
- package/server/targets/middleware-validator.js +22 -22
- package/server/targets/path-validator.js +21 -21
- package/server/targets/registry.js +160 -160
- package/server/targets/shoot-validator.js +21 -21
- package/te.js +428 -402
- package/utils/auto-register.js +17 -17
- package/utils/configuration.js +64 -64
- package/utils/errors-llm-config.js +84 -84
- package/utils/request-logger.js +43 -43
- package/utils/status-codes.js +82 -82
- package/utils/tejas-entrypoint-html.js +18 -18
package/database/mongodb.js
CHANGED
|
@@ -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
|
+
};
|