@forklaunch/hyper-express 0.3.4 → 0.3.6

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 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, DocsConfiguration, 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';
@@ -13,12 +13,13 @@ export { ParsedQs } from 'qs';
13
13
  * @template SV - A type that extends AnySchemaValidator.
14
14
  */
15
15
  declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext> {
16
+ private readonly docsConfiguration?;
16
17
  /**
17
18
  * Creates an instance of the Application class.
18
19
  *
19
20
  * @param {SV} schemaValidator - The schema validator.
20
21
  */
21
- constructor(schemaValidator: SV);
22
+ constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, docsConfiguration?: DocsConfiguration | undefined);
22
23
  /**
23
24
  * Starts the server and sets up Swagger documentation.
24
25
  *
@@ -33,7 +34,7 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
33
34
 
34
35
  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
36
  basePath: BasePath;
36
- constructor(basePath: BasePath, schemaValidator: SV);
37
+ constructor(basePath: BasePath, schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
37
38
  route(path: string): this;
38
39
  any: TypedMiddlewareDefinition<this, SV, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext>;
39
40
  }
@@ -46,7 +47,7 @@ type App<SV extends AnySchemaValidator> = Application<SV>;
46
47
  * @param {SV} schemaValidator - The schema validator.
47
48
  * @returns {Application<SV>} - The new application instance.
48
49
  */
49
- declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
50
+ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, docsConfiguration?: DocsConfiguration): Application<SV>;
50
51
  /**
51
52
  * Creates a new instance of Router with the given base path and schema validator.
52
53
  *
@@ -55,7 +56,7 @@ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidato
55
56
  * @param {SV} schemaValidator - The schema validator.
56
57
  * @returns {Router<SV>} - The new router instance.
57
58
  */
58
- declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
59
+ declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>): Router<SV, BasePath>;
59
60
 
60
61
  declare const handlers: {
61
62
  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, DocsConfiguration, 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';
@@ -13,12 +13,13 @@ export { ParsedQs } from 'qs';
13
13
  * @template SV - A type that extends AnySchemaValidator.
14
14
  */
15
15
  declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext> {
16
+ private readonly docsConfiguration?;
16
17
  /**
17
18
  * Creates an instance of the Application class.
18
19
  *
19
20
  * @param {SV} schemaValidator - The schema validator.
20
21
  */
21
- constructor(schemaValidator: SV);
22
+ constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, docsConfiguration?: DocsConfiguration | undefined);
22
23
  /**
23
24
  * Starts the server and sets up Swagger documentation.
24
25
  *
@@ -33,7 +34,7 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
33
34
 
34
35
  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
36
  basePath: BasePath;
36
- constructor(basePath: BasePath, schemaValidator: SV);
37
+ constructor(basePath: BasePath, schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
37
38
  route(path: string): this;
38
39
  any: TypedMiddlewareDefinition<this, SV, Request<Record<string, unknown>>, Response<Record<string, unknown>>, MiddlewareNext>;
39
40
  }
@@ -46,7 +47,7 @@ type App<SV extends AnySchemaValidator> = Application<SV>;
46
47
  * @param {SV} schemaValidator - The schema validator.
47
48
  * @returns {Application<SV>} - The new application instance.
48
49
  */
49
- declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV): Application<SV>;
50
+ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, docsConfiguration?: DocsConfiguration): Application<SV>;
50
51
  /**
51
52
  * Creates a new instance of Router with the given base path and schema validator.
52
53
  *
@@ -55,7 +56,7 @@ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidato
55
56
  * @param {SV} schemaValidator - The schema validator.
56
57
  * @returns {Router<SV>} - The new router instance.
57
58
  */
58
- declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV): Router<SV, BasePath>;
59
+ declare function forklaunchRouter<SV extends AnySchemaValidator, BasePath extends `/${string}`>(basePath: BasePath, schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>): Router<SV, BasePath>;
59
60
 
60
61
  declare const handlers: {
61
62
  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,49 +166,56 @@ 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, docsConfiguration) {
170
+ super(schemaValidator, new import_hyper_express_fork.Server(), openTelemetryCollector);
171
+ this.docsConfiguration = docsConfiguration;
170
172
  }
171
173
  async listen(arg0, arg1, arg2) {
172
174
  if (typeof arg0 === "number") {
173
175
  const port = arg0 || Number(process.env.PORT);
174
176
  this.internal.set_error_handler((req, res, err) => {
175
177
  res.locals.errorMessage = err.message;
178
+ res.type("text/plain");
176
179
  res.status(
177
180
  res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
178
181
  ).send(
179
182
  `Internal server error:
180
183
 
181
- ${(0, import_http11.isForklaunchRequest)(req) ? req.context.correlationId : "No correlation ID"}`
184
+ Correlation id: ${(0, import_http11.isForklaunchRequest)(req) ? req.context.correlationId : "No correlation ID"}`
182
185
  );
183
186
  (0, import_http11.logger)("error").error(err.stack ?? err.message, {
184
187
  [import_http11.ATTR_HTTP_RESPONSE_STATUS_CODE]: res.statusCode ?? 500
185
188
  });
186
189
  });
187
- const { apiReference } = await import("@scalar/express-api-reference");
188
- this.internal.use(
189
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
190
- apiReference({
191
- spec: {
192
- content: (0, import_http11.generateSwaggerDocument)(
190
+ if (this.docsConfiguration == null || this.docsConfiguration.type === "scalar") {
191
+ this.internal.use(
192
+ `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
193
+ (0, import_express_api_reference.apiReference)({
194
+ spec: {
195
+ content: (0, import_http11.generateSwaggerDocument)(
196
+ this.schemaValidator,
197
+ port,
198
+ this.routers
199
+ )
200
+ },
201
+ ...this.docsConfiguration
202
+ })
203
+ );
204
+ } else if (this.docsConfiguration.type === "swagger") {
205
+ const swaggerPath = `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`;
206
+ this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
207
+ this.internal.get(
208
+ `${swaggerPath}/*`,
209
+ swagger(
210
+ swaggerPath,
211
+ (0, import_http11.generateSwaggerDocument)(
193
212
  this.schemaValidator,
194
213
  port,
195
214
  this.routers
196
215
  )
197
- },
198
- theme: "deepSpace",
199
- layout: "modern"
200
- })
201
- );
202
- const swaggerPath = `/api/${process.env.VERSION ?? "v1"}${"/swagger"}`;
203
- this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
204
- this.internal.get(
205
- `${swaggerPath}/*`,
206
- swagger(
207
- swaggerPath,
208
- (0, import_http11.generateSwaggerDocument)(this.schemaValidator, port, this.routers)
209
- )
210
- );
216
+ )
217
+ );
218
+ }
211
219
  if (arg1 && typeof arg1 === "string") {
212
220
  return this.internal.listen(port, arg1, arg2);
213
221
  } else if (arg1 && typeof arg1 === "function") {
@@ -321,8 +329,13 @@ function polyfillGetHeaders(_req, res, next) {
321
329
 
322
330
  // src/hyperExpressRouter.ts
323
331
  var Router = class extends import_http13.ForklaunchExpressLikeRouter {
324
- constructor(basePath, schemaValidator) {
325
- super(basePath, schemaValidator, new import_hyper_express_fork2.Router());
332
+ constructor(basePath, schemaValidator, openTelemetryCollector) {
333
+ super(
334
+ basePath,
335
+ schemaValidator,
336
+ new import_hyper_express_fork2.Router(),
337
+ openTelemetryCollector
338
+ );
326
339
  this.basePath = basePath;
327
340
  this.internal.use(polyfillGetHeaders);
328
341
  this.internal.use(contentParse);
@@ -348,11 +361,15 @@ var Router = class extends import_http13.ForklaunchExpressLikeRouter {
348
361
  };
349
362
 
350
363
  // index.ts
351
- function forklaunchExpress(schemaValidator) {
352
- return new Application(schemaValidator);
364
+ function forklaunchExpress(schemaValidator, openTelemetryCollector, docsConfiguration) {
365
+ return new Application(
366
+ schemaValidator,
367
+ openTelemetryCollector,
368
+ docsConfiguration
369
+ );
353
370
  }
354
- function forklaunchRouter(basePath, schemaValidator) {
355
- const router = new Router(basePath, schemaValidator);
371
+ function forklaunchRouter(basePath, schemaValidator, openTelemetryCollector) {
372
+ const router = new Router(basePath, schemaValidator, openTelemetryCollector);
356
373
  return router;
357
374
  }
358
375
  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,49 +156,56 @@ 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, docsConfiguration) {
160
+ super(schemaValidator, new Server(), openTelemetryCollector);
161
+ this.docsConfiguration = docsConfiguration;
160
162
  }
161
163
  async listen(arg0, arg1, arg2) {
162
164
  if (typeof arg0 === "number") {
163
165
  const port = arg0 || Number(process.env.PORT);
164
166
  this.internal.set_error_handler((req, res, err) => {
165
167
  res.locals.errorMessage = err.message;
168
+ res.type("text/plain");
166
169
  res.status(
167
170
  res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
168
171
  ).send(
169
172
  `Internal server error:
170
173
 
171
- ${isForklaunchRequest(req) ? req.context.correlationId : "No correlation ID"}`
174
+ Correlation id: ${isForklaunchRequest(req) ? req.context.correlationId : "No correlation ID"}`
172
175
  );
173
176
  logger("error").error(err.stack ?? err.message, {
174
177
  [ATTR_HTTP_RESPONSE_STATUS_CODE]: res.statusCode ?? 500
175
178
  });
176
179
  });
177
- const { apiReference } = await import("@scalar/express-api-reference");
178
- this.internal.use(
179
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
180
- apiReference({
181
- spec: {
182
- content: generateSwaggerDocument(
180
+ if (this.docsConfiguration == null || this.docsConfiguration.type === "scalar") {
181
+ this.internal.use(
182
+ `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
183
+ apiReference({
184
+ spec: {
185
+ content: generateSwaggerDocument(
186
+ this.schemaValidator,
187
+ port,
188
+ this.routers
189
+ )
190
+ },
191
+ ...this.docsConfiguration
192
+ })
193
+ );
194
+ } else if (this.docsConfiguration.type === "swagger") {
195
+ const swaggerPath = `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`;
196
+ this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
197
+ this.internal.get(
198
+ `${swaggerPath}/*`,
199
+ swagger(
200
+ swaggerPath,
201
+ generateSwaggerDocument(
183
202
  this.schemaValidator,
184
203
  port,
185
204
  this.routers
186
205
  )
187
- },
188
- theme: "deepSpace",
189
- layout: "modern"
190
- })
191
- );
192
- const swaggerPath = `/api/${process.env.VERSION ?? "v1"}${"/swagger"}`;
193
- this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
194
- this.internal.get(
195
- `${swaggerPath}/*`,
196
- swagger(
197
- swaggerPath,
198
- generateSwaggerDocument(this.schemaValidator, port, this.routers)
199
- )
200
- );
206
+ )
207
+ );
208
+ }
201
209
  if (arg1 && typeof arg1 === "string") {
202
210
  return this.internal.listen(port, arg1, arg2);
203
211
  } else if (arg1 && typeof arg1 === "function") {
@@ -317,8 +325,13 @@ function polyfillGetHeaders(_req, res, next) {
317
325
 
318
326
  // src/hyperExpressRouter.ts
319
327
  var Router = class extends ForklaunchExpressLikeRouter {
320
- constructor(basePath, schemaValidator) {
321
- super(basePath, schemaValidator, new ExpressRouter());
328
+ constructor(basePath, schemaValidator, openTelemetryCollector) {
329
+ super(
330
+ basePath,
331
+ schemaValidator,
332
+ new ExpressRouter(),
333
+ openTelemetryCollector
334
+ );
322
335
  this.basePath = basePath;
323
336
  this.internal.use(polyfillGetHeaders);
324
337
  this.internal.use(contentParse);
@@ -344,11 +357,15 @@ var Router = class extends ForklaunchExpressLikeRouter {
344
357
  };
345
358
 
346
359
  // index.ts
347
- function forklaunchExpress(schemaValidator) {
348
- return new Application(schemaValidator);
360
+ function forklaunchExpress(schemaValidator, openTelemetryCollector, docsConfiguration) {
361
+ return new Application(
362
+ schemaValidator,
363
+ openTelemetryCollector,
364
+ docsConfiguration
365
+ );
349
366
  }
350
- function forklaunchRouter(basePath, schemaValidator) {
351
- const router = new Router(basePath, schemaValidator);
367
+ function forklaunchRouter(basePath, schemaValidator, openTelemetryCollector) {
368
+ const router = new Router(basePath, schemaValidator, openTelemetryCollector);
352
369
  return router;
353
370
  }
354
371
  var handlers = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/hyper-express",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Forklaunch framework for hyper-express.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -34,9 +34,9 @@
34
34
  "swagger-ui-dist": "^5.20.0",
35
35
  "swagger-ui-express": "^5.0.1",
36
36
  "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.44.0",
37
+ "@forklaunch/validator": "0.4.6",
37
38
  "@forklaunch/common": "0.2.3",
38
- "@forklaunch/core": "0.5.3",
39
- "@forklaunch/validator": "0.4.6"
39
+ "@forklaunch/core": "0.5.5"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@eslint/js": "^9.22.0",