qhttpx 1.8.12 → 1.9.1

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 (206) hide show
  1. package/package.json +26 -4
  2. package/prebuilds/darwin-arm64/qhttpx.node +0 -0
  3. package/prebuilds/linux-x64/qhttpx.node +0 -0
  4. package/prebuilds/win32-x64/qhttpx.node +0 -0
  5. package/src/native/index.ts +104 -24
  6. package/src/native/picohttpparser.h +5 -0
  7. package/src/native/server.cc +2 -0
  8. package/dist/examples/api-server.d.ts +0 -1
  9. package/dist/examples/api-server.js +0 -77
  10. package/dist/examples/basic.d.ts +0 -1
  11. package/dist/examples/basic.js +0 -10
  12. package/dist/examples/compression.d.ts +0 -1
  13. package/dist/examples/compression.js +0 -17
  14. package/dist/examples/cors.d.ts +0 -1
  15. package/dist/examples/cors.js +0 -19
  16. package/dist/examples/errors.d.ts +0 -1
  17. package/dist/examples/errors.js +0 -25
  18. package/dist/examples/file-upload.d.ts +0 -1
  19. package/dist/examples/file-upload.js +0 -24
  20. package/dist/examples/fusion.d.ts +0 -1
  21. package/dist/examples/fusion.js +0 -21
  22. package/dist/examples/rate-limiting.d.ts +0 -1
  23. package/dist/examples/rate-limiting.js +0 -17
  24. package/dist/examples/validation.d.ts +0 -1
  25. package/dist/examples/validation.js +0 -23
  26. package/dist/examples/websockets.d.ts +0 -1
  27. package/dist/examples/websockets.js +0 -20
  28. package/dist/package.json +0 -101
  29. package/dist/src/benchmarks/quantam-users.d.ts +0 -1
  30. package/dist/src/benchmarks/quantam-users.js +0 -56
  31. package/dist/src/benchmarks/simple-json.d.ts +0 -1
  32. package/dist/src/benchmarks/simple-json.js +0 -60
  33. package/dist/src/benchmarks/ultra-mode.d.ts +0 -1
  34. package/dist/src/benchmarks/ultra-mode.js +0 -94
  35. package/dist/src/cli/index.d.ts +0 -2
  36. package/dist/src/cli/index.js +0 -222
  37. package/dist/src/client/index.d.ts +0 -17
  38. package/dist/src/client/index.js +0 -72
  39. package/dist/src/core/batch.d.ts +0 -24
  40. package/dist/src/core/batch.js +0 -97
  41. package/dist/src/core/body-parser.d.ts +0 -15
  42. package/dist/src/core/body-parser.js +0 -121
  43. package/dist/src/core/buffer-pool.d.ts +0 -41
  44. package/dist/src/core/buffer-pool.js +0 -70
  45. package/dist/src/core/config.d.ts +0 -7
  46. package/dist/src/core/config.js +0 -50
  47. package/dist/src/core/errors.d.ts +0 -34
  48. package/dist/src/core/errors.js +0 -70
  49. package/dist/src/core/fusion.d.ts +0 -14
  50. package/dist/src/core/fusion.js +0 -183
  51. package/dist/src/core/logger.d.ts +0 -22
  52. package/dist/src/core/logger.js +0 -49
  53. package/dist/src/core/metrics.d.ts +0 -45
  54. package/dist/src/core/metrics.js +0 -111
  55. package/dist/src/core/native-adapter.d.ts +0 -11
  56. package/dist/src/core/native-adapter.js +0 -211
  57. package/dist/src/core/resources.d.ts +0 -9
  58. package/dist/src/core/resources.js +0 -25
  59. package/dist/src/core/scheduler.d.ts +0 -34
  60. package/dist/src/core/scheduler.js +0 -85
  61. package/dist/src/core/scope.d.ts +0 -26
  62. package/dist/src/core/scope.js +0 -68
  63. package/dist/src/core/serializer.d.ts +0 -10
  64. package/dist/src/core/serializer.js +0 -44
  65. package/dist/src/core/server.d.ts +0 -138
  66. package/dist/src/core/server.js +0 -1082
  67. package/dist/src/core/stream.d.ts +0 -15
  68. package/dist/src/core/stream.js +0 -71
  69. package/dist/src/core/tasks.d.ts +0 -29
  70. package/dist/src/core/tasks.js +0 -87
  71. package/dist/src/core/types.d.ts +0 -173
  72. package/dist/src/core/types.js +0 -19
  73. package/dist/src/core/websocket.d.ts +0 -25
  74. package/dist/src/core/websocket.js +0 -86
  75. package/dist/src/core/worker-queue.d.ts +0 -41
  76. package/dist/src/core/worker-queue.js +0 -73
  77. package/dist/src/database/adapters/memory.d.ts +0 -21
  78. package/dist/src/database/adapters/memory.js +0 -90
  79. package/dist/src/database/adapters/mongo.d.ts +0 -11
  80. package/dist/src/database/adapters/mongo.js +0 -141
  81. package/dist/src/database/adapters/postgres.d.ts +0 -10
  82. package/dist/src/database/adapters/postgres.js +0 -111
  83. package/dist/src/database/adapters/sqlite.d.ts +0 -10
  84. package/dist/src/database/adapters/sqlite.js +0 -42
  85. package/dist/src/database/coalescer.d.ts +0 -14
  86. package/dist/src/database/coalescer.js +0 -134
  87. package/dist/src/database/manager.d.ts +0 -35
  88. package/dist/src/database/manager.js +0 -87
  89. package/dist/src/database/types.d.ts +0 -20
  90. package/dist/src/database/types.js +0 -2
  91. package/dist/src/index.d.ts +0 -50
  92. package/dist/src/index.js +0 -91
  93. package/dist/src/middleware/compression.d.ts +0 -2
  94. package/dist/src/middleware/compression.js +0 -133
  95. package/dist/src/middleware/cors.d.ts +0 -2
  96. package/dist/src/middleware/cors.js +0 -66
  97. package/dist/src/middleware/presets.d.ts +0 -16
  98. package/dist/src/middleware/presets.js +0 -52
  99. package/dist/src/middleware/rate-limit.d.ts +0 -14
  100. package/dist/src/middleware/rate-limit.js +0 -83
  101. package/dist/src/middleware/security.d.ts +0 -21
  102. package/dist/src/middleware/security.js +0 -69
  103. package/dist/src/middleware/static.d.ts +0 -11
  104. package/dist/src/middleware/static.js +0 -191
  105. package/dist/src/native/index.d.ts +0 -29
  106. package/dist/src/native/index.js +0 -64
  107. package/dist/src/openapi/generator.d.ts +0 -19
  108. package/dist/src/openapi/generator.js +0 -149
  109. package/dist/src/router/radix-router.d.ts +0 -18
  110. package/dist/src/router/radix-router.js +0 -89
  111. package/dist/src/router/radix-tree.d.ts +0 -18
  112. package/dist/src/router/radix-tree.js +0 -131
  113. package/dist/src/router/router.d.ts +0 -34
  114. package/dist/src/router/router.js +0 -186
  115. package/dist/src/testing/index.d.ts +0 -25
  116. package/dist/src/testing/index.js +0 -84
  117. package/dist/src/utils/cookies.d.ts +0 -3
  118. package/dist/src/utils/cookies.js +0 -59
  119. package/dist/src/utils/logger.d.ts +0 -12
  120. package/dist/src/utils/logger.js +0 -45
  121. package/dist/src/utils/signals.d.ts +0 -6
  122. package/dist/src/utils/signals.js +0 -31
  123. package/dist/src/utils/sse.d.ts +0 -6
  124. package/dist/src/utils/sse.js +0 -32
  125. package/dist/src/validation/index.d.ts +0 -3
  126. package/dist/src/validation/index.js +0 -19
  127. package/dist/src/validation/simple.d.ts +0 -5
  128. package/dist/src/validation/simple.js +0 -102
  129. package/dist/src/validation/types.d.ts +0 -32
  130. package/dist/src/validation/types.js +0 -12
  131. package/dist/src/validation/zod.d.ts +0 -4
  132. package/dist/src/validation/zod.js +0 -18
  133. package/dist/src/views/index.d.ts +0 -1
  134. package/dist/src/views/index.js +0 -17
  135. package/dist/src/views/types.d.ts +0 -3
  136. package/dist/src/views/types.js +0 -2
  137. package/dist/tests/adapters.test.d.ts +0 -1
  138. package/dist/tests/adapters.test.js +0 -106
  139. package/dist/tests/batch.test.d.ts +0 -1
  140. package/dist/tests/batch.test.js +0 -117
  141. package/dist/tests/body-parser.test.d.ts +0 -1
  142. package/dist/tests/body-parser.test.js +0 -52
  143. package/dist/tests/compression-sse.test.d.ts +0 -1
  144. package/dist/tests/compression-sse.test.js +0 -87
  145. package/dist/tests/cookies.test.d.ts +0 -1
  146. package/dist/tests/cookies.test.js +0 -63
  147. package/dist/tests/cors.test.d.ts +0 -1
  148. package/dist/tests/cors.test.js +0 -55
  149. package/dist/tests/database.test.d.ts +0 -1
  150. package/dist/tests/database.test.js +0 -80
  151. package/dist/tests/dx.test.d.ts +0 -1
  152. package/dist/tests/dx.test.js +0 -114
  153. package/dist/tests/ecosystem.test.d.ts +0 -1
  154. package/dist/tests/ecosystem.test.js +0 -133
  155. package/dist/tests/features.test.d.ts +0 -1
  156. package/dist/tests/features.test.js +0 -47
  157. package/dist/tests/fusion.test.d.ts +0 -1
  158. package/dist/tests/fusion.test.js +0 -92
  159. package/dist/tests/http-basic.test.d.ts +0 -1
  160. package/dist/tests/http-basic.test.js +0 -124
  161. package/dist/tests/logger.test.d.ts +0 -1
  162. package/dist/tests/logger.test.js +0 -33
  163. package/dist/tests/middleware.test.d.ts +0 -1
  164. package/dist/tests/middleware.test.js +0 -109
  165. package/dist/tests/native-adapter.test.d.ts +0 -1
  166. package/dist/tests/native-adapter.test.js +0 -71
  167. package/dist/tests/observability.test.d.ts +0 -1
  168. package/dist/tests/observability.test.js +0 -59
  169. package/dist/tests/openapi.test.d.ts +0 -1
  170. package/dist/tests/openapi.test.js +0 -64
  171. package/dist/tests/plugin.test.d.ts +0 -1
  172. package/dist/tests/plugin.test.js +0 -65
  173. package/dist/tests/plugins.test.d.ts +0 -1
  174. package/dist/tests/plugins.test.js +0 -71
  175. package/dist/tests/rate-limit.test.d.ts +0 -1
  176. package/dist/tests/rate-limit.test.js +0 -77
  177. package/dist/tests/resources.test.d.ts +0 -1
  178. package/dist/tests/resources.test.js +0 -47
  179. package/dist/tests/scheduler.test.d.ts +0 -1
  180. package/dist/tests/scheduler.test.js +0 -46
  181. package/dist/tests/schema-routes.test.d.ts +0 -1
  182. package/dist/tests/schema-routes.test.js +0 -77
  183. package/dist/tests/security.test.d.ts +0 -1
  184. package/dist/tests/security.test.js +0 -83
  185. package/dist/tests/server-db.test.d.ts +0 -1
  186. package/dist/tests/server-db.test.js +0 -72
  187. package/dist/tests/smoke.test.d.ts +0 -1
  188. package/dist/tests/smoke.test.js +0 -10
  189. package/dist/tests/sqlite-fusion.test.d.ts +0 -1
  190. package/dist/tests/sqlite-fusion.test.js +0 -92
  191. package/dist/tests/static.test.d.ts +0 -1
  192. package/dist/tests/static.test.js +0 -102
  193. package/dist/tests/stream.test.d.ts +0 -1
  194. package/dist/tests/stream.test.js +0 -44
  195. package/dist/tests/task-metrics.test.d.ts +0 -1
  196. package/dist/tests/task-metrics.test.js +0 -53
  197. package/dist/tests/tasks.test.d.ts +0 -1
  198. package/dist/tests/tasks.test.js +0 -62
  199. package/dist/tests/testing.test.d.ts +0 -1
  200. package/dist/tests/testing.test.js +0 -47
  201. package/dist/tests/validation.test.d.ts +0 -1
  202. package/dist/tests/validation.test.js +0 -107
  203. package/dist/tests/websocket.test.d.ts +0 -1
  204. package/dist/tests/websocket.test.js +0 -146
  205. package/dist/vitest.config.d.ts +0 -2
  206. package/dist/vitest.config.js +0 -9
package/dist/package.json DELETED
@@ -1,101 +0,0 @@
1
- {
2
- "name": "qhttpx",
3
- "version": "1.8.12",
4
- "description": "The High-Performance Hybrid HTTP Runtime for Node.js. Built for extreme concurrency, request fusion, and zero-overhead scaling.",
5
- "main": "dist/src/index.js",
6
- "types": "dist/src/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/src/index.d.ts",
10
- "require": "./dist/src/index.js",
11
- "default": "./dist/src/index.js"
12
- }
13
- },
14
- "bin": {
15
- "qhttpx": "./dist/src/cli/index.js"
16
- },
17
- "files": [
18
- "dist",
19
- "src/native",
20
- "binding.gyp",
21
- "README.md",
22
- "LICENSE",
23
- "CHANGELOG.md",
24
- "docs"
25
- ],
26
- "directories": {
27
- "doc": "docs"
28
- },
29
- "scripts": {
30
- "build": "tsc -p tsconfig.json",
31
- "lint": "eslint src tests --ext .ts",
32
- "test": "vitest run",
33
- "example": "npx tsx examples/api-server.ts",
34
- "bench": "npm run build && node dist/src/benchmarks/simple-json.js",
35
- "bench:quantam": "npm run build && node dist/src/benchmarks/quantam-users.js",
36
- "bench:ultra": "npm run build && node dist/src/benchmarks/ultra-mode.js"
37
- },
38
- "keywords": [
39
- "http",
40
- "server",
41
- "web",
42
- "framework",
43
- "typescript",
44
- "fast",
45
- "performance",
46
- "high-performance",
47
- "async",
48
- "concurrency",
49
- "request-fusion",
50
- "coalescing",
51
- "middleware",
52
- "websocket",
53
- "sse",
54
- "rate-limit",
55
- "rest",
56
- "api",
57
- "json",
58
- "router",
59
- "radix-tree",
60
- "scheduler",
61
- "ultra-fast",
62
- "nodejs"
63
- ],
64
- "author": "Quantam Open Source",
65
- "license": "MIT",
66
- "type": "commonjs",
67
- "devDependencies": {
68
- "@types/autocannon": "^7.12.7",
69
- "@types/better-sqlite3": "^7.6.13",
70
- "@types/busboy": "^1.5.4",
71
- "@types/ioredis": "^4.28.10",
72
- "@types/mongodb": "^4.0.6",
73
- "@types/node": "^25.0.9",
74
- "@types/pg": "^8.16.0",
75
- "@types/ws": "^8.18.1",
76
- "@typescript-eslint/eslint-plugin": "^8.53.0",
77
- "@typescript-eslint/parser": "^8.53.0",
78
- "autocannon": "^8.0.0",
79
- "dotenv": "^17.2.3",
80
- "eslint": "^9.39.2",
81
- "eslint-config-prettier": "^10.1.8",
82
- "eslint-plugin-prettier": "^5.5.5",
83
- "mongodb": "^7.0.0",
84
- "pg": "^8.17.1",
85
- "prettier": "^3.8.0",
86
- "tsx": "^4.21.0",
87
- "typescript": "^5.9.3",
88
- "vitest": "^4.0.17"
89
- },
90
- "dependencies": {
91
- "better-sqlite3": "^12.6.2",
92
- "busboy": "^1.6.0",
93
- "fast-json-stringify": "^5.15.1",
94
- "node-addon-api": "^8.5.0",
95
- "pino": "^10.2.0",
96
- "pino-pretty": "^13.1.3",
97
- "quantam-async": "^0.1.1",
98
- "ws": "^8.19.0",
99
- "zod": "^4.3.5"
100
- }
101
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const quantam_async_1 = require("quantam-async");
4
- const index_1 = require("../index");
5
- async function run() {
6
- const app = new index_1.QHTTPX({
7
- maxConcurrency: 512,
8
- requestTimeoutMs: 10000,
9
- });
10
- app.get('/json', (ctx) => {
11
- ctx.json({ message: 'hello from qhttpx' });
12
- });
13
- const { port } = await app.listen(0, '127.0.0.1');
14
- const url = `http://127.0.0.1:${port}/json`;
15
- const requestsPerUser = 10;
16
- const userCount = 10000;
17
- const maxConcurrentUsers = 1000;
18
- const flow = (0, quantam_async_1.quantam)()
19
- .name('user-flow')
20
- .step(async (userId) => {
21
- for (let i = 0; i < requestsPerUser; i += 1) {
22
- const response = await fetch(url);
23
- if (!response.ok) {
24
- throw new Error(`user ${userId} request ${i} failed with status ${response.status}`);
25
- }
26
- await response.text();
27
- }
28
- return userId;
29
- })
30
- .retry(3, 50)
31
- .timeout(30000);
32
- const inputs = [];
33
- for (let i = 0; i < userCount; i += 1) {
34
- inputs.push(i);
35
- }
36
- const start = Date.now();
37
- try {
38
- await flow.runMany(inputs, {
39
- concurrency: maxConcurrentUsers,
40
- });
41
- }
42
- catch (err) {
43
- console.error('Quantam runMany error', err);
44
- }
45
- const durationSec = (Date.now() - start) / 1000;
46
- const totalRequests = userCount * requestsPerUser;
47
- const rps = totalRequests / durationSec;
48
- console.log(`Quantam bench: users=${userCount}, requestsPerUser=${requestsPerUser}, ` +
49
- `totalRequests=${totalRequests}, duration=${durationSec.toFixed(2)}s, rps=${rps.toFixed(0)}, concurrency=${maxConcurrentUsers}`);
50
- await app.close();
51
- process.exit(0);
52
- }
53
- run().catch((err) => {
54
- console.error(err);
55
- process.exit(1);
56
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,60 +0,0 @@
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
- const autocannon_1 = __importDefault(require("autocannon"));
7
- const index_1 = require("../index");
8
- function runAutocannon(url) {
9
- return new Promise((resolve, reject) => {
10
- const instance = (0, autocannon_1.default)({
11
- url,
12
- connections: 100,
13
- pipelining: 10,
14
- duration: 40,
15
- }, (err, result) => {
16
- if (err) {
17
- reject(err);
18
- return;
19
- }
20
- resolve(result);
21
- });
22
- instance.on('error', (err) => {
23
- reject(err);
24
- });
25
- });
26
- }
27
- async function run() {
28
- const payloadBuffer = Buffer.from(JSON.stringify({ message: 'hello from qhttpx' }));
29
- const app = new index_1.QHTTPX({
30
- maxConcurrency: 512,
31
- metricsEnabled: false,
32
- jsonSerializer: () => payloadBuffer,
33
- });
34
- app.get('/json', (ctx) => {
35
- ctx.json({ message: 'hello from qhttpx' });
36
- });
37
- const { port } = await app.listen(0, '127.0.0.1');
38
- const url = `http://127.0.0.1:${port}/json`;
39
- console.log('Running warmup (1/2)...');
40
- await runAutocannon(url);
41
- console.log('Running benchmark (2/2)...');
42
- const result = await runAutocannon(url);
43
- autocannon_1.default.printResult(result);
44
- const totalRequests = result.requests.total;
45
- const sent = result.requests.sent;
46
- const avgRps = result.requests.average.toFixed(0);
47
- const p99 = result.latency.p99.toFixed(1);
48
- const connections = result.connections;
49
- const pipelining = result.pipelining;
50
- // Summary line that shows up clearly in CI/dev logs
51
- console.log(`QHTTPX bench: total=${totalRequests} (sent=${sent}) req, ` +
52
- `${avgRps} req/sec, p99=${p99}ms, connections=${connections}, ` +
53
- `pipelining=${pipelining}`);
54
- await app.close();
55
- process.exit(0);
56
- }
57
- run().catch((err) => {
58
- console.error(err);
59
- process.exit(1);
60
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,94 +0,0 @@
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
- const autocannon_1 = __importDefault(require("autocannon"));
7
- const index_1 = require("../index");
8
- async function runAutocannon(name, url) {
9
- const result = await (0, autocannon_1.default)({
10
- url,
11
- connections: 200,
12
- pipelining: 10,
13
- duration: 10,
14
- });
15
- const total = result.requests.total;
16
- const sent = result.requests.sent;
17
- const rps = result.requests.average;
18
- const p99 = result.latency.p99;
19
- console.log(`${name} bench: total=${total} (sent=${sent}) req, ` +
20
- `${rps.toFixed(0)} req/sec, p99=${p99.toFixed(1)}ms, connections=${result.connections}, pipelining=${result.pipelining}`);
21
- return {
22
- name,
23
- total,
24
- sent,
25
- rps,
26
- p99,
27
- };
28
- }
29
- async function startQHTTPXBalanced() {
30
- const payloadBuffer = Buffer.from(JSON.stringify({ message: 'hello from qhttpx' }));
31
- const app = new index_1.QHTTPX({
32
- maxConcurrency: 1024,
33
- metricsEnabled: false,
34
- performanceMode: 'balanced',
35
- jsonSerializer: () => payloadBuffer,
36
- });
37
- app.get('/json', (ctx) => {
38
- ctx.json({ message: 'hello from qhttpx' });
39
- });
40
- const { port } = await app.listen(0, '127.0.0.1');
41
- const url = `http://127.0.0.1:${port}/json`;
42
- return { app, url };
43
- }
44
- async function startQHTTPXUltra() {
45
- const payloadBuffer = Buffer.from(JSON.stringify({ message: 'hello from qhttpx ultra' }));
46
- const app = new index_1.QHTTPX({
47
- maxConcurrency: 1024,
48
- performanceMode: 'ultra',
49
- jsonSerializer: () => payloadBuffer,
50
- });
51
- app.get('/json', (ctx) => {
52
- ctx.json({ message: 'hello from qhttpx ultra' });
53
- });
54
- const { port } = await app.listen(0, '127.0.0.1');
55
- const url = `http://127.0.0.1:${port}/json`;
56
- return { app, url };
57
- }
58
- async function run() {
59
- const results = [];
60
- console.log('=== QHTTPX Balanced Mode ===');
61
- const balanced = await startQHTTPXBalanced();
62
- try {
63
- const r = await runAutocannon('QHTTPX-Balanced', balanced.url);
64
- results.push(r);
65
- }
66
- finally {
67
- await balanced.app.close();
68
- }
69
- console.log('\n=== QHTTPX Ultra Mode ===');
70
- const ultra = await startQHTTPXUltra();
71
- try {
72
- const r = await runAutocannon('QHTTPX-Ultra', ultra.url);
73
- results.push(r);
74
- }
75
- finally {
76
- await ultra.app.close();
77
- }
78
- console.log('\n=== Summary ===');
79
- for (const r of results) {
80
- console.log(`${r.name}: ${r.rps.toFixed(0)} req/sec, p99=${r.p99.toFixed(1)}ms, total=${r.total}`);
81
- }
82
- // Calculate improvement
83
- const balanced_rps = results[0]?.rps || 0;
84
- const ultra_rps = results[1]?.rps || 0;
85
- if (ultra_rps > 0 && balanced_rps > 0) {
86
- const improvement = ((ultra_rps - balanced_rps) / balanced_rps * 100).toFixed(1);
87
- console.log(`\nUltra vs Balanced improvement: ${improvement}%`);
88
- }
89
- process.exit(0);
90
- }
91
- run().catch((err) => {
92
- console.error(err);
93
- process.exit(1);
94
- });
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,222 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const child_process_1 = require("child_process");
8
- const cluster_1 = __importDefault(require("cluster"));
9
- const os_1 = __importDefault(require("os"));
10
- const path_1 = __importDefault(require("path"));
11
- const fs_1 = __importDefault(require("fs"));
12
- const args = process.argv.slice(2);
13
- const command = args[0];
14
- if (!command) {
15
- printHelp();
16
- process.exit(1);
17
- }
18
- const targetFile = args[1];
19
- if (command === 'start') {
20
- if (!targetFile) {
21
- console.error('Error: Please provide an entry file (e.g., qhttpx start dist/index.js)');
22
- process.exit(1);
23
- }
24
- runStart(targetFile);
25
- }
26
- else if (command === 'dev') {
27
- if (!targetFile) {
28
- console.error('Error: Please provide an entry file (e.g., qhttpx dev src/index.ts)');
29
- process.exit(1);
30
- }
31
- runDev(targetFile);
32
- }
33
- else if (command === 'new') {
34
- if (!targetFile) {
35
- console.error('Error: Please provide a project name (e.g., qhttpx new my-app)');
36
- process.exit(1);
37
- }
38
- runNew(targetFile);
39
- }
40
- else {
41
- console.error(`Unknown command: ${command}`);
42
- printHelp();
43
- process.exit(1);
44
- }
45
- function printHelp() {
46
- console.log('Usage: qhttpx <command> [options]');
47
- console.log('Commands:');
48
- console.log(' start <file> Run in production cluster mode (Node.js)');
49
- console.log(' dev <file> Run in development mode with hot reload (tsx)');
50
- console.log(' new <name> Create a new QHTTPX project');
51
- }
52
- function runStart(entry) {
53
- const absoluteEntry = path_1.default.resolve(process.cwd(), entry);
54
- if (cluster_1.default.isPrimary) {
55
- const numCPUs = os_1.default.cpus().length;
56
- console.log(`[QCLI] 🚀 Starting Cluster Mode`);
57
- console.log(`[QCLI] 📂 Entry: ${absoluteEntry}`);
58
- console.log(`[QCLI] 💻 Workers: ${numCPUs}`);
59
- for (let i = 0; i < numCPUs; i++) {
60
- cluster_1.default.fork();
61
- }
62
- cluster_1.default.on('exit', (worker) => {
63
- console.log(`[QCLI] 💀 Worker ${worker.process.pid} died. Restarting...`);
64
- cluster_1.default.fork();
65
- });
66
- }
67
- else {
68
- try {
69
- // eslint-disable-next-line @typescript-eslint/no-require-imports
70
- require(absoluteEntry);
71
- }
72
- catch (err) {
73
- console.error(`[QCLI] Failed to load entry file: ${absoluteEntry}`);
74
- console.error(err);
75
- process.exit(1);
76
- }
77
- }
78
- }
79
- function runDev(entry) {
80
- const absoluteEntry = path_1.default.resolve(process.cwd(), entry);
81
- console.log(`[QCLI] 🛠️ Starting Dev Mode`);
82
- console.log(`[QCLI] 📂 Entry: ${absoluteEntry}`);
83
- let child = null;
84
- const startChild = () => {
85
- // Use tsx for dev execution
86
- child = (0, child_process_1.spawn)('npx', ['tsx', absoluteEntry], {
87
- stdio: 'inherit',
88
- shell: true,
89
- cwd: process.cwd()
90
- });
91
- child.on('close', (code) => {
92
- if (code !== 0 && code !== null) {
93
- console.log(`[QCLI] App crashed (code ${code}). Waiting for changes...`);
94
- }
95
- });
96
- };
97
- const restartChild = () => {
98
- if (child) {
99
- console.log('[QCLI] 🔄 File changed. Restarting...');
100
- // On Windows, killing a shell-spawned process is tricky.
101
- // But 'child.kill()' usually works for the handle.
102
- // For deeper tree killing, we might need a library, but let's try standard kill.
103
- child.kill();
104
- child = null;
105
- }
106
- startChild();
107
- };
108
- startChild();
109
- // Watcher
110
- let debounceTimer;
111
- const watchDir = path_1.default.dirname(absoluteEntry); // Watch the directory of the entry file (usually src)
112
- console.log(`[QCLI] 👀 Watching: ${watchDir}`);
113
- // Recursive watch is platform dependent, but 'recursive: true' works on Windows/macOS
114
- try {
115
- fs_1.default.watch(watchDir, { recursive: true }, (eventType, filename) => {
116
- if (!filename)
117
- return;
118
- // Ignore node_modules and .git
119
- if (filename.includes('node_modules') || filename.includes('.git'))
120
- return;
121
- clearTimeout(debounceTimer);
122
- debounceTimer = setTimeout(() => {
123
- restartChild();
124
- }, 200); // 200ms debounce
125
- });
126
- }
127
- catch {
128
- console.warn('[QCLI] Recursive watch not supported or failed. Falling back to simple watch.');
129
- // Fallback or just fail gracefully
130
- }
131
- }
132
- function runNew(projectName) {
133
- const projectDir = path_1.default.resolve(process.cwd(), projectName);
134
- if (fs_1.default.existsSync(projectDir)) {
135
- console.error(`Error: Directory ${projectName} already exists.`);
136
- process.exit(1);
137
- }
138
- console.log(`[QCLI] ✨ Creating new QHTTPX project in ${projectName}...`);
139
- fs_1.default.mkdirSync(projectDir);
140
- fs_1.default.mkdirSync(path_1.default.join(projectDir, 'src'));
141
- // package.json
142
- const pkgJson = {
143
- name: projectName,
144
- version: '0.0.1',
145
- type: 'module',
146
- scripts: {
147
- dev: 'qhttpx dev src/index.ts',
148
- start: 'qhttpx start dist/index.js',
149
- build: 'tsc'
150
- },
151
- dependencies: {
152
- 'qhttpx': '^1.8.6',
153
- 'dotenv': '^16.4.1'
154
- },
155
- devDependencies: {
156
- 'typescript': '^5.3.3',
157
- '@types/node': '^20.11.16',
158
- 'tsx': '^4.7.0'
159
- }
160
- };
161
- fs_1.default.writeFileSync(path_1.default.join(projectDir, 'package.json'), JSON.stringify(pkgJson, null, 2));
162
- // tsconfig.json
163
- const tsConfig = {
164
- compilerOptions: {
165
- target: 'ES2022',
166
- module: 'Node16',
167
- moduleResolution: 'Node16',
168
- rootDir: 'src',
169
- outDir: 'dist',
170
- strict: true,
171
- esModuleInterop: true,
172
- skipLibCheck: true,
173
- forceConsistentCasingInFileNames: true
174
- },
175
- include: ['src']
176
- };
177
- fs_1.default.writeFileSync(path_1.default.join(projectDir, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2));
178
- // src/index.ts
179
- const indexTs = `import { createHttpApp } from 'qhttpx';
180
- import 'dotenv/config';
181
-
182
- const app = createHttpApp({
183
- // ⚡ Performance: Auto-coalesce duplicate requests
184
- enableRequestFusion: true,
185
-
186
- // 🛡️ Security: Built-in CORS & Rate Limiting
187
- cors: true,
188
- rateLimit: {
189
- windowMs: 15 * 60 * 1000, // 15 min
190
- max: 100, // 100 reqs per IP
191
- trustProxy: true
192
- },
193
-
194
- // 🗜️ Optimization: Gzip/Brotli compression
195
- compression: true
196
- });
197
-
198
- app.get('/', ({ json }) => {
199
- json({
200
- message: 'Welcome to QHTTPX 🚀',
201
- status: 'online',
202
- timestamp: Date.now()
203
- });
204
- });
205
-
206
- app.listen(Number(process.env.PORT) || 3000, () => {
207
- console.log(\`Server running on http://localhost:\${process.env.PORT || 3000}\`);
208
- });
209
- `;
210
- fs_1.default.writeFileSync(path_1.default.join(projectDir, 'src', 'index.ts'), indexTs);
211
- // .gitignore
212
- const gitignore = `node_modules
213
- dist
214
- .env
215
- `;
216
- fs_1.default.writeFileSync(path_1.default.join(projectDir, '.gitignore'), gitignore);
217
- console.log(`[QCLI] ✅ Project created successfully!`);
218
- console.log(`\nNext steps:`);
219
- console.log(` cd ${projectName}`);
220
- console.log(` npm install`);
221
- console.log(` npm run dev`);
222
- }
@@ -1,17 +0,0 @@
1
- export type InferRequestType<T> = T extends {
2
- request: infer R;
3
- } ? R : never;
4
- export type InferResponseType<T> = T extends {
5
- response: infer R;
6
- } ? R : never;
7
- export declare function hc<T extends Record<string, any>>(baseUrl: string, options?: RequestInit): Client<T>;
8
- type Client<T> = {
9
- [K in keyof T]: T[K] extends Function ? never : Client<T[K]>;
10
- } & {
11
- $get: (args?: any) => Promise<any>;
12
- $post: (args?: any) => Promise<any>;
13
- $put: (args?: any) => Promise<any>;
14
- $delete: (args?: any) => Promise<any>;
15
- $patch: (args?: any) => Promise<any>;
16
- };
17
- export {};
@@ -1,72 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
- /* eslint-disable @typescript-eslint/no-unsafe-function-type */
4
- // RPC Client for QHTTPX
5
- // Allows end-to-end type safety similar to Hono's 'hc' or Elysia's 'eden'
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.hc = hc;
8
- // Proxy-based client generator
9
- function hc(baseUrl, options = {}) {
10
- const handler = {
11
- get(target, prop, receiver) {
12
- if (typeof prop !== 'string')
13
- return Reflect.get(target, prop, receiver);
14
- // If it's a method call like .$get()
15
- if (prop.startsWith('$')) {
16
- const method = prop.slice(1).toUpperCase();
17
- return async (args = {}) => {
18
- let url = baseUrl;
19
- const path = target.__path || '';
20
- // Replace params in path :id
21
- let finalPath = path;
22
- if (args.param) {
23
- Object.entries(args.param).forEach(([key, value]) => {
24
- finalPath = finalPath.replace(`:${key}`, String(value));
25
- });
26
- }
27
- url += finalPath;
28
- // Append query params
29
- if (args.query) {
30
- const searchParams = new URLSearchParams();
31
- Object.entries(args.query).forEach(([key, value]) => {
32
- searchParams.append(key, String(value));
33
- });
34
- url += `?${searchParams.toString()}`;
35
- }
36
- const fetchOptions = {
37
- ...options,
38
- method,
39
- headers: {
40
- ...options.headers,
41
- ...(args.header || {}),
42
- ...(args.json ? { 'Content-Type': 'application/json' } : {}),
43
- },
44
- };
45
- if (args.json) {
46
- fetchOptions.body = JSON.stringify(args.json);
47
- }
48
- else if (args.form) {
49
- // Handle FormData
50
- fetchOptions.body = args.form;
51
- }
52
- const res = await fetch(url, fetchOptions);
53
- // Return a wrapper that allows typed access
54
- return {
55
- ok: res.ok,
56
- status: res.status,
57
- statusText: res.statusText,
58
- headers: res.headers,
59
- json: () => res.json(),
60
- text: () => res.text(),
61
- blob: () => res.blob(),
62
- };
63
- };
64
- }
65
- // It's a path segment
66
- const newPath = (target.__path || '') + '/' + prop;
67
- const proxy = new Proxy({ __path: newPath }, handler);
68
- return proxy;
69
- }
70
- };
71
- return new Proxy({ __path: '' }, handler);
72
- }
@@ -1,24 +0,0 @@
1
- import { QHTTPXContext, QHTTPXOpHandler } from './types';
2
- import { DatabaseManager } from '../database/manager';
3
- export declare class BatchExecutor {
4
- private ops;
5
- private dbManager?;
6
- private coalescers;
7
- constructor(dbManager?: DatabaseManager);
8
- register(name: string, handler: QHTTPXOpHandler): void;
9
- handleBatch(ctx: QHTTPXContext, batch: Array<{
10
- op: string;
11
- params: unknown;
12
- id?: unknown;
13
- }>): Promise<{
14
- results: ({
15
- error: string;
16
- id: unknown;
17
- result?: undefined;
18
- } | {
19
- result: any;
20
- id: unknown;
21
- error?: undefined;
22
- })[];
23
- }>;
24
- }