@rapidrest/service-core 1.0.0-rc.9 → 1.0.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/LICENSE +382 -23
- package/README.md +79 -5
- package/dist/lib/ApiErrors.js +10 -0
- package/dist/lib/ApiErrors.js.map +1 -1
- package/dist/lib/BackgroundService.js +1 -4
- package/dist/lib/BackgroundService.js.map +1 -1
- package/dist/lib/BackgroundServiceManager.js +47 -6
- package/dist/lib/BackgroundServiceManager.js.map +1 -1
- package/dist/lib/BulkError.js +4 -0
- package/dist/lib/BulkError.js.map +1 -1
- package/dist/lib/EventListenerManager.js +53 -18
- package/dist/lib/EventListenerManager.js.map +1 -1
- package/dist/lib/NetUtils.js +1 -0
- package/dist/lib/NetUtils.js.map +1 -1
- package/dist/lib/NotificationUtils.js +27 -8
- package/dist/lib/NotificationUtils.js.map +1 -1
- package/dist/lib/ObjectFactory.js +25 -44
- package/dist/lib/ObjectFactory.js.map +1 -1
- package/dist/lib/OpenApiSpec.js +31 -11
- package/dist/lib/OpenApiSpec.js.map +1 -1
- package/dist/lib/Server.js +74 -110
- package/dist/lib/Server.js.map +1 -1
- package/dist/lib/auth/AuthMiddleware.js +11 -16
- package/dist/lib/auth/AuthMiddleware.js.map +1 -1
- package/dist/lib/auth/JWTStrategy.js +68 -17
- package/dist/lib/auth/JWTStrategy.js.map +1 -1
- package/dist/lib/auth/index.js +0 -1
- package/dist/lib/auth/index.js.map +1 -1
- package/dist/lib/database/ConnectionKinds.js +15 -0
- package/dist/lib/database/ConnectionKinds.js.map +1 -1
- package/dist/lib/database/ConnectionManager.js +140 -61
- package/dist/lib/database/ConnectionManager.js.map +1 -1
- package/dist/lib/database/MongoConnection.js +13 -3
- package/dist/lib/database/MongoConnection.js.map +1 -1
- package/dist/lib/database/MongoRepository.js +61 -15
- package/dist/lib/database/MongoRepository.js.map +1 -1
- package/dist/lib/database/MongoSchemaSync.js +3 -3
- package/dist/lib/database/MongoSchemaSync.js.map +1 -1
- package/dist/lib/database/NamingUtils.js +3 -2
- package/dist/lib/database/NamingUtils.js.map +1 -1
- package/dist/lib/database/RedisCache.js +64 -0
- package/dist/lib/database/RedisCache.js.map +1 -0
- package/dist/lib/database/TypeOrmSupport.js +53 -13
- package/dist/lib/database/TypeOrmSupport.js.map +1 -1
- package/dist/lib/database/index.js +1 -0
- package/dist/lib/database/index.js.map +1 -1
- package/dist/lib/decorators/DatabaseDecorators.js +264 -20
- package/dist/lib/decorators/DatabaseDecorators.js.map +1 -1
- package/dist/lib/decorators/DocDecorators.js +30 -9
- package/dist/lib/decorators/DocDecorators.js.map +1 -1
- package/dist/lib/decorators/EventDecorators.js +1 -0
- package/dist/lib/decorators/EventDecorators.js.map +1 -1
- package/dist/lib/decorators/ModelDecorators.js +39 -23
- package/dist/lib/decorators/ModelDecorators.js.map +1 -1
- package/dist/lib/decorators/PersistenceDecorators.js +4 -3
- package/dist/lib/decorators/PersistenceDecorators.js.map +1 -1
- package/dist/lib/decorators/RouteDecorators.js +139 -36
- package/dist/lib/decorators/RouteDecorators.js.map +1 -1
- package/dist/lib/http/IWebSocketShim.js +2 -0
- package/dist/lib/http/IWebSocketShim.js.map +1 -0
- package/dist/lib/http/MiddlewareChain.js +167 -0
- package/dist/lib/http/MiddlewareChain.js.map +1 -0
- package/dist/lib/http/RuntimeDetect.js +9 -0
- package/dist/lib/http/RuntimeDetect.js.map +1 -0
- package/dist/lib/http/bun/BunAdapters.js +326 -0
- package/dist/lib/http/bun/BunAdapters.js.map +1 -0
- package/dist/lib/http/bun/BunRouter.js +391 -0
- package/dist/lib/http/bun/BunRouter.js.map +1 -0
- package/dist/lib/http/bun/BunWebSocket.js +49 -0
- package/dist/lib/http/bun/BunWebSocket.js.map +1 -0
- package/dist/lib/http/index.js +16 -3
- package/dist/lib/http/index.js.map +1 -1
- package/dist/lib/http/session/RedisSessionStore.js +30 -0
- package/dist/lib/http/session/RedisSessionStore.js.map +1 -0
- package/dist/lib/http/session/SessionManager.js +113 -0
- package/dist/lib/http/session/SessionManager.js.map +1 -0
- package/dist/lib/http/session/SessionStore.js +6 -0
- package/dist/lib/http/session/SessionStore.js.map +1 -0
- package/dist/lib/http/session/sessionMiddleware.js +42 -0
- package/dist/lib/http/session/sessionMiddleware.js.map +1 -0
- package/dist/lib/http/types.js +0 -3
- package/dist/lib/http/types.js.map +1 -1
- package/dist/lib/http/uWS/Adapters.js +421 -0
- package/dist/lib/http/uWS/Adapters.js.map +1 -0
- package/dist/lib/http/{Router.js → uWS/Router.js} +73 -173
- package/dist/lib/http/uWS/Router.js.map +1 -0
- package/dist/lib/http/{WebSocket.js → uWS/WebSocket.js} +4 -1
- package/dist/lib/http/uWS/WebSocket.js.map +1 -0
- package/dist/lib/models/BaseEntity.js +2 -1
- package/dist/lib/models/BaseEntity.js.map +1 -1
- package/dist/lib/models/BaseMongoEntity.js +2 -2
- package/dist/lib/models/BaseMongoEntity.js.map +1 -1
- package/dist/lib/models/ModelUtils.js +248 -101
- package/dist/lib/models/ModelUtils.js.map +1 -1
- package/dist/lib/models/RecoverableBaseEntity.js +6 -1
- package/dist/lib/models/RecoverableBaseEntity.js.map +1 -1
- package/dist/lib/models/RecoverableBaseMongoEntity.js +1 -0
- package/dist/lib/models/RecoverableBaseMongoEntity.js.map +1 -1
- package/dist/lib/models/RepoUtils.js +641 -213
- package/dist/lib/models/RepoUtils.js.map +1 -1
- package/dist/lib/models/SimpleEntity.js +1 -0
- package/dist/lib/models/SimpleEntity.js.map +1 -1
- package/dist/lib/models/SimpleMongoEntity.js +2 -1
- package/dist/lib/models/SimpleMongoEntity.js.map +1 -1
- package/dist/lib/models/StatusExtraData.js +4 -0
- package/dist/lib/models/StatusExtraData.js.map +1 -1
- package/dist/lib/routes/{AdminRoute.js → BaseAdminRoute.js} +98 -80
- package/dist/lib/routes/BaseAdminRoute.js.map +1 -0
- package/dist/lib/routes/{MetricsRoute.js → BaseMetricsRoute.js} +29 -15
- package/dist/lib/routes/BaseMetricsRoute.js.map +1 -0
- package/dist/lib/routes/{OpenAPIRoute.js → BaseOpenAPIRoute.js} +32 -32
- package/dist/lib/routes/BaseOpenAPIRoute.js.map +1 -0
- package/dist/lib/routes/BasePushRoute.js +305 -0
- package/dist/lib/routes/BasePushRoute.js.map +1 -0
- package/dist/lib/routes/BaseStaticRoute.js +153 -0
- package/dist/lib/routes/BaseStaticRoute.js.map +1 -0
- package/dist/lib/routes/BaseStatusRoute.js +80 -0
- package/dist/lib/routes/BaseStatusRoute.js.map +1 -0
- package/dist/lib/routes/CRUDRoute.js +284 -0
- package/dist/lib/routes/CRUDRoute.js.map +1 -0
- package/dist/lib/routes/ModelRoute.js +84 -57
- package/dist/lib/routes/ModelRoute.js.map +1 -1
- package/dist/lib/routes/RouteUtils.js +108 -20
- package/dist/lib/routes/RouteUtils.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 +297 -170
- package/dist/lib/security/ACLUtils.js.map +1 -1
- package/dist/lib/security/AccessControlList.js +18 -10
- package/dist/lib/security/AccessControlList.js.map +1 -1
- package/dist/lib/security/AccessControlListMongo.js +19 -68
- package/dist/lib/security/AccessControlListMongo.js.map +1 -1
- package/dist/lib/security/AccessControlListSQL.js +21 -70
- 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 +62 -5
- package/dist/lib/test/request.js.map +1 -1
- package/dist/lib/test/requestws.js +34 -10
- package/dist/lib/test/requestws.js.map +1 -1
- package/dist/types/ApiErrors.d.ts +8 -2
- package/dist/types/BackgroundService.d.ts +0 -5
- package/dist/types/BackgroundServiceManager.d.ts +2 -1
- package/dist/types/EventListenerManager.d.ts +7 -6
- package/dist/types/NotificationUtils.d.ts +5 -3
- package/dist/types/OpenApiSpec.d.ts +2 -2
- package/dist/types/Server.d.ts +28 -10
- package/dist/types/auth/AuthMiddleware.d.ts +3 -3
- package/dist/types/auth/AuthStrategy.d.ts +10 -7
- package/dist/types/auth/JWTStrategy.d.ts +6 -4
- package/dist/types/auth/index.d.ts +0 -1
- package/dist/types/database/ConnectionKinds.d.ts +7 -0
- package/dist/types/database/ConnectionManager.d.ts +29 -4
- package/dist/types/database/MongoConnection.d.ts +16 -4
- package/dist/types/database/MongoRepository.d.ts +32 -11
- package/dist/types/database/RedisCache.d.ts +23 -0
- package/dist/types/database/TypeOrmSupport.d.ts +4 -4
- package/dist/types/database/index.d.ts +1 -0
- package/dist/types/decorators/DatabaseDecorators.d.ts +139 -8
- package/dist/types/decorators/DocDecorators.d.ts +11 -2
- package/dist/types/decorators/ModelDecorators.d.ts +12 -5
- package/dist/types/decorators/PersistenceDecorators.d.ts +11 -4
- package/dist/types/decorators/RouteDecorators.d.ts +36 -6
- package/dist/types/http/IWebSocketShim.d.ts +11 -0
- package/dist/types/http/MiddlewareChain.d.ts +47 -0
- package/dist/types/http/RuntimeDetect.d.ts +2 -0
- package/dist/types/http/bun/BunAdapters.d.ts +139 -0
- package/dist/types/http/bun/BunRouter.d.ts +79 -0
- package/dist/types/http/bun/BunWebSocket.d.ts +35 -0
- package/dist/types/http/index.d.ts +16 -6
- package/dist/types/http/session/RedisSessionStore.d.ts +15 -0
- package/dist/types/http/session/SessionManager.d.ts +35 -0
- package/dist/types/http/session/SessionStore.d.ts +12 -0
- package/dist/types/http/session/sessionMiddleware.d.ts +10 -0
- package/dist/types/http/types.d.ts +42 -3
- package/dist/types/http/uWS/Adapters.d.ts +129 -0
- package/dist/types/http/{Router.d.ts → uWS/Router.d.ts} +14 -38
- package/dist/types/http/{WebSocket.d.ts → uWS/WebSocket.d.ts} +6 -5
- package/dist/types/models/BaseEntity.d.ts +1 -1
- package/dist/types/models/ModelUtils.d.ts +47 -14
- package/dist/types/models/RecoverableBaseEntity.d.ts +3 -1
- package/dist/types/models/RepoUtils.d.ts +84 -14
- package/dist/types/routes/BaseAdminRoute.d.ts +65 -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 +53 -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 +57 -0
- package/dist/types/routes/ModelRoute.d.ts +39 -36
- package/dist/types/routes/RouteUtils.d.ts +19 -0
- package/dist/types/routes/index.d.ts +7 -4
- package/dist/types/security/ACLUtils.d.ts +94 -18
- package/dist/types/security/AccessControlList.d.ts +37 -59
- package/dist/types/security/AccessControlListMongo.d.ts +3 -8
- package/dist/types/security/AccessControlListSQL.d.ts +3 -8
- package/dist/types/security/BaseACLRoute.d.ts +73 -0
- package/dist/types/security/index.d.ts +3 -0
- package/dist/types/test/request.d.ts +18 -1
- package/package.json +135 -129
- package/tsconfig.export.json +17 -0
- package/dist/lib/auth/BasicStrategy.js +0 -113
- package/dist/lib/auth/BasicStrategy.js.map +0 -1
- package/dist/lib/http/Adapters.js +0 -241
- package/dist/lib/http/Adapters.js.map +0 -1
- package/dist/lib/http/Router.js.map +0 -1
- package/dist/lib/http/WebSocket.js.map +0 -1
- 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/auth/BasicStrategy.d.ts +0 -37
- package/dist/types/http/Adapters.d.ts +0 -68
- 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 -446
- 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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JWTUser } from "@rapidrest/core";
|
|
1
2
|
/**
|
|
2
3
|
* Framework-agnostic HTTP request interface. Mirrors the Express `Request` surface used throughout
|
|
3
4
|
* this codebase so that route handlers, middleware, and utilities require no changes when the
|
|
@@ -14,12 +15,17 @@ export interface HttpRequest {
|
|
|
14
15
|
rawBody?: Buffer;
|
|
15
16
|
cookies: Record<string, string>;
|
|
16
17
|
signedCookies: Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Populated by the optional session middleware (see SessionManager). Undefined when no
|
|
20
|
+
* session middleware is registered (i.e. the `session` config block is absent).
|
|
21
|
+
*/
|
|
22
|
+
session?: Record<string, any>;
|
|
17
23
|
/** Minimal socket interface; populated with remote address for IP extraction. */
|
|
18
24
|
socket: {
|
|
19
25
|
remoteAddress?: string;
|
|
20
26
|
};
|
|
21
27
|
/** Set by JWT auth middleware after successful token verification. */
|
|
22
|
-
user?:
|
|
28
|
+
user?: JWTUser;
|
|
23
29
|
/** Full decoded JWT payload, set by JWT auth middleware. */
|
|
24
30
|
authPayload?: any;
|
|
25
31
|
/** Raw JWT token string, set by JWT auth middleware. */
|
|
@@ -38,11 +44,23 @@ export interface HttpResponse {
|
|
|
38
44
|
/** Intermediate result passed between middleware via res.result. */
|
|
39
45
|
result?: any;
|
|
40
46
|
status(code: number): this;
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
/** Sets a header, replacing any value(s) previously set for the same key. */
|
|
48
|
+
setHeader(key: string, value: string | number | string[]): this;
|
|
49
|
+
/**
|
|
50
|
+
* Adds a value for a header without clobbering any value(s) already set for the same key —
|
|
51
|
+
* the header is sent as multiple lines on the wire (e.g. multiple `Set-Cookie` headers).
|
|
52
|
+
*/
|
|
53
|
+
appendHeader(key: string, value: string | number): this;
|
|
54
|
+
getHeader(key: string): string | string[] | undefined;
|
|
43
55
|
json(data: any): void;
|
|
44
56
|
send(data?: any): void;
|
|
45
57
|
end(data?: any): void;
|
|
58
|
+
/**
|
|
59
|
+
* Registers a callback fired exactly once when the response actually completes — either a
|
|
60
|
+
* normal end() or client/stream abort. Does not delay or await end(). Used to persist
|
|
61
|
+
* request-scoped state (e.g. session data) after downstream handlers finish mutating it.
|
|
62
|
+
*/
|
|
63
|
+
onFinish(handler: () => void | Promise<void>): void;
|
|
46
64
|
/** Allow arbitrary per-response properties. */
|
|
47
65
|
[key: string]: any;
|
|
48
66
|
}
|
|
@@ -52,3 +70,24 @@ export type NextFunction = (err?: any) => void;
|
|
|
52
70
|
export type RequestHandler = (req: HttpRequest, res: HttpResponse, next: NextFunction) => void | Promise<void>;
|
|
53
71
|
/** Standard 4-param error-handling middleware function. */
|
|
54
72
|
export type ErrorHandler = (err: any, req: HttpRequest, res: HttpResponse, next: NextFunction) => void | Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Public surface shared by every HTTP router implementation (uWS-backed, Bun-backed, ...).
|
|
75
|
+
* `Server.ts` depends only on this interface, never on a concrete router class, so the
|
|
76
|
+
* underlying HTTP server can be swapped per-runtime without touching route registration.
|
|
77
|
+
*/
|
|
78
|
+
export interface IHttpRouter {
|
|
79
|
+
use(...handlers: RequestHandler[]): this;
|
|
80
|
+
get(path: string, ...handlers: RequestHandler[]): this;
|
|
81
|
+
post(path: string, ...handlers: RequestHandler[]): this;
|
|
82
|
+
put(path: string, ...handlers: RequestHandler[]): this;
|
|
83
|
+
delete(path: string, ...handlers: RequestHandler[]): this;
|
|
84
|
+
patch(path: string, ...handlers: RequestHandler[]): this;
|
|
85
|
+
head(path: string, ...handlers: RequestHandler[]): this;
|
|
86
|
+
options(path: string, ...handlers: RequestHandler[]): this;
|
|
87
|
+
ws(path: string, handlers: RequestHandler[], wsOptions?: any, upgradeAuth?: any): this;
|
|
88
|
+
listen(host: string, port: number): Promise<void>;
|
|
89
|
+
close(): void;
|
|
90
|
+
readonly isListening: boolean;
|
|
91
|
+
listenPort: number;
|
|
92
|
+
[key: string]: any;
|
|
93
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { HttpRequest, HttpResponse } from "../types.js";
|
|
2
|
+
import type { HttpRequest as UWSHttpRequest, HttpResponse as UWSHttpResponse } from "uWebSockets.js";
|
|
3
|
+
/** Parses a `cookie` header string into a key/value map. */
|
|
4
|
+
export declare function parseCookies(cookieHeader: string): Record<string, string>;
|
|
5
|
+
/** Parses a URL query string (without leading `?`) into a key/value map. */
|
|
6
|
+
export declare function parseQueryString(qs: string): Record<string, string | string[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Parses a raw request body Buffer according to its content-type header. Shared by both the
|
|
9
|
+
* uWS-backed and Bun-backed HTTP adapters so body-parsing rules stay in one place:
|
|
10
|
+
* `application/json` is parsed (falling back to the raw string on parse failure),
|
|
11
|
+
* `application/x-www-form-urlencoded` is parsed into a plain object, and anything else is
|
|
12
|
+
* returned as the raw Buffer. Returns `undefined` for an empty body.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseBodyByContentType(raw: Buffer, contentType: string): any;
|
|
15
|
+
/**
|
|
16
|
+
* Adapts a uWS `HttpRequest` to the framework-agnostic `HttpRequest` interface.
|
|
17
|
+
*
|
|
18
|
+
* IMPORTANT: uWS HttpRequest is stack-allocated and only valid during the synchronous portion of
|
|
19
|
+
* the handler. All request data MUST be captured in the constructor before any `await`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class UWSRequest implements HttpRequest {
|
|
22
|
+
readonly method: string;
|
|
23
|
+
readonly url: string;
|
|
24
|
+
readonly path: string;
|
|
25
|
+
readonly headers: Record<string, string>;
|
|
26
|
+
params: Record<string, string>;
|
|
27
|
+
readonly query: Record<string, string | string[]>;
|
|
28
|
+
body: any;
|
|
29
|
+
rawBody?: Buffer;
|
|
30
|
+
readonly cookies: Record<string, string>;
|
|
31
|
+
readonly signedCookies: Record<string, string>;
|
|
32
|
+
readonly socket: {
|
|
33
|
+
remoteAddress?: string;
|
|
34
|
+
};
|
|
35
|
+
user?: any;
|
|
36
|
+
authPayload?: any;
|
|
37
|
+
authToken?: string;
|
|
38
|
+
/** Allow arbitrary per-request properties (websocket, wsHandled, etc.) */
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
constructor(uwsReq: UWSHttpRequest, remoteAddress?: string);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Adapts a uWS `HttpResponse` to the framework-agnostic `HttpResponse` interface.
|
|
44
|
+
*
|
|
45
|
+
* Buffers headers and status code until the first write. Tracks abort state to safely
|
|
46
|
+
* skip writes on aborted connections. All uWS writes are wrapped in `res.cork()` for
|
|
47
|
+
* optimal performance.
|
|
48
|
+
*/
|
|
49
|
+
export declare class UWSResponse implements HttpResponse {
|
|
50
|
+
private readonly uwsRes;
|
|
51
|
+
private _statusCode;
|
|
52
|
+
private _headers;
|
|
53
|
+
private _headersSent;
|
|
54
|
+
private _writableEnded;
|
|
55
|
+
private _streaming;
|
|
56
|
+
private _aborted;
|
|
57
|
+
private _abortHandlers;
|
|
58
|
+
private _finished;
|
|
59
|
+
private _finishHandlers;
|
|
60
|
+
/** Set to true for HEAD requests — body bytes must not be sent. */
|
|
61
|
+
isHead: boolean;
|
|
62
|
+
/** Intermediate result passed between middleware. */
|
|
63
|
+
result?: any;
|
|
64
|
+
/** Allow arbitrary per-response properties. */
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
constructor(uwsRes: UWSHttpResponse);
|
|
67
|
+
get statusCode(): number;
|
|
68
|
+
get headersSent(): boolean;
|
|
69
|
+
get writableEnded(): boolean;
|
|
70
|
+
status(code: number): this;
|
|
71
|
+
setHeader(key: string, value: string | number | string[]): this;
|
|
72
|
+
appendHeader(key: string, value: string | number): this;
|
|
73
|
+
getHeader(key: string): string | string[] | undefined;
|
|
74
|
+
json(data: any): void;
|
|
75
|
+
send(data?: any): void;
|
|
76
|
+
end(data?: any): void;
|
|
77
|
+
/**
|
|
78
|
+
* Flushes status and headers to the wire immediately without ending the response.
|
|
79
|
+
* Required before streaming data (e.g. SSE). Safe to call multiple times — only
|
|
80
|
+
* acts on the first call.
|
|
81
|
+
*/
|
|
82
|
+
flushHeaders(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Writes all buffered headers to the wire, skipping content-length (uWS sets it
|
|
85
|
+
* automatically via end(data)/endWithoutBody(n)). Headers with multiple values (e.g. one
|
|
86
|
+
* set via `appendHeader`, such as multiple `Set-Cookie` cookies) are written as repeated
|
|
87
|
+
* `writeHeader` calls — uWS emits a separate header line per call rather than overwriting.
|
|
88
|
+
*/
|
|
89
|
+
private _writeHeaders;
|
|
90
|
+
/**
|
|
91
|
+
* Writes a chunk to the response without ending it (streaming / SSE).
|
|
92
|
+
* Flushes headers on the first call if they haven't been sent yet.
|
|
93
|
+
*/
|
|
94
|
+
write(data: string | Buffer): void;
|
|
95
|
+
/**
|
|
96
|
+
* Registers a callback to run when the client aborts the connection.
|
|
97
|
+
* Safe to call multiple times — all registered callbacks are invoked on abort.
|
|
98
|
+
* Uses the single uWS `onAborted` slot registered in the constructor.
|
|
99
|
+
*/
|
|
100
|
+
onAbort(callback: () => void): void;
|
|
101
|
+
/**
|
|
102
|
+
* Registers a callback fired exactly once when the response lifecycle ends — either a normal
|
|
103
|
+
* end() or a client abort. Fires immediately if the response has already finished. Handlers run
|
|
104
|
+
* fire-and-forget (via a resolved microtask) so slow/async work (e.g. a Redis write) never
|
|
105
|
+
* delays or blocks the actual response flush.
|
|
106
|
+
*/
|
|
107
|
+
onFinish(handler: () => void | Promise<void>): void;
|
|
108
|
+
private _fireFinish;
|
|
109
|
+
/** Converts a numeric status code to the "200 OK" string format uWS expects. */
|
|
110
|
+
private _statusToString;
|
|
111
|
+
}
|
|
112
|
+
/** Default maximum accepted request body size (10 MiB) when no explicit limit is configured. */
|
|
113
|
+
export declare const DEFAULT_MAX_BODY_SIZE: number;
|
|
114
|
+
/**
|
|
115
|
+
* Reads the full request body from a uWS response object as a Buffer.
|
|
116
|
+
* Body parsing (JSON / URL-encoded) is applied based on content-type and the result
|
|
117
|
+
* is cached on `req.body` / `req.rawBody`.
|
|
118
|
+
*
|
|
119
|
+
* If the accumulated body exceeds `maxBodySize`, a `413 Payload Too Large` response is written
|
|
120
|
+
* directly and the connection is ended — the caller must check the resolved value and skip running
|
|
121
|
+
* any further middleware/routing for this request when it's `false`, since a response has already
|
|
122
|
+
* been sent.
|
|
123
|
+
*
|
|
124
|
+
* @returns `true` if the body was read normally (or there was none to read), `false` if the request
|
|
125
|
+
* was rejected for exceeding `maxBodySize`.
|
|
126
|
+
*/
|
|
127
|
+
export declare function readBody(uwsRes: UWSHttpResponse, req: UWSRequest, maxBodySize?: number, res?: {
|
|
128
|
+
onAbort: (callback: () => void) => void;
|
|
129
|
+
}): Promise<boolean>;
|
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
import uWS from "uWebSockets.js";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* error handlers. On error, execution skips to the next error handler.
|
|
7
|
-
*
|
|
8
|
-
* Each handler is awaited via a Promise that resolves when next() is called, not when
|
|
9
|
-
* the handler's return value resolves. This correctly handles: (1) sync handlers that
|
|
10
|
-
* call next() synchronously, (2) async handlers that return next() or await before
|
|
11
|
-
* calling it, and (3) sync handlers that schedule next() via callbacks such as
|
|
12
|
-
* setTimeout or socket.once. The chain terminates early when a handler ends the
|
|
13
|
-
* response without calling next().
|
|
14
|
-
*/
|
|
15
|
-
export declare function runChain(handlers: RequestHandler[], req: HttpRequest, res: HttpResponse): Promise<void>;
|
|
16
|
-
/** Result returned by a pre-upgrade WebSocket auth function. */
|
|
17
|
-
export type WsUpgradeAuthResult = {
|
|
18
|
-
user?: any;
|
|
19
|
-
authPayload?: any;
|
|
20
|
-
authToken?: string;
|
|
21
|
-
/** Set to `true` to reject the connection with HTTP 401 before the WebSocket handshake. */
|
|
22
|
-
reject?: boolean;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Optional pre-upgrade auth function for WebSocket routes. Called synchronously inside the uWS
|
|
26
|
-
* `upgrade` callback — before the WebSocket handshake completes. Returning `{ reject: true }`
|
|
27
|
-
* sends an HTTP 401 and skips the upgrade entirely. Returning `{}` falls through to the
|
|
28
|
-
* post-upgrade message-based LOGIN flow. Returning `{ user, ... }` pre-authenticates the
|
|
29
|
-
* connection so clients that can send an Authorization header skip the LOGIN step.
|
|
30
|
-
*/
|
|
31
|
-
export type WsUpgradeAuth = (req: HttpRequest) => WsUpgradeAuthResult;
|
|
2
|
+
import type { IHttpRouter, RequestHandler } from "../types.js";
|
|
3
|
+
import { type WsUpgradeAuth } from "../MiddlewareChain.js";
|
|
4
|
+
export { runChain, extractParamNames } from "../MiddlewareChain.js";
|
|
5
|
+
export type { WsUpgradeAuth, WsUpgradeAuthResult } from "../MiddlewareChain.js";
|
|
32
6
|
/**
|
|
33
7
|
* Thin Express-compatible wrapper over `uWS.TemplatedApp`.
|
|
34
8
|
*
|
|
@@ -38,10 +12,9 @@ export type WsUpgradeAuth = (req: HttpRequest) => WsUpgradeAuthResult;
|
|
|
38
12
|
*
|
|
39
13
|
* Also supports:
|
|
40
14
|
* - `ws(path, handlers)` — native uWS WebSocket routing
|
|
41
|
-
* - `static(basePath)` — basic static file serving
|
|
42
15
|
* - `listen(host, port)` / `close()` — server lifecycle
|
|
43
16
|
*/
|
|
44
|
-
export declare class HttpRouter {
|
|
17
|
+
export declare class HttpRouter implements IHttpRouter {
|
|
45
18
|
private readonly uwsApp;
|
|
46
19
|
private readonly globalMiddleware;
|
|
47
20
|
private listenSocket;
|
|
@@ -52,7 +25,15 @@ export declare class HttpRouter {
|
|
|
52
25
|
private preRouteCount;
|
|
53
26
|
/** The port the server is currently listening on (set after a successful `listen()` call). */
|
|
54
27
|
listenPort: number;
|
|
55
|
-
|
|
28
|
+
/**
|
|
29
|
+
* HTTP verbs for which the application has already registered its own literal `/*` route
|
|
30
|
+
* (e.g. a `BaseStaticRoute` mounted at the site root via `@Route("/")`). Used by `listen()` to
|
|
31
|
+
* avoid clobbering an app-defined root catch-all with the default JSON 404 fallback.
|
|
32
|
+
*/
|
|
33
|
+
private readonly rootWildcardVerbs;
|
|
34
|
+
/** Maximum accepted request body size, in bytes. */
|
|
35
|
+
private readonly maxBodySize;
|
|
36
|
+
constructor(uwsApp: uWS.TemplatedApp, maxBodySize?: number);
|
|
56
37
|
/** Returns `true` if the server is currently listening. */
|
|
57
38
|
get isListening(): boolean;
|
|
58
39
|
/** Register global middleware that runs before every route handler. */
|
|
@@ -83,11 +64,6 @@ export declare class HttpRouter {
|
|
|
83
64
|
* Both `path` and `path + "/"` are registered to avoid trailing-slash mismatch.
|
|
84
65
|
*/
|
|
85
66
|
ws(routePath: string, handlers: RequestHandler[], wsOptions?: Partial<uWS.WebSocketBehavior<any>>, upgradeAuth?: WsUpgradeAuth): this;
|
|
86
|
-
/**
|
|
87
|
-
* Serves static files from a directory via a wildcard GET route.
|
|
88
|
-
* Files not found on disk return 404.
|
|
89
|
-
*/
|
|
90
|
-
static(basePath: string): this;
|
|
91
67
|
/**
|
|
92
68
|
* Starts listening on the given host and port.
|
|
93
69
|
* Resolves when the server is ready; rejects if the port cannot be bound.
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
2
|
import { Duplex } from "stream";
|
|
3
3
|
import type { WebSocket } from "uWebSockets.js";
|
|
4
|
-
import type { HttpRequest } from "
|
|
4
|
+
import type { HttpRequest } from "../types.js";
|
|
5
|
+
import type { IWebSocketShim } from "../IWebSocketShim.js";
|
|
5
6
|
/**
|
|
6
7
|
* HTTP request type for handling WebSocket upgrade requests.
|
|
7
8
|
* Extends `HttpRequest` with WebSocket-specific properties set by the router
|
|
8
|
-
* after the
|
|
9
|
+
* after the WebSocket connection is opened.
|
|
9
10
|
*/
|
|
10
11
|
export interface RequestWS extends HttpRequest {
|
|
11
12
|
/**
|
|
12
|
-
* The
|
|
13
|
+
* The WebSocket shim for this connection. Set on `open` after the upgrade.
|
|
13
14
|
*/
|
|
14
|
-
websocket:
|
|
15
|
+
websocket: IWebSocketShim | undefined;
|
|
15
16
|
/**
|
|
16
17
|
* Indicates that the WebSocket handler has processed this connection and the
|
|
17
18
|
* connection should remain open. Set to `true` by `wrapMiddleware` when a
|
|
@@ -31,7 +32,7 @@ export interface RequestWS extends HttpRequest {
|
|
|
31
32
|
* The Router's `ws()` implementation stores the shim in `ws.getUserData()` so that
|
|
32
33
|
* behavior callbacks can call `shim.emit(...)`.
|
|
33
34
|
*/
|
|
34
|
-
export declare class UWSWebSocketShim extends EventEmitter {
|
|
35
|
+
export declare class UWSWebSocketShim extends EventEmitter implements IWebSocketShim {
|
|
35
36
|
private readonly _ws;
|
|
36
37
|
readyState: number;
|
|
37
38
|
constructor(ws: WebSocket<any>);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provides a common base class for all entity's that will be persisted to a
|
|
2
|
+
* Provides a common base class for all entity's that will be persisted to a datasource.
|
|
3
3
|
*
|
|
4
4
|
* Note that the `@CreateDateColumn`, `@UpdateDateColumn`, and `@VersionColumn` decorators from TypeORM are not supported
|
|
5
5
|
* because they are not implemented in TypeORM's MongoDB support. They are instead implemented directly by this
|
|
@@ -10,9 +10,10 @@ export declare class ModelUtils {
|
|
|
10
10
|
/** The `typeorm` module containing the query operators used to build SQL queries. */
|
|
11
11
|
private static typeOrm;
|
|
12
12
|
private static idPropertyCache;
|
|
13
|
+
private static readOnlyPropertyCache;
|
|
13
14
|
/**
|
|
14
15
|
* Provides the `typeorm` module to use when building SQL queries. This is called automatically when a SQL
|
|
15
|
-
*
|
|
16
|
+
* datasource connection is established.
|
|
16
17
|
*
|
|
17
18
|
* @param module The `typeorm` module.
|
|
18
19
|
*/
|
|
@@ -28,6 +29,13 @@ export declare class ModelUtils {
|
|
|
28
29
|
* @returns The list of all property names that have the @Identifier decorator applied.
|
|
29
30
|
*/
|
|
30
31
|
static getIdPropertyNames(modelClass: any): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves a list of all of the specified class's properties that have the @ReadOnly decorator applied.
|
|
34
|
+
*
|
|
35
|
+
* @param modelClass The class definition to search for read-only properties from.
|
|
36
|
+
* @returns The list of all property names that have the @ReadOnly decorator applied.
|
|
37
|
+
*/
|
|
38
|
+
static getReadOnlyPropertyNames(modelClass: any): string[];
|
|
31
39
|
/**
|
|
32
40
|
* Builds a query object for use with `find` functions of the given repository for retrieving objects matching the
|
|
33
41
|
* specified unique identifier.
|
|
@@ -36,9 +44,14 @@ export declare class ModelUtils {
|
|
|
36
44
|
* @param modelClass The class definition of the data model to build a search query for.
|
|
37
45
|
* @param id The unique identifier to search for.
|
|
38
46
|
* @param version The version number of the document to search for.
|
|
47
|
+
* @param includeDeleted Set to false to exclude soft-deleted `RecoverableBaseEntity` records from matching.
|
|
48
|
+
* Defaults to true (matches regardless of deleted state) to preserve existing lookup/validation behavior;
|
|
49
|
+
* callers that expose a record by id to an API client (e.g. `findOne`, `exists`) should pass false so a
|
|
50
|
+
* soft-deleted record doesn't remain fully readable/resurrectable, the same way `buildSearchQuery` already
|
|
51
|
+
* excludes deleted records by default for list-style queries.
|
|
39
52
|
* @returns An object that can be passed to a TypeORM `find` function.
|
|
40
53
|
*/
|
|
41
|
-
static buildIdSearchQuery<T extends {}>(repo: Repository<T> | MongoRepository<T> | undefined, modelClass: any, id: any | any[], version?: number): any;
|
|
54
|
+
static buildIdSearchQuery<T extends {}>(repo: Repository<T> | MongoRepository<T> | undefined, modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean): any;
|
|
42
55
|
/**
|
|
43
56
|
* Builds a TypeORM compatible query object for use in `find` functions for retrieving objects matching the
|
|
44
57
|
* specified unique identifier.
|
|
@@ -48,7 +61,7 @@ export declare class ModelUtils {
|
|
|
48
61
|
* @param version The version number of the document to search for.
|
|
49
62
|
* @returns An object that can be passed to a TypeORM `find` function.
|
|
50
63
|
*/
|
|
51
|
-
static buildIdSearchQuerySQL(modelClass: any, id: any | any[], version?: number): any;
|
|
64
|
+
static buildIdSearchQuerySQL(modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean): any;
|
|
52
65
|
/**
|
|
53
66
|
* Builds a MongoDB compatible query object for use in `find` functions for retrieving objects matching the
|
|
54
67
|
* specified unique identifier.
|
|
@@ -56,9 +69,10 @@ export declare class ModelUtils {
|
|
|
56
69
|
* @param modelClass The class definition of the data model to build a search query for.
|
|
57
70
|
* @param id The unique identifier to search for.
|
|
58
71
|
* @param version The version number of the document to search for.
|
|
72
|
+
* @param includeDeleted Set to true to also match soft-deleted `RecoverableBaseEntity` records.
|
|
59
73
|
* @returns An object that can be passed to a MongoDB `find` function.
|
|
60
74
|
*/
|
|
61
|
-
static buildIdSearchQueryMongo(modelClass: any, id: any | any[], version?: number): any;
|
|
75
|
+
static buildIdSearchQueryMongo(modelClass: any, id: any | any[], version?: number, includeDeleted?: boolean): any;
|
|
62
76
|
/**
|
|
63
77
|
* Given a string containing a parameter value and/or a comparison operation return a TypeORM compatible find value.
|
|
64
78
|
* e.g.
|
|
@@ -68,6 +82,28 @@ export declare class ModelUtils {
|
|
|
68
82
|
* @param param
|
|
69
83
|
*/
|
|
70
84
|
private static getQueryParamValue;
|
|
85
|
+
/**
|
|
86
|
+
* Recursively verifies that no key in the given value (at any depth, including keys of objects nested inside
|
|
87
|
+
* arrays) is a MongoDB operator (starts with `$`) or uses dot-notation field addressing (contains `.`). Client
|
|
88
|
+
* input is only ever meant to supply plain field values/comparison operands — never raw Mongo query operators —
|
|
89
|
+
* so any such key indicates an attempt to inject arbitrary query behavior (e.g. `$where`, `$expr`, or reaching
|
|
90
|
+
* into a field the API doesn't expose via dot-notation).
|
|
91
|
+
*
|
|
92
|
+
* @param value The value to check, typically a parsed query parameter.
|
|
93
|
+
* @throws {ApiError} If an operator-like or dotted key is found anywhere in `value`.
|
|
94
|
+
*/
|
|
95
|
+
private static assertNoOperatorInjection;
|
|
96
|
+
/** Maximum accepted length of a client-supplied `like()` search pattern. */
|
|
97
|
+
private static readonly MAX_LIKE_PATTERN_LENGTH;
|
|
98
|
+
/**
|
|
99
|
+
* Best-effort check for regex patterns vulnerable to catastrophic backtracking (ReDoS). Rejects patterns that
|
|
100
|
+
* are unreasonably long, or that contain a quantified group whose contents are themselves quantified (e.g.
|
|
101
|
+
* `(a+)+`, `(a*)*`) — the classic shape that causes exponential backtracking in JS's regex engine. This is not
|
|
102
|
+
* an exhaustive defense; it catches the common cases a client would realistically send.
|
|
103
|
+
*
|
|
104
|
+
* @param pattern The user-supplied `like()` pattern.
|
|
105
|
+
*/
|
|
106
|
+
private static isUnsafeRegexPattern;
|
|
71
107
|
/**
|
|
72
108
|
* Given a string containing a parameter value and/or a comparison operation return a MongoDB compatible find value.
|
|
73
109
|
* e.g.
|
|
@@ -97,13 +133,12 @@ export declare class ModelUtils {
|
|
|
97
133
|
*
|
|
98
134
|
* @param modelClass The class definition of the data model to build a search query for.
|
|
99
135
|
* @param repo The repository to build a search query for.
|
|
100
|
-
* @param {any}
|
|
101
|
-
* @param {any} queryParams The URI query parameters that were included in the request.
|
|
136
|
+
* @param {any} query The search query parameters to include.
|
|
102
137
|
* @param {bool} exactMatch Set to true to create a query where parameters are to be matched exactly, otherwise set to false to use a 'contains' search.
|
|
103
138
|
* @param {any} user The user that is performing the request.
|
|
104
139
|
* @returns {object} The TypeORM compatible query object.
|
|
105
140
|
*/
|
|
106
|
-
static buildSearchQuery<T extends {}>(modelClass: any, repo: Repository<T> | MongoRepository<T> | undefined,
|
|
141
|
+
static buildSearchQuery<T extends {}>(modelClass: any, repo: Repository<T> | MongoRepository<T> | undefined, query?: any, exactMatch?: boolean, user?: any): any;
|
|
107
142
|
/**
|
|
108
143
|
* Builds a TypeORM compatible query object for the given criteria. Query params can have a value containing a
|
|
109
144
|
* conditional operator to apply for the search. The operator is encoded with the format `op(value)`. The following
|
|
@@ -121,13 +156,12 @@ export declare class ModelUtils {
|
|
|
121
156
|
* When no operator is provided the comparison will always be evaluated as `eq`.
|
|
122
157
|
*
|
|
123
158
|
* @param modelClass The class definition of the data model to build a search query for.
|
|
124
|
-
* @param {any}
|
|
125
|
-
* @param {any} queryParams The URI query parameters that were included in the request.
|
|
159
|
+
* @param {any} query The search query parameters to include.
|
|
126
160
|
* @param {bool} exactMatch Set to true to create a query where parameters are to be matched exactly, otherwise set to false to use a 'contains' search.
|
|
127
161
|
* @param {any} user The user that is performing the request.
|
|
128
162
|
* @returns {object} The TypeORM compatible query object.
|
|
129
163
|
*/
|
|
130
|
-
static buildSearchQuerySQL(modelClass: any,
|
|
164
|
+
static buildSearchQuerySQL(modelClass: any, query?: any, exactMatch?: boolean, user?: any): any;
|
|
131
165
|
/**
|
|
132
166
|
* Builds a MongoDB compatible query object for the given criteria. Query params can have a value containing a
|
|
133
167
|
* conditional operator to apply for the search. The operator is encoded with the format `op(value)`. The following
|
|
@@ -147,13 +181,12 @@ export declare class ModelUtils {
|
|
|
147
181
|
* NOTE: The result of this function is only compatible with the `aggregate()` function.
|
|
148
182
|
*
|
|
149
183
|
* @param modelClass The class definition of the data model to build a search query for.
|
|
150
|
-
* @param {any}
|
|
151
|
-
* @param {any} queryParams The URI query parameters that were included in the request.
|
|
184
|
+
* @param {any} query The search query parameters to include.
|
|
152
185
|
* @param {bool} exactMatch Set to true to create a query where parameters are to be matched exactly, otherwise set to false to use a 'contains' search.
|
|
153
186
|
* @param {any} user The user that is performing the request.
|
|
154
|
-
* @returns {object} The
|
|
187
|
+
* @returns {object} The MongoDB compatible query object.
|
|
155
188
|
*/
|
|
156
|
-
static buildSearchQueryMongo(modelClass: any,
|
|
189
|
+
static buildSearchQueryMongo(modelClass: any, query?: any, exactMatch?: boolean, user?: any): any;
|
|
157
190
|
/**
|
|
158
191
|
* Loads all model schema files from the specified path and returns a map containing all the definitions.
|
|
159
192
|
*
|
|
@@ -9,7 +9,9 @@ import { BaseEntity } from "./BaseEntity.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare abstract class RecoverableBaseEntity extends BaseEntity {
|
|
11
11
|
/**
|
|
12
|
-
* Indicates if the document has been soft deleted.
|
|
12
|
+
* Indicates if the document has been soft deleted. Only `RepoUtils.delete()` (gated on `ACLAction.DELETE`)
|
|
13
|
+
* may change this — `@ReadOnly` prevents it from being set via the ordinary create/update paths, which are
|
|
14
|
+
* only gated on `ACLAction.CREATE`/`UPDATE`.
|
|
13
15
|
*/
|
|
14
16
|
deleted: boolean;
|
|
15
17
|
constructor(other?: Partial<RecoverableBaseEntity>);
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import type { Repository } from "typeorm";
|
|
1
|
+
import type { EntityManager, Repository } from "typeorm";
|
|
2
2
|
import { MongoRepository } from "../database/MongoRepository.js";
|
|
3
3
|
import { BaseEntity } from "../models/BaseEntity.js";
|
|
4
4
|
import { SimpleEntity } from "../models/SimpleEntity.js";
|
|
5
|
-
import { JWTUser } from "@rapidrest/core";
|
|
6
|
-
import { Redis } from "ioredis";
|
|
7
|
-
import { ObjectFactory } from "../ObjectFactory.js";
|
|
5
|
+
import { type JWTUser } from "@rapidrest/core";
|
|
8
6
|
import { NotificationUtils } from "../NotificationUtils.js";
|
|
9
|
-
import { AccessControlList } from "../security/index.js";
|
|
7
|
+
import { type AccessControlList } from "../security/index.js";
|
|
10
8
|
import type { ACLUtils } from "../security/ACLUtils.js";
|
|
11
|
-
import { ConnectionManager } from "../database/index.js";
|
|
9
|
+
import { ConnectionManager, RedisCache } from "../database/index.js";
|
|
10
|
+
import type { ClientSession } from "mongodb";
|
|
11
|
+
export interface TransactionInfo {
|
|
12
|
+
entityManager?: EntityManager;
|
|
13
|
+
session?: ClientSession;
|
|
14
|
+
}
|
|
12
15
|
/**
|
|
13
16
|
* The available options used for `RepoUtils` operations.
|
|
14
17
|
*/
|
|
@@ -21,6 +24,8 @@ export interface RepoOperationOptions {
|
|
|
21
24
|
recordEvent?: boolean;
|
|
22
25
|
/** Set to `true` to not send a push notification. */
|
|
23
26
|
skipPush?: boolean;
|
|
27
|
+
/** The transactional session to execute the operation within. */
|
|
28
|
+
transaction?: TransactionInfo;
|
|
24
29
|
/** The authenticated user making the request. */
|
|
25
30
|
user?: JWTUser;
|
|
26
31
|
}
|
|
@@ -41,6 +46,17 @@ export interface RepoDeleteOptions extends RepoOperationOptions {
|
|
|
41
46
|
version?: number | string;
|
|
42
47
|
}
|
|
43
48
|
export interface RepoFindOptions extends RepoOperationOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Overrides the `ACLAction` checked for this operation instead of its usual default (`COUNT` for `count()`,
|
|
51
|
+
* `LIST` for `find()`, `READ` for `findOne()`). Used by callers layering a different operation on top of one
|
|
52
|
+
* of these (e.g. `exists()` checking `ACLAction.EXISTS` instead of `COUNT` when reusing `count()`).
|
|
53
|
+
*/
|
|
54
|
+
action?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Set to `true` to include soft-deleted `RecoverableBaseEntity` rows/documents that would otherwise be
|
|
57
|
+
* excluded by default. Has no effect for a non-recoverable model class.
|
|
58
|
+
*/
|
|
59
|
+
includeDeleted?: boolean;
|
|
44
60
|
/** The total number of resources to retrieve. */
|
|
45
61
|
limit?: number;
|
|
46
62
|
/** The page number of the paginated results to retrieve. */
|
|
@@ -61,16 +77,16 @@ export interface RepoUpdateOptions<T extends BaseEntity | SimpleEntity> extends
|
|
|
61
77
|
* @author Jean-Philippe Steinmetz
|
|
62
78
|
*/
|
|
63
79
|
export declare class RepoUtils<T extends BaseEntity | SimpleEntity> {
|
|
80
|
+
private _objectFactory?;
|
|
64
81
|
protected aclUtils?: ACLUtils;
|
|
65
|
-
/** The
|
|
66
|
-
protected
|
|
82
|
+
/** The store that will be used as a 2nd level cache for all cacheable models. */
|
|
83
|
+
protected cache?: RedisCache<T>;
|
|
67
84
|
protected config: any;
|
|
68
85
|
protected connectionManager?: ConnectionManager;
|
|
69
86
|
/** The unique identifier of the default ACL for the model type. */
|
|
70
87
|
defaultACLUid: string;
|
|
71
88
|
protected logger: any;
|
|
72
89
|
protected modelClass: any;
|
|
73
|
-
protected objectFactory?: ObjectFactory;
|
|
74
90
|
protected notificationUtils?: NotificationUtils;
|
|
75
91
|
/** The model class associated with the controller to perform operations against. */
|
|
76
92
|
repo?: Repository<T> | MongoRepository<T>;
|
|
@@ -78,12 +94,41 @@ export declare class RepoUtils<T extends BaseEntity | SimpleEntity> {
|
|
|
78
94
|
constructor(modelClass: any, repo?: Repository<T> | MongoRepository<T>);
|
|
79
95
|
protected init(): Promise<void>;
|
|
80
96
|
/**
|
|
81
|
-
*
|
|
97
|
+
* Retrieves every uid matching the given (already-built) search query, ignoring any pagination `take`/`page`
|
|
98
|
+
* baked into it by `ModelUtils.buildSearchQuery`. Used by `count`/`exists`/`truncate`, which must narrow by
|
|
99
|
+
* record-level ACLs against the *entire* matching set rather than a single page of it — applying the default
|
|
100
|
+
* `take` here would silently undercount, under-check existence for, or under-delete a large result set.
|
|
82
101
|
*/
|
|
83
|
-
|
|
102
|
+
private findAllUids;
|
|
103
|
+
/**
|
|
104
|
+
* Filters the given uids down to those the user has `action` permission for, checking in bounded-size
|
|
105
|
+
* batches rather than a single unbounded `Promise.all` so a large matching set can't fire an unbounded
|
|
106
|
+
* number of concurrent permission-check round trips at once.
|
|
107
|
+
*/
|
|
108
|
+
private filterPermittedUids;
|
|
84
109
|
count(query: any, options?: RepoFindOptions): Promise<number>;
|
|
85
110
|
/**
|
|
86
|
-
*
|
|
111
|
+
* Determines whether an object with the given unique identifier (and, optionally, a specific version) exists
|
|
112
|
+
* in the datasource. Respects record-level ACLs the same way `count()` does.
|
|
113
|
+
*
|
|
114
|
+
* @param id The unique identifier of the object to check for.
|
|
115
|
+
* @param options The additional options to consider, such as `version` and the requesting `user`.
|
|
116
|
+
*/
|
|
117
|
+
exists(id: string, options?: RepoFindOptions): Promise<number>;
|
|
118
|
+
/**
|
|
119
|
+
* Runs the actual existence check/count for `exists()`, deduped by uid and clamped to at most 1. Split out
|
|
120
|
+
* so `exists()` can run it twice — once for a live record, once (gated on DELETE+UPDATE permission) for a
|
|
121
|
+
* soft-deleted one — without duplicating the Mongo/SQL/record-ACL branching.
|
|
122
|
+
*
|
|
123
|
+
* @param id The unique identifier of the object to check for.
|
|
124
|
+
* @param options The additional options to consider, such as `version`.
|
|
125
|
+
* @param includeDeleted Whether to match a soft-deleted record.
|
|
126
|
+
* @param enforceAction The ACL action to check per matched record on a `recordACL` model, or `null` to skip
|
|
127
|
+
* that check (used for the second, already-authorized `includeDeleted` pass).
|
|
128
|
+
*/
|
|
129
|
+
private existsQuery;
|
|
130
|
+
/**
|
|
131
|
+
* Stores a new record of the provided object in the datasource. Performs pre-processing, permission checks against
|
|
87
132
|
* the class ACL, cache seeding, telemetry recording and push notifications.
|
|
88
133
|
*
|
|
89
134
|
* @param obj The object to store.
|
|
@@ -92,7 +137,7 @@ export declare class RepoUtils<T extends BaseEntity | SimpleEntity> {
|
|
|
92
137
|
create(obj: Partial<T>, options?: RepoCreateOptions): Promise<T>;
|
|
93
138
|
delete(uid: string, options: RepoDeleteOptions): Promise<void>;
|
|
94
139
|
/**
|
|
95
|
-
* Retrieves an array of objects from the
|
|
140
|
+
* Retrieves an array of objects from the datasource matching the given search query. This function will first
|
|
96
141
|
* attempt to look up the results in the cache. Also checks ACLs for READ permission.
|
|
97
142
|
*
|
|
98
143
|
* @param query The constructed search query to run.
|
|
@@ -112,6 +157,23 @@ export declare class RepoUtils<T extends BaseEntity | SimpleEntity> {
|
|
|
112
157
|
* full acccess to any user (including unauthenticated anonymous users).
|
|
113
158
|
*/
|
|
114
159
|
getDefaultACL(): AccessControlList | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Checks whether the caller has both `DELETE` and `UPDATE` permission against the given ACL (or ACL uid).
|
|
162
|
+
* Ordinary READ/LIST/EXISTS permission on a record says nothing about whether its owner
|
|
163
|
+
* consented to its "deleted" state being visible, so those two actions (the ones actually needed to
|
|
164
|
+
* restore the record) are required instead.
|
|
165
|
+
*
|
|
166
|
+
* @param user The user to check.
|
|
167
|
+
* @param acl The ACL (or ACL uid) governing the record.
|
|
168
|
+
*/
|
|
169
|
+
private canViewDeleted;
|
|
170
|
+
/**
|
|
171
|
+
* Logs a swallowed error from a fire-and-forget cache operation. Cache reads/writes are best-effort and
|
|
172
|
+
* must never propagate into (and thus fail/retry) the write they're attached to.
|
|
173
|
+
* @param op The cache operation that failed (e.g. "save", "delete").
|
|
174
|
+
* @param err The error thrown by the cache operation.
|
|
175
|
+
*/
|
|
176
|
+
private logCacheError;
|
|
115
177
|
/**
|
|
116
178
|
* Hashes the given query object to a unique string.
|
|
117
179
|
* @param query The query object to hash.
|
|
@@ -125,6 +187,10 @@ export declare class RepoUtils<T extends BaseEntity | SimpleEntity> {
|
|
|
125
187
|
* @returns The class type (constructor) associated with the given object.
|
|
126
188
|
*/
|
|
127
189
|
getClassType(obj: any): any;
|
|
190
|
+
/**
|
|
191
|
+
* Returns the current transactional session information, if present.
|
|
192
|
+
*/
|
|
193
|
+
protected getTransaction(options?: RepoOperationOptions): TransactionInfo | undefined;
|
|
128
194
|
/**
|
|
129
195
|
* Creates a new instance of obj scoped to the correct model class or sub-class.
|
|
130
196
|
*/
|
|
@@ -133,8 +199,12 @@ export declare class RepoUtils<T extends BaseEntity | SimpleEntity> {
|
|
|
133
199
|
* Search for existing object based on passed in id and version and product uid.
|
|
134
200
|
*
|
|
135
201
|
* The result of this function is compatible with all `Repository.find()` functions.
|
|
202
|
+
*
|
|
203
|
+
* @param includeDeleted Set to false to exclude soft-deleted `RecoverableBaseEntity` records from matching.
|
|
204
|
+
* Defaults to true; pass false when the result is exposed directly to an API client (e.g. `findOne`, `exists`)
|
|
205
|
+
* so a soft-deleted record isn't returned as if it still existed.
|
|
136
206
|
*/
|
|
137
|
-
searchIdQuery(id: string, version?: number | string): any;
|
|
207
|
+
searchIdQuery(id: string, version?: number | string, includeDeleted?: boolean): any;
|
|
138
208
|
truncate(query: any, options: RepoFindOptions): Promise<void>;
|
|
139
209
|
update(obj: Partial<T>, existing: T, options?: RepoUpdateOptions<T>): Promise<T>;
|
|
140
210
|
/**
|