@rapidrest/service-core 1.0.0-rc.2 → 1.0.0-rc.21
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/dist/lib/BackgroundService.js +0 -4
- package/dist/lib/BackgroundService.js.map +1 -1
- package/dist/lib/BackgroundServiceManager.js +21 -4
- package/dist/lib/BackgroundServiceManager.js.map +1 -1
- package/dist/lib/EventListenerManager.js.map +1 -1
- package/dist/lib/OpenApiSpec.js +3 -2
- package/dist/lib/OpenApiSpec.js.map +1 -1
- package/dist/lib/Server.js +18 -79
- package/dist/lib/Server.js.map +1 -1
- package/dist/lib/database/TypeOrmSupport.js +18 -2
- package/dist/lib/database/TypeOrmSupport.js.map +1 -1
- package/dist/lib/decorators/DocDecorators.js +19 -1
- package/dist/lib/decorators/DocDecorators.js.map +1 -1
- package/dist/lib/decorators/PersistenceDecorators.js.map +1 -1
- package/dist/lib/decorators/RouteDecorators.js +71 -20
- package/dist/lib/decorators/RouteDecorators.js.map +1 -1
- package/dist/lib/http/Adapters.js +45 -2
- package/dist/lib/http/Adapters.js.map +1 -1
- package/dist/lib/http/Router.js +53 -56
- package/dist/lib/http/Router.js.map +1 -1
- package/dist/lib/models/ModelUtils.js +18 -8
- package/dist/lib/models/ModelUtils.js.map +1 -1
- package/dist/lib/models/RepoUtils.js +96 -31
- package/dist/lib/models/RepoUtils.js.map +1 -1
- package/dist/lib/routes/{AdminRoute.js → BaseAdminRoute.js} +51 -36
- package/dist/lib/routes/BaseAdminRoute.js.map +1 -0
- package/dist/lib/routes/{MetricsRoute.js → BaseMetricsRoute.js} +28 -15
- package/dist/lib/routes/BaseMetricsRoute.js.map +1 -0
- package/dist/lib/routes/{OpenAPIRoute.js → BaseOpenAPIRoute.js} +31 -32
- package/dist/lib/routes/BaseOpenAPIRoute.js.map +1 -0
- package/dist/lib/routes/BasePushRoute.js +193 -0
- package/dist/lib/routes/BasePushRoute.js.map +1 -0
- package/dist/lib/routes/BaseStaticRoute.js +152 -0
- package/dist/lib/routes/BaseStaticRoute.js.map +1 -0
- package/dist/lib/routes/BaseStatusRoute.js +79 -0
- package/dist/lib/routes/BaseStatusRoute.js.map +1 -0
- package/dist/lib/routes/CRUDRoute.js +238 -0
- package/dist/lib/routes/CRUDRoute.js.map +1 -0
- package/dist/lib/routes/ModelRoute.js +20 -28
- package/dist/lib/routes/ModelRoute.js.map +1 -1
- package/dist/lib/routes/index.js +7 -4
- package/dist/lib/routes/index.js.map +1 -1
- package/dist/lib/security/ACLUtils.js +10 -13
- package/dist/lib/security/ACLUtils.js.map +1 -1
- package/dist/lib/security/AccessControlListMongo.js +5 -1
- package/dist/lib/security/AccessControlListMongo.js.map +1 -1
- package/dist/lib/security/AccessControlListSQL.js +7 -3
- package/dist/lib/security/AccessControlListSQL.js.map +1 -1
- package/dist/lib/security/BaseACLRoute.js +239 -0
- package/dist/lib/security/BaseACLRoute.js.map +1 -0
- package/dist/lib/security/index.js +3 -0
- package/dist/lib/security/index.js.map +1 -1
- package/dist/lib/test/request.js +6 -2
- package/dist/lib/test/request.js.map +1 -1
- package/dist/types/BackgroundService.d.ts +0 -5
- package/dist/types/BackgroundServiceManager.d.ts +1 -1
- package/dist/types/EventListenerManager.d.ts +4 -4
- package/dist/types/Server.d.ts +21 -6
- package/dist/types/decorators/DocDecorators.d.ts +9 -0
- package/dist/types/decorators/PersistenceDecorators.d.ts +7 -0
- package/dist/types/decorators/RouteDecorators.d.ts +14 -5
- package/dist/types/http/Adapters.d.ts +19 -0
- package/dist/types/http/Router.d.ts +6 -6
- package/dist/types/models/ModelUtils.d.ts +2 -1
- package/dist/types/routes/BaseAdminRoute.d.ts +59 -0
- package/dist/types/routes/BaseMetricsRoute.d.ts +37 -0
- package/dist/types/routes/BaseOpenAPIRoute.d.ts +33 -0
- package/dist/types/routes/BasePushRoute.d.ts +39 -0
- package/dist/types/routes/BaseStaticRoute.d.ts +44 -0
- package/dist/types/routes/BaseStatusRoute.d.ts +37 -0
- package/dist/types/routes/CRUDRoute.d.ts +47 -0
- package/dist/types/routes/ModelRoute.d.ts +23 -16
- package/dist/types/routes/index.d.ts +7 -4
- package/dist/types/security/ACLUtils.d.ts +1 -1
- package/dist/types/security/AccessControlList.d.ts +1 -1
- package/dist/types/security/AccessControlListMongo.d.ts +1 -1
- package/dist/types/security/AccessControlListSQL.d.ts +1 -1
- package/dist/types/security/BaseACLRoute.d.ts +73 -0
- package/dist/types/security/index.d.ts +3 -0
- package/package.json +132 -129
- package/tsconfig.export.json +17 -0
- package/dist/lib/routes/AdminRoute.js.map +0 -1
- package/dist/lib/routes/MetricsRoute.js.map +0 -1
- package/dist/lib/routes/OpenAPIRoute.js.map +0 -1
- package/dist/lib/routes/StatusRoute.js +0 -55
- package/dist/lib/routes/StatusRoute.js.map +0 -1
- package/dist/lib/security/ACLRouteMongo.js +0 -194
- package/dist/lib/security/ACLRouteMongo.js.map +0 -1
- package/dist/lib/security/ACLRouteSQL.js +0 -193
- package/dist/lib/security/ACLRouteSQL.js.map +0 -1
- package/dist/types/routes/AdminRoute.d.ts +0 -47
- package/dist/types/routes/MetricsRoute.d.ts +0 -15
- package/dist/types/routes/OpenAPIRoute.d.ts +0 -17
- package/dist/types/routes/StatusRoute.d.ts +0 -11
- package/dist/types/security/ACLRouteMongo.d.ts +0 -19
- package/dist/types/security/ACLRouteSQL.d.ts +0 -19
- package/docs/Makefile +0 -20
- package/docs/conf.py +0 -58
- package/docs/index.rst +0 -17
- package/docs/make.bat +0 -35
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/README.md +0 -13
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/MongoRepository.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/RedisConnection.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/Repository.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/README.md +0 -23
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Default.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Description.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Document.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Example.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Format.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Returns.md +0 -28
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Summary.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Tags.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/TypeInfo.md +0 -28
- package/docs/reference/@rapidrest/namespaces/DocDecorators/interfaces/DocumentsData.md +0 -57
- package/docs/reference/@rapidrest/namespaces/EventDecorators/README.md +0 -12
- package/docs/reference/@rapidrest/namespaces/EventDecorators/functions/EventListener.md +0 -17
- package/docs/reference/@rapidrest/namespaces/EventDecorators/functions/OnEvent.md +0 -26
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/README.md +0 -26
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Cache.md +0 -25
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/ChildEntity.md +0 -18
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/DataStore.md +0 -25
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Identifier.md +0 -27
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Protect.md +0 -35
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Reference.md +0 -25
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Shard.md +0 -27
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/TrackChanges.md +0 -26
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/interfaces/PendingTypeOrmColumn.md +0 -45
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/variables/pendingTypeOrmColumns.md +0 -14
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/README.md +0 -27
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Column.md +0 -25
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Entity.md +0 -25
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Index.md +0 -119
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/PrimaryColumn.md +0 -25
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Unique.md +0 -68
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getColumnMetadata.md +0 -26
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getEntityName.md +0 -26
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getIndexMetadata.md +0 -27
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/CollationOptions.md +0 -79
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/ColumnInfo.md +0 -41
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/ColumnOptions.md +0 -51
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/EntityOptions.md +0 -32
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/IndexInfo.md +0 -41
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/IndexOptions.md +0 -61
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/README.md +0 -36
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/After.md +0 -26
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Auth.md +0 -33
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/AuthResult.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Before.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/ContentType.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Delete.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Get.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Head.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Header.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Method.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Model.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Options.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Param.md +0 -26
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Patch.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Post.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Protect.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Put.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Query.md +0 -26
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Request.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/RequiresRole.md +0 -26
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Response.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Route.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Socket.md +0 -33
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/User.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Validate.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/WebSocket.md +0 -25
- package/docs/reference/README.md +0 -20
- package/docs/reference/classes/ACLUtils.md +0 -263
- package/docs/reference/classes/AdminRoute.md +0 -51
- package/docs/reference/classes/AuthMiddleware.md +0 -173
- package/docs/reference/classes/BackgroundService.md +0 -117
- package/docs/reference/classes/BackgroundServiceManager.md +0 -172
- package/docs/reference/classes/BaseEntity.md +0 -82
- package/docs/reference/classes/BaseMongoEntity.md +0 -107
- package/docs/reference/classes/BasicStrategy.md +0 -131
- package/docs/reference/classes/BasicStrategyOptions.md +0 -115
- package/docs/reference/classes/BulkError.md +0 -271
- package/docs/reference/classes/ConnectionManager.md +0 -75
- package/docs/reference/classes/EventListenerManager.md +0 -88
- package/docs/reference/classes/HttpRouter.md +0 -343
- package/docs/reference/classes/JWTStrategy.md +0 -100
- package/docs/reference/classes/JWTStrategyOptions.md +0 -97
- package/docs/reference/classes/MetricsRoute.md +0 -27
- package/docs/reference/classes/ModelRoute.md +0 -527
- package/docs/reference/classes/ModelUtils.md +0 -430
- package/docs/reference/classes/MongoConnection.md +0 -218
- package/docs/reference/classes/MongoRepository.md +0 -390
- package/docs/reference/classes/MongoSchemaSync.md +0 -97
- package/docs/reference/classes/NetUtils.md +0 -90
- package/docs/reference/classes/NotificationUtils.md +0 -77
- package/docs/reference/classes/ObjectFactory.md +0 -336
- package/docs/reference/classes/OpenAPIRoute.md +0 -77
- package/docs/reference/classes/OpenApiSpec.md +0 -892
- package/docs/reference/classes/RecoverableBaseEntity.md +0 -114
- package/docs/reference/classes/RecoverableBaseMongoEntity.md +0 -124
- package/docs/reference/classes/RedisTransport.md +0 -2202
- package/docs/reference/classes/RepoUtils.md +0 -482
- package/docs/reference/classes/RouteUtils.md +0 -191
- package/docs/reference/classes/Server.md +0 -408
- package/docs/reference/classes/SimpleEntity.md +0 -48
- package/docs/reference/classes/SimpleMongoEntity.md +0 -66
- package/docs/reference/classes/StatusExtraData.md +0 -57
- package/docs/reference/classes/StatusRoute.md +0 -26
- package/docs/reference/classes/UWSRequest.md +0 -226
- package/docs/reference/classes/UWSResponse.md +0 -257
- package/docs/reference/classes/UWSWebSocketShim.md +0 -958
- package/docs/reference/enumerations/ACLAction.md +0 -63
- package/docs/reference/enumerations/ApiErrorMessages.md +0 -123
- package/docs/reference/enumerations/ApiErrors.md +0 -123
- package/docs/reference/functions/createWebSocketStream.md +0 -27
- package/docs/reference/functions/isSqlDataSource.md +0 -26
- package/docs/reference/functions/readBody.md +0 -29
- package/docs/reference/functions/resolveCollectionName.md +0 -33
- package/docs/reference/functions/runChain.md +0 -40
- package/docs/reference/functions/snakeCase.md +0 -28
- package/docs/reference/globals.md +0 -106
- package/docs/reference/interfaces/ACLRecord.md +0 -96
- package/docs/reference/interfaces/AccessControlList.md +0 -76
- package/docs/reference/interfaces/AuthResult.md +0 -55
- package/docs/reference/interfaces/AuthStrategy.md +0 -95
- package/docs/reference/interfaces/CreateRequestOptions.md +0 -121
- package/docs/reference/interfaces/DeleteRequestOptions.md +0 -137
- package/docs/reference/interfaces/FindRequestOptions.md +0 -133
- package/docs/reference/interfaces/HttpRequest.md +0 -147
- package/docs/reference/interfaces/HttpResponse.md +0 -164
- package/docs/reference/interfaces/JWTAuthResult.md +0 -84
- package/docs/reference/interfaces/RepoCreateOptions.md +0 -95
- package/docs/reference/interfaces/RepoDeleteOptions.md +0 -105
- package/docs/reference/interfaces/RepoFindOptions.md +0 -125
- package/docs/reference/interfaces/RepoOperationOptions.md +0 -69
- package/docs/reference/interfaces/RepoUpdateOptions.md +0 -101
- package/docs/reference/interfaces/RequestOptions.md +0 -112
- package/docs/reference/interfaces/RequestWS.md +0 -225
- package/docs/reference/interfaces/TruncateRequestOptions.md +0 -161
- package/docs/reference/interfaces/UpdateRequestOptions.md +0 -139
- package/docs/reference/type-aliases/ErrorHandler.md +0 -35
- package/docs/reference/type-aliases/NextFunction.md +0 -23
- package/docs/reference/type-aliases/OneOrMany.md +0 -19
- package/docs/reference/type-aliases/OneOrNull.md +0 -19
- package/docs/reference/type-aliases/PartialBaseEntity.md +0 -17
- package/docs/reference/type-aliases/PartialSimpleEntity.md +0 -17
- package/docs/reference/type-aliases/RequestHandler.md +0 -31
- package/docs/reference/type-aliases/UpdateObject.md +0 -19
- package/docs/reference/type-aliases/WsUpgradeAuth.md +0 -27
- package/docs/reference/type-aliases/WsUpgradeAuthResult.md +0 -47
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
14
|
+
// Copyright (C) 2020-2026 Jean-Philippe Steinmetz
|
|
15
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
16
|
+
import { Get, Request, Response } from "../decorators/RouteDecorators.js";
|
|
17
|
+
import { Summary } from "../decorators/DocDecorators.js";
|
|
18
|
+
import * as fs from "fs";
|
|
19
|
+
import * as path from "path";
|
|
20
|
+
import { ObjectDecorators } from "@rapidrest/core";
|
|
21
|
+
const { Config, Init } = ObjectDecorators;
|
|
22
|
+
/** MIME types for static file serving. */
|
|
23
|
+
const MIME_TYPES = {
|
|
24
|
+
".html": "text/html",
|
|
25
|
+
".css": "text/css",
|
|
26
|
+
".js": "application/javascript",
|
|
27
|
+
".mjs": "application/javascript",
|
|
28
|
+
".json": "application/json",
|
|
29
|
+
".png": "image/png",
|
|
30
|
+
".jpg": "image/jpeg",
|
|
31
|
+
".jpeg": "image/jpeg",
|
|
32
|
+
".gif": "image/gif",
|
|
33
|
+
".svg": "image/svg+xml",
|
|
34
|
+
".ico": "image/x-icon",
|
|
35
|
+
".woff": "font/woff",
|
|
36
|
+
".woff2": "font/woff2",
|
|
37
|
+
".ttf": "font/ttf",
|
|
38
|
+
".txt": "text/plain",
|
|
39
|
+
".map": "application/json",
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The `BaseStaticRoute` class provides a single endpoint for serving static files from a designated path on the filesystem (e.g. `./public`).
|
|
43
|
+
* Uses the path specified in the project configuration key `static_files`. Default is `public`.
|
|
44
|
+
*
|
|
45
|
+
* Exposed endpoints:
|
|
46
|
+
*
|
|
47
|
+
* | Name | HTTP Method | What it does |
|
|
48
|
+
* | --- | --- | --- |
|
|
49
|
+
* | `get` | `GET /<base_path>/*` | Serves static files from the configured `static_files`. |
|
|
50
|
+
*
|
|
51
|
+
* !!Note!! that the `BaseStaticRoute` is not automatically registered with a server by default. You must create
|
|
52
|
+
* your own class that extends `AdminRoute` and apply the desired base path with `@Route()`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { BaseStaticRoute, RouteDecorators } from "@rapidrest/service-core";
|
|
57
|
+
* const { Route } = RouteDecorators;
|
|
58
|
+
*
|
|
59
|
+
* @Route("/static")
|
|
60
|
+
* export class StaticRoute extends BaseStaticRoute {}
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @author Jean-Philippe Steinmetz
|
|
64
|
+
*/
|
|
65
|
+
let BaseStaticRoute = class BaseStaticRoute {
|
|
66
|
+
constructor() {
|
|
67
|
+
/**
|
|
68
|
+
* The URL prefix derived from `@Route` metadata at init time.
|
|
69
|
+
* E.g. `@Route("/app/*")` → prefix = "/app". Used to strip the prefix from req.path
|
|
70
|
+
* before resolving app page files, and to scope the dev-reload SSE endpoint.
|
|
71
|
+
*/
|
|
72
|
+
this.routePrefix = "";
|
|
73
|
+
/** The location of the static files to serve. Defaults to `./public`. */
|
|
74
|
+
this.staticDir = "public";
|
|
75
|
+
}
|
|
76
|
+
async init() {
|
|
77
|
+
// Derive the route prefix from @Route metadata so page resolution is prefix-agnostic.
|
|
78
|
+
// @Route("/app/*") → prefix "/app", @Route("/*") → prefix ""
|
|
79
|
+
const routePaths = Reflect.getMetadata("rrst:routePaths", Object.getPrototypeOf(this)) || [];
|
|
80
|
+
this.routePrefix = (routePaths[0] || "")
|
|
81
|
+
.replace(/\/\*$/, "") // strip trailing /*
|
|
82
|
+
.replace(/\/$/, ""); // strip trailing /
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolve a file in the static directory by trying multiple extensions in order.
|
|
86
|
+
* If the path segment ends in a `/`, `index.html` is automatically appended.
|
|
87
|
+
*
|
|
88
|
+
* @returns The full path to the file on disk if exists, otherwise `null`.
|
|
89
|
+
*/
|
|
90
|
+
resolveFile(segment) {
|
|
91
|
+
const root = path.resolve(process.cwd(), this.staticDir);
|
|
92
|
+
let file = path.resolve(root, segment.replace(/^\//, ""));
|
|
93
|
+
if (file.endsWith("/")) {
|
|
94
|
+
file += "index.html";
|
|
95
|
+
}
|
|
96
|
+
// Reject any path that escapes the configured static directory (e.g. via `../` segments).
|
|
97
|
+
// Without this check a request path is joined onto `root` and resolved as-is, so a raw
|
|
98
|
+
// (non-normalizing) HTTP client could read arbitrary files reachable from `root`.
|
|
99
|
+
if (file !== root && !file.startsWith(root + path.sep)) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (fs.existsSync(file)) {
|
|
103
|
+
return file;
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
async get(req, res) {
|
|
108
|
+
// Strip the route prefix (e.g. "/app" from "/app/pets" → "/pets") so the page
|
|
109
|
+
// file resolution is independent of where the route is mounted.
|
|
110
|
+
const subPath = this.routePrefix && req.path.startsWith(this.routePrefix)
|
|
111
|
+
? req.path.slice(this.routePrefix.length) || "/"
|
|
112
|
+
: req.path;
|
|
113
|
+
const requestedPath = subPath === "/" ? "index.html" : subPath.replace(/^\/+/, "");
|
|
114
|
+
const filePath = this.resolveFile(requestedPath);
|
|
115
|
+
if (!filePath) {
|
|
116
|
+
res.status(404).end();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const ext = path.extname(filePath);
|
|
121
|
+
const data = await fs.promises.readFile(filePath);
|
|
122
|
+
res.setHeader("content-type", MIME_TYPES[ext] || "application/octet-stream");
|
|
123
|
+
res.end(data);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
res.status(404).end();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
__decorate([
|
|
131
|
+
Config("static_files", "public"),
|
|
132
|
+
__metadata("design:type", String)
|
|
133
|
+
], BaseStaticRoute.prototype, "staticDir", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
Init,
|
|
136
|
+
__metadata("design:type", Function),
|
|
137
|
+
__metadata("design:paramtypes", []),
|
|
138
|
+
__metadata("design:returntype", Promise)
|
|
139
|
+
], BaseStaticRoute.prototype, "init", null);
|
|
140
|
+
__decorate([
|
|
141
|
+
Get("/*"),
|
|
142
|
+
__param(0, Request),
|
|
143
|
+
__param(1, Response),
|
|
144
|
+
__metadata("design:type", Function),
|
|
145
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
146
|
+
__metadata("design:returntype", Promise)
|
|
147
|
+
], BaseStaticRoute.prototype, "get", null);
|
|
148
|
+
BaseStaticRoute = __decorate([
|
|
149
|
+
Summary("Serves static files from the filesystem.")
|
|
150
|
+
], BaseStaticRoute);
|
|
151
|
+
export { BaseStaticRoute };
|
|
152
|
+
//# sourceMappingURL=BaseStaticRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseStaticRoute.js","sourceRoot":"","sources":["../../../src/routes/BaseStaticRoute.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+EAA+E;AAC/E,kDAAkD;AAClD,+EAA+E;AAC/E,OAAO,EAAE,GAAG,EAAE,OA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C,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACnF,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;YACtB,OAAO;QACX,CAAC;QAED,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACnC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAClD,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,0BAA0B,CAAC,CAAC;YAC7E,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;QAAC,MAAM,CAAC;YACL,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QAC1B,CAAC;IACL,CAAC;CACJ,CAAA;AAhEsB;IADlB,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC;;kDACe;AAGhC;IADf,IAAI;;;;2CAQJ;AA8BY;IADZ,GAAG,CAAC,IAAI,CAAC;IACQ,WAAA,OAAO,CAAA;IAAoB,WAAA,QAAQ,CAAA;;;;0CAuBpD;AAzEQ,eAAe;IAD3B,OAAO,CAAC,0CAA0C,CAAC;GACvC,eAAe,CA0E3B"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
11
|
+
// Copyright (C) 2020-2026 Jean-Philippe Steinmetz
|
|
12
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
13
|
+
import { Get } from "../decorators/RouteDecorators.js";
|
|
14
|
+
import { Description, Returns, Summary } from "../decorators/DocDecorators.js";
|
|
15
|
+
import { ObjectDecorators } from "@rapidrest/core";
|
|
16
|
+
import { StatusExtraData } from "../models/StatusExtraData.js";
|
|
17
|
+
const { Config, Inject } = ObjectDecorators;
|
|
18
|
+
/**
|
|
19
|
+
* The `BaseStatusRoute` class provides a base set of endpoints exposing status metadata information about the server.
|
|
20
|
+
*
|
|
21
|
+
* Included Metadata:
|
|
22
|
+
* | Name | Description |
|
|
23
|
+
* | --- | --- |
|
|
24
|
+
* | `name` | The name of the server (e.g. `petstore_example`) |
|
|
25
|
+
* | `time` | The current UTC timestamp of the server |
|
|
26
|
+
* | `version` | The release version of the server. (e.g. `1.0.0`) |
|
|
27
|
+
*
|
|
28
|
+
* Exposed endpoints:
|
|
29
|
+
*
|
|
30
|
+
* | Name | HTTP Method | What it does |
|
|
31
|
+
* | --- | --- | --- |
|
|
32
|
+
* | `get` | `GET /<base_path>` | Returns the server's status metadata |
|
|
33
|
+
*
|
|
34
|
+
* !!Note!! that the `BaseAdminRoute` is not automatically registered with a server by default. You must create
|
|
35
|
+
* your own class that extends `AdminRoute` and apply the desired base path with `@Route()`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { BaseStatusRoute, RouteDecorators } from "@rapidrest/service-core";
|
|
40
|
+
* const { Route } = RouteDecorators;
|
|
41
|
+
*
|
|
42
|
+
* @Route("/status")
|
|
43
|
+
* export class StatusRoute extends BaseStatusRoute {}
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @author Jean-Philippe Steinmetz
|
|
47
|
+
*/
|
|
48
|
+
export class BaseStatusRoute {
|
|
49
|
+
get() {
|
|
50
|
+
return {
|
|
51
|
+
name: this.serviceName,
|
|
52
|
+
time: Date.now(),
|
|
53
|
+
version: this.serviceVersion,
|
|
54
|
+
...this.statusExtraData?.data,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
__decorate([
|
|
59
|
+
Config("service_name"),
|
|
60
|
+
__metadata("design:type", Object)
|
|
61
|
+
], BaseStatusRoute.prototype, "serviceName", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
Config("version"),
|
|
64
|
+
__metadata("design:type", Object)
|
|
65
|
+
], BaseStatusRoute.prototype, "serviceVersion", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
Inject(StatusExtraData),
|
|
68
|
+
__metadata("design:type", Object)
|
|
69
|
+
], BaseStatusRoute.prototype, "statusExtraData", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
Summary("Server status"),
|
|
72
|
+
Description("Returns information about the server and it's operational status."),
|
|
73
|
+
Get(),
|
|
74
|
+
Returns([Object]),
|
|
75
|
+
__metadata("design:type", Function),
|
|
76
|
+
__metadata("design:paramtypes", []),
|
|
77
|
+
__metadata("design:returntype", Object)
|
|
78
|
+
], BaseStatusRoute.prototype, "get", null);
|
|
79
|
+
//# sourceMappingURL=BaseStatusRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseStatusRoute.js","sourceRoot":"","sources":["../../../src/routes/BaseStatusRoute.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+EAA+E;AAC/E,kDAAkD;AAClD,+EAA+E;AAC/E,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,eAAe;IAajB,GAAG;QACN,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,WAAW;YACtB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,OAAO,EAAE,IAAI,CAAC,cAAc;YAC5B,GAAG,IAAI,CAAC,eAAe,EAAE,IAAI;SAChC,CAAC;IACN,CAAC;CACJ;AAnBa;IADT,MAAM,CAAC,cAAc,CAAC;;oDACI;AAEjB;IADT,MAAM,CAAC,SAAS,CAAC;;uDACY;AAGpB;IADT,MAAM,CAAC,eAAe,CAAC;;wDAC+B;AAMhD;IAJN,OAAO,CAAC,eAAe,CAAC;IACxB,WAAW,CAAC,mEAAmE,CAAC;IAChF,GAAG,EAAE;IACL,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;;;;0CAQjB"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
14
|
+
// Copyright (C) 2020-2026 Jean-Philippe Steinmetz. All rights reserved.
|
|
15
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
16
|
+
import { RepoUtils } from "../models/RepoUtils.js";
|
|
17
|
+
import { Description, Returns, Summary, TypeInfo } from "../decorators/DocDecorators.js";
|
|
18
|
+
import { Delete, Get, Head, Param, Post, Put, Query, Request, Response, User, Validate, } from "../decorators/RouteDecorators.js";
|
|
19
|
+
import { ModelRoute } from "./ModelRoute.js";
|
|
20
|
+
/**
|
|
21
|
+
* The `CRUDRoute` provides a base implementation of all CRUD endpoint behaviors that `ModelRoute` offers for a given
|
|
22
|
+
* data model class. This class provides the most common default settings for each route handler. If you desire additional
|
|
23
|
+
* functionality you may override the handler function and add desired functionality via additional decorators or override
|
|
24
|
+
* existing decorator behavior.
|
|
25
|
+
*
|
|
26
|
+
* The route endpoints provided by this class do not explicitly require authentication. However, if the RBAC system
|
|
27
|
+
* is enabled these handlers will still validate permissions appropriately.
|
|
28
|
+
*
|
|
29
|
+
* Included Endpoints:
|
|
30
|
+
*
|
|
31
|
+
* | Name | HTTP Method | What it does |
|
|
32
|
+
* | --- | --- | --- |
|
|
33
|
+
* | `count` | `HEAD /` | Counts the number of objects matching the provided set of criteria in the request's query parameters. Returns the count as the value of the `Content-Length` header. |
|
|
34
|
+
* | `create` | `POST /` | Adds one or more new objects to the datastore. |
|
|
35
|
+
* | `delete` | `DELETE /:id` | Removes an existing object from the datastore. |
|
|
36
|
+
* | `exists` | `HEAD /:id` | Checks if the object with the given ID exists in the datastore. Sets `Content-Length` header to `1` if the object exists, otherwise `0`. |
|
|
37
|
+
* | `find` | `GET /` | Returns all objects matching the provided set of criteria in the request's query parameters. |
|
|
38
|
+
* | `findById` | `GET /:id` | Returns a single object with a specified unique identifier. |
|
|
39
|
+
* | `truncate` | `DELETE /` | Removes all objects from the datastore. |
|
|
40
|
+
* | `update` | `PUT /:id` | Modifies an existing object in the datastore. |
|
|
41
|
+
* | `updateBulk` | `PUT /` | Modifies multiple existing objects in the datastore. |
|
|
42
|
+
* | `updateProperty` | `PUT /:id/:property` | Modifies an single property of the given name of an existing object in the datastore. |
|
|
43
|
+
*
|
|
44
|
+
* @author Jean-Philippe Steinmetz
|
|
45
|
+
*/
|
|
46
|
+
export class CRUDRoute extends ModelRoute {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
this.repoUtilsClass = RepoUtils;
|
|
50
|
+
}
|
|
51
|
+
async count(params, query, res, user) {
|
|
52
|
+
return super.doCount({ params, query, res, user });
|
|
53
|
+
}
|
|
54
|
+
validateCreate(obj, user) {
|
|
55
|
+
return super.validate(obj, { user });
|
|
56
|
+
}
|
|
57
|
+
create(obj, req, user) {
|
|
58
|
+
return super.doCreate(obj, { req, user });
|
|
59
|
+
}
|
|
60
|
+
async delete(id, version, purge, req, user) {
|
|
61
|
+
return super.doDelete(id, { user, req, version, purge: purge === "true" });
|
|
62
|
+
}
|
|
63
|
+
async exists(id, query, res, user) {
|
|
64
|
+
return super.doExists(id, { query, res, user });
|
|
65
|
+
}
|
|
66
|
+
async find(params, query, user) {
|
|
67
|
+
return super.doFind({ params, query, user });
|
|
68
|
+
}
|
|
69
|
+
async findById(id, query, user) {
|
|
70
|
+
return super.doFindById(id, { query, user });
|
|
71
|
+
}
|
|
72
|
+
async truncate(params, query, user) {
|
|
73
|
+
return super.doTruncate({ params, query, user });
|
|
74
|
+
}
|
|
75
|
+
async validateUpdate(id, obj, user) {
|
|
76
|
+
return this.validate(obj, { user });
|
|
77
|
+
}
|
|
78
|
+
async update(id, obj, req, user) {
|
|
79
|
+
return super.doUpdate(id, obj, { user });
|
|
80
|
+
}
|
|
81
|
+
async validateUpdateBulk(objs, user) {
|
|
82
|
+
return super.validate(objs, { user });
|
|
83
|
+
}
|
|
84
|
+
async updateBulk(obj, req, user) {
|
|
85
|
+
return super.doBulkUpdate(obj, { user, req });
|
|
86
|
+
}
|
|
87
|
+
updateProperty(id, propertyName, obj, user) {
|
|
88
|
+
return super.doUpdateProperty(id, propertyName, obj, { user });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
__decorate([
|
|
92
|
+
Summary("Count {{name}}s"),
|
|
93
|
+
Description("Returns the total count of {{name}}s in the datastore based on the given criteria " +
|
|
94
|
+
"in the header as `Content-Length`."),
|
|
95
|
+
Returns([null]),
|
|
96
|
+
Head(),
|
|
97
|
+
__param(0, Param()),
|
|
98
|
+
__param(1, Query()),
|
|
99
|
+
__param(2, Response),
|
|
100
|
+
__param(3, User),
|
|
101
|
+
__metadata("design:type", Function),
|
|
102
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
103
|
+
__metadata("design:returntype", Promise)
|
|
104
|
+
], CRUDRoute.prototype, "count", null);
|
|
105
|
+
__decorate([
|
|
106
|
+
__param(1, User),
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
109
|
+
__metadata("design:returntype", void 0)
|
|
110
|
+
], CRUDRoute.prototype, "validateCreate", null);
|
|
111
|
+
__decorate([
|
|
112
|
+
Summary("Create {{model}}(s)"),
|
|
113
|
+
Description("Create a new {{model}}."),
|
|
114
|
+
Returns([Object]),
|
|
115
|
+
Post(),
|
|
116
|
+
Validate("validateCreate"),
|
|
117
|
+
__param(1, Request),
|
|
118
|
+
__param(2, User),
|
|
119
|
+
__metadata("design:type", Function),
|
|
120
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
121
|
+
__metadata("design:returntype", Promise)
|
|
122
|
+
], CRUDRoute.prototype, "create", null);
|
|
123
|
+
__decorate([
|
|
124
|
+
Summary("Delete {{name}} by ID"),
|
|
125
|
+
Description("Deletes the {{name}} from the service."),
|
|
126
|
+
Returns([null]),
|
|
127
|
+
Delete("/:id"),
|
|
128
|
+
__param(0, Param("id")),
|
|
129
|
+
__param(1, Query("version")),
|
|
130
|
+
__param(2, Query("purge")),
|
|
131
|
+
__param(3, Request),
|
|
132
|
+
__param(4, User),
|
|
133
|
+
__metadata("design:type", Function),
|
|
134
|
+
__metadata("design:paramtypes", [String, Object, Object, Object, Object]),
|
|
135
|
+
__metadata("design:returntype", Promise)
|
|
136
|
+
], CRUDRoute.prototype, "delete", null);
|
|
137
|
+
__decorate([
|
|
138
|
+
Summary("Exists"),
|
|
139
|
+
Description("Returns the total count of {{name}}s in the datastore based on the given criteria " +
|
|
140
|
+
"in the header as `Content-Length`."),
|
|
141
|
+
Returns([null]),
|
|
142
|
+
Head("/:id"),
|
|
143
|
+
__param(0, Param("id")),
|
|
144
|
+
__param(1, Query()),
|
|
145
|
+
__param(2, Response),
|
|
146
|
+
__param(3, User),
|
|
147
|
+
__metadata("design:type", Function),
|
|
148
|
+
__metadata("design:paramtypes", [String, Object, Object, Object]),
|
|
149
|
+
__metadata("design:returntype", Promise)
|
|
150
|
+
], CRUDRoute.prototype, "exists", null);
|
|
151
|
+
__decorate([
|
|
152
|
+
Summary("Find All {{model}}s"),
|
|
153
|
+
Description("Returns all {{model}}s from the system that the user has access to."),
|
|
154
|
+
Returns([[Array, Object]]),
|
|
155
|
+
Get(),
|
|
156
|
+
__param(0, Param()),
|
|
157
|
+
__param(1, Query()),
|
|
158
|
+
__param(2, User),
|
|
159
|
+
__metadata("design:type", Function),
|
|
160
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
161
|
+
__metadata("design:returntype", Promise)
|
|
162
|
+
], CRUDRoute.prototype, "find", null);
|
|
163
|
+
__decorate([
|
|
164
|
+
Summary("Find {{model}} by ID"),
|
|
165
|
+
Description("Returns a single {{model}} from the system that the user has access to."),
|
|
166
|
+
Returns([Object]),
|
|
167
|
+
Get("/:id"),
|
|
168
|
+
__param(0, Param("id")),
|
|
169
|
+
__param(1, Query()),
|
|
170
|
+
__param(2, User),
|
|
171
|
+
__metadata("design:type", Function),
|
|
172
|
+
__metadata("design:paramtypes", [String, Object, Object]),
|
|
173
|
+
__metadata("design:returntype", Promise)
|
|
174
|
+
], CRUDRoute.prototype, "findById", null);
|
|
175
|
+
__decorate([
|
|
176
|
+
Summary("Truncate {{model}}s"),
|
|
177
|
+
Description("Deletes all {{model}}s from the datastore that the user has access to."),
|
|
178
|
+
Returns([null]),
|
|
179
|
+
Delete(),
|
|
180
|
+
__param(0, Param()),
|
|
181
|
+
__param(1, Query()),
|
|
182
|
+
__param(2, User),
|
|
183
|
+
__metadata("design:type", Function),
|
|
184
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
185
|
+
__metadata("design:returntype", Promise)
|
|
186
|
+
], CRUDRoute.prototype, "truncate", null);
|
|
187
|
+
__decorate([
|
|
188
|
+
__param(0, Param("id")),
|
|
189
|
+
__param(2, User),
|
|
190
|
+
__metadata("design:type", Function),
|
|
191
|
+
__metadata("design:paramtypes", [String, Object, Object]),
|
|
192
|
+
__metadata("design:returntype", Promise)
|
|
193
|
+
], CRUDRoute.prototype, "validateUpdate", null);
|
|
194
|
+
__decorate([
|
|
195
|
+
Summary("Update {{model}} by ID"),
|
|
196
|
+
Description("Updates a single {{model}}."),
|
|
197
|
+
Returns([Object]),
|
|
198
|
+
Put("/:id"),
|
|
199
|
+
Validate("validateUpdate"),
|
|
200
|
+
__param(0, Param("id")),
|
|
201
|
+
__param(2, Request),
|
|
202
|
+
__param(3, User),
|
|
203
|
+
__metadata("design:type", Function),
|
|
204
|
+
__metadata("design:paramtypes", [String, Object, Object, Object]),
|
|
205
|
+
__metadata("design:returntype", Promise)
|
|
206
|
+
], CRUDRoute.prototype, "update", null);
|
|
207
|
+
__decorate([
|
|
208
|
+
__param(1, User),
|
|
209
|
+
__metadata("design:type", Function),
|
|
210
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
211
|
+
__metadata("design:returntype", Promise)
|
|
212
|
+
], CRUDRoute.prototype, "validateUpdateBulk", null);
|
|
213
|
+
__decorate([
|
|
214
|
+
Summary("Update {{model}}s in bulk"),
|
|
215
|
+
Description("Updates a collection of existing {{model}}s."),
|
|
216
|
+
Returns([[Array, Object]]),
|
|
217
|
+
Put(),
|
|
218
|
+
Validate("validateUpdateBulk"),
|
|
219
|
+
__param(1, Request),
|
|
220
|
+
__param(2, User),
|
|
221
|
+
__metadata("design:type", Function),
|
|
222
|
+
__metadata("design:paramtypes", [Array, Object, Object]),
|
|
223
|
+
__metadata("design:returntype", Promise)
|
|
224
|
+
], CRUDRoute.prototype, "updateBulk", null);
|
|
225
|
+
__decorate([
|
|
226
|
+
Summary("Update {{model}} by ID and property"),
|
|
227
|
+
Put(":id/:property"),
|
|
228
|
+
Description("Updates a single property of an existing {{model}}."),
|
|
229
|
+
TypeInfo([Object]),
|
|
230
|
+
Returns([Object]),
|
|
231
|
+
__param(0, Param("id")),
|
|
232
|
+
__param(1, Param("property")),
|
|
233
|
+
__param(3, User),
|
|
234
|
+
__metadata("design:type", Function),
|
|
235
|
+
__metadata("design:paramtypes", [String, String, Object, Object]),
|
|
236
|
+
__metadata("design:returntype", Promise)
|
|
237
|
+
], CRUDRoute.prototype, "updateProperty", null);
|
|
238
|
+
//# sourceMappingURL=CRUDRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CRUDRoute.js","sourceRoot":"","sources":["../../../src/routes/CRUDRoute.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+EAA+E;AAC/E,wEAAwE;AACxE,+EAA+E;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAKnD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AACzF,OAAO,EACH,MA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AC;IACpC,WAAW,CAAC,8CAA8C,CAAC;IAC3D,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1B,GAAG,EAAE;IACL,QAAQ,CAAC,oBAAoB,CAAC;IACkB,WAAA,OAAO,CAAA;IAAoB,WAAA,IAAI,CAAA;;;;2CAE/E;AAOM;IALN,OAAO,CAAC,qCAAqC,CAAC;IAC9C,GAAG,CAAC,eAAe,CAAC;IACpB,WAAW,CAAC,qDAAqD,CAAC;IAClE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;IAClB,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;IAEb,WAAA,KAAK,CAAC,IAAI,CAAC,CAAA;IACX,WAAA,KAAK,CAAC,UAAU,CAAC,CAAA;IAEjB,WAAA,IAAI,CAAA;;;;+CAGR"}
|
|
@@ -25,16 +25,23 @@ import { ObjectFactory } from "../ObjectFactory.js";
|
|
|
25
25
|
const { Config, Init, Inject, Logger } = ObjectDecorators;
|
|
26
26
|
/**
|
|
27
27
|
* The `ModelRoute` is an abstract base class that provides a set of built-in route behavior functions for handling
|
|
28
|
-
* requests for a given data model that is managed by a persistent datastore.
|
|
28
|
+
* requests for a given data model that is managed by a persistent datastore. This class _does not_ provide route
|
|
29
|
+
* handlers for the defined behaviors. This class is intended to serve as a base class for you to extend and hook
|
|
30
|
+
* up your own route handlers that use the included functionality as desired so that you only expose the CRUD
|
|
31
|
+
* endpoints for your model that you desire. If you desire a fully functional set of route handlers that implements
|
|
32
|
+
* all of these behaviors you should extend the `CRUDRoute` class instead.
|
|
29
33
|
*
|
|
30
34
|
* Provided behaviors:
|
|
31
|
-
* * `
|
|
32
|
-
* * `
|
|
33
|
-
* * `
|
|
34
|
-
* * `
|
|
35
|
-
* * `
|
|
36
|
-
* * `
|
|
37
|
-
* * `
|
|
35
|
+
* * `doCount`: Counts the number of objects matching the provided set of criteria in the request's query parameters. Returns the count as the value of the `Content-Length` header.
|
|
36
|
+
* * `doCreate`: Adds one or more new objects to the datastore.
|
|
37
|
+
* * `doDelete`: Removes an existing object from the datastore.
|
|
38
|
+
* * `doExists`: Checks if the object with the given ID exists in the datastore. Sets `Content-Length` header to `1` if the object exists, otherwise `0`.
|
|
39
|
+
* * `doFind`: Returns all objects matching the provided set of criteria in the request's query parameters.
|
|
40
|
+
* * `doFindById`: Returns a single object with a specified unique identifier.
|
|
41
|
+
* * `doTruncate`: Removes all objects from the datastore.
|
|
42
|
+
* * `doUpdate`: Modifies an existing object in the datastore.
|
|
43
|
+
* * `doUpdateBulk`: Modifies multiple existing objects in the datastore.
|
|
44
|
+
* * `doUpdateProperty`: Modifies an single property of the given name of an existing object in the datastore.
|
|
38
45
|
*
|
|
39
46
|
* @author Jean-Philippe Steinmetz
|
|
40
47
|
*/
|
|
@@ -197,6 +204,7 @@ export class ModelRoute {
|
|
|
197
204
|
}
|
|
198
205
|
const existing = await this.repoUtils.findOne(id, {
|
|
199
206
|
version: options.version,
|
|
207
|
+
user: options.user,
|
|
200
208
|
});
|
|
201
209
|
if (!existing) {
|
|
202
210
|
throw new ApiError(ApiErrors.NOT_FOUND, 404, ApiErrorMessages.NOT_FOUND);
|
|
@@ -233,12 +241,6 @@ export class ModelRoute {
|
|
|
233
241
|
throw new ApiError(ApiErrors.SEARCH_INVALID_ME_REFERENCE, 403, ApiErrorMessages.SEARCH_INVALID_ME_REFERENCE);
|
|
234
242
|
}
|
|
235
243
|
}
|
|
236
|
-
// Check user permissions
|
|
237
|
-
if (this.aclUtils?.enabled && !options.ignoreACL) {
|
|
238
|
-
if (!(await this.aclUtils.hasPermission(options.user, this.defaultACLUid, ACLAction.READ))) {
|
|
239
|
-
throw new ApiError(ApiErrors.AUTH_PERMISSION_FAILURE, 403, ApiErrorMessages.AUTH_PERMISSION_FAILURE);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
244
|
const query = this.repoUtils.searchIdQuery(id, options.query.version);
|
|
243
245
|
const result = await this.repoUtils.count(query);
|
|
244
246
|
if (result > 0) {
|
|
@@ -255,16 +257,10 @@ export class ModelRoute {
|
|
|
255
257
|
*
|
|
256
258
|
* @param options The options to process the request using.
|
|
257
259
|
*/
|
|
258
|
-
async
|
|
260
|
+
async doFind(options) {
|
|
259
261
|
if (!this.repoUtils) {
|
|
260
262
|
throw new ApiError(ApiErrors.INTERNAL_ERROR, 500, ApiErrorMessages.INTERNAL_ERROR);
|
|
261
263
|
}
|
|
262
|
-
// Check user permissions
|
|
263
|
-
if (this.aclUtils?.enabled && !options.ignoreACL) {
|
|
264
|
-
if (!(await this.aclUtils.hasPermission(options.user, this.defaultACLUid, ACLAction.READ))) {
|
|
265
|
-
throw new ApiError(ApiErrors.AUTH_PERMISSION_FAILURE, 403, ApiErrorMessages.AUTH_PERMISSION_FAILURE);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
264
|
const searchQuery = ModelUtils.buildSearchQuery(this.modelClass, this.repoUtils.repo, options.params, options.query, true, options.user);
|
|
269
265
|
return await this.repoUtils.find(searchQuery, {
|
|
270
266
|
limit: options.query?.limit,
|
|
@@ -293,16 +289,11 @@ export class ModelRoute {
|
|
|
293
289
|
}
|
|
294
290
|
const result = await this.repoUtils.findOne(id, {
|
|
295
291
|
version: options.params?.version || options.query?.version,
|
|
292
|
+
user: options.user,
|
|
296
293
|
});
|
|
297
294
|
if (!result) {
|
|
298
295
|
throw new ApiError(ApiErrors.NOT_FOUND, 404, ApiErrorMessages.NOT_FOUND);
|
|
299
296
|
}
|
|
300
|
-
if (this.aclUtils?.enabled && !options.ignoreACL) {
|
|
301
|
-
const acl = await this.aclUtils.findACL(result.uid);
|
|
302
|
-
if (!(await this.aclUtils.hasPermission(options.user, acl ? acl : this.defaultACLUid, ACLAction.READ))) {
|
|
303
|
-
throw new ApiError(ApiErrors.AUTH_PERMISSION_FAILURE, 403, ApiErrorMessages.AUTH_PERMISSION_FAILURE);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
297
|
return result;
|
|
307
298
|
}
|
|
308
299
|
/**
|
|
@@ -379,6 +370,7 @@ export class ModelRoute {
|
|
|
379
370
|
}
|
|
380
371
|
const existing = await this.repoUtils.findOne(id, {
|
|
381
372
|
skipCache: true,
|
|
373
|
+
user: options.user,
|
|
382
374
|
});
|
|
383
375
|
if (!existing) {
|
|
384
376
|
throw new ApiError(ApiErrors.NOT_FOUND, 404, ApiErrorMessages.NOT_FOUND);
|
|
@@ -431,7 +423,7 @@ export class ModelRoute {
|
|
|
431
423
|
/**
|
|
432
424
|
* Calls `repoUtils.validate()` to validate the object(s) provided.
|
|
433
425
|
*/
|
|
434
|
-
async
|
|
426
|
+
async validate(objs, options) {
|
|
435
427
|
await this.repoUtils?.validate(objs, options);
|
|
436
428
|
}
|
|
437
429
|
}
|