qhttpx 2.1.0 → 2.3.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.
- package/LICENSE +201 -21
- package/README.md +117 -221
- package/dist/chunk-QW72SEAS.mjs +98 -0
- package/dist/{src/cli/index.d.ts → cli.d.mts} +0 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +287 -0
- package/dist/cli.mjs +209 -0
- package/dist/index.d.mts +433 -0
- package/dist/index.d.ts +433 -0
- package/dist/index.js +1955 -0
- package/dist/index.mjs +1863 -0
- package/dist/qhttpx-core-new.linux-x64-gnu.node +0 -0
- package/dist/qhttpx-core-new.node +0 -0
- package/dist/qhttpx-core-new.win32-x64-msvc.node +0 -0
- package/examples/benchmark.ts +67 -0
- package/examples/body_demo.ts +32 -0
- package/examples/chat_client.ts +36 -0
- package/examples/chat_demo.ts +41 -0
- package/examples/cluster_demo.ts +26 -0
- package/examples/cors_demo.ts +25 -0
- package/examples/db_auth_demo.ts +66 -0
- package/examples/demo.ts +52 -0
- package/examples/headers_demo.ts +24 -0
- package/examples/hello.ts +7 -0
- package/examples/http2_demo.ts +52 -0
- package/examples/magic-dev.ts +15 -0
- package/examples/middleware_demo.ts +34 -0
- package/examples/mongo_demo.ts +40 -0
- package/examples/native_policy_demo.ts +33 -0
- package/examples/observability_demo.ts +24 -0
- package/examples/public/1mb.dat +1 -0
- package/examples/query_demo.ts +29 -0
- package/examples/response_demo.ts +21 -0
- package/examples/routing_demo.ts +24 -0
- package/examples/server.ts +51 -0
- package/examples/static_demo.ts +29 -0
- package/examples/test_middleware_client.ts +33 -0
- package/examples/test_query_client.ts +34 -0
- package/examples/test_response_client.ts +30 -0
- package/examples/tls_demo.ts +32 -0
- package/examples/upload_demo.ts +43 -0
- package/examples/uploads/test.txt +1 -0
- package/examples/verify_upload.ts +69 -0
- package/examples/ws_client.ts +26 -0
- package/examples/ws_demo.ts +21 -0
- package/package.json +65 -81
- package/CHANGELOG.md +0 -285
- package/dist/examples/api-server.d.ts +0 -1
- package/dist/examples/api-server.js +0 -80
- package/dist/examples/basic.d.ts +0 -1
- package/dist/examples/basic.js +0 -9
- package/dist/examples/compression.d.ts +0 -1
- package/dist/examples/compression.js +0 -15
- package/dist/examples/cors.d.ts +0 -1
- package/dist/examples/cors.js +0 -18
- package/dist/examples/errors.d.ts +0 -1
- package/dist/examples/errors.js +0 -26
- package/dist/examples/file-upload.d.ts +0 -1
- package/dist/examples/file-upload.js +0 -22
- package/dist/examples/fusion.d.ts +0 -1
- package/dist/examples/fusion.js +0 -21
- package/dist/examples/rate-limiting.d.ts +0 -1
- package/dist/examples/rate-limiting.js +0 -17
- package/dist/examples/validation.d.ts +0 -1
- package/dist/examples/validation.js +0 -22
- package/dist/examples/websockets.d.ts +0 -1
- package/dist/examples/websockets.js +0 -19
- package/dist/package.json +0 -107
- package/dist/src/benchmarks/quantam-users.d.ts +0 -1
- package/dist/src/benchmarks/quantam-users.js +0 -56
- package/dist/src/benchmarks/quick-bench.d.ts +0 -1
- package/dist/src/benchmarks/quick-bench.js +0 -57
- package/dist/src/benchmarks/simple-json.d.ts +0 -1
- package/dist/src/benchmarks/simple-json.js +0 -171
- package/dist/src/benchmarks/ultra-mode.d.ts +0 -1
- package/dist/src/benchmarks/ultra-mode.js +0 -64
- package/dist/src/cli/index.js +0 -222
- package/dist/src/client/index.d.ts +0 -17
- package/dist/src/client/index.js +0 -72
- package/dist/src/core/batch.d.ts +0 -24
- package/dist/src/core/batch.js +0 -97
- package/dist/src/core/body-parser.d.ts +0 -15
- package/dist/src/core/body-parser.js +0 -121
- package/dist/src/core/buffer-pool.d.ts +0 -41
- package/dist/src/core/buffer-pool.js +0 -70
- package/dist/src/core/config.d.ts +0 -7
- package/dist/src/core/config.js +0 -50
- package/dist/src/core/context-pool.d.ts +0 -12
- package/dist/src/core/context-pool.js +0 -34
- package/dist/src/core/errors.d.ts +0 -34
- package/dist/src/core/errors.js +0 -70
- package/dist/src/core/fusion.d.ts +0 -20
- package/dist/src/core/fusion.js +0 -191
- package/dist/src/core/logger.d.ts +0 -22
- package/dist/src/core/logger.js +0 -49
- package/dist/src/core/metrics.d.ts +0 -50
- package/dist/src/core/metrics.js +0 -123
- package/dist/src/core/resources.d.ts +0 -9
- package/dist/src/core/resources.js +0 -25
- package/dist/src/core/scheduler.d.ts +0 -38
- package/dist/src/core/scheduler.js +0 -126
- package/dist/src/core/scope.d.ts +0 -41
- package/dist/src/core/scope.js +0 -107
- package/dist/src/core/serializer.d.ts +0 -10
- package/dist/src/core/serializer.js +0 -82
- package/dist/src/core/server.d.ts +0 -179
- package/dist/src/core/server.js +0 -1511
- package/dist/src/core/stream.d.ts +0 -15
- package/dist/src/core/stream.js +0 -71
- package/dist/src/core/tasks.d.ts +0 -29
- package/dist/src/core/tasks.js +0 -87
- package/dist/src/core/timer.d.ts +0 -11
- package/dist/src/core/timer.js +0 -29
- package/dist/src/core/types.d.ts +0 -225
- package/dist/src/core/types.js +0 -19
- package/dist/src/core/websocket.d.ts +0 -25
- package/dist/src/core/websocket.js +0 -86
- package/dist/src/core/worker-queue.d.ts +0 -41
- package/dist/src/core/worker-queue.js +0 -73
- package/dist/src/database/adapters/memory.d.ts +0 -21
- package/dist/src/database/adapters/memory.js +0 -90
- package/dist/src/database/adapters/mongo.d.ts +0 -11
- package/dist/src/database/adapters/mongo.js +0 -141
- package/dist/src/database/adapters/postgres.d.ts +0 -10
- package/dist/src/database/adapters/postgres.js +0 -111
- package/dist/src/database/adapters/sqlite.d.ts +0 -10
- package/dist/src/database/adapters/sqlite.js +0 -42
- package/dist/src/database/coalescer.d.ts +0 -14
- package/dist/src/database/coalescer.js +0 -134
- package/dist/src/database/manager.d.ts +0 -35
- package/dist/src/database/manager.js +0 -87
- package/dist/src/database/types.d.ts +0 -20
- package/dist/src/database/types.js +0 -2
- package/dist/src/index.d.ts +0 -52
- package/dist/src/index.js +0 -92
- package/dist/src/middleware/compression.d.ts +0 -2
- package/dist/src/middleware/compression.js +0 -133
- package/dist/src/middleware/cors.d.ts +0 -2
- package/dist/src/middleware/cors.js +0 -66
- package/dist/src/middleware/presets.d.ts +0 -15
- package/dist/src/middleware/presets.js +0 -52
- package/dist/src/middleware/rate-limit.d.ts +0 -14
- package/dist/src/middleware/rate-limit.js +0 -83
- package/dist/src/middleware/security.d.ts +0 -10
- package/dist/src/middleware/security.js +0 -74
- package/dist/src/middleware/static.d.ts +0 -11
- package/dist/src/middleware/static.js +0 -191
- package/dist/src/openapi/generator.d.ts +0 -19
- package/dist/src/openapi/generator.js +0 -149
- package/dist/src/router/radix-router.d.ts +0 -18
- package/dist/src/router/radix-router.js +0 -89
- package/dist/src/router/radix-tree.d.ts +0 -21
- package/dist/src/router/radix-tree.js +0 -175
- package/dist/src/router/router.d.ts +0 -37
- package/dist/src/router/router.js +0 -203
- package/dist/src/testing/index.d.ts +0 -25
- package/dist/src/testing/index.js +0 -84
- package/dist/src/utils/cookies.d.ts +0 -3
- package/dist/src/utils/cookies.js +0 -59
- package/dist/src/utils/logger.d.ts +0 -2
- package/dist/src/utils/logger.js +0 -45
- package/dist/src/utils/signals.d.ts +0 -6
- package/dist/src/utils/signals.js +0 -31
- package/dist/src/utils/sse.d.ts +0 -6
- package/dist/src/utils/sse.js +0 -32
- package/dist/src/validation/index.d.ts +0 -3
- package/dist/src/validation/index.js +0 -19
- package/dist/src/validation/simple.d.ts +0 -5
- package/dist/src/validation/simple.js +0 -102
- package/dist/src/validation/types.d.ts +0 -32
- package/dist/src/validation/types.js +0 -12
- package/dist/src/validation/zod.d.ts +0 -4
- package/dist/src/validation/zod.js +0 -18
- package/dist/src/views/index.d.ts +0 -1
- package/dist/src/views/index.js +0 -17
- package/dist/src/views/types.d.ts +0 -3
- package/dist/src/views/types.js +0 -2
- package/dist/tests/adapters.test.d.ts +0 -1
- package/dist/tests/adapters.test.js +0 -106
- package/dist/tests/batch.test.d.ts +0 -1
- package/dist/tests/batch.test.js +0 -117
- package/dist/tests/body-parser.test.d.ts +0 -1
- package/dist/tests/body-parser.test.js +0 -52
- package/dist/tests/compression-sse.test.d.ts +0 -1
- package/dist/tests/compression-sse.test.js +0 -87
- package/dist/tests/cookies.test.d.ts +0 -1
- package/dist/tests/cookies.test.js +0 -63
- package/dist/tests/cors.test.d.ts +0 -1
- package/dist/tests/cors.test.js +0 -55
- package/dist/tests/database.test.d.ts +0 -1
- package/dist/tests/database.test.js +0 -80
- package/dist/tests/dx.test.d.ts +0 -1
- package/dist/tests/dx.test.js +0 -114
- package/dist/tests/ecosystem.test.d.ts +0 -1
- package/dist/tests/ecosystem.test.js +0 -133
- package/dist/tests/features.test.d.ts +0 -1
- package/dist/tests/features.test.js +0 -47
- package/dist/tests/fusion.test.d.ts +0 -1
- package/dist/tests/fusion.test.js +0 -92
- package/dist/tests/http-basic.test.d.ts +0 -1
- package/dist/tests/http-basic.test.js +0 -124
- package/dist/tests/logger.test.d.ts +0 -1
- package/dist/tests/logger.test.js +0 -33
- package/dist/tests/middleware.test.d.ts +0 -1
- package/dist/tests/middleware.test.js +0 -109
- package/dist/tests/observability.test.d.ts +0 -1
- package/dist/tests/observability.test.js +0 -59
- package/dist/tests/openapi.test.d.ts +0 -1
- package/dist/tests/openapi.test.js +0 -64
- package/dist/tests/plugin.test.d.ts +0 -1
- package/dist/tests/plugin.test.js +0 -65
- package/dist/tests/plugins.test.d.ts +0 -1
- package/dist/tests/plugins.test.js +0 -71
- package/dist/tests/rate-limit.test.d.ts +0 -1
- package/dist/tests/rate-limit.test.js +0 -77
- package/dist/tests/resources.test.d.ts +0 -1
- package/dist/tests/resources.test.js +0 -47
- package/dist/tests/scheduler.test.d.ts +0 -1
- package/dist/tests/scheduler.test.js +0 -46
- package/dist/tests/schema-routes.test.d.ts +0 -1
- package/dist/tests/schema-routes.test.js +0 -79
- package/dist/tests/security.test.d.ts +0 -1
- package/dist/tests/security.test.js +0 -83
- package/dist/tests/server-db.test.d.ts +0 -1
- package/dist/tests/server-db.test.js +0 -72
- package/dist/tests/smoke.test.d.ts +0 -1
- package/dist/tests/smoke.test.js +0 -10
- package/dist/tests/sqlite-fusion.test.d.ts +0 -1
- package/dist/tests/sqlite-fusion.test.js +0 -92
- package/dist/tests/static.test.d.ts +0 -1
- package/dist/tests/static.test.js +0 -102
- package/dist/tests/stream.test.d.ts +0 -1
- package/dist/tests/stream.test.js +0 -44
- package/dist/tests/task-metrics.test.d.ts +0 -1
- package/dist/tests/task-metrics.test.js +0 -53
- package/dist/tests/tasks.test.d.ts +0 -1
- package/dist/tests/tasks.test.js +0 -62
- package/dist/tests/testing.test.d.ts +0 -1
- package/dist/tests/testing.test.js +0 -47
- package/dist/tests/validation.test.d.ts +0 -1
- package/dist/tests/validation.test.js +0 -107
- package/dist/tests/websocket.test.d.ts +0 -1
- package/dist/tests/websocket.test.js +0 -146
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -9
- package/docs/AEGIS.md +0 -91
- package/docs/API_REFERENCE.md +0 -749
- package/docs/BENCHMARKS.md +0 -39
- package/docs/CAPABILITIES.md +0 -70
- package/docs/CLI.md +0 -43
- package/docs/DATABASE.md +0 -142
- package/docs/ECOSYSTEM.md +0 -146
- package/docs/ERRORS.md +0 -112
- package/docs/FUSION.md +0 -87
- package/docs/MIDDLEWARE.md +0 -65
- package/docs/MIGRATION_1.9_TO_2.0.md +0 -495
- package/docs/NEXT_STEPS.md +0 -99
- package/docs/OPENAPI.md +0 -99
- package/docs/PLUGINS.md +0 -59
- package/docs/PRODUCTION_DEPLOYMENT.md +0 -798
- package/docs/REAL_WORLD_EXAMPLES.md +0 -109
- package/docs/ROADMAP.md +0 -366
- package/docs/ROUTING.md +0 -78
- package/docs/SECURITY.md +0 -876
- package/docs/STATIC.md +0 -61
- package/docs/VALIDATION.md +0 -114
- package/docs/WEBSOCKETS.md +0 -76
package/dist/src/core/scope.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { QHTTPX } from './server';
|
|
2
|
-
import { QHTTPXHandler, QHTTPXRouteOptions, QHTTPXRouteConfig, QHTTPXMiddleware, QHTTPXPlugin, QHTTPXPluginOptions, HttpError } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* A Scope represents a prefixed or isolated context for plugins.
|
|
5
|
-
* It proxies methods to the main QHTTPX instance but handles prefixing.
|
|
6
|
-
*/
|
|
7
|
-
export declare class QHTTPXScope {
|
|
8
|
-
private readonly app;
|
|
9
|
-
private readonly prefix;
|
|
10
|
-
constructor(app: QHTTPX, prefix?: string);
|
|
11
|
-
/**
|
|
12
|
-
* Registers a sub-plugin within this scope.
|
|
13
|
-
* Prefixes are concatenated (e.g. /v1 + /users = /v1/users).
|
|
14
|
-
*/
|
|
15
|
-
register<Options extends QHTTPXPluginOptions>(plugin: QHTTPXPlugin<Options>, options?: Options): Promise<void>;
|
|
16
|
-
use(middleware: QHTTPXMiddleware): void;
|
|
17
|
-
get(path: string, handler: QHTTPXHandler): void;
|
|
18
|
-
get(path: string, options: QHTTPXRouteOptions): void;
|
|
19
|
-
get(path: string, handler: QHTTPXHandler, options: QHTTPXRouteConfig): void;
|
|
20
|
-
post(path: string, handler: QHTTPXHandler): void;
|
|
21
|
-
post(path: string, options: QHTTPXRouteOptions): void;
|
|
22
|
-
post(path: string, handler: QHTTPXHandler, options: QHTTPXRouteConfig): void;
|
|
23
|
-
put(path: string, handler: QHTTPXHandler): void;
|
|
24
|
-
put(path: string, options: QHTTPXRouteOptions): void;
|
|
25
|
-
put(path: string, handler: QHTTPXHandler, options: QHTTPXRouteConfig): void;
|
|
26
|
-
delete(path: string, handler: QHTTPXHandler): void;
|
|
27
|
-
delete(path: string, options: QHTTPXRouteOptions): void;
|
|
28
|
-
delete(path: string, handler: QHTTPXHandler, options: QHTTPXRouteConfig): void;
|
|
29
|
-
patch(path: string, handler: QHTTPXHandler): void;
|
|
30
|
-
patch(path: string, options: QHTTPXRouteOptions): void;
|
|
31
|
-
patch(path: string, handler: QHTTPXHandler, options: QHTTPXRouteConfig): void;
|
|
32
|
-
options(path: string, handler: QHTTPXHandler): void;
|
|
33
|
-
options(path: string, options: QHTTPXRouteOptions): void;
|
|
34
|
-
options(path: string, handler: QHTTPXHandler, options: QHTTPXRouteConfig): void;
|
|
35
|
-
head(path: string, handler: QHTTPXHandler): void;
|
|
36
|
-
head(path: string, options: QHTTPXRouteOptions): void;
|
|
37
|
-
head(path: string, handler: QHTTPXHandler, options: QHTTPXRouteConfig): void;
|
|
38
|
-
httpError(status: number, message?: string, details?: unknown): HttpError;
|
|
39
|
-
getApp(): QHTTPX;
|
|
40
|
-
private joinPaths;
|
|
41
|
-
}
|
package/dist/src/core/scope.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QHTTPXScope = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
/**
|
|
6
|
-
* A Scope represents a prefixed or isolated context for plugins.
|
|
7
|
-
* It proxies methods to the main QHTTPX instance but handles prefixing.
|
|
8
|
-
*/
|
|
9
|
-
class QHTTPXScope {
|
|
10
|
-
constructor(app, prefix = '') {
|
|
11
|
-
this.app = app;
|
|
12
|
-
this.prefix = prefix;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Registers a sub-plugin within this scope.
|
|
16
|
-
* Prefixes are concatenated (e.g. /v1 + /users = /v1/users).
|
|
17
|
-
*/
|
|
18
|
-
async register(plugin, options) {
|
|
19
|
-
const newPrefix = this.joinPaths(this.prefix, options?.prefix || '');
|
|
20
|
-
const scope = new QHTTPXScope(this.app, newPrefix);
|
|
21
|
-
await plugin(scope, options);
|
|
22
|
-
}
|
|
23
|
-
use(middleware) {
|
|
24
|
-
// Middleware in scopes is currently global (TODO: Encapsulated middleware)
|
|
25
|
-
this.app.use(middleware);
|
|
26
|
-
}
|
|
27
|
-
get(path, arg1, arg2) {
|
|
28
|
-
if (typeof arg1 === 'function' && arg2) {
|
|
29
|
-
this.app._registerRoute('GET', this.joinPaths(this.prefix, path), arg2, arg1);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
this.app._registerRoute('GET', this.joinPaths(this.prefix, path), arg1);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
post(path, arg1, arg2) {
|
|
36
|
-
if (typeof arg1 === 'function' && arg2) {
|
|
37
|
-
this.app._registerRoute('POST', this.joinPaths(this.prefix, path), arg2, arg1);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.app._registerRoute('POST', this.joinPaths(this.prefix, path), arg1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
put(path, arg1, arg2) {
|
|
44
|
-
if (typeof arg1 === 'function' && arg2) {
|
|
45
|
-
this.app._registerRoute('PUT', this.joinPaths(this.prefix, path), arg2, arg1);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
this.app._registerRoute('PUT', this.joinPaths(this.prefix, path), arg1);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
delete(path, arg1, arg2) {
|
|
52
|
-
if (typeof arg1 === 'function' && arg2) {
|
|
53
|
-
this.app._registerRoute('DELETE', this.joinPaths(this.prefix, path), arg2, arg1);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
this.app._registerRoute('DELETE', this.joinPaths(this.prefix, path), arg1);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
patch(path, arg1, arg2) {
|
|
60
|
-
if (typeof arg1 === 'function' && arg2) {
|
|
61
|
-
this.app._registerRoute('PATCH', this.joinPaths(this.prefix, path), arg2, arg1);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this.app._registerRoute('PATCH', this.joinPaths(this.prefix, path), arg1);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
options(path, arg1, arg2) {
|
|
68
|
-
if (typeof arg1 === 'function' && arg2) {
|
|
69
|
-
this.app._registerRoute('OPTIONS', this.joinPaths(this.prefix, path), arg2, arg1);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
this.app._registerRoute('OPTIONS', this.joinPaths(this.prefix, path), arg1);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
head(path, arg1, arg2) {
|
|
76
|
-
if (typeof arg1 === 'function' && arg2) {
|
|
77
|
-
this.app._registerRoute('HEAD', this.joinPaths(this.prefix, path), arg2, arg1);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this.app._registerRoute('HEAD', this.joinPaths(this.prefix, path), arg1);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
httpError(status, message, details) {
|
|
84
|
-
return new types_1.HttpError(status, message, { details });
|
|
85
|
-
}
|
|
86
|
-
// Helper to access the main app if needed
|
|
87
|
-
getApp() {
|
|
88
|
-
return this.app;
|
|
89
|
-
}
|
|
90
|
-
joinPaths(head, tail) {
|
|
91
|
-
if (!head)
|
|
92
|
-
return tail;
|
|
93
|
-
if (!tail)
|
|
94
|
-
return head;
|
|
95
|
-
// Ensure clean slash joining
|
|
96
|
-
const headSlash = head.endsWith('/');
|
|
97
|
-
const tailSlash = tail.startsWith('/');
|
|
98
|
-
if (headSlash && tailSlash) {
|
|
99
|
-
return head + tail.slice(1);
|
|
100
|
-
}
|
|
101
|
-
if (!headSlash && !tailSlash) {
|
|
102
|
-
return head + '/' + tail;
|
|
103
|
-
}
|
|
104
|
-
return head + tail;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.QHTTPXScope = QHTTPXScope;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fast JSON serializer using fast-json-stringify with optimization for simple objects
|
|
3
|
-
* For best performance, use schema-based stringifiers per route
|
|
4
|
-
*/
|
|
5
|
-
export declare function fastJsonStringify(value: unknown, schema?: unknown): string;
|
|
6
|
-
/**
|
|
7
|
-
* Get a pre-compiled stringifier for a specific schema
|
|
8
|
-
* Use this in route handlers for maximum performance
|
|
9
|
-
*/
|
|
10
|
-
export declare function getStringifier(schema: unknown): (value: unknown) => string;
|
|
@@ -1,82 +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
|
-
exports.fastJsonStringify = fastJsonStringify;
|
|
7
|
-
exports.getStringifier = getStringifier;
|
|
8
|
-
const fast_json_stringify_1 = __importDefault(require("fast-json-stringify"));
|
|
9
|
-
// Cache of compiled stringifiers per schema
|
|
10
|
-
const stringifierCache = new Map();
|
|
11
|
-
function isSimpleObject(obj) {
|
|
12
|
-
if (typeof obj !== 'object' || obj === null || Array.isArray(obj))
|
|
13
|
-
return false;
|
|
14
|
-
const keys = Object.keys(obj);
|
|
15
|
-
if (keys.length > 20)
|
|
16
|
-
return false; // Threshold for "simple"
|
|
17
|
-
for (let i = 0; i < keys.length; i++) {
|
|
18
|
-
const val = obj[keys[i]];
|
|
19
|
-
const type = typeof val;
|
|
20
|
-
if (type !== 'string' && type !== 'number' && type !== 'boolean' && val !== null) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
function stringifySimple(obj) {
|
|
27
|
-
// Manual stringification for simple objects (faster than JSON.stringify)
|
|
28
|
-
const keys = Object.keys(obj);
|
|
29
|
-
const parts = new Array(keys.length);
|
|
30
|
-
for (let i = 0; i < keys.length; i++) {
|
|
31
|
-
const key = keys[i];
|
|
32
|
-
const val = obj[key];
|
|
33
|
-
const valStr = typeof val === 'string' ? `"${val}"` : val;
|
|
34
|
-
parts[i] = `"${key}":${valStr}`;
|
|
35
|
-
}
|
|
36
|
-
return `{${parts.join(',')}}`;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Fast JSON serializer using fast-json-stringify with optimization for simple objects
|
|
40
|
-
* For best performance, use schema-based stringifiers per route
|
|
41
|
-
*/
|
|
42
|
-
function fastJsonStringify(value, schema) {
|
|
43
|
-
// Fast path for primitives
|
|
44
|
-
if (value === null || value === undefined) {
|
|
45
|
-
return 'null';
|
|
46
|
-
}
|
|
47
|
-
if (typeof value === 'string') {
|
|
48
|
-
return JSON.stringify(value);
|
|
49
|
-
}
|
|
50
|
-
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
51
|
-
return String(value);
|
|
52
|
-
}
|
|
53
|
-
// Fast path for simple objects (no nesting, all string values)
|
|
54
|
-
if (isSimpleObject(value)) {
|
|
55
|
-
return stringifySimple(value);
|
|
56
|
-
}
|
|
57
|
-
if (schema) {
|
|
58
|
-
const schemaKey = JSON.stringify(schema);
|
|
59
|
-
let stringifier = stringifierCache.get(schemaKey);
|
|
60
|
-
if (!stringifier) {
|
|
61
|
-
stringifier = (0, fast_json_stringify_1.default)(schema);
|
|
62
|
-
stringifierCache.set(schemaKey, stringifier);
|
|
63
|
-
}
|
|
64
|
-
return stringifier(value);
|
|
65
|
-
}
|
|
66
|
-
// Fallback to native JSON.stringify for schema-less complex objects
|
|
67
|
-
// It is often faster than generic fast-json-stringify
|
|
68
|
-
return JSON.stringify(value);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get a pre-compiled stringifier for a specific schema
|
|
72
|
-
* Use this in route handlers for maximum performance
|
|
73
|
-
*/
|
|
74
|
-
function getStringifier(schema) {
|
|
75
|
-
const schemaKey = JSON.stringify(schema);
|
|
76
|
-
let stringifier = stringifierCache.get(schemaKey);
|
|
77
|
-
if (!stringifier) {
|
|
78
|
-
stringifier = (0, fast_json_stringify_1.default)(schema);
|
|
79
|
-
stringifierCache.set(schemaKey, stringifier);
|
|
80
|
-
}
|
|
81
|
-
return stringifier;
|
|
82
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import http, { IncomingMessage, ServerResponse, IncomingHttpHeaders } from 'http';
|
|
2
|
-
import { URL } from 'url';
|
|
3
|
-
import { WebSocketManager } from './websocket';
|
|
4
|
-
import { Validator } from '../validation/types';
|
|
5
|
-
import { OpenAPIOptions } from '../openapi/generator';
|
|
6
|
-
import { HTTPMethod, HttpError, QHTTPXContext, QHTTPXErrorHandler, QHTTPXHandler, QHTTPXMethodNotAllowedHandler, QHTTPXMiddleware, QHTTPXNotFoundHandler, QHTTPXOptions, QHTTPXRouteOptions, QHTTPXPlugin, QHTTPXPluginOptions, CookieOptions, QHTTPXFile } from './types';
|
|
7
|
-
import { Logger } from './logger';
|
|
8
|
-
export declare class QHTTPXContextImpl implements QHTTPXContext {
|
|
9
|
-
req: IncomingMessage;
|
|
10
|
-
res: ServerResponse;
|
|
11
|
-
headers: IncomingHttpHeaders;
|
|
12
|
-
method: HTTPMethod;
|
|
13
|
-
private _params;
|
|
14
|
-
get params(): Record<string, string>;
|
|
15
|
-
set params(v: Record<string, string>);
|
|
16
|
-
private _body;
|
|
17
|
-
get body(): unknown;
|
|
18
|
-
set body(v: unknown);
|
|
19
|
-
private _files?;
|
|
20
|
-
get files(): Record<string, QHTTPXFile | QHTTPXFile[]> | undefined;
|
|
21
|
-
set files(v: Record<string, QHTTPXFile | QHTTPXFile[]> | undefined);
|
|
22
|
-
private _state;
|
|
23
|
-
requestId: string | undefined;
|
|
24
|
-
requestStart: number | undefined;
|
|
25
|
-
serializer?: (value: unknown) => string;
|
|
26
|
-
disableAutoEnd?: boolean;
|
|
27
|
-
path: string;
|
|
28
|
-
error?: Error;
|
|
29
|
-
next?: () => Promise<void>;
|
|
30
|
-
private _url;
|
|
31
|
-
private _ip;
|
|
32
|
-
private _app;
|
|
33
|
-
private _appJsonSerializer;
|
|
34
|
-
private _cookies;
|
|
35
|
-
private _query;
|
|
36
|
-
_generation: number;
|
|
37
|
-
_dirty: number;
|
|
38
|
-
private _customHeaders;
|
|
39
|
-
httpError(status: number, message?: string, details?: unknown): HttpError;
|
|
40
|
-
constructor(app: QHTTPX);
|
|
41
|
-
get cookies(): Record<string, string>;
|
|
42
|
-
set cookies(v: Record<string, string>);
|
|
43
|
-
get query(): Record<string, string | string[]>;
|
|
44
|
-
set query(v: Record<string, string | string[]>);
|
|
45
|
-
private _parseQuery;
|
|
46
|
-
private _parseCookies;
|
|
47
|
-
get bufferPool(): any;
|
|
48
|
-
get db(): any;
|
|
49
|
-
get state(): Record<string, unknown>;
|
|
50
|
-
set state(v: Record<string, unknown>);
|
|
51
|
-
get ip(): string;
|
|
52
|
-
set ip(v: string);
|
|
53
|
-
get url(): URL;
|
|
54
|
-
set url(v: URL);
|
|
55
|
-
json(payload: unknown, status?: number): void;
|
|
56
|
-
send(payload: string | Buffer, status?: number): void;
|
|
57
|
-
html(payload: string, status?: number): void;
|
|
58
|
-
redirect(url: string, status?: number): void;
|
|
59
|
-
setCookie(name: string, value: string, options: CookieOptions | undefined): void;
|
|
60
|
-
render(view: string, locals?: Record<string, unknown>): Promise<void>;
|
|
61
|
-
validate<T>(schema: unknown, data?: unknown): Promise<T>;
|
|
62
|
-
reset(): void;
|
|
63
|
-
}
|
|
64
|
-
export declare class QHTTPX {
|
|
65
|
-
private static readonly EMPTY_PARAMS;
|
|
66
|
-
private static readonly EMPTY_MATCH;
|
|
67
|
-
private readonly options;
|
|
68
|
-
private readonly server;
|
|
69
|
-
readonly logger: Logger;
|
|
70
|
-
private readonly router;
|
|
71
|
-
private readonly scheduler;
|
|
72
|
-
private readonly middlewares;
|
|
73
|
-
private readonly workerCount;
|
|
74
|
-
private readonly tasks;
|
|
75
|
-
private _metrics;
|
|
76
|
-
private readonly contextPool;
|
|
77
|
-
private readonly bufferPool;
|
|
78
|
-
private pipelineRunner;
|
|
79
|
-
private errorHandler?;
|
|
80
|
-
private notFoundHandler?;
|
|
81
|
-
private methodNotAllowedHandler?;
|
|
82
|
-
private readonly tracer?;
|
|
83
|
-
private readonly onStartHooks;
|
|
84
|
-
private readonly onBeforeShutdownHooks;
|
|
85
|
-
private readonly onShutdownHooks;
|
|
86
|
-
private nextRequestId;
|
|
87
|
-
private lastDateNow;
|
|
88
|
-
private lastDateString;
|
|
89
|
-
private requestCounter;
|
|
90
|
-
private readonly wsManager;
|
|
91
|
-
private readonly batchExecutor?;
|
|
92
|
-
private _fusion?;
|
|
93
|
-
readonly validator: Validator;
|
|
94
|
-
private readonly poolLimit;
|
|
95
|
-
constructor(options?: QHTTPXOptions);
|
|
96
|
-
get serverInstance(): http.Server;
|
|
97
|
-
get websocket(): WebSocketManager;
|
|
98
|
-
setErrorHandler(handler: QHTTPXErrorHandler): void;
|
|
99
|
-
setNotFoundHandler(handler: QHTTPXNotFoundHandler): void;
|
|
100
|
-
setMethodNotAllowedHandler(handler: QHTTPXMethodNotAllowedHandler): void;
|
|
101
|
-
set404Handler(handler: QHTTPXNotFoundHandler): void;
|
|
102
|
-
set405Handler(handler: QHTTPXMethodNotAllowedHandler): void;
|
|
103
|
-
/**
|
|
104
|
-
* Alias for setErrorHandler
|
|
105
|
-
*/
|
|
106
|
-
onError(handler: QHTTPXErrorHandler): void;
|
|
107
|
-
/**
|
|
108
|
-
* Alias for setNotFoundHandler
|
|
109
|
-
*/
|
|
110
|
-
notFound(handler: QHTTPXNotFoundHandler): void;
|
|
111
|
-
onStart(hook: () => void | Promise<void>): void;
|
|
112
|
-
onBeforeShutdown(hook: () => void | Promise<void>): void;
|
|
113
|
-
onShutdown(hook: () => void | Promise<void>): void;
|
|
114
|
-
upgrade(path: string, handler: import('./websocket').WSHandler): void;
|
|
115
|
-
use(middleware: QHTTPXMiddleware): void;
|
|
116
|
-
private compileMiddlewarePipeline;
|
|
117
|
-
private compileRoutePipeline;
|
|
118
|
-
_registerRoute(method: HTTPMethod, path: string, handlerOrOptions: QHTTPXHandler | QHTTPXRouteOptions | import('./types').QHTTPXRouteConfig, handlerIfOptions?: QHTTPXHandler): void;
|
|
119
|
-
register<Options extends QHTTPXPluginOptions>(plugin: QHTTPXPlugin<Options>, options?: Options): Promise<void>;
|
|
120
|
-
private registerRoute;
|
|
121
|
-
get(path: string, handler: QHTTPXHandler | QHTTPXRouteOptions): void;
|
|
122
|
-
get(path: string, handler: QHTTPXHandler, config: import('./types').QHTTPXRouteConfig): void;
|
|
123
|
-
get(path: string, config: import('./types').QHTTPXRouteConfig, handler: QHTTPXHandler): void;
|
|
124
|
-
post(path: string, handler: QHTTPXHandler | QHTTPXRouteOptions): void;
|
|
125
|
-
post(path: string, handler: QHTTPXHandler, config: import('./types').QHTTPXRouteConfig): void;
|
|
126
|
-
post(path: string, config: import('./types').QHTTPXRouteConfig, handler: QHTTPXHandler): void;
|
|
127
|
-
put(path: string, handler: QHTTPXHandler | QHTTPXRouteOptions): void;
|
|
128
|
-
put(path: string, handler: QHTTPXHandler, config: import('./types').QHTTPXRouteConfig): void;
|
|
129
|
-
put(path: string, config: import('./types').QHTTPXRouteConfig, handler: QHTTPXHandler): void;
|
|
130
|
-
delete(path: string, handler: QHTTPXHandler | QHTTPXRouteOptions): void;
|
|
131
|
-
delete(path: string, handler: QHTTPXHandler, config: import('./types').QHTTPXRouteConfig): void;
|
|
132
|
-
delete(path: string, config: import('./types').QHTTPXRouteConfig, handler: QHTTPXHandler): void;
|
|
133
|
-
patch(path: string, handler: QHTTPXHandler | QHTTPXRouteOptions): void;
|
|
134
|
-
patch(path: string, handler: QHTTPXHandler, config: import('./types').QHTTPXRouteConfig): void;
|
|
135
|
-
patch(path: string, config: import('./types').QHTTPXRouteConfig, handler: QHTTPXHandler): void;
|
|
136
|
-
route(path: string): {
|
|
137
|
-
get(handler: QHTTPXHandler | QHTTPXRouteOptions): /*elided*/ any;
|
|
138
|
-
post(handler: QHTTPXHandler | QHTTPXRouteOptions): /*elided*/ any;
|
|
139
|
-
put(handler: QHTTPXHandler | QHTTPXRouteOptions): /*elided*/ any;
|
|
140
|
-
delete(handler: QHTTPXHandler | QHTTPXRouteOptions): /*elided*/ any;
|
|
141
|
-
};
|
|
142
|
-
task(name: string, handler: import('./types').QHTTPXTaskHandler, options?: import('./types').QHTTPXTaskOptions): void;
|
|
143
|
-
enqueue(name: string, payload: unknown): Promise<void>;
|
|
144
|
-
op(name: string, handler: import('./types').QHTTPXOpHandler): void;
|
|
145
|
-
private registerInternalRoutes;
|
|
146
|
-
database(manager: import('../database/manager').DatabaseManager): this;
|
|
147
|
-
security(options?: import('./types').SecureDefaultsOptions): this;
|
|
148
|
-
log(options?: import('./types').LoggerOptions | boolean): this;
|
|
149
|
-
validate(validator?: Validator): this;
|
|
150
|
-
production(): this;
|
|
151
|
-
routes(prefix: string, plugin: QHTTPXPlugin): this;
|
|
152
|
-
rateLimit(option: import('./types').RateLimitPreset | number, interval?: string): this;
|
|
153
|
-
allow(count: number): {
|
|
154
|
-
per: (interval: string) => QHTTPX;
|
|
155
|
-
};
|
|
156
|
-
fusion(enable?: boolean | import('./types').RequestFusionOptions): this;
|
|
157
|
-
bodyLimit(bytes: number): this;
|
|
158
|
-
metrics(enable?: boolean): this;
|
|
159
|
-
error(status: number, message: string, details?: unknown): HttpError;
|
|
160
|
-
start(port: number): Promise<{
|
|
161
|
-
port: number;
|
|
162
|
-
}>;
|
|
163
|
-
getOpenAPI(options: OpenAPIOptions): object;
|
|
164
|
-
listen(port: number, hostnameOrCallback?: string | (() => void), callback?: () => void): Promise<{
|
|
165
|
-
port: number;
|
|
166
|
-
}>;
|
|
167
|
-
close(): Promise<void>;
|
|
168
|
-
shutdown(): Promise<void>;
|
|
169
|
-
private createContext;
|
|
170
|
-
private acquireContext;
|
|
171
|
-
private releaseContext;
|
|
172
|
-
private handleNoMatch;
|
|
173
|
-
handleRequest(req: IncomingMessage, res: ServerResponse): void;
|
|
174
|
-
private dispatch;
|
|
175
|
-
private handleUpgrade;
|
|
176
|
-
private runLifecycleHooks;
|
|
177
|
-
private handleError;
|
|
178
|
-
private generateRequestId;
|
|
179
|
-
}
|