@meghjs/core 0.5.4 → 0.6.0
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 +54 -137
- package/dist/common/container.js +0 -1
- package/dist/common/container.js.map +1 -1
- package/dist/common/exceptions/http-exceptions.d.ts +1 -50
- package/dist/common/exceptions/http-exceptions.js +15 -80
- package/dist/common/exceptions/http-exceptions.js.map +1 -1
- package/dist/common/exceptions/system-exception.d.ts +0 -10
- package/dist/common/exceptions/system-exception.js +7 -12
- package/dist/common/exceptions/system-exception.js.map +1 -1
- package/dist/common/utils/compiled-validation.d.ts +43 -0
- package/dist/common/utils/compiled-validation.js +299 -0
- package/dist/common/utils/compiled-validation.js.map +1 -0
- package/dist/common/utils/object-utils.d.ts +4 -0
- package/dist/common/utils/object-utils.js +44 -7
- package/dist/common/utils/object-utils.js.map +1 -1
- package/dist/common/utils/path-utils.d.ts +7 -0
- package/dist/common/utils/path-utils.js +15 -0
- package/dist/common/utils/path-utils.js.map +1 -1
- package/dist/config/environment-variables.d.ts +2 -0
- package/dist/config/environment-variables.js +24 -12
- package/dist/config/environment-variables.js.map +1 -1
- package/dist/core/application.d.ts +90 -12
- package/dist/core/application.js +166 -100
- package/dist/core/application.js.map +1 -1
- package/dist/core/interfaces.d.ts +48 -4
- package/dist/core/router.d.ts +59 -9
- package/dist/core/router.js +233 -123
- package/dist/core/router.js.map +1 -1
- package/dist/core/testing.js +2 -12
- package/dist/core/testing.js.map +1 -1
- package/dist/core/types.d.ts +6 -0
- package/dist/errors/error-handler.d.ts +56 -0
- package/dist/errors/error-handler.js +206 -0
- package/dist/errors/error-handler.js.map +1 -0
- package/dist/errors/exception-filter.d.ts +96 -0
- package/dist/errors/exception-filter.js +68 -0
- package/dist/errors/exception-filter.js.map +1 -0
- package/dist/errors/http-exceptions.d.ts +413 -0
- package/dist/errors/http-exceptions.js +155 -0
- package/dist/errors/http-exceptions.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +24 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/event-subscriber.js +14 -3
- package/dist/events/event-subscriber.js.map +1 -1
- package/dist/events/socket-dispatcher.d.ts +1 -3
- package/dist/events/socket-dispatcher.js +2 -10
- package/dist/events/socket-dispatcher.js.map +1 -1
- package/dist/http/multipart.js.map +1 -1
- package/dist/http/params.js +3 -1
- package/dist/http/params.js.map +1 -1
- package/dist/http/route-methods.js.map +1 -1
- package/dist/http/validator-extend.js +1 -1
- package/dist/http/validator-extend.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/observability/health.d.ts +45 -0
- package/dist/observability/health.js +74 -0
- package/dist/observability/health.js.map +1 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.js +5 -0
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/logger.js +8 -1
- package/dist/observability/logger.js.map +1 -1
- package/dist/observability/request-context.d.ts +29 -0
- package/dist/observability/request-context.js +54 -0
- package/dist/observability/request-context.js.map +1 -0
- package/dist/openapi/swagger-schema.d.ts +0 -2
- package/dist/openapi/swagger-schema.js +21 -5
- package/dist/openapi/swagger-schema.js.map +1 -1
- package/dist/orm/connect.d.ts +2 -0
- package/dist/orm/connect.js +6 -1
- package/dist/orm/connect.js.map +1 -1
- package/dist/orm/plugin.js +2 -0
- package/dist/orm/plugin.js.map +1 -1
- package/dist/plugins/plugin.d.ts +3 -0
- package/dist/plugins/plugin.js.map +1 -1
- package/dist/plugins/registry.js +1 -0
- package/dist/plugins/registry.js.map +1 -1
- package/dist/realtime/websocket.d.ts +1 -7
- package/dist/realtime/websocket.js +2 -18
- package/dist/realtime/websocket.js.map +1 -1
- package/dist/storage/file-storage.js +6 -4
- package/dist/storage/file-storage.js.map +1 -1
- package/dist/validator/compat.d.ts +5 -0
- package/dist/validator/compat.js +42 -0
- package/dist/validator/compat.js.map +1 -0
- package/dist/validator/compiler.d.ts +20 -0
- package/dist/validator/compiler.js +219 -0
- package/dist/validator/compiler.js.map +1 -0
- package/dist/validator/decorators.d.ts +81 -0
- package/dist/validator/decorators.js +377 -0
- package/dist/validator/decorators.js.map +1 -0
- package/dist/validator/index.d.ts +16 -0
- package/dist/validator/index.js +36 -0
- package/dist/validator/index.js.map +1 -0
- package/dist/validator/is-email.d.ts +25 -0
- package/dist/validator/is-email.js +204 -0
- package/dist/validator/is-email.js.map +1 -0
- package/dist/validator/messages.d.ts +20 -0
- package/dist/validator/messages.js +186 -0
- package/dist/validator/messages.js.map +1 -0
- package/dist/validator/metadata.d.ts +118 -0
- package/dist/validator/metadata.js +153 -0
- package/dist/validator/metadata.js.map +1 -0
- package/dist/validator/transform.d.ts +29 -0
- package/dist/validator/transform.js +210 -0
- package/dist/validator/transform.js.map +1 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -58,7 +58,9 @@ Megh is a TypeScript-first web framework built on top of [Fastify](https://fasti
|
|
|
58
58
|
- 🎯 **Decorator-based routing** — define controllers and routes with TypeScript decorators
|
|
59
59
|
- 💉 **Dependency injection** — `MeghContainer`, `@Injectable` and `Token`, on Megh's own container (no third-party DI library)
|
|
60
60
|
- 📄 **OpenAPI / Swagger** — automatic docs with Swagger UI or [Scalar](https://scalar.com)
|
|
61
|
-
- ✅ **Validation** — request DTOs validated and whitelisted
|
|
61
|
+
- ✅ **Validation** — request DTOs validated and whitelisted, with Megh's own compiled decorators or [class-validator](https://github.com/typestack/class-validator)
|
|
62
|
+
- 🚨 **Error handling** — HTTP exceptions and pluggable exception filters
|
|
63
|
+
- ❤️ **Health checks & request IDs** — `/health` and `/ready` probes, an `x-request-id` on every response and log line
|
|
62
64
|
- 🔑 **Authentication** — pluggable handler that populates `request.user`
|
|
63
65
|
- 🔒 **Authorization** — deny-by-default `@Authorized` routes
|
|
64
66
|
- 📁 **File uploads** — multipart support with safe, confined storage
|
|
@@ -289,6 +291,11 @@ Error responses have the shape `{ code, status: "Error", message, data? }`.
|
|
|
289
291
|
Outside development, 5xx responses hide the message and data and return
|
|
290
292
|
`"Internal Server Error"`.
|
|
291
293
|
|
|
294
|
+
To change how errors are turned into responses, register exception filters
|
|
295
|
+
with `@Catch`, `@UseFilters` or `app.useExceptionFilters()`, or replace the
|
|
296
|
+
handler with `app.useErrorHandler()`. See
|
|
297
|
+
[Error Handling](https://meghjs.github.io/core-concept/error-handling).
|
|
298
|
+
|
|
292
299
|
---
|
|
293
300
|
|
|
294
301
|
### Middleware
|
|
@@ -329,12 +336,16 @@ class UserController {
|
|
|
329
336
|
Requests pass through these stages in order:
|
|
330
337
|
|
|
331
338
|
1. Global middlewares (`useMiddlewares`)
|
|
332
|
-
2.
|
|
333
|
-
3.
|
|
334
|
-
4. Class `@
|
|
335
|
-
5. Parameter validation
|
|
339
|
+
2. Class `@UseMiddleware`, then method `@UseMiddleware`
|
|
340
|
+
3. Authentication (sets `request.user`)
|
|
341
|
+
4. Class `@Authorized`, then method `@Authorized`
|
|
342
|
+
5. Parameter and DTO validation
|
|
336
343
|
6. Handler
|
|
337
344
|
|
|
345
|
+
Middleware runs before authentication, so it can reject a request early but
|
|
346
|
+
cannot read `request.user`. Inline routes follow the same order. (Before
|
|
347
|
+
0.5.5, `@UseMiddleware` ran after `@Authorized`.)
|
|
348
|
+
|
|
338
349
|
---
|
|
339
350
|
|
|
340
351
|
### Authentication
|
|
@@ -439,10 +450,15 @@ under that name makes `app.run()` fail.
|
|
|
439
450
|
|
|
440
451
|
### Validation
|
|
441
452
|
|
|
442
|
-
|
|
453
|
+
Decorate your DTOs and Megh validates `@Body()` and `@Query()` automatically.
|
|
454
|
+
The decorators come from `@meghjs/core`, with the same names, options and
|
|
455
|
+
messages as `class-validator`, and each DTO is compiled once into a single
|
|
456
|
+
function, so validation is several times faster. DTOs written with
|
|
457
|
+
`class-validator` keep working; switching is a change of import. See
|
|
458
|
+
[Validation](https://meghjs.github.io/core-concept/validation).
|
|
443
459
|
|
|
444
460
|
```typescript
|
|
445
|
-
import { IsString, IsNotEmpty, IsEmail, IsInt, Min, Max, IsOptional } from '
|
|
461
|
+
import { IsString, IsNotEmpty, IsEmail, IsInt, Min, Max, IsOptional } from '@meghjs/core';
|
|
446
462
|
|
|
447
463
|
class CreateUserDto {
|
|
448
464
|
@IsString()
|
|
@@ -999,8 +1015,20 @@ app.useMultipart({
|
|
|
999
1015
|
});
|
|
1000
1016
|
```
|
|
1001
1017
|
|
|
1018
|
+
`useMultipart()` passes its options to `@fastify/multipart`. Megh sets
|
|
1019
|
+
`attachFieldsToBody: true` (needed by `@UploadFile`) and a **10 MB** per-file
|
|
1020
|
+
limit unless you pass your own `limits`. The smaller of this limit and
|
|
1021
|
+
`FileStorage`'s `maxFileSize` (50 MB) wins, so raise both for bigger files.
|
|
1022
|
+
|
|
1002
1023
|
```typescript
|
|
1003
|
-
import {
|
|
1024
|
+
import {
|
|
1025
|
+
ApiController,
|
|
1026
|
+
Post,
|
|
1027
|
+
FileStorage,
|
|
1028
|
+
UploadFile,
|
|
1029
|
+
MultipartFile,
|
|
1030
|
+
OpenApi,
|
|
1031
|
+
} from "@meghjs/core";
|
|
1004
1032
|
|
|
1005
1033
|
@ApiController("/files")
|
|
1006
1034
|
class FileController {
|
|
@@ -1062,7 +1090,7 @@ import path from "path";
|
|
|
1062
1090
|
|
|
1063
1091
|
// requires @fastify/static
|
|
1064
1092
|
app.useStaticFiles({
|
|
1065
|
-
|
|
1093
|
+
root: path.join(process.cwd(), "public"),
|
|
1066
1094
|
prefix: "/static/",
|
|
1067
1095
|
});
|
|
1068
1096
|
```
|
|
@@ -1200,8 +1228,12 @@ dispatches jobs without Redis.
|
|
|
1200
1228
|
- Set `NODE_ENV=production`. Unset also counts as production, but be explicit.
|
|
1201
1229
|
Production mode hides 5xx details, writes JSON logs, and makes
|
|
1202
1230
|
`app.isDevelopment()` false.
|
|
1203
|
-
- `app.run(port)` defaults to
|
|
1204
|
-
|
|
1231
|
+
- `app.run(port)` defaults to `PORT`, else 4000, and listens on `HOST` or `0.0.0.0`
|
|
1232
|
+
(`app.run(port, { host })` to change it). It handles `SIGTERM`/`SIGINT` by
|
|
1233
|
+
stopping the scheduler, closing registered workers and the cache, and gives
|
|
1234
|
+
up after `shutdownTimeout`.
|
|
1235
|
+
- Add `app.useHealth()` for `/health` and `/ready` probes. See
|
|
1236
|
+
[Health Checks](https://meghjs.github.io/advanced/health).
|
|
1205
1237
|
- Register an authorizer if you use `@Authorized`; without one those routes
|
|
1206
1238
|
return 403.
|
|
1207
1239
|
|
|
@@ -1235,141 +1267,26 @@ These are regressions or gaps in 0.3.0 that are expected to be fixed in a patch
|
|
|
1235
1267
|
under dependency injection.** Add `constructor() { super(); }`.
|
|
1236
1268
|
- **Status codes from `Results.Created`, `Results.NoContent`,
|
|
1237
1269
|
`Results.NotFound`, `HttpResponse.Created` and `@HttpCode` are not applied.**
|
|
1238
|
-
The response is 200. Throw `HttpExceptions` to send error statuses.
|
|
1270
|
+
The response is 200. Throw `HttpExceptions` to send error statuses. Fixed in 0.5.5.
|
|
1239
1271
|
- **`@Body()`/`@Query()` DTOs are missing from the generated OpenAPI document.**
|
|
1240
1272
|
Validation still runs. Describe them with `@OpenApi({ requestBody, query })`
|
|
1241
1273
|
for now.
|
|
1242
|
-
- **`@All()` crashes `app.run()`.**
|
|
1274
|
+
- **`@All()` crashes `app.run()`.** Fixed in 0.5.5.
|
|
1243
1275
|
- **Upload policy violations return 500**, not 400 or 413.
|
|
1244
|
-
- **`app.run()` has no `host` option.** The server binds to localhost.
|
|
1276
|
+
- **`app.run()` has no `host` option.** The server binds to localhost. Fixed in 0.5.5.
|
|
1245
1277
|
|
|
1246
1278
|
---
|
|
1247
1279
|
|
|
1248
1280
|
## Roadmap to 1.0.0
|
|
1249
1281
|
|
|
1250
|
-
1.0.0 is the first release with a stable API
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
- [x] Handlers receive the validated DTO; unknown properties are rejected (mass-assignment protection)
|
|
1259
|
-
- [x] File storage confines every read, write and delete to `baseDir`, including sibling-prefix and symlink escapes
|
|
1260
|
-
- [x] Uploads get random names, don't overwrite, and are checked against an extension allowlist and a size limit
|
|
1261
|
-
- [x] Path traversal in `UploadFileFromRequest` closed
|
|
1262
|
-
- [x] `Content-Disposition` header injection closed
|
|
1263
|
-
- [x] Credentials are no longer logged, and production hides 5xx details and requires `NODE_ENV=development` for dev mode
|
|
1264
|
-
- [x] Concurrent requests no longer share `FileStorage` transform settings
|
|
1265
|
-
|
|
1266
|
-
**Correctness**
|
|
1267
|
-
|
|
1268
|
-
- [x] Built-in `Validator` accepts `0` and enforces `min` / `max` / `exact` / `optional`
|
|
1269
|
-
- [x] Missing decorator metadata (tsx, esbuild, SWC) no longer crashes; `@Body({ type })` supplies the type
|
|
1270
|
-
- [x] TypeORM query operators work at runtime
|
|
1271
|
-
- [x] `MeghRepository.transaction()` runs inside the transaction, and `@InjectRepository` works after `useTypeORM()`
|
|
1272
|
-
- [x] Collection fixes: `paginate`, `min`, `findAsync`
|
|
1273
|
-
- [x] One pagination shape across Collection, TypeORM and Knex
|
|
1274
|
-
- [x] Events keyed by class, exactly-once `once` listeners, `delay` honoured when queued, failed jobs kept
|
|
1275
|
-
- [x] Scheduler decorators no longer leak into parent classes
|
|
1276
|
-
- [x] In-memory cache enforces TTL; Redis tag sets expire
|
|
1277
|
-
- [x] JSON logs in production; framework logs go through `LoggerService`
|
|
1278
|
-
- [x] OpenAPI component schemas generated without instantiating classes
|
|
1279
|
-
|
|
1280
|
-
**Features**
|
|
1281
|
-
|
|
1282
|
-
- [x] Producer-only queues (`worker: false`) and workers that no longer start on import
|
|
1283
|
-
- [x] In-memory `memory` and `sync` queue drivers for tests
|
|
1284
|
-
- [x] `Results.Created` / `NoContent` / `OkStream` and `@HttpCode` APIs (not yet applied; see below)
|
|
1285
|
-
|
|
1286
|
-
**Packaging and tooling**
|
|
1287
|
-
|
|
1288
|
-
- [x] CommonJS-only build with an `exports` map and `sideEffects`
|
|
1289
|
-
- [x] Integrations moved to optional peer dependencies
|
|
1290
|
-
- [x] Replace typedi with Megh's own container behind `MeghContainer`
|
|
1291
|
-
- [x] MIT license file matches `package.json`
|
|
1292
|
-
- [x] Build without rimraf, ESLint/Jest configs fixed, husky 9, coverage off by default
|
|
1293
|
-
- [x] CI on Node 22 and 24 (typecheck, lint, test, build) and a tag-based publish workflow
|
|
1294
|
-
- [x] Request-pipeline integration tests
|
|
1295
|
-
|
|
1296
|
-
**Docs**
|
|
1297
|
-
|
|
1298
|
-
- [x] README and docs site rewritten for the current API, with an upgrade guide
|
|
1299
|
-
- [x] New pages: authentication, file uploads, caching, logging
|
|
1300
|
-
- [x] Docs site moved to VitePress, with template links removed and typos fixed
|
|
1301
|
-
|
|
1302
|
-
### Left for 1.0.0
|
|
1303
|
-
|
|
1304
|
-
**Regressions from 0.3.0** (see [Known Issues](#known-issues-in-030))
|
|
1305
|
-
|
|
1306
|
-
- [x] `@UseMiddleware(SomeClass)` crashes boot (fixed in 0.5.2)
|
|
1307
|
-
- [ ] `@Repository` / `@Queue` classes without a constructor break under DI
|
|
1308
|
-
- [ ] Apply status codes from `Results`, `HttpResponse.Created` and `@HttpCode`
|
|
1309
|
-
- [ ] Put `@Body()` / `@Query()` DTO schemas back into the OpenAPI document
|
|
1310
|
-
- [ ] Upload policy violations should return 400 / 413, not 500
|
|
1311
|
-
|
|
1312
|
-
**Core correctness**
|
|
1313
|
-
|
|
1314
|
-
- [ ] `useScheduler({ path })` crashes `run()` (wrong `require` path)
|
|
1315
|
-
- [ ] `@UploadFile` / `@UploadFiles` don't await `saveRequestFiles()`
|
|
1316
|
-
- [ ] `@All()` crashes at registration
|
|
1317
|
-
- [ ] Respect `error.statusCode` (401, 413, 415, 429, …) for non-HTTP-exception errors
|
|
1318
|
-
- [ ] One consistent middleware order; resolve `@UseMiddleware` through DI
|
|
1319
|
-
- [ ] Route metadata cache is keyed on `constructor.name`, so same-named classes collide
|
|
1320
|
-
- [ ] Controller discovery: `_resolveControllerDir` ignores its argument and rewrites the first `src` in the path; repeated `useControllers` calls overwrite each other
|
|
1321
|
-
- [ ] Functional routes: add `mapPatch`, and run authentication, DI and the standard error shape
|
|
1322
|
-
- [ ] `run()` `host` option (default `0.0.0.0` in containers)
|
|
1323
|
-
- [ ] Graceful shutdown: `app.close()` and close TypeORM, Knex, Redis and Socket.IO with a drain timeout instead of `process.exit(0)`
|
|
1324
|
-
- [ ] `PartialType` / `OmitType` / `PickType` don't carry class-validator rules correctly
|
|
1325
|
-
- [ ] Scalar `spec.content` returns the plugin module instead of the spec
|
|
1326
|
-
- [ ] `Environment` re-reads `.env` on every `get()`, and `dotenv` loads on import
|
|
1327
|
-
- [ ] Socket handler errors become unhandled rejections
|
|
1328
|
-
- [ ] `@MeghWorker` `autoStart` is not wired to app boot
|
|
1329
|
-
- [ ] `class-validator` / `class-transformer` are loaded at import time despite being optional peers
|
|
1330
|
-
|
|
1331
|
-
**Missing features**
|
|
1332
|
-
|
|
1333
|
-
- [ ] Security headers (helmet) and rate limiting as `use*` options
|
|
1334
|
-
- [ ] Health and readiness endpoints
|
|
1335
|
-
- [ ] Request IDs in logs, and the logger wired into Fastify
|
|
1336
|
-
- [ ] Redirects and response headers from handlers
|
|
1337
|
-
- [ ] Pluggable error handler / exception filters
|
|
1338
|
-
- [x] Lifecycle hooks (`onInit`, `onReady`, `onClose`, `app.close()`)
|
|
1339
|
-
- [ ] Config schema validation at boot
|
|
1340
|
-
- [ ] Global route prefix and API versioning
|
|
1341
|
-
- [ ] Compression
|
|
1342
|
-
- [ ] Socket.IO handshake authentication and per-channel authorization
|
|
1343
|
-
|
|
1344
|
-
**API cleanup** (a 1.0 surface is a promise)
|
|
1345
|
-
|
|
1346
|
-
- [ ] Finish or remove the no-ops `useHttps()`, `useSerialization()` and `mapFeatures()`
|
|
1347
|
-
- [x] Move TypeORM and Knex to the `@meghjs/data` plugin, and remove deprecated `useDatasource()`
|
|
1348
|
-
- [ ] Remove the `MeghSocketIo` stubs and unused adapter types
|
|
1349
|
-
- [ ] Remove `KnexHooks` / `KnexHooksFactory`, `DuplicateRouteException`, `mapRoute()` and `registerMiddleware()`
|
|
1350
|
-
- [x] Stop exporting `mock-db` from the public index, and build without Jest types
|
|
1351
|
-
- [ ] Replace remaining `console.log` calls with the logger
|
|
1352
|
-
|
|
1353
|
-
**Tests**
|
|
1354
|
-
|
|
1355
|
-
- [ ] `application.ts`: `run()`, shutdown, controller auto-discovery, `useScheduler({ path })`
|
|
1356
|
-
- [ ] Events, scheduler, workers, Redis cache, `testing.ts`, `map-types.ts`, config
|
|
1357
|
-
- [ ] Fix hollow tests and `MeghTest` (`from()` race, global container mutation)
|
|
1358
|
-
- [ ] Coverage thresholds
|
|
1359
|
-
|
|
1360
|
-
**CLI** (`@meghjs/cli`, rewrite in progress)
|
|
1361
|
-
|
|
1362
|
-
- [ ] Finish the commander-based rewrite: `--help` / `--version`, consistent flags and naming, refuse to overwrite existing projects
|
|
1363
|
-
- [ ] Generated code compiles against `@meghjs/core`
|
|
1364
|
-
- [ ] CLI tests (snapshots for every `make:*` command)
|
|
1365
|
-
- [ ] Release with versions matched to core
|
|
1366
|
-
|
|
1367
|
-
**Docs and release**
|
|
1368
|
-
|
|
1369
|
-
- [ ] Pages for configuration, scheduler, testing, dependency injection, responses, deployment and security hardening
|
|
1370
|
-
- [ ] API reference and FAQ
|
|
1371
|
-
- [ ] Contributor guide: project structure, and the exports that CLI-generated code relies on
|
|
1372
|
-
- [ ] Changelog and a versioning policy across core, CLI and docs
|
|
1282
|
+
1.0.0 is the first release with a stable API. Until then, minor releases
|
|
1283
|
+
(0.6, 0.7, …) can contain breaking changes, each with an upgrade guide.
|
|
1284
|
+
|
|
1285
|
+
Work left for 1.0.0 is tracked as issues in the
|
|
1286
|
+
[`1.0.0` milestone](https://github.com/meghjs/megh/milestone/1), with an
|
|
1287
|
+
overview in [`1.0-CHECKLIST.md`](https://github.com/meghjs/megh/blob/main/1.0-CHECKLIST.md).
|
|
1288
|
+
What's left is mainly core correctness fixes, security headers, rate limiting
|
|
1289
|
+
and compression, a global route prefix, tests, and trimming the public API.
|
|
1373
1290
|
|
|
1374
1291
|
---
|
|
1375
1292
|
|
package/dist/common/container.js
CHANGED
|
@@ -26,7 +26,6 @@ exports.DATASOURCE_META_KEY = Symbol("idatasource:options");
|
|
|
26
26
|
exports.AUTHORIZATION_META_KEY = Symbol("idatasource:authorization");
|
|
27
27
|
const controllerRegistry = new Set();
|
|
28
28
|
const serviceRegistry = new Set();
|
|
29
|
-
const optionsRegistry = new Map();
|
|
30
29
|
function registerController(controller) {
|
|
31
30
|
controllerRegistry.add(controller);
|
|
32
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/common/container.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/common/container.ts"],"names":[],"mappings":";;;AAsBA,gDAEC;AACD,0CAGC;AAED,sDAEC;AACD,4DAEC;AAID,0CAEC;AAzCD;;;;;GAKG;AACH,8BAAkC;AACrB,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,qBAAqB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACjD,QAAA,qBAAqB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACjD,QAAA,sBAAsB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAClD,QAAA,qBAAqB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACjD,QAAA,uBAAuB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACpD,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,sBAAsB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAE1E,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAY,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAI,GAAG,EAAY,CAAC;AAE5C,SAAgB,kBAAkB,CAAC,UAAoB;IACrD,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACrC,CAAC;AACD,SAAgB,eAAe,CAAC,OAAiB;IAC/C,cAAS,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC;AAED,SAAgB,qBAAqB;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACrC,CAAC;AACD,SAAgB,wBAAwB;IACtC,OAAO,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AACxC,CAAC;AAEY,QAAA,2BAA2B,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAEnE,SAAgB,eAAe,CAAC,MAAgB;IAC9C,OAAO,OAAO,CAAC,WAAW,CAAC,mCAA2B,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;AAC3E,CAAC"}
|
|
@@ -1,50 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @copyright 2024
|
|
3
|
-
* @author Tareq Hossain
|
|
4
|
-
* @email xtrinsic96@gmail.com
|
|
5
|
-
* @url https://github.com/xtareq
|
|
6
|
-
*/
|
|
7
|
-
export declare abstract class BaseHttpException extends Error {
|
|
8
|
-
code: number;
|
|
9
|
-
name: string;
|
|
10
|
-
payload: any;
|
|
11
|
-
constructor(message: any);
|
|
12
|
-
isCustomException(): boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare class BadRequestException extends BaseHttpException {
|
|
15
|
-
name: string;
|
|
16
|
-
code: number;
|
|
17
|
-
constructor(message: any);
|
|
18
|
-
}
|
|
19
|
-
export declare class ValidationErrorException extends BadRequestException {
|
|
20
|
-
name: string;
|
|
21
|
-
}
|
|
22
|
-
export declare class InternalErrorException extends BaseHttpException {
|
|
23
|
-
name: string;
|
|
24
|
-
code: number;
|
|
25
|
-
constructor(message?: any);
|
|
26
|
-
}
|
|
27
|
-
export declare class NotFoundException extends BaseHttpException {
|
|
28
|
-
name: string;
|
|
29
|
-
code: number;
|
|
30
|
-
constructor(message: any);
|
|
31
|
-
}
|
|
32
|
-
export declare class UnauthorizedException extends BaseHttpException {
|
|
33
|
-
name: string;
|
|
34
|
-
code: number;
|
|
35
|
-
constructor(message: any);
|
|
36
|
-
}
|
|
37
|
-
export declare class ForbiddenException extends BaseHttpException {
|
|
38
|
-
name: string;
|
|
39
|
-
code: number;
|
|
40
|
-
constructor(message: any);
|
|
41
|
-
}
|
|
42
|
-
export type HttpExceptionTypes = NotFoundException | BadRequestException | UnauthorizedException | InternalErrorException | ForbiddenException;
|
|
43
|
-
export declare const HttpExceptions: {
|
|
44
|
-
notFound: (message?: any) => NotFoundException;
|
|
45
|
-
validationError: (message?: any) => ValidationErrorException;
|
|
46
|
-
badRequest: (message?: any) => BadRequestException;
|
|
47
|
-
unauthorized: (message?: any) => UnauthorizedException;
|
|
48
|
-
forbidden: (message?: any) => ForbiddenException;
|
|
49
|
-
internalError: (message?: any) => InternalErrorException;
|
|
50
|
-
};
|
|
1
|
+
export * from "../../errors/http-exceptions";
|
|
@@ -1,84 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @email xtrinsic96@gmail.com
|
|
8
|
-
* @url https://github.com/xtareq
|
|
9
|
-
*/
|
|
10
|
-
class BaseHttpException extends Error {
|
|
11
|
-
code = 500;
|
|
12
|
-
name = "HttpException";
|
|
13
|
-
payload;
|
|
14
|
-
constructor(message) {
|
|
15
|
-
const stringMessage = typeof message === "string" ? message : JSON.stringify(message);
|
|
16
|
-
super(stringMessage);
|
|
17
|
-
this.payload = typeof message === "string" ? { message } : message;
|
|
18
|
-
}
|
|
19
|
-
isCustomException() {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.BaseHttpException = BaseHttpException;
|
|
24
|
-
class BadRequestException extends BaseHttpException {
|
|
25
|
-
name = "BadRequest";
|
|
26
|
-
code = 400;
|
|
27
|
-
constructor(message) {
|
|
28
|
-
super(message);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.BadRequestException = BadRequestException;
|
|
32
|
-
class ValidationErrorException extends BadRequestException {
|
|
33
|
-
name = "ValidationError";
|
|
34
|
-
}
|
|
35
|
-
exports.ValidationErrorException = ValidationErrorException;
|
|
36
|
-
class InternalErrorException extends BaseHttpException {
|
|
37
|
-
name = "InternalError";
|
|
38
|
-
code = 500;
|
|
39
|
-
constructor(message = "Something going wrong") {
|
|
40
|
-
super(message);
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
41
7
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.NotFoundException = NotFoundException;
|
|
52
|
-
class UnauthorizedException extends BaseHttpException {
|
|
53
|
-
name = "Unauthorized";
|
|
54
|
-
code = 401;
|
|
55
|
-
constructor(message) {
|
|
56
|
-
super(message);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.UnauthorizedException = UnauthorizedException;
|
|
60
|
-
class ForbiddenException extends BaseHttpException {
|
|
61
|
-
name = "Forbidden";
|
|
62
|
-
code = 403;
|
|
63
|
-
constructor(message) {
|
|
64
|
-
super(message);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.ForbiddenException = ForbiddenException;
|
|
68
|
-
// export type HttpExceptions = {
|
|
69
|
-
// NotFound: (message: any) => NotFoundException,
|
|
70
|
-
// ValidationError: (message: any) =>ValidationErrorException,
|
|
71
|
-
// BadRequest: (message: any) => BadRequestException,
|
|
72
|
-
// Unauthorized: (message: any) => UnauthorizedException,
|
|
73
|
-
// Forbidden: (message: any) => ForbiddenException,
|
|
74
|
-
// InternalError: (message: any) => InternalErrorException
|
|
75
|
-
// }
|
|
76
|
-
exports.HttpExceptions = {
|
|
77
|
-
notFound: (message = "") => new NotFoundException(message),
|
|
78
|
-
validationError: (message = "") => new ValidationErrorException(message),
|
|
79
|
-
badRequest: (message = "") => new BadRequestException(message),
|
|
80
|
-
unauthorized: (message = "") => new UnauthorizedException(message),
|
|
81
|
-
forbidden: (message = "") => new ForbiddenException(message),
|
|
82
|
-
internalError: (message = "") => new InternalErrorException(message),
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
83
15
|
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Moved to `src/errors`. Re-exported so existing imports keep working.
|
|
18
|
+
__exportStar(require("../../errors/http-exceptions"), exports);
|
|
84
19
|
//# sourceMappingURL=http-exceptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-exceptions.js","sourceRoot":"","sources":["../../../src/common/exceptions/http-exceptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-exceptions.js","sourceRoot":"","sources":["../../../src/common/exceptions/http-exceptions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uEAAuE;AACvE,+DAA6C"}
|
|
@@ -4,19 +4,9 @@
|
|
|
4
4
|
* @email xtrinsic96@gmail.com
|
|
5
5
|
* @url https://github.com/xtareq
|
|
6
6
|
*/
|
|
7
|
-
export interface IRouteDuplicateErr {
|
|
8
|
-
path: string;
|
|
9
|
-
mpath: string;
|
|
10
|
-
method: string;
|
|
11
|
-
controller: string;
|
|
12
|
-
inverseController?: string;
|
|
13
|
-
}
|
|
14
7
|
export declare class SystemUseError extends Error {
|
|
15
8
|
constructor(message: string);
|
|
16
9
|
}
|
|
17
|
-
export declare class DuplicateRouteException extends Error {
|
|
18
|
-
constructor(params: IRouteDuplicateErr);
|
|
19
|
-
}
|
|
20
10
|
export declare class EnvironmentVariableNotFound extends Error {
|
|
21
11
|
constructor(key: string);
|
|
22
12
|
}
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnvironmentVariableNotFound = exports.
|
|
3
|
+
exports.EnvironmentVariableNotFound = exports.SystemUseError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @copyright 2024
|
|
6
|
+
* @author Tareq Hossain
|
|
7
|
+
* @email xtrinsic96@gmail.com
|
|
8
|
+
* @url https://github.com/xtareq
|
|
9
|
+
*/
|
|
4
10
|
class SystemUseError extends Error {
|
|
5
11
|
constructor(message) {
|
|
6
12
|
super(message);
|
|
7
13
|
}
|
|
8
14
|
}
|
|
9
15
|
exports.SystemUseError = SystemUseError;
|
|
10
|
-
class DuplicateRouteException extends Error {
|
|
11
|
-
constructor(params) {
|
|
12
|
-
let sameController = params.controller == params.inverseController;
|
|
13
|
-
let message = `Duplicate route found for method ${params.method.toUpperCase()}:${params.path == "" ? "'/'" : params.path} `;
|
|
14
|
-
message += sameController
|
|
15
|
-
? `in ${params.controller}`
|
|
16
|
-
: `both in ${params.controller} and ${params.inverseController}`;
|
|
17
|
-
super(message);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.DuplicateRouteException = DuplicateRouteException;
|
|
21
16
|
class EnvironmentVariableNotFound extends Error {
|
|
22
17
|
constructor(key) {
|
|
23
18
|
super(`${key} not found in environment variables.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-exception.js","sourceRoot":"","sources":["../../../src/common/exceptions/system-exception.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"system-exception.js","sourceRoot":"","sources":["../../../src/common/exceptions/system-exception.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,wCAIC;AACD,MAAa,2BAA4B,SAAQ,KAAK;IACpD,YAAY,GAAW;QACrB,KAAK,CAAC,GAAG,GAAG,sCAAsC,CAAC,CAAC;IACtD,CAAC;CACF;AAJD,kEAIC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2024
|
|
3
|
+
* @author Tareq Hossain
|
|
4
|
+
* @email xtrinsic96@gmail.com
|
|
5
|
+
* @url https://github.com/xtareq
|
|
6
|
+
*
|
|
7
|
+
* Experimental: compiled request DTO validation.
|
|
8
|
+
*
|
|
9
|
+
* `transformAndValidate` runs `plainToInstance` and then class-validator's
|
|
10
|
+
* `validate()` on every request. Both re-read decorator metadata, allocate a
|
|
11
|
+
* `ValidationError` per property and go through promises even when every
|
|
12
|
+
* constraint is synchronous.
|
|
13
|
+
*
|
|
14
|
+
* `compileValidator` reads the same metadata once per DTO class and returns a
|
|
15
|
+
* synchronous function that does the same work: it builds the instance the way
|
|
16
|
+
* `plainToInstance` does, then calls the same constraint objects in the same
|
|
17
|
+
* order with the same options (`whitelist` + `forbidNonWhitelisted`). Messages
|
|
18
|
+
* are built only when a constraint fails, with class-validator's own message
|
|
19
|
+
* functions and token replacement. The result is the same `{ value, errors }`
|
|
20
|
+
* that `transformAndValidate` returns.
|
|
21
|
+
*
|
|
22
|
+
* Only DTOs whose behaviour can be reproduced exactly are compiled. Anything
|
|
23
|
+
* else returns `undefined` from `compileValidator`, and the caller keeps using
|
|
24
|
+
* `transformAndValidate`:
|
|
25
|
+
* - class-transformer metadata on the class (`@Type`, `@Transform`,
|
|
26
|
+
* `@Expose`, `@Exclude`)
|
|
27
|
+
* - nested or promise validation (`@ValidateNested`, `@ValidatePromise`)
|
|
28
|
+
* - constraints declared `async`
|
|
29
|
+
* - a class with no applicable validation metadata
|
|
30
|
+
* At request time the compiled function returns `undefined` (meaning "use the
|
|
31
|
+
* slow path for this request") if a constraint returns a promise anyway, or the
|
|
32
|
+
* payload holds an object the plain-copy rules don't cover.
|
|
33
|
+
*/
|
|
34
|
+
import { Constructor } from "./common-utils";
|
|
35
|
+
import type { RequestValidationResult } from "./validation-utils";
|
|
36
|
+
/** A compiled validator. `undefined` means: validate this payload the slow way. */
|
|
37
|
+
export type CompiledValidator<T = any> = (value: unknown) => RequestValidationResult<T> | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Compile a validator for the DTO class `target`, or return `undefined` when
|
|
40
|
+
* the class uses something the compiled path does not reproduce exactly.
|
|
41
|
+
* Results are cached per class.
|
|
42
|
+
*/
|
|
43
|
+
export declare function compileValidator<T extends object>(target: Constructor<T>): CompiledValidator<T> | undefined;
|