@forklaunch/hyper-express 0.3.4 → 0.3.5
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/lib/index.d.mts +5 -5
- package/lib/index.d.ts +5 -5
- package/lib/index.js +16 -10
- package/lib/index.mjs +15 -9
- package/package.json +2 -2
package/lib/index.d.mts
CHANGED
@@ -2,7 +2,7 @@ import * as _forklaunch_hyper_express_fork from '@forklaunch/hyper-express-fork'
|
|
2
2
|
import { Server, MiddlewareHandler, Request, Response, MiddlewareNext, Router as Router$1 } from '@forklaunch/hyper-express-fork';
|
3
3
|
export { MiddlewareNext as NextFunction, Request, Response } from '@forklaunch/hyper-express-fork';
|
4
4
|
import * as _forklaunch_core_http from '@forklaunch/core/http';
|
5
|
-
import { ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
5
|
+
import { ForklaunchExpressLikeApplication, OpenTelemetryCollector, MetricsDefinition, ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
6
6
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
7
7
|
import * as uWebsockets from 'uWebSockets.js';
|
8
8
|
export { ParsedQs } from 'qs';
|
@@ -18,7 +18,7 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
|
|
18
18
|
*
|
19
19
|
* @param {SV} schemaValidator - The schema validator.
|
20
20
|
*/
|
21
|
-
constructor(schemaValidator: SV);
|
21
|
+
constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
|
22
22
|
/**
|
23
23
|
* Starts the server and sets up Swagger documentation.
|
24
24
|
*
|
@@ -33,7 +33,7 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
|
|
33
33
|
|
34
34
|
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext> implements ForklaunchRouter<SV> {
|
35
35
|
basePath: BasePath;
|
36
|
-
constructor(basePath: BasePath, schemaValidator: SV);
|
36
|
+
constructor(basePath: BasePath, schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
|
37
37
|
route(path: string): this;
|
38
38
|
any: TypedMiddlewareDefinition<this, SV, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext>;
|
39
39
|
}
|
@@ -46,7 +46,7 @@ type App<SV extends AnySchemaValidator> = Application<SV>;
|
|
46
46
|
* @param {SV} schemaValidator - The schema validator.
|
47
47
|
* @returns {Application<SV>} - The new application instance.
|
48
48
|
*/
|
49
|
-
declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
|
49
|
+
declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>): Application<SV>;
|
50
50
|
/**
|
51
51
|
* Creates a new instance of Router with the given base path and schema validator.
|
52
52
|
*
|
@@ -55,7 +55,7 @@ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidato
|
|
55
55
|
* @param {SV} schemaValidator - The schema validator.
|
56
56
|
* @returns {Router<SV>} - The new router instance.
|
57
57
|
*/
|
58
|
-
declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
|
58
|
+
declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>): Router<SV, BasePath>;
|
59
59
|
|
60
60
|
declare const handlers: {
|
61
61
|
any: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => {
|
package/lib/index.d.ts
CHANGED
@@ -2,7 +2,7 @@ import * as _forklaunch_hyper_express_fork from '@forklaunch/hyper-express-fork'
|
|
2
2
|
import { Server, MiddlewareHandler, Request, Response, MiddlewareNext, Router as Router$1 } from '@forklaunch/hyper-express-fork';
|
3
3
|
export { MiddlewareNext as NextFunction, Request, Response } from '@forklaunch/hyper-express-fork';
|
4
4
|
import * as _forklaunch_core_http from '@forklaunch/core/http';
|
5
|
-
import { ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
5
|
+
import { ForklaunchExpressLikeApplication, OpenTelemetryCollector, MetricsDefinition, ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
6
6
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
7
7
|
import * as uWebsockets from 'uWebSockets.js';
|
8
8
|
export { ParsedQs } from 'qs';
|
@@ -18,7 +18,7 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
|
|
18
18
|
*
|
19
19
|
* @param {SV} schemaValidator - The schema validator.
|
20
20
|
*/
|
21
|
-
constructor(schemaValidator: SV);
|
21
|
+
constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
|
22
22
|
/**
|
23
23
|
* Starts the server and sets up Swagger documentation.
|
24
24
|
*
|
@@ -33,7 +33,7 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
|
|
33
33
|
|
34
34
|
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext> implements ForklaunchRouter<SV> {
|
35
35
|
basePath: BasePath;
|
36
|
-
constructor(basePath: BasePath, schemaValidator: SV);
|
36
|
+
constructor(basePath: BasePath, schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
|
37
37
|
route(path: string): this;
|
38
38
|
any: TypedMiddlewareDefinition<this, SV, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext>;
|
39
39
|
}
|
@@ -46,7 +46,7 @@ type App<SV extends AnySchemaValidator> = Application<SV>;
|
|
46
46
|
* @param {SV} schemaValidator - The schema validator.
|
47
47
|
* @returns {Application<SV>} - The new application instance.
|
48
48
|
*/
|
49
|
-
declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
|
49
|
+
declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>): Application<SV>;
|
50
50
|
/**
|
51
51
|
* Creates a new instance of Router with the given base path and schema validator.
|
52
52
|
*
|
@@ -55,7 +55,7 @@ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidato
|
|
55
55
|
* @param {SV} schemaValidator - The schema validator.
|
56
56
|
* @returns {Router<SV>} - The new router instance.
|
57
57
|
*/
|
58
|
-
declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
|
58
|
+
declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>): Router<SV, BasePath>;
|
59
59
|
|
60
60
|
declare const handlers: {
|
61
61
|
any: <SV extends AnySchemaValidator, Path extends `/${string}`, P extends _forklaunch_core_http.ParamsObject<SV>, ResBodyMap extends _forklaunch_core_http.ResponsesObject<SV>, ReqBody extends _forklaunch_core_http.Body<SV>, ReqQuery extends _forklaunch_core_http.QueryObject<SV>, ReqHeaders extends _forklaunch_core_http.HeadersObject<SV>, ResHeaders extends _forklaunch_core_http.HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(schemaValidator: SV, path: Path, contractDetails: _forklaunch_core_http.ContractDetails<SV, "middleware", Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, _forklaunch_hyper_express_fork.Request<LocalsObj>>, ...handlers: _forklaunch_core_http.ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, _forklaunch_hyper_express_fork.Request<LocalsObj>, _forklaunch_hyper_express_fork.Response<LocalsObj>, _forklaunch_hyper_express_fork.MiddlewareNext>[]) => {
|
package/lib/index.js
CHANGED
@@ -99,6 +99,7 @@ var trace = (schemaValidator, path, contractDetails, ...handlers2) => {
|
|
99
99
|
// src/hyperExpressApplication.ts
|
100
100
|
var import_http11 = require("@forklaunch/core/http");
|
101
101
|
var import_hyper_express_fork = require("@forklaunch/hyper-express-fork");
|
102
|
+
var import_express_api_reference = require("@scalar/express-api-reference");
|
102
103
|
|
103
104
|
// src/middleware/swagger.middleware.ts
|
104
105
|
var import_live_directory = __toESM(require("live-directory"));
|
@@ -165,14 +166,15 @@ var Application = class extends import_http11.ForklaunchExpressLikeApplication {
|
|
165
166
|
*
|
166
167
|
* @param {SV} schemaValidator - The schema validator.
|
167
168
|
*/
|
168
|
-
constructor(schemaValidator) {
|
169
|
-
super(schemaValidator, new import_hyper_express_fork.Server());
|
169
|
+
constructor(schemaValidator, openTelemetryCollector) {
|
170
|
+
super(schemaValidator, new import_hyper_express_fork.Server(), openTelemetryCollector);
|
170
171
|
}
|
171
172
|
async listen(arg0, arg1, arg2) {
|
172
173
|
if (typeof arg0 === "number") {
|
173
174
|
const port = arg0 || Number(process.env.PORT);
|
174
175
|
this.internal.set_error_handler((req, res, err) => {
|
175
176
|
res.locals.errorMessage = err.message;
|
177
|
+
res.type("text/plain");
|
176
178
|
res.status(
|
177
179
|
res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
|
178
180
|
).send(
|
@@ -184,10 +186,9 @@ ${(0, import_http11.isForklaunchRequest)(req) ? req.context.correlationId : "No
|
|
184
186
|
[import_http11.ATTR_HTTP_RESPONSE_STATUS_CODE]: res.statusCode ?? 500
|
185
187
|
});
|
186
188
|
});
|
187
|
-
const { apiReference } = await import("@scalar/express-api-reference");
|
188
189
|
this.internal.use(
|
189
190
|
`/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
|
190
|
-
apiReference({
|
191
|
+
(0, import_express_api_reference.apiReference)({
|
191
192
|
spec: {
|
192
193
|
content: (0, import_http11.generateSwaggerDocument)(
|
193
194
|
this.schemaValidator,
|
@@ -321,8 +322,13 @@ function polyfillGetHeaders(_req, res, next) {
|
|
321
322
|
|
322
323
|
// src/hyperExpressRouter.ts
|
323
324
|
var Router = class extends import_http13.ForklaunchExpressLikeRouter {
|
324
|
-
constructor(basePath, schemaValidator) {
|
325
|
-
super(
|
325
|
+
constructor(basePath, schemaValidator, openTelemetryCollector) {
|
326
|
+
super(
|
327
|
+
basePath,
|
328
|
+
schemaValidator,
|
329
|
+
new import_hyper_express_fork2.Router(),
|
330
|
+
openTelemetryCollector
|
331
|
+
);
|
326
332
|
this.basePath = basePath;
|
327
333
|
this.internal.use(polyfillGetHeaders);
|
328
334
|
this.internal.use(contentParse);
|
@@ -348,11 +354,11 @@ var Router = class extends import_http13.ForklaunchExpressLikeRouter {
|
|
348
354
|
};
|
349
355
|
|
350
356
|
// index.ts
|
351
|
-
function forklaunchExpress(schemaValidator) {
|
352
|
-
return new Application(schemaValidator);
|
357
|
+
function forklaunchExpress(schemaValidator, openTelemetryCollector) {
|
358
|
+
return new Application(schemaValidator, openTelemetryCollector);
|
353
359
|
}
|
354
|
-
function forklaunchRouter(basePath, schemaValidator) {
|
355
|
-
const router = new Router(basePath, schemaValidator);
|
360
|
+
function forklaunchRouter(basePath, schemaValidator, openTelemetryCollector) {
|
361
|
+
const router = new Router(basePath, schemaValidator, openTelemetryCollector);
|
356
362
|
return router;
|
357
363
|
}
|
358
364
|
var handlers = {
|
package/lib/index.mjs
CHANGED
@@ -89,6 +89,7 @@ import {
|
|
89
89
|
import {
|
90
90
|
Server
|
91
91
|
} from "@forklaunch/hyper-express-fork";
|
92
|
+
import { apiReference } from "@scalar/express-api-reference";
|
92
93
|
|
93
94
|
// src/middleware/swagger.middleware.ts
|
94
95
|
import LiveDirectory from "live-directory";
|
@@ -155,14 +156,15 @@ var Application = class extends ForklaunchExpressLikeApplication {
|
|
155
156
|
*
|
156
157
|
* @param {SV} schemaValidator - The schema validator.
|
157
158
|
*/
|
158
|
-
constructor(schemaValidator) {
|
159
|
-
super(schemaValidator, new Server());
|
159
|
+
constructor(schemaValidator, openTelemetryCollector) {
|
160
|
+
super(schemaValidator, new Server(), openTelemetryCollector);
|
160
161
|
}
|
161
162
|
async listen(arg0, arg1, arg2) {
|
162
163
|
if (typeof arg0 === "number") {
|
163
164
|
const port = arg0 || Number(process.env.PORT);
|
164
165
|
this.internal.set_error_handler((req, res, err) => {
|
165
166
|
res.locals.errorMessage = err.message;
|
167
|
+
res.type("text/plain");
|
166
168
|
res.status(
|
167
169
|
res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
|
168
170
|
).send(
|
@@ -174,7 +176,6 @@ ${isForklaunchRequest(req) ? req.context.correlationId : "No correlation ID"}`
|
|
174
176
|
[ATTR_HTTP_RESPONSE_STATUS_CODE]: res.statusCode ?? 500
|
175
177
|
});
|
176
178
|
});
|
177
|
-
const { apiReference } = await import("@scalar/express-api-reference");
|
178
179
|
this.internal.use(
|
179
180
|
`/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
|
180
181
|
apiReference({
|
@@ -317,8 +318,13 @@ function polyfillGetHeaders(_req, res, next) {
|
|
317
318
|
|
318
319
|
// src/hyperExpressRouter.ts
|
319
320
|
var Router = class extends ForklaunchExpressLikeRouter {
|
320
|
-
constructor(basePath, schemaValidator) {
|
321
|
-
super(
|
321
|
+
constructor(basePath, schemaValidator, openTelemetryCollector) {
|
322
|
+
super(
|
323
|
+
basePath,
|
324
|
+
schemaValidator,
|
325
|
+
new ExpressRouter(),
|
326
|
+
openTelemetryCollector
|
327
|
+
);
|
322
328
|
this.basePath = basePath;
|
323
329
|
this.internal.use(polyfillGetHeaders);
|
324
330
|
this.internal.use(contentParse);
|
@@ -344,11 +350,11 @@ var Router = class extends ForklaunchExpressLikeRouter {
|
|
344
350
|
};
|
345
351
|
|
346
352
|
// index.ts
|
347
|
-
function forklaunchExpress(schemaValidator) {
|
348
|
-
return new Application(schemaValidator);
|
353
|
+
function forklaunchExpress(schemaValidator, openTelemetryCollector) {
|
354
|
+
return new Application(schemaValidator, openTelemetryCollector);
|
349
355
|
}
|
350
|
-
function forklaunchRouter(basePath, schemaValidator) {
|
351
|
-
const router = new Router(basePath, schemaValidator);
|
356
|
+
function forklaunchRouter(basePath, schemaValidator, openTelemetryCollector) {
|
357
|
+
const router = new Router(basePath, schemaValidator, openTelemetryCollector);
|
352
358
|
return router;
|
353
359
|
}
|
354
360
|
var handlers = {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@forklaunch/hyper-express",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.5",
|
4
4
|
"description": "Forklaunch framework for hyper-express.",
|
5
5
|
"homepage": "https://github.com/forklaunch/forklaunch-js#readme",
|
6
6
|
"bugs": {
|
@@ -35,7 +35,7 @@
|
|
35
35
|
"swagger-ui-express": "^5.0.1",
|
36
36
|
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.44.0",
|
37
37
|
"@forklaunch/common": "0.2.3",
|
38
|
-
"@forklaunch/core": "0.5.
|
38
|
+
"@forklaunch/core": "0.5.4",
|
39
39
|
"@forklaunch/validator": "0.4.6"
|
40
40
|
},
|
41
41
|
"devDependencies": {
|