@rapidrest/service-core 1.0.0-rc.7 → 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 -203
- 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
|
@@ -9,11 +9,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
// Copyright (C) 2020-2026 Jean-Philippe Steinmetz
|
|
12
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
12
13
|
///////////////////////////////////////////////////////////////////////////////
|
|
13
14
|
import { JWTUtils, ObjectDecorators } from "@rapidrest/core";
|
|
14
15
|
import dayjs from "dayjs";
|
|
15
16
|
import { createRequire } from "module";
|
|
16
|
-
|
|
17
|
+
import { NetUtils } from "../NetUtils.js";
|
|
18
|
+
const { Config, Init, Logger } = ObjectDecorators;
|
|
17
19
|
const _require = createRequire(process.cwd() + "/package.json");
|
|
18
20
|
const duration = _require("dayjs/plugin/duration");
|
|
19
21
|
dayjs.extend(duration);
|
|
@@ -61,6 +63,29 @@ export class JWTStrategy {
|
|
|
61
63
|
this.options.headerKey = options.headerKey.toLowerCase();
|
|
62
64
|
this._headerSchemeRegex = new RegExp("^" + this.options.headerScheme + "$", "i");
|
|
63
65
|
}
|
|
66
|
+
init() {
|
|
67
|
+
// Signed-cookie verification was never implemented (req.signedCookies is always `{}` in both HTTP
|
|
68
|
+
// adapters — see getAuthToken() below), so enabling this option silently disables cookie-based
|
|
69
|
+
// authentication entirely rather than adding the extra verification an operator would expect from the
|
|
70
|
+
// name. Warn loudly at startup instead of letting that be discovered as a confusing runtime auth failure.
|
|
71
|
+
if (this.options.cookieSecure) {
|
|
72
|
+
this.logger?.warn("JWTStrategyOptions.cookieSecure is enabled, but signed-cookie verification is not implemented. " +
|
|
73
|
+
"Cookie-based authentication is disabled while this option is set to true — set it to false " +
|
|
74
|
+
"to authenticate via the plain `jwt` cookie instead.");
|
|
75
|
+
}
|
|
76
|
+
// Defense-in-depth only: the underlying jsonwebtoken library already restricts verification to
|
|
77
|
+
// algorithms compatible with the configured key's type when `options.algorithms` is left unset, so
|
|
78
|
+
// this isn't currently exploitable. Pinning it explicitly for the common case of a plain symmetric
|
|
79
|
+
// secret removes any reliance on that library default. Left untouched for PEM/asymmetric keys —
|
|
80
|
+
// there's no reliable way to guess the intended algorithm family (RS/ES/PS, key size) from the key's
|
|
81
|
+
// runtime shape alone, and guessing wrong would break those apps' verification entirely.
|
|
82
|
+
if (this.config &&
|
|
83
|
+
!this.config.options?.algorithms &&
|
|
84
|
+
typeof this.config.secret === "string" &&
|
|
85
|
+
!this.config.secret.includes("BEGIN")) {
|
|
86
|
+
this.config.options = { ...this.config.options, algorithms: ["HS256"] };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
64
89
|
/**
|
|
65
90
|
* Scans the provided request object for an authentication token this strategy can process.
|
|
66
91
|
* @param req The request to scan for an auth token.
|
|
@@ -76,14 +101,16 @@ export class JWTStrategy {
|
|
|
76
101
|
this.options.queryKey in req.query) {
|
|
77
102
|
authToken = req.query[this.options.queryKey];
|
|
78
103
|
}
|
|
79
|
-
// Next check the headers
|
|
104
|
+
// Next check the headers, but only if a higher-precedence source (the query parameter above)
|
|
105
|
+
// hasn't already supplied a token — a later-checked, lower-precedence source must never override
|
|
106
|
+
// an earlier one. It's possible there is more than one header value defined; loop through each of
|
|
80
107
|
// them until we have a verified token.
|
|
81
|
-
if (this.options.headerKey && this.options.headerKey in req.headers) {
|
|
108
|
+
if (!authToken && this.options.headerKey && this.options.headerKey in req.headers) {
|
|
82
109
|
const value = req.headers[this.options.headerKey];
|
|
83
110
|
const headers = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
|
|
84
111
|
// Loop through the headers looking for Authentication and our scheme
|
|
85
|
-
for (const header
|
|
86
|
-
const parts =
|
|
112
|
+
for (const header of headers) {
|
|
113
|
+
const parts = header.split(" ");
|
|
87
114
|
if (parts.length !== 2) {
|
|
88
115
|
continue;
|
|
89
116
|
}
|
|
@@ -91,17 +118,21 @@ export class JWTStrategy {
|
|
|
91
118
|
continue;
|
|
92
119
|
}
|
|
93
120
|
authToken = parts[1];
|
|
121
|
+
break;
|
|
94
122
|
}
|
|
95
123
|
}
|
|
96
|
-
// Check the cookie header — only
|
|
97
|
-
|
|
98
|
-
|
|
124
|
+
// Check the cookie header — lowest precedence, so only consulted if neither the query parameter
|
|
125
|
+
// nor the header supplied a token above.
|
|
126
|
+
// TODO Decrypt the signed cookie — until this is implemented, req.signedCookies is always `{}` (see
|
|
127
|
+
// both HTTP adapters), so this branch never finds a token; init() warns at startup when cookieSecure
|
|
128
|
+
// is enabled so that's not a silent failure.
|
|
129
|
+
if (!authToken && this.options.cookieSecure && this.options.cookieName && req.signedCookies) {
|
|
99
130
|
const cookieToken = req.signedCookies[this.options.cookieName];
|
|
100
131
|
if (cookieToken) {
|
|
101
132
|
authToken = cookieToken;
|
|
102
133
|
}
|
|
103
134
|
}
|
|
104
|
-
if (!this.options.cookieSecure && this.options.cookieName && req.cookies) {
|
|
135
|
+
if (!authToken && !this.options.cookieSecure && this.options.cookieName && req.cookies) {
|
|
105
136
|
const cookieToken = req.cookies[this.options.cookieName];
|
|
106
137
|
if (cookieToken) {
|
|
107
138
|
authToken = cookieToken;
|
|
@@ -109,7 +140,7 @@ export class JWTStrategy {
|
|
|
109
140
|
}
|
|
110
141
|
return authToken;
|
|
111
142
|
}
|
|
112
|
-
async authenticate(req, res
|
|
143
|
+
async authenticate(req, res) {
|
|
113
144
|
let user = undefined;
|
|
114
145
|
let authPayload = undefined;
|
|
115
146
|
let authToken = this.getAuthToken(req);
|
|
@@ -122,6 +153,14 @@ export class JWTStrategy {
|
|
|
122
153
|
}
|
|
123
154
|
authPayload = payload;
|
|
124
155
|
if (user) {
|
|
156
|
+
// If sessions are enabled, update the stored information about the authenticated user
|
|
157
|
+
if (req.session) {
|
|
158
|
+
const now = Date.now();
|
|
159
|
+
req.session.ip = NetUtils.getIPAddress(req);
|
|
160
|
+
req.session.lastAccess = now;
|
|
161
|
+
req.session.lastLogin = req.session.lastLogin ?? now;
|
|
162
|
+
req.session.userUid = user.uid;
|
|
163
|
+
}
|
|
125
164
|
return {
|
|
126
165
|
data: authToken,
|
|
127
166
|
method: this.name,
|
|
@@ -131,12 +170,9 @@ export class JWTStrategy {
|
|
|
131
170
|
};
|
|
132
171
|
}
|
|
133
172
|
}
|
|
134
|
-
if (required) {
|
|
135
|
-
throw new Error("Invalid or missing auth token.");
|
|
136
|
-
}
|
|
137
173
|
return undefined;
|
|
138
174
|
}
|
|
139
|
-
authenticateSync(req, res
|
|
175
|
+
authenticateSync(req, res) {
|
|
140
176
|
let user = undefined;
|
|
141
177
|
let authPayload = undefined;
|
|
142
178
|
let authToken = this.getAuthToken(req);
|
|
@@ -149,6 +185,14 @@ export class JWTStrategy {
|
|
|
149
185
|
}
|
|
150
186
|
authPayload = payload;
|
|
151
187
|
if (user) {
|
|
188
|
+
// If sessions are enabled, update the stored information about the authenticated user
|
|
189
|
+
if (req.session) {
|
|
190
|
+
const now = Date.now();
|
|
191
|
+
req.session.ip = NetUtils.getIPAddress(req);
|
|
192
|
+
req.session.lastAccess = now;
|
|
193
|
+
req.session.lastLogin = req.session.lastLogin ?? now;
|
|
194
|
+
req.session.userUid = user.uid;
|
|
195
|
+
}
|
|
152
196
|
return {
|
|
153
197
|
data: authToken,
|
|
154
198
|
method: this.name,
|
|
@@ -158,9 +202,6 @@ export class JWTStrategy {
|
|
|
158
202
|
};
|
|
159
203
|
}
|
|
160
204
|
}
|
|
161
|
-
if (required) {
|
|
162
|
-
throw new Error("Invalid or missing auth token.");
|
|
163
|
-
}
|
|
164
205
|
return undefined;
|
|
165
206
|
}
|
|
166
207
|
}
|
|
@@ -168,4 +209,14 @@ __decorate([
|
|
|
168
209
|
Config("auth"),
|
|
169
210
|
__metadata("design:type", Object)
|
|
170
211
|
], JWTStrategy.prototype, "config", void 0);
|
|
212
|
+
__decorate([
|
|
213
|
+
Logger,
|
|
214
|
+
__metadata("design:type", Object)
|
|
215
|
+
], JWTStrategy.prototype, "logger", void 0);
|
|
216
|
+
__decorate([
|
|
217
|
+
Init,
|
|
218
|
+
__metadata("design:type", Function),
|
|
219
|
+
__metadata("design:paramtypes", []),
|
|
220
|
+
__metadata("design:returntype", void 0)
|
|
221
|
+
], JWTStrategy.prototype, "init", null);
|
|
171
222
|
//# sourceMappingURL=JWTStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JWTStrategy.js","sourceRoot":"","sources":["../../../src/auth/JWTStrategy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gFAAgF;AAChF,kDAAkD;AAClD,+EAA+E;AAC/E,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"JWTStrategy.js","sourceRoot":"","sources":["../../../src/auth/JWTStrategy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gFAAgF;AAChF,kDAAkD;AAClD,mCAAmC;AACnC,+EAA+E;AAC/E,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAsD,MAAM,iBAAiB,CAAC;AAEjH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;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IADP,MAAM,CAAC,MAAM,CAAC;;2CACK;AAGZ;IADP,MAAM;;2CACa;AAcZ;IADP,IAAI;;;;uCA4BJ"}
|
package/dist/lib/auth/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
///////////////////////////////////////////////////////////////////////////////
|
|
2
2
|
// Copyright (C) 2020-2026 Jean-Philippe Steinmetz. All rights reserved.
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
4
5
|
import { MongoConnection } from "./MongoConnection.js";
|
|
5
6
|
/**
|
|
@@ -11,4 +12,18 @@ import { MongoConnection } from "./MongoConnection.js";
|
|
|
11
12
|
export function isSqlDataSource(conn) {
|
|
12
13
|
return !!conn && typeof conn.getRepository === "function" && !(conn instanceof MongoConnection);
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Dynamically imports the `redis` package, throwing a helpful error if it isn't installed. `redis` is a peer
|
|
17
|
+
* dependency (like `mongodb` and `typeorm`) rather than a hard dependency of this package, so it must only be
|
|
18
|
+
* loaded when a consumer actually configures a redis-backed feature — never imported at the top of a module
|
|
19
|
+
* that's always loaded, or every consumer would be forced to install it regardless of whether they use it.
|
|
20
|
+
*/
|
|
21
|
+
export async function importRedis() {
|
|
22
|
+
try {
|
|
23
|
+
return await import("redis");
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
throw new Error("This feature requires the optional peer dependency 'redis'. Install it with: yarn add redis");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
14
29
|
//# sourceMappingURL=ConnectionKinds.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionKinds.js","sourceRoot":"","sources":["../../../src/database/ConnectionKinds.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,wEAAwE;AACxE,+EAA+E;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAS;IACrC,OAAO,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,aAAa,KAAK,UAAU,IAAI,CAAC,CAAC,IAAI,YAAY,eAAe,CAAC,CAAC;AACpG,CAAC"}
|
|
1
|
+
{"version":3,"file":"ConnectionKinds.js","sourceRoot":"","sources":["../../../src/database/ConnectionKinds.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,wEAAwE;AACxE,mCAAmC;AACnC,+EAA+E;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAS;IACrC,OAAO,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,aAAa,KAAK,UAAU,IAAI,CAAC,CAAC,IAAI,YAAY,eAAe,CAAC,CAAC;AACpG,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC7B,IAAI,CAAC;QACD,OAAO,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,6FAA6F,CAAC,CAAC;IACnH,CAAC;AACL,CAAC"}
|
|
@@ -9,10 +9,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
// Copyright (C) 2020-2026 Jean-Philippe Steinmetz
|
|
12
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
12
13
|
///////////////////////////////////////////////////////////////////////////////
|
|
13
14
|
import { ObjectDecorators } from "@rapidrest/core";
|
|
14
|
-
import {
|
|
15
|
-
import { isSqlDataSource } from "./ConnectionKinds.js";
|
|
15
|
+
import { importRedis, isSqlDataSource } from "./ConnectionKinds.js";
|
|
16
16
|
import { MongoConnection } from "./MongoConnection.js";
|
|
17
17
|
import { MongoSchemaSync } from "./MongoSchemaSync.js";
|
|
18
18
|
const { Destroy, Logger } = ObjectDecorators;
|
|
@@ -35,17 +35,24 @@ export class ConnectionManager {
|
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
if (!config.type || !config.host) {
|
|
38
|
-
throw new Error(`Invalid
|
|
38
|
+
throw new Error(`Invalid datasource config: ${JSON.stringify(config)}.`);
|
|
39
39
|
}
|
|
40
40
|
return `${config.protocol ? config.protocol : config.type}://${config.username && config.password ? `${config.username}:${config.password}@` : ""}${config.host}${config.port ? `:${config.port}` : ""}${config.database ? `/${config.database}` : ""}${config.options ? `?${config.options}` : ""}`;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Redacts the userinfo (credentials) portion of a connection URI for safe logging, regardless of
|
|
45
|
+
* whether the URI came from a `url` config field or was built from separate username/password fields.
|
|
46
|
+
*/
|
|
47
|
+
redactUri(uri) {
|
|
48
|
+
return uri.replace(/:\/\/[^@/]+@/, "://****@");
|
|
49
|
+
}
|
|
43
50
|
/**
|
|
44
51
|
* Dynamically imports the given optional peer dependency, throwing a helpful error if it is not installed.
|
|
45
52
|
*
|
|
46
53
|
* @param pkg The name of the package to import.
|
|
47
|
-
* @param datastoreName The name of the
|
|
48
|
-
* @param datastoreType The type of the
|
|
54
|
+
* @param datastoreName The name of the datasource requiring the package.
|
|
55
|
+
* @param datastoreType The type of the datasource requiring the package.
|
|
49
56
|
*/
|
|
50
57
|
async importOptionalDependency(pkg, datastoreName, datastoreType) {
|
|
51
58
|
try {
|
|
@@ -55,6 +62,33 @@ export class ConnectionManager {
|
|
|
55
62
|
throw new Error(`Datastore '${datastoreName}' is of type '${datastoreType}' which requires the optional peer dependency '${pkg}'. Install it with: yarn add ${pkg}`);
|
|
56
63
|
}
|
|
57
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Determines whether the given MongoDB deployment supports multi-document transactions (i.e. is configured
|
|
67
|
+
* as a replica set or a sharded cluster) by inspecting the `hello` handshake response. A standalone
|
|
68
|
+
* `mongod` responds with neither `setName` (replica set membership) nor `msg: "isdbgrid"` (mongos), and
|
|
69
|
+
* doesn't support transactions at all.
|
|
70
|
+
*
|
|
71
|
+
* @param db The database to check.
|
|
72
|
+
* @param name The name of the datastore, used only for the log message if transactions aren't supported.
|
|
73
|
+
*/
|
|
74
|
+
async detectMongoTransactionSupport(db, name) {
|
|
75
|
+
try {
|
|
76
|
+
const hello = await db.admin().command({ hello: 1 });
|
|
77
|
+
const supported = !!hello.setName || hello.msg === "isdbgrid";
|
|
78
|
+
if (!supported) {
|
|
79
|
+
this.logger.warn(`Datastore '${name}' is a standalone MongoDB instance and does not support multi-document ` +
|
|
80
|
+
`transactions. @Transactional will run without a transaction for models on this ` +
|
|
81
|
+
`datastore. Configure MongoDB as a replica set (or sharded cluster) to enable it.`);
|
|
82
|
+
}
|
|
83
|
+
return supported;
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
this.logger.warn(`Datastore '${name}': failed to determine whether the MongoDB deployment supports ` +
|
|
87
|
+
`transactions (${err.message}). Assuming it does not; @Transactional will run without a ` +
|
|
88
|
+
`transaction for models on this datastore.`);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
58
92
|
/**
|
|
59
93
|
* Attempts to initiate all database connections as defined in the config.
|
|
60
94
|
*
|
|
@@ -63,65 +97,96 @@ export class ConnectionManager {
|
|
|
63
97
|
*/
|
|
64
98
|
async connect(datastores, models) {
|
|
65
99
|
const processedModels = new Map();
|
|
66
|
-
//
|
|
100
|
+
// Redis-type datastores are connected sequentially, separately from the concurrent Promise.all below
|
|
101
|
+
// for every other datastore. Two concurrent *first* dynamic imports of the same module can, under
|
|
102
|
+
// some tooling that mocks dynamic imports (e.g. Vitest), non-deterministically resolve to a mix of
|
|
103
|
+
// the mocked and the real module instead of consistently returning the mock — sequencing avoids ever
|
|
104
|
+
// having two redis connection attempts in flight at once, which is where that surfaces. Redis
|
|
105
|
+
// connections are cheap enough that this isn't a meaningful hit to startup concurrency.
|
|
106
|
+
const redisNames = Object.keys(datastores).filter((name) => datastores[name]?.type === "redis");
|
|
107
|
+
for (const name of redisNames) {
|
|
108
|
+
await this.connectDatastore(name, datastores[name], models, processedModels);
|
|
109
|
+
}
|
|
110
|
+
const pending = [];
|
|
67
111
|
for (const name in datastores) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// attempt to reconnect instead of creating a new connection.
|
|
71
|
-
let connection = this.connections.get(name);
|
|
72
|
-
if (connection && isSqlDataSource(connection) && !connection.isInitialized) {
|
|
73
|
-
this.logger.info(`Reconnecting to database ${name}...`);
|
|
74
|
-
await connection.initialize();
|
|
112
|
+
if (!redisNames.includes(name)) {
|
|
113
|
+
pending.push(this.connectDatastore(name, datastores[name], models, processedModels));
|
|
75
114
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
}
|
|
116
|
+
await Promise.all(pending);
|
|
117
|
+
this.logger.info(`Successfully connected to all configured databases.`);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Establishes (or reconnects) a single configured datasource connection and stores it in `this.connections`.
|
|
121
|
+
*
|
|
122
|
+
* @param name The configured name of the datasource.
|
|
123
|
+
* @param datasource The datasource's configuration.
|
|
124
|
+
* @param models A map of model names and associated class definitions to establish database connections for.
|
|
125
|
+
* @param processedModels Tracks which datasource each model class has already been claimed as an entity for,
|
|
126
|
+
* shared across every concurrent call from `connect()` so a model claimed by two datastores is still caught.
|
|
127
|
+
*/
|
|
128
|
+
async connectDatastore(name, datasource, models, processedModels) {
|
|
129
|
+
// It's possible that the connection was already configured during a previous run. In that case we will
|
|
130
|
+
// attempt to reconnect instead of creating a new connection.
|
|
131
|
+
let connection = this.connections.get(name);
|
|
132
|
+
if (connection && isSqlDataSource(connection) && !connection.isInitialized) {
|
|
133
|
+
this.logger.info(`Reconnecting to database ${name}...`);
|
|
134
|
+
await connection.initialize();
|
|
135
|
+
}
|
|
136
|
+
if (!connection) {
|
|
137
|
+
datasource.name = name;
|
|
138
|
+
const url = this.buildConnectionUri(datasource);
|
|
139
|
+
this.logger.info(`Connecting to database ${name} [${this.redactUri(url)}]...`);
|
|
140
|
+
if (datasource.type === "redis") {
|
|
141
|
+
// Uses a literal `import("redis")` specifier (via importRedis()) rather than this class's
|
|
142
|
+
// generic importOptionalDependency(pkg, ...) helper, whose variable specifier bundler/test
|
|
143
|
+
// tooling (e.g. Vitest's module mocking) can't always statically analyze and intercept.
|
|
144
|
+
const { createClient } = await importRedis();
|
|
145
|
+
const redisConn = createClient({ url });
|
|
146
|
+
await redisConn.connect();
|
|
147
|
+
connection = redisConn;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// Make an array of all entities associated with this connection
|
|
151
|
+
const entities = [];
|
|
152
|
+
for (const className of models.keys()) {
|
|
153
|
+
// Get the class type
|
|
154
|
+
const clazz = models.get(className);
|
|
155
|
+
const ds = Reflect.getMetadata("rrst:datasource", clazz);
|
|
156
|
+
// Search for the associated datasource with the model via either config or @Model decorator
|
|
157
|
+
if (ds === name || (datasource.entities && datasource.entities.includes(className))) {
|
|
158
|
+
const processedDatastore = processedModels.get(clazz.name);
|
|
159
|
+
if (processedDatastore) {
|
|
160
|
+
throw new Error(`Model ${clazz.name} already defined as an entity for ${processedDatastore}`);
|
|
112
161
|
}
|
|
162
|
+
clazz.datasource = name;
|
|
163
|
+
entities.push(clazz);
|
|
164
|
+
processedModels.set(clazz.name, name);
|
|
113
165
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
166
|
+
}
|
|
167
|
+
if (datasource.type === "mongodb" || datasource.type === "mongodb+srv") {
|
|
168
|
+
// Connect using the native MongoDB driver
|
|
169
|
+
const { MongoClient } = await this.importOptionalDependency("mongodb", name, datasource.type);
|
|
170
|
+
const client = new MongoClient(url, datasource.clientOptions);
|
|
171
|
+
await client.connect();
|
|
172
|
+
const db = client.db(datasource.database);
|
|
173
|
+
const supportsTransactions = await this.detectMongoTransactionSupport(db, name);
|
|
174
|
+
connection = new MongoConnection(name, client, db, entities, supportsTransactions);
|
|
175
|
+
// Perform structure synchronization when requested
|
|
176
|
+
if (datasource.synchronize) {
|
|
177
|
+
const schemaSync = new MongoSchemaSync(db, this.logger);
|
|
178
|
+
await schemaSync.synchronize(entities);
|
|
119
179
|
}
|
|
120
180
|
}
|
|
181
|
+
else {
|
|
182
|
+
// Connect using TypeORM
|
|
183
|
+
await this.importOptionalDependency("typeorm", name, datasource.type);
|
|
184
|
+
const orm = await import("./TypeOrmSupport.js");
|
|
185
|
+
connection = await orm.connect(name, datasource, entities, url);
|
|
186
|
+
}
|
|
121
187
|
}
|
|
122
|
-
this.connections.set(name, connection);
|
|
123
188
|
}
|
|
124
|
-
this.
|
|
189
|
+
this.connections.set(name, connection);
|
|
125
190
|
}
|
|
126
191
|
/**
|
|
127
192
|
* Attempts to disconnect all active database connections.
|
|
@@ -134,13 +199,27 @@ export class ConnectionManager {
|
|
|
134
199
|
await conn.close();
|
|
135
200
|
}
|
|
136
201
|
}
|
|
137
|
-
else if (conn
|
|
138
|
-
|
|
139
|
-
|
|
202
|
+
else if (isSqlDataSource(conn)) {
|
|
203
|
+
const sqlConn = conn;
|
|
204
|
+
if (sqlConn.isInitialized) {
|
|
205
|
+
await sqlConn.destroy();
|
|
140
206
|
}
|
|
141
207
|
}
|
|
142
|
-
else if (
|
|
143
|
-
|
|
208
|
+
else if (typeof conn.disconnect === "function") {
|
|
209
|
+
// The only other connection kind this class ever creates is a redis client. Duck-typed
|
|
210
|
+
// (rather than `instanceof RedisClient`) so `redis` doesn't need to be imported here just
|
|
211
|
+
// to identify a connection this class already knows isn't Mongo or SQL — it's a peer
|
|
212
|
+
// dependency, loaded dynamically only where actually needed (see connectDatastore()).
|
|
213
|
+
const redis = conn;
|
|
214
|
+
// Disconnect regardless of whether the connection ever reached "ready" — one
|
|
215
|
+
// stuck retrying against an unreachable server (isOpen stays true while it keeps
|
|
216
|
+
// retrying in the background) must still be torn down here, or it leaks an
|
|
217
|
+
// endlessly-retrying client with active reconnect timers past this
|
|
218
|
+
// ConnectionManager's lifetime. `isOpen` is false only once the client has actually
|
|
219
|
+
// closed, so a redundant disconnect() call is skipped in that case.
|
|
220
|
+
if (redis.isOpen) {
|
|
221
|
+
await redis.disconnect();
|
|
222
|
+
}
|
|
144
223
|
}
|
|
145
224
|
}
|
|
146
225
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionManager.js","sourceRoot":"","sources":["../../../src/database/ConnectionManager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gFAAgF;AAChF,kDAAkD;AAClD,+EAA+E;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3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BACtF,MAAM,KAAK,GAAoB,IAAuB,CAAC;oBACvD,6EAA6E;oBAC7E,iFAAiF;oBACjF,2EAA2E;oBAC3E,mEAAmE;oBACnE,oFAAoF;oBACpF,oEAAoE;oBACpE,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;wBACf,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC;oBAC7B,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0DAA0D,CAAC,CAAC;IACjF,CAAC;CACJ;AAnOW;IADP,MAAM;;iDACa;AAiMP;IADZ,OAAO;;;;mDAkCP"}
|
|
@@ -2,7 +2,7 @@ import { MongoRepository } from "./MongoRepository.js";
|
|
|
2
2
|
import { resolveCollectionName } from "./NamingUtils.js";
|
|
3
3
|
/**
|
|
4
4
|
* Represents a single named connection to a MongoDB database using the native `mongodb` driver, including the
|
|
5
|
-
* registry of all model classes assigned to the connection's
|
|
5
|
+
* registry of all model classes assigned to the connection's datasource.
|
|
6
6
|
*
|
|
7
7
|
* Note that this class only references the `mongodb` package via type-only imports and is therefore safe to load
|
|
8
8
|
* when the optional `mongodb` peer dependency is not installed.
|
|
@@ -10,13 +10,14 @@ import { resolveCollectionName } from "./NamingUtils.js";
|
|
|
10
10
|
* @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
|
|
11
11
|
*/
|
|
12
12
|
export class MongoConnection {
|
|
13
|
-
constructor(name, client, db, entities) {
|
|
13
|
+
constructor(name, client, db, entities, supportsTransactions = false) {
|
|
14
14
|
this.connected = true;
|
|
15
15
|
this.entities = new Map();
|
|
16
16
|
this.repos = new Map();
|
|
17
17
|
this.name = name;
|
|
18
18
|
this.client = client;
|
|
19
19
|
this.db = db;
|
|
20
|
+
this.supportsTransactions = supportsTransactions;
|
|
20
21
|
if (entities) {
|
|
21
22
|
for (const clazz of entities) {
|
|
22
23
|
this.entities.set(clazz.name, clazz);
|
|
@@ -62,7 +63,7 @@ export class MongoConnection {
|
|
|
62
63
|
if (typeof classOrName === "string") {
|
|
63
64
|
clazz = this.entities.get(classOrName);
|
|
64
65
|
if (!clazz) {
|
|
65
|
-
throw new Error(`No entity named '${classOrName}' is registered with
|
|
66
|
+
throw new Error(`No entity named '${classOrName}' is registered with datasource '${this.name}'.`);
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
let repo = this.repos.get(clazz);
|
|
@@ -82,5 +83,14 @@ export class MongoConnection {
|
|
|
82
83
|
getMongoRepository(classOrName) {
|
|
83
84
|
return this.getRepository(classOrName);
|
|
84
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new client session for performing transactions using the provided options.
|
|
88
|
+
*
|
|
89
|
+
* @param options The options to start the session with.
|
|
90
|
+
* @returns The newly started session.
|
|
91
|
+
*/
|
|
92
|
+
startSession(options) {
|
|
93
|
+
return this.client.startSession(options);
|
|
94
|
+
}
|
|
85
95
|
}
|
|
86
96
|
//# sourceMappingURL=MongoConnection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoConnection.js","sourceRoot":"","sources":["../../../src/database/MongoConnection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MongoConnection.js","sourceRoot":"","sources":["../../../src/database/MongoConnection.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IAkBxB,YACI,IAAY,EACZ,MAAmB,EACnB,EAAM,EACN,QAAwB,EACxB,uBAAgC,KAAK;QATjC,cAAS,GAAY,IAAI,CAAC;QAC1B,aAAQ,GAAqB,IAAI,GAAG,EAAE,CAAC;QACvC,UAAK,GAAmC,IAAI,GAAG,EAAE,CAAC;QAStD,IAAI,CAAC,IAAI,GAAG,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