@extk/expressive 0.9.0 → 0.10.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/README.md +11 -2
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +2 -11
- package/dist/index.mjs +2 -11
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -107,7 +107,6 @@ addRoute(
|
|
|
107
107
|
// 3. Build the Express app
|
|
108
108
|
const app = expressiveServer()
|
|
109
109
|
.withHelmet()
|
|
110
|
-
.withQs()
|
|
111
110
|
.withMorgan()
|
|
112
111
|
.withRoutes(router)
|
|
113
112
|
.withSwagger(
|
|
@@ -225,6 +224,17 @@ addRoute({
|
|
|
225
224
|
}, handler);
|
|
226
225
|
```
|
|
227
226
|
|
|
227
|
+
Pass `enabled: false` to skip swagger registration conditionally without breaking the chain:
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
.withSwagger(
|
|
231
|
+
b => b.withInfo({ title: 'My API', version: '1.0' }),
|
|
232
|
+
{ path: '/api-docs', enabled: isDev() },
|
|
233
|
+
)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
When `enabled` is `false`, `withSwagger` is a no-op and the chain continues normally. Omitting `enabled` (or passing `true`) keeps existing behavior.
|
|
237
|
+
|
|
228
238
|
Configure security schemes via the `configure` callback in `withSwagger`:
|
|
229
239
|
|
|
230
240
|
```ts
|
|
@@ -271,7 +281,6 @@ import z from 'zod';
|
|
|
271
281
|
|
|
272
282
|
const app = expressiveServer()
|
|
273
283
|
.withHelmet()
|
|
274
|
-
.withQs()
|
|
275
284
|
.withMorgan()
|
|
276
285
|
.withSwagger(
|
|
277
286
|
b => b
|
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import express__default, { RequestHandler } from 'express';
|
|
3
3
|
import * as express_serve_static_core from 'express-serve-static-core';
|
|
4
|
-
import { RouteParameters } from 'express-serve-static-core';
|
|
4
|
+
import { RouteParameters, Query } from 'express-serve-static-core';
|
|
5
5
|
import { HelmetOptions } from 'helmet';
|
|
6
6
|
import morgan from 'morgan';
|
|
7
7
|
import { SwaggerUiOptions, SwaggerOptions } from 'swagger-ui-express';
|
|
8
8
|
|
|
9
9
|
type ExpressRoute = string;
|
|
10
10
|
type ExpressLocalsObj = Record<string, any>;
|
|
11
|
-
type ExpressHandler = RequestHandler<RouteParameters<ExpressRoute>, any, any,
|
|
11
|
+
type ExpressHandler = RequestHandler<RouteParameters<ExpressRoute>, any, any, Query, ExpressLocalsObj>;
|
|
12
12
|
type PaginationQuery = {
|
|
13
13
|
limit?: string | number;
|
|
14
14
|
page?: string | number;
|
|
@@ -229,6 +229,7 @@ type SwaggerRef = {
|
|
|
229
229
|
};
|
|
230
230
|
type ExpressiveSwaggerOptions = {
|
|
231
231
|
path: ExpressRoute;
|
|
232
|
+
enabled?: boolean;
|
|
232
233
|
uiOpts?: SwaggerUiOptions;
|
|
233
234
|
options?: SwaggerOptions;
|
|
234
235
|
customCss?: string;
|
|
@@ -243,9 +244,7 @@ declare class ServerBuilder {
|
|
|
243
244
|
constructor(app: express__default.Express, container: Container, swaggerRef: SwaggerRef);
|
|
244
245
|
build(): express__default.Express;
|
|
245
246
|
withHelmet(options?: Readonly<HelmetOptions>): this;
|
|
246
|
-
|
|
247
|
-
withMorgan(format?: string, // TODO: FormatFn
|
|
248
|
-
options?: Parameters<typeof morgan>[1]): this;
|
|
247
|
+
withMorgan(format?: string | morgan.FormatFn, options?: Parameters<typeof morgan>[1]): this;
|
|
249
248
|
withRoutes(routes: express__default.Router): this;
|
|
250
249
|
/**
|
|
251
250
|
* Helper function for fluent design
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import express__default, { RequestHandler } from 'express';
|
|
3
3
|
import * as express_serve_static_core from 'express-serve-static-core';
|
|
4
|
-
import { RouteParameters } from 'express-serve-static-core';
|
|
4
|
+
import { RouteParameters, Query } from 'express-serve-static-core';
|
|
5
5
|
import { HelmetOptions } from 'helmet';
|
|
6
6
|
import morgan from 'morgan';
|
|
7
7
|
import { SwaggerUiOptions, SwaggerOptions } from 'swagger-ui-express';
|
|
8
8
|
|
|
9
9
|
type ExpressRoute = string;
|
|
10
10
|
type ExpressLocalsObj = Record<string, any>;
|
|
11
|
-
type ExpressHandler = RequestHandler<RouteParameters<ExpressRoute>, any, any,
|
|
11
|
+
type ExpressHandler = RequestHandler<RouteParameters<ExpressRoute>, any, any, Query, ExpressLocalsObj>;
|
|
12
12
|
type PaginationQuery = {
|
|
13
13
|
limit?: string | number;
|
|
14
14
|
page?: string | number;
|
|
@@ -229,6 +229,7 @@ type SwaggerRef = {
|
|
|
229
229
|
};
|
|
230
230
|
type ExpressiveSwaggerOptions = {
|
|
231
231
|
path: ExpressRoute;
|
|
232
|
+
enabled?: boolean;
|
|
232
233
|
uiOpts?: SwaggerUiOptions;
|
|
233
234
|
options?: SwaggerOptions;
|
|
234
235
|
customCss?: string;
|
|
@@ -243,9 +244,7 @@ declare class ServerBuilder {
|
|
|
243
244
|
constructor(app: express__default.Express, container: Container, swaggerRef: SwaggerRef);
|
|
244
245
|
build(): express__default.Express;
|
|
245
246
|
withHelmet(options?: Readonly<HelmetOptions>): this;
|
|
246
|
-
|
|
247
|
-
withMorgan(format?: string, // TODO: FormatFn
|
|
248
|
-
options?: Parameters<typeof morgan>[1]): this;
|
|
247
|
+
withMorgan(format?: string | morgan.FormatFn, options?: Parameters<typeof morgan>[1]): this;
|
|
249
248
|
withRoutes(routes: express__default.Router): this;
|
|
250
249
|
/**
|
|
251
250
|
* Helper function for fluent design
|
package/dist/index.js
CHANGED
|
@@ -63,7 +63,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
63
63
|
var import_express = __toESM(require("express"));
|
|
64
64
|
var import_helmet = __toESM(require("helmet"));
|
|
65
65
|
var import_morgan = __toESM(require("morgan"));
|
|
66
|
-
var import_qs = __toESM(require("qs"));
|
|
67
66
|
var import_swagger_ui_express = __toESM(require("swagger-ui-express"));
|
|
68
67
|
|
|
69
68
|
// src/swagger.ts
|
|
@@ -221,18 +220,9 @@ var ServerBuilder = class {
|
|
|
221
220
|
this.app.use((0, import_helmet.default)(options ?? {}));
|
|
222
221
|
return this;
|
|
223
222
|
}
|
|
224
|
-
withQs() {
|
|
225
|
-
this.app.set("query parser", function(str) {
|
|
226
|
-
return import_qs.default.parse(str, { decoder(s) {
|
|
227
|
-
return decodeURIComponent(s);
|
|
228
|
-
} });
|
|
229
|
-
});
|
|
230
|
-
return this;
|
|
231
|
-
}
|
|
232
223
|
withMorgan(format, options) {
|
|
233
224
|
this.app.use((0, import_morgan.default)(
|
|
234
|
-
format ?? ":
|
|
235
|
-
// TODO: ip or x-real-ip; also, default to json?
|
|
225
|
+
format ?? ":remote-addr :method :url :status :res[content-length] - :response-time ms",
|
|
236
226
|
options ?? { stream: { write: (message) => {
|
|
237
227
|
this.container.logger.info(message.trim());
|
|
238
228
|
} } }
|
|
@@ -251,6 +241,7 @@ var ServerBuilder = class {
|
|
|
251
241
|
return this;
|
|
252
242
|
}
|
|
253
243
|
withSwagger(configure, opts, ...handlers) {
|
|
244
|
+
if (opts.enabled === false) return this;
|
|
254
245
|
const config = this.swaggerRef.doc;
|
|
255
246
|
if (!config) throw new Error("withSwagger must be called before build()");
|
|
256
247
|
configure(new SwaggerBuilder(config));
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import express from "express";
|
|
3
3
|
import helmet from "helmet";
|
|
4
4
|
import morgan from "morgan";
|
|
5
|
-
import qs from "qs";
|
|
6
5
|
import swaggerUi from "swagger-ui-express";
|
|
7
6
|
|
|
8
7
|
// src/swagger.ts
|
|
@@ -160,18 +159,9 @@ var ServerBuilder = class {
|
|
|
160
159
|
this.app.use(helmet(options ?? {}));
|
|
161
160
|
return this;
|
|
162
161
|
}
|
|
163
|
-
withQs() {
|
|
164
|
-
this.app.set("query parser", function(str) {
|
|
165
|
-
return qs.parse(str, { decoder(s) {
|
|
166
|
-
return decodeURIComponent(s);
|
|
167
|
-
} });
|
|
168
|
-
});
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
162
|
withMorgan(format, options) {
|
|
172
163
|
this.app.use(morgan(
|
|
173
|
-
format ?? ":
|
|
174
|
-
// TODO: ip or x-real-ip; also, default to json?
|
|
164
|
+
format ?? ":remote-addr :method :url :status :res[content-length] - :response-time ms",
|
|
175
165
|
options ?? { stream: { write: (message) => {
|
|
176
166
|
this.container.logger.info(message.trim());
|
|
177
167
|
} } }
|
|
@@ -190,6 +180,7 @@ var ServerBuilder = class {
|
|
|
190
180
|
return this;
|
|
191
181
|
}
|
|
192
182
|
withSwagger(configure, opts, ...handlers) {
|
|
183
|
+
if (opts.enabled === false) return this;
|
|
193
184
|
const config = this.swaggerRef.doc;
|
|
194
185
|
if (!config) throw new Error("withSwagger must be called before build()");
|
|
195
186
|
configure(new SwaggerBuilder(config));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extk/expressive",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"dotenv": "^17.1.0",
|
|
46
46
|
"helmet": "^8.0.0",
|
|
47
47
|
"morgan": "^1.10.0",
|
|
48
|
-
"qs": "^6.14.1",
|
|
49
48
|
"swagger-ui-express": "^5.0.1"
|
|
50
49
|
},
|
|
51
50
|
"author": "",
|