te.js 1.3.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 (80) hide show
  1. package/.cursor/plans/ai_native_framework_features_5bb1a20a.plan.md +234 -0
  2. package/.cursor/plans/auto_error_fix_agent_e68979c5.plan.md +356 -0
  3. package/.cursor/plans/tejas_framework_test_suite_5e3c6fad.plan.md +168 -0
  4. package/.prettierignore +31 -0
  5. package/README.md +156 -14
  6. package/auto-docs/analysis/handler-analyzer.js +58 -0
  7. package/auto-docs/analysis/source-resolver.js +101 -0
  8. package/auto-docs/constants.js +37 -0
  9. package/auto-docs/index.js +146 -0
  10. package/auto-docs/llm/index.js +6 -0
  11. package/auto-docs/llm/parse.js +88 -0
  12. package/auto-docs/llm/prompts.js +222 -0
  13. package/auto-docs/llm/provider.js +187 -0
  14. package/auto-docs/openapi/endpoint-processor.js +277 -0
  15. package/auto-docs/openapi/generator.js +107 -0
  16. package/auto-docs/openapi/level3.js +131 -0
  17. package/auto-docs/openapi/spec-builders.js +244 -0
  18. package/auto-docs/ui/docs-ui.js +186 -0
  19. package/auto-docs/utils/logger.js +17 -0
  20. package/auto-docs/utils/strip-usage.js +10 -0
  21. package/cli/docs-command.js +315 -0
  22. package/cli/fly-command.js +71 -0
  23. package/cli/index.js +57 -0
  24. package/database/index.js +163 -5
  25. package/database/mongodb.js +146 -0
  26. package/database/redis.js +201 -0
  27. package/docs/README.md +36 -0
  28. package/docs/ammo.md +362 -0
  29. package/docs/api-reference.md +489 -0
  30. package/docs/auto-docs.md +215 -0
  31. package/docs/cli.md +152 -0
  32. package/docs/configuration.md +233 -0
  33. package/docs/database.md +391 -0
  34. package/docs/error-handling.md +417 -0
  35. package/docs/file-uploads.md +334 -0
  36. package/docs/getting-started.md +181 -0
  37. package/docs/middleware.md +356 -0
  38. package/docs/rate-limiting.md +394 -0
  39. package/docs/routing.md +302 -0
  40. package/example/API_OVERVIEW.md +77 -0
  41. package/example/README.md +155 -0
  42. package/example/index.js +27 -2
  43. package/example/openapi.json +390 -0
  44. package/example/package.json +5 -2
  45. package/example/services/cache.service.js +25 -0
  46. package/example/services/user.service.js +42 -0
  47. package/example/start-redis.js +2 -0
  48. package/example/targets/cache.target.js +35 -0
  49. package/example/targets/index.target.js +11 -2
  50. package/example/targets/users.target.js +60 -0
  51. package/example/tejas.config.json +13 -1
  52. package/package.json +20 -5
  53. package/rate-limit/algorithms/fixed-window.js +141 -0
  54. package/rate-limit/algorithms/sliding-window.js +147 -0
  55. package/rate-limit/algorithms/token-bucket.js +115 -0
  56. package/rate-limit/base.js +165 -0
  57. package/rate-limit/index.js +147 -0
  58. package/rate-limit/storage/base.js +104 -0
  59. package/rate-limit/storage/memory.js +102 -0
  60. package/rate-limit/storage/redis.js +88 -0
  61. package/server/ammo/body-parser.js +152 -25
  62. package/server/ammo/enhancer.js +6 -2
  63. package/server/ammo.js +356 -327
  64. package/server/endpoint.js +21 -0
  65. package/server/handler.js +113 -87
  66. package/server/target.js +50 -9
  67. package/server/targets/registry.js +111 -6
  68. package/te.js +363 -137
  69. package/tests/auto-docs/handler-analyzer.test.js +44 -0
  70. package/tests/auto-docs/openapi-generator.test.js +103 -0
  71. package/tests/auto-docs/parse.test.js +63 -0
  72. package/tests/auto-docs/source-resolver.test.js +58 -0
  73. package/tests/helpers/index.js +37 -0
  74. package/tests/helpers/mock-http.js +342 -0
  75. package/tests/helpers/test-utils.js +446 -0
  76. package/tests/setup.test.js +148 -0
  77. package/utils/configuration.js +13 -10
  78. package/vitest.config.js +54 -0
  79. package/database/mongo.js +0 -67
  80. package/example/targets/user/user.target.js +0 -17
package/database/mongo.js DELETED
@@ -1,67 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import { pathToFileURL } from 'node:url';
3
- import TejLogger from 'tej-logger';
4
-
5
- const packagePath = `${process.cwd()}/node_modules/mongoose/index.js`;
6
- const logger = new TejLogger('Tejas CLI');
7
-
8
- let mongoose = undefined;
9
-
10
- const connect = async (uri, options, cb) => {
11
-
12
- try {
13
- mongoose = await import(pathToFileURL(packagePath));
14
-
15
- } catch (error) {
16
- if (error.code === 'ERR_MODULE_NOT_FOUND') {
17
- await installMongoose('npm install mongoose');
18
- mongoose = await import(pathToFileURL(packagePath));
19
-
20
- } else {
21
- cb(error);
22
- }
23
-
24
- } finally {
25
- mongoose.connect(uri, options).then(() => {
26
- cb(undefined);
27
- }).catch((error) => {
28
- cb(error);
29
- });
30
- }
31
- };
32
-
33
- function installMongoose(command) {
34
- return new Promise((resolve, reject) => {
35
- const spinner = ['|', '/', '-', '\\'];
36
- let current = 0;
37
-
38
- // Start the spinner
39
- const intervalId = setInterval(() => {
40
- process.stdout.write(`\r${spinner[current]} Installing mongoose...`);
41
- current = (current + 1) % spinner.length;
42
- }, 100);
43
-
44
- // Execute the command asynchronously to keep the spinner going
45
- const child = spawn(command, { shell: true });
46
- logger.info('Tejas will install mongoose to connect to mongodb...');
47
-
48
- child.stderr.on('data', (data) => {
49
- logger.error(`\n${data}`);
50
- });
51
-
52
- child.on('close', (code) => {
53
- process.stdout.write('\r');
54
- clearInterval(intervalId);
55
- if (code === 0) {
56
- // Remove stdout of Installing mongodb...
57
- logger.info('Mongoose installed successfully');
58
- resolve();
59
- } else {
60
- logger.error('Mongoose installation failed');
61
- reject();
62
- }
63
- });
64
- });
65
- }
66
-
67
- export default connect;
@@ -1,17 +0,0 @@
1
- import { Target, TejFileUploader } from 'te.js';
2
-
3
- const target = new Target('/user');
4
-
5
- const upload = new TejFileUploader({
6
- destination: 'public/uploads',
7
- maxFileSize: 5 * 1024 * 1024,
8
- });
9
-
10
- target.register(
11
- '/updateProfileImage',
12
- upload.file("image"),
13
- (ammo) => {
14
- console.log(ammo.payload);
15
- ammo.fire('Profile image updated successfully!')
16
- },
17
- );