@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
package/dist/types/Server.d.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import * as prom from "prom-client";
|
|
2
2
|
import "reflect-metadata";
|
|
3
3
|
import { ConnectionManager } from "./database/ConnectionManager.js";
|
|
4
|
+
import { ClassLoader } from "@rapidrest/core";
|
|
4
5
|
import { ObjectFactory } from "./ObjectFactory.js";
|
|
5
6
|
import { BackgroundServiceManager } from "./BackgroundServiceManager.js";
|
|
6
7
|
import { RouteUtils } from "./routes/RouteUtils.js";
|
|
7
8
|
import { OpenApiSpec } from "./OpenApiSpec.js";
|
|
8
9
|
import { EventListenerManager } from "./EventListenerManager.js";
|
|
9
|
-
import {
|
|
10
|
+
import type { IHttpRouter } from "./http/types.js";
|
|
11
|
+
import { SessionManager } from "./http/session/SessionManager.js";
|
|
12
|
+
/**
|
|
13
|
+
* The configuration options to use when constructing a new Server instance.
|
|
14
|
+
*/
|
|
15
|
+
export interface ServerOptions {
|
|
16
|
+
/** The nconf-compatible configuration object to initialize the server with. */
|
|
17
|
+
config: any;
|
|
18
|
+
/** The base file system path that models and routes will be searched from. Default is `.` */
|
|
19
|
+
basePath?: string;
|
|
20
|
+
/** The logging utility to use for outputing to console/file. Default is `Logger()` from `@rapidrest/core`. */
|
|
21
|
+
logger?: any;
|
|
22
|
+
/** The ClassLoader used to scan the source for all exported classes. */
|
|
23
|
+
classLoader?: ClassLoader;
|
|
24
|
+
/** The object factory to use for automatic dependency injection (IOC). */
|
|
25
|
+
objectFactory?: ObjectFactory;
|
|
26
|
+
}
|
|
10
27
|
/**
|
|
11
28
|
* Provides an HTTP server utilizing uWebSockets.js. The server automatically registers all routes, and
|
|
12
29
|
* establishes database connections for all configured data stores. Additionally provides automatic authentication
|
|
@@ -116,14 +133,16 @@ import { HttpRouter } from "./http/Router.js";
|
|
|
116
133
|
export declare class Server {
|
|
117
134
|
/** The OpenAPI specification object to use to construct the server with. */
|
|
118
135
|
protected apiSpec?: OpenApiSpec;
|
|
119
|
-
/** The underlying HTTP router (uWS-backed) that provides HTTP processing services. */
|
|
120
|
-
protected app:
|
|
136
|
+
/** The underlying HTTP router (uWS-backed on Node, Bun.serve()-backed under the Bun runtime) that provides HTTP processing services. */
|
|
137
|
+
protected app: IHttpRouter;
|
|
121
138
|
/** The base file system path that will be searched for models and routes. */
|
|
122
139
|
protected readonly basePath: string;
|
|
123
140
|
/** The global object containing configuration information to use. */
|
|
124
141
|
protected readonly config?: any;
|
|
125
142
|
/** The manager for handling database connections. */
|
|
126
143
|
protected connectionManager?: ConnectionManager;
|
|
144
|
+
/** The ClassLoader used to scan the source for all exported classes. */
|
|
145
|
+
protected classLoader: ClassLoader;
|
|
127
146
|
/** The manager for handling events. */
|
|
128
147
|
protected eventListenerManager?: EventListenerManager;
|
|
129
148
|
/** The logging utility to use when outputing to console/file. */
|
|
@@ -134,6 +153,8 @@ export declare class Server {
|
|
|
134
153
|
readonly port: number;
|
|
135
154
|
protected routeUtils?: RouteUtils;
|
|
136
155
|
protected serviceManager?: BackgroundServiceManager;
|
|
156
|
+
/** Manages cross-request session support. Only set when a `session` config block is present. */
|
|
157
|
+
protected sessionManager?: SessionManager;
|
|
137
158
|
protected metricRequestPath: prom.Counter<string>;
|
|
138
159
|
protected metricRequestStatus: prom.Counter<string>;
|
|
139
160
|
protected metricRequestTime: prom.Histogram<string>;
|
|
@@ -141,18 +162,15 @@ export declare class Server {
|
|
|
141
162
|
protected metricFailedRequests: prom.Counter<string>;
|
|
142
163
|
protected metricTotalRequests: prom.Counter<string>;
|
|
143
164
|
/**
|
|
144
|
-
* Creates a new instance of Server with the specified
|
|
165
|
+
* Creates a new instance of Server with the specified default options.
|
|
145
166
|
*
|
|
146
|
-
* @param
|
|
147
|
-
* @param {string} basePath The base file system path that models and routes will be searched from.
|
|
148
|
-
* @param {Logger} logger The logging utility to use for outputing to console/file.
|
|
149
|
-
* @param objectFactory The object factory to use for automatic dependency injection (IOC).
|
|
167
|
+
* @param options The configuration options to apply for this server.
|
|
150
168
|
*/
|
|
151
|
-
constructor(
|
|
169
|
+
constructor(options: ServerOptions);
|
|
152
170
|
/**
|
|
153
171
|
* Returns the HTTP router instance.
|
|
154
172
|
*/
|
|
155
|
-
getApplication():
|
|
173
|
+
getApplication(): IHttpRouter;
|
|
156
174
|
/**
|
|
157
175
|
* Returns `true` if the server is running, otherwise `false`.
|
|
158
176
|
*/
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { HttpRequest, HttpResponse, RequestHandler } from "../http/types.js";
|
|
2
|
-
import { AuthResult, AuthStrategy } from "./AuthStrategy.js";
|
|
1
|
+
import type { HttpRequest, HttpResponse, RequestHandler } from "../http/types.js";
|
|
2
|
+
import type { AuthResult, AuthStrategy } from "./AuthStrategy.js";
|
|
3
3
|
/**
|
|
4
4
|
* A set of common utilities for performing authentication using one or more strategies.
|
|
5
5
|
*
|
|
6
6
|
* @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
|
|
7
7
|
*/
|
|
8
8
|
export declare class AuthMiddleware {
|
|
9
|
+
private _objectFactory?;
|
|
9
10
|
private authConfig;
|
|
10
11
|
private authSocketTimeout;
|
|
11
|
-
private objectFactory?;
|
|
12
12
|
/** The authentication strategies that have been registered. */
|
|
13
13
|
readonly strategies: Map<string, AuthStrategy>;
|
|
14
14
|
private init;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { JWTUser } from "@rapidrest/core";
|
|
2
|
-
import { HttpRequest, HttpResponse } from "../http/types.js";
|
|
1
|
+
import type { JWTUser } from "@rapidrest/core";
|
|
2
|
+
import type { HttpRequest, HttpResponse } from "../http/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Result returned by `AuthStrategy.authenticate()`.
|
|
5
5
|
*/
|
|
6
6
|
export interface AuthResult {
|
|
7
7
|
/** The raw auth data that was verified. */
|
|
8
|
-
data?:
|
|
8
|
+
data?: any;
|
|
9
9
|
/** The name of the auth strategy that produced this result. */
|
|
10
10
|
method: string;
|
|
11
11
|
/** The fully decoded payload from the auth data. */
|
|
12
12
|
payload?: any;
|
|
13
|
+
/**
|
|
14
|
+
* Client-supplied app-correlation data extracted from the `state` round-trip, if any (see
|
|
15
|
+
* OAuthStrategy's combined state/CSRF design). Available to route handlers via `@AuthResult`.
|
|
16
|
+
*/
|
|
17
|
+
state?: string;
|
|
13
18
|
/** The authenticated user profile, or `undefined` if authentication failed. */
|
|
14
19
|
user?: JWTUser;
|
|
15
20
|
}
|
|
@@ -26,9 +31,8 @@ export interface AuthStrategy {
|
|
|
26
31
|
*
|
|
27
32
|
* @param req The request containing data to attempt authentication with.
|
|
28
33
|
* @param res The response to use when writing back directly to the client.
|
|
29
|
-
* @param required Set to `true` to if authentication is required to pass, otherwise set to `false`.
|
|
30
34
|
*/
|
|
31
|
-
authenticate(req: HttpRequest, res?: HttpResponse
|
|
35
|
+
authenticate(req: HttpRequest, res?: HttpResponse): Promise<AuthResult | undefined>;
|
|
32
36
|
/**
|
|
33
37
|
* Attempts to perform authentication with the given request data. If authentication was successful, returns an
|
|
34
38
|
* `AuthResult` containing the authentication details. If authentication fails and `required` is set to `true`
|
|
@@ -38,7 +42,6 @@ export interface AuthStrategy {
|
|
|
38
42
|
*
|
|
39
43
|
* @param req The request containing data to attempt authentication with.
|
|
40
44
|
* @param res The response to use when writing back directly to the client.
|
|
41
|
-
* @param required Set to `true` to if authentication is required to pass, otherwise set to `false`.
|
|
42
45
|
*/
|
|
43
|
-
authenticateSync(req: HttpRequest, res?: HttpResponse
|
|
46
|
+
authenticateSync(req: HttpRequest, res?: HttpResponse): AuthResult | undefined;
|
|
44
47
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JWTUtilsConfig } from "@rapidrest/core";
|
|
1
|
+
import { type JWTUtilsConfig } from "@rapidrest/core";
|
|
2
2
|
import type { HttpRequest, HttpResponse } from "../http/types.js";
|
|
3
|
-
import { AuthResult } from "./AuthStrategy.js";
|
|
3
|
+
import type { AuthResult } from "./AuthStrategy.js";
|
|
4
4
|
/**
|
|
5
5
|
* Describes the configuration options that can be used to initialize JWTStrategy.
|
|
6
6
|
*
|
|
@@ -50,16 +50,18 @@ export interface JWTAuthResult extends AuthResult {
|
|
|
50
50
|
*/
|
|
51
51
|
export declare class JWTStrategy {
|
|
52
52
|
private config;
|
|
53
|
+
private logger;
|
|
53
54
|
readonly name: string;
|
|
54
55
|
private options;
|
|
55
56
|
private readonly _headerSchemeRegex;
|
|
56
57
|
constructor(options?: JWTStrategyOptions);
|
|
58
|
+
private init;
|
|
57
59
|
/**
|
|
58
60
|
* Scans the provided request object for an authentication token this strategy can process.
|
|
59
61
|
* @param req The request to scan for an auth token.
|
|
60
62
|
* @returns The auth token if found, otherwise `undefined`.
|
|
61
63
|
*/
|
|
62
64
|
private getAuthToken;
|
|
63
|
-
authenticate(req: HttpRequest, res: HttpResponse
|
|
64
|
-
authenticateSync(req: HttpRequest, res: HttpResponse
|
|
65
|
+
authenticate(req: HttpRequest, res: HttpResponse): Promise<JWTAuthResult | undefined>;
|
|
66
|
+
authenticateSync(req: HttpRequest, res: HttpResponse): JWTAuthResult | undefined;
|
|
65
67
|
}
|
|
@@ -5,3 +5,10 @@
|
|
|
5
5
|
* @param conn The connection object to inspect.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isSqlDataSource(conn: any): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Dynamically imports the `redis` package, throwing a helpful error if it isn't installed. `redis` is a peer
|
|
10
|
+
* dependency (like `mongodb` and `typeorm`) rather than a hard dependency of this package, so it must only be
|
|
11
|
+
* loaded when a consumer actually configures a redis-backed feature — never imported at the top of a module
|
|
12
|
+
* that's always loaded, or every consumer would be forced to install it regardless of whether they use it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function importRedis(): Promise<typeof import("redis")>;
|
|
@@ -1,26 +1,41 @@
|
|
|
1
|
-
import { Redis } from "ioredis";
|
|
2
1
|
import type { DataSource } from "typeorm";
|
|
3
2
|
import { MongoConnection } from "./MongoConnection.js";
|
|
3
|
+
import type { RedisClientType } from "redis";
|
|
4
4
|
/**
|
|
5
5
|
* Provides database connection management.
|
|
6
6
|
*
|
|
7
7
|
* @author Jean-Philippe Steinmetz
|
|
8
8
|
*/
|
|
9
9
|
export declare class ConnectionManager {
|
|
10
|
-
connections: Map<string, DataSource | MongoConnection |
|
|
10
|
+
connections: Map<string, DataSource | MongoConnection | RedisClientType>;
|
|
11
11
|
private logger;
|
|
12
12
|
/**
|
|
13
13
|
* Builds a compatible connection URI for the database by the provided configuration.
|
|
14
14
|
*/
|
|
15
15
|
private buildConnectionUri;
|
|
16
|
+
/**
|
|
17
|
+
* Redacts the userinfo (credentials) portion of a connection URI for safe logging, regardless of
|
|
18
|
+
* whether the URI came from a `url` config field or was built from separate username/password fields.
|
|
19
|
+
*/
|
|
20
|
+
private redactUri;
|
|
16
21
|
/**
|
|
17
22
|
* Dynamically imports the given optional peer dependency, throwing a helpful error if it is not installed.
|
|
18
23
|
*
|
|
19
24
|
* @param pkg The name of the package to import.
|
|
20
|
-
* @param datastoreName The name of the
|
|
21
|
-
* @param datastoreType The type of the
|
|
25
|
+
* @param datastoreName The name of the datasource requiring the package.
|
|
26
|
+
* @param datastoreType The type of the datasource requiring the package.
|
|
22
27
|
*/
|
|
23
28
|
private importOptionalDependency;
|
|
29
|
+
/**
|
|
30
|
+
* Determines whether the given MongoDB deployment supports multi-document transactions (i.e. is configured
|
|
31
|
+
* as a replica set or a sharded cluster) by inspecting the `hello` handshake response. A standalone
|
|
32
|
+
* `mongod` responds with neither `setName` (replica set membership) nor `msg: "isdbgrid"` (mongos), and
|
|
33
|
+
* doesn't support transactions at all.
|
|
34
|
+
*
|
|
35
|
+
* @param db The database to check.
|
|
36
|
+
* @param name The name of the datastore, used only for the log message if transactions aren't supported.
|
|
37
|
+
*/
|
|
38
|
+
private detectMongoTransactionSupport;
|
|
24
39
|
/**
|
|
25
40
|
* Attempts to initiate all database connections as defined in the config.
|
|
26
41
|
*
|
|
@@ -28,6 +43,16 @@ export declare class ConnectionManager {
|
|
|
28
43
|
* @param models A map of model names and associated class definitions to establish database connections for.
|
|
29
44
|
*/
|
|
30
45
|
connect(datastores: any, models: Map<string, any>): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Establishes (or reconnects) a single configured datasource connection and stores it in `this.connections`.
|
|
48
|
+
*
|
|
49
|
+
* @param name The configured name of the datasource.
|
|
50
|
+
* @param datasource The datasource's configuration.
|
|
51
|
+
* @param models A map of model names and associated class definitions to establish database connections for.
|
|
52
|
+
* @param processedModels Tracks which datasource each model class has already been claimed as an entity for,
|
|
53
|
+
* shared across every concurrent call from `connect()` so a model claimed by two datastores is still caught.
|
|
54
|
+
*/
|
|
55
|
+
private connectDatastore;
|
|
31
56
|
/**
|
|
32
57
|
* Attempts to disconnect all active database connections.
|
|
33
58
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Admin, Db, MongoClient } from "mongodb";
|
|
1
|
+
import type { Admin, ClientSession, ClientSessionOptions, Db, MongoClient } from "mongodb";
|
|
2
2
|
import { MongoRepository } from "./MongoRepository.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.
|
|
@@ -14,12 +14,17 @@ export declare class MongoConnection {
|
|
|
14
14
|
readonly client: MongoClient;
|
|
15
15
|
/** The database that this connection is bound to. */
|
|
16
16
|
readonly db: Db;
|
|
17
|
-
/** The name of the
|
|
17
|
+
/** The name of the datasource that this connection was created for. */
|
|
18
18
|
readonly name: string;
|
|
19
|
+
/**
|
|
20
|
+
* Indicates whether this connection's MongoDB deployment supports multi-document transactions.
|
|
21
|
+
* Defaults to `false`.
|
|
22
|
+
*/
|
|
23
|
+
readonly supportsTransactions: boolean;
|
|
19
24
|
private connected;
|
|
20
25
|
private entities;
|
|
21
26
|
private repos;
|
|
22
|
-
constructor(name: string, client: MongoClient, db: Db, entities?: Iterable<any
|
|
27
|
+
constructor(name: string, client: MongoClient, db: Db, entities?: Iterable<any>, supportsTransactions?: boolean);
|
|
23
28
|
/** Indicates whether or not the connection is currently active. */
|
|
24
29
|
get isConnected(): boolean;
|
|
25
30
|
/** Returns the admin interface of the underlying database. */
|
|
@@ -51,4 +56,11 @@ export declare class MongoConnection {
|
|
|
51
56
|
* @param classOrName The model class, or the name of a registered model class, to retrieve a repository for.
|
|
52
57
|
*/
|
|
53
58
|
getMongoRepository<T extends object = any>(classOrName: any | string): MongoRepository<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new client session for performing transactions using the provided options.
|
|
61
|
+
*
|
|
62
|
+
* @param options The options to start the session with.
|
|
63
|
+
* @returns The newly started session.
|
|
64
|
+
*/
|
|
65
|
+
startSession(options?: ClientSessionOptions): ClientSession;
|
|
54
66
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AggregationCursor, Collection, CountDocumentsOptions, Db, DeleteOptions, DeleteResult, Document, Filter, FindCursor, FindOptions, UpdateOptions, UpdateResult } from "mongodb";
|
|
1
|
+
import type { Abortable, AggregateOptions, AggregationCursor, Collection, CountDocumentsOptions, Db, DeleteOptions, DeleteResult, DistinctOptions, Document, Filter, FindCursor, FindOneAndDeleteOptions, FindOptions, InsertOneOptions, ReplaceOptions, UpdateOptions, UpdateResult } from "mongodb";
|
|
2
2
|
/**
|
|
3
3
|
* Provides a lightweight repository for performing common operations against a single MongoDB collection using the
|
|
4
4
|
* native `mongodb` driver. Instances of this class are obtained via `MongoConnection.getRepository`.
|
|
@@ -23,19 +23,19 @@ export declare class MongoRepository<T extends Document = any> {
|
|
|
23
23
|
*
|
|
24
24
|
* @param pipeline The aggregation pipeline stages to execute.
|
|
25
25
|
*/
|
|
26
|
-
aggregate(pipeline: Document[]): AggregationCursor<any>;
|
|
26
|
+
aggregate(pipeline: Document[], options?: AggregateOptions & Abortable): AggregationCursor<any>;
|
|
27
27
|
/**
|
|
28
28
|
* Drops the entire collection from the database, removing all documents and indexes. Does nothing if the
|
|
29
29
|
* collection does not exist.
|
|
30
30
|
*/
|
|
31
|
-
clear(): Promise<void>;
|
|
31
|
+
clear(options?: DeleteOptions & Abortable): Promise<void>;
|
|
32
32
|
/**
|
|
33
33
|
* Returns the number of documents matching the given filter.
|
|
34
34
|
*
|
|
35
35
|
* @param filter - The filter for the count
|
|
36
36
|
* @param options - Optional settings for the command
|
|
37
37
|
*/
|
|
38
|
-
count(filter?: Filter<T>, options?: CountDocumentsOptions): Promise<number>;
|
|
38
|
+
count(filter?: Filter<T>, options?: CountDocumentsOptions & Abortable): Promise<number>;
|
|
39
39
|
/**
|
|
40
40
|
* Deletes all documents matching the given filter.
|
|
41
41
|
*
|
|
@@ -50,35 +50,56 @@ export declare class MongoRepository<T extends Document = any> {
|
|
|
50
50
|
* @param options - Optional settings for the command
|
|
51
51
|
*/
|
|
52
52
|
deleteOne(filter?: Filter<T>, options?: DeleteOptions): Promise<DeleteResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Atomically finds and deletes the first document matching the given filter, returning the document that
|
|
55
|
+
* was deleted (or `null` if none matched). This is a single round trip rather than a separate `findOne()` +
|
|
56
|
+
* `deleteOne()`, so a caller that needs to know exactly what it removed (e.g. to snapshot it for a
|
|
57
|
+
* possible restore) isn't racing its own read against a concurrent write to the same document.
|
|
58
|
+
*
|
|
59
|
+
* @param filter The query filter to match documents against.
|
|
60
|
+
* @param options - Optional settings for the command
|
|
61
|
+
*/
|
|
62
|
+
findOneAndDelete(filter: Filter<T>, options?: FindOneAndDeleteOptions): Promise<T | null>;
|
|
53
63
|
/**
|
|
54
64
|
* Returns the list of distinct values of the given field for all documents matching the given filter.
|
|
55
65
|
*
|
|
56
66
|
* @param field The name of the document field to return distinct values of.
|
|
57
67
|
* @param filter The query filter to match documents against.
|
|
58
68
|
*/
|
|
59
|
-
distinct(field: string, filter?: Filter<T
|
|
69
|
+
distinct(field: string, filter?: Filter<T>, options?: DistinctOptions): Promise<any[]>;
|
|
60
70
|
/**
|
|
61
71
|
* Returns all documents matching the given filter.
|
|
62
72
|
*
|
|
63
73
|
* @param filter The query filter to match documents against.
|
|
64
74
|
* @param options - Optional settings for the command
|
|
65
75
|
*/
|
|
66
|
-
find(filter?: Filter<T>, options?: FindOptions): FindCursor<T>;
|
|
76
|
+
find(filter?: Filter<T>, options?: FindOptions & Abortable): FindCursor<T>;
|
|
67
77
|
/**
|
|
68
78
|
* Returns the first document matching the given filter.
|
|
69
79
|
*
|
|
70
80
|
* @param filter The query filter to match documents against.
|
|
71
81
|
*/
|
|
72
|
-
findOne(filter: any): Promise<T | null>;
|
|
82
|
+
findOne(filter: any, options?: FindOptions & Abortable): Promise<T | null>;
|
|
73
83
|
/**
|
|
74
|
-
* Saves the given document to the collection.
|
|
75
|
-
* replaced (inserting if missing), otherwise the document is inserted and its newly assigned
|
|
76
|
-
* the returned object.
|
|
84
|
+
* Saves the given document to the collection. By default, if the document has an existing `_id` the stored
|
|
85
|
+
* document is replaced (inserting if missing), otherwise the document is inserted and its newly assigned
|
|
86
|
+
* `_id` is set on the returned object. This is the behavior a trackChanges-style caller relies on to keep
|
|
87
|
+
* multiple documents per `uid` (one per version): a document built for a fresh version deliberately carries
|
|
88
|
+
* no `_id` yet, and must always become a genuinely new row, never merged into an existing one.
|
|
89
|
+
*
|
|
90
|
+
* Pass `mergeByUid: true` to instead match (and replace, or insert if missing) by the document's `uid`, the
|
|
91
|
+
* framework's true logical primary key, regardless of whether `_id` was carried forward from a prior read.
|
|
92
|
+
* Useful for a single-row-per-uid document that may have been built fresh (e.g. by spreading an update onto
|
|
93
|
+
* a plain object) without preserving `_id`, where the default `_id`-only behavior would insert a *second*,
|
|
94
|
+
* duplicate document instead of updating the existing one (see `ACLUtils.saveACL()`).
|
|
77
95
|
*
|
|
78
96
|
* @param doc The document to save.
|
|
97
|
+
* @param options Driver options, plus optionally `mergeByUid` (see above).
|
|
79
98
|
* @returns The saved document.
|
|
80
99
|
*/
|
|
81
|
-
save(doc: any)
|
|
100
|
+
save(doc: any, options?: (InsertOneOptions | ReplaceOptions) & {
|
|
101
|
+
mergeByUid?: boolean;
|
|
102
|
+
}): Promise<T>;
|
|
82
103
|
/**
|
|
83
104
|
* Updates all documents matching the given filter with the provided update operations.
|
|
84
105
|
*
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RedisStore } from "@rapidrest/core";
|
|
2
|
+
import type { RedisClientType } from "redis";
|
|
3
|
+
import { BaseEntity } from "typeorm";
|
|
4
|
+
import { SimpleEntity } from "../models/SimpleEntity.js";
|
|
5
|
+
/**
|
|
6
|
+
* Implements a cache system for storing entities. Uses the `cache` Redis datastore (when configured) as the
|
|
7
|
+
* backing database. Otherwise, provides an in-memory cache store for entities.
|
|
8
|
+
*
|
|
9
|
+
* @author Jean-Philippe Steinmetz
|
|
10
|
+
*/
|
|
11
|
+
export declare class RedisCache<T extends BaseEntity | SimpleEntity> extends RedisStore {
|
|
12
|
+
protected redisClient?: RedisClientType;
|
|
13
|
+
/** The entity type that is to be stored in this cache. */
|
|
14
|
+
protected readonly type: any;
|
|
15
|
+
constructor(type: any);
|
|
16
|
+
private init;
|
|
17
|
+
load(id: string, skipRedis?: boolean): Promise<T | undefined>;
|
|
18
|
+
loadMany(ids: string[]): Promise<(T | undefined)[]>;
|
|
19
|
+
loadSet(id: string): Promise<(T | undefined)[] | undefined>;
|
|
20
|
+
save(id: string, data: T, ttl?: number, skipRedis?: boolean): Promise<void>;
|
|
21
|
+
saveMany(ids: string[], data: T[], ttl?: number): Promise<void>;
|
|
22
|
+
saveSet(id: string, data: T[], idProp?: string, ttl?: number): Promise<void>;
|
|
23
|
+
}
|
|
@@ -9,12 +9,12 @@ import * as typeorm from "typeorm";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function registerFrameworkMetadata(entities: any[]): void;
|
|
11
11
|
/**
|
|
12
|
-
* Establishes a TypeORM connection for the given SQL
|
|
12
|
+
* Establishes a TypeORM connection for the given SQL datasource configuration. If a connection with the given name
|
|
13
13
|
* already exists it is reused (and reconnected if necessary).
|
|
14
14
|
*
|
|
15
|
-
* @param name The name of the
|
|
16
|
-
* @param
|
|
15
|
+
* @param name The name of the datasource to connect to.
|
|
16
|
+
* @param datasource The datasource configuration to pass to TypeORM.
|
|
17
17
|
* @param entities The list of entity classes assigned to this connection.
|
|
18
18
|
* @param url The connection URL of the database.
|
|
19
19
|
*/
|
|
20
|
-
export declare function connect(name: string,
|
|
20
|
+
export declare function connect(name: string, datasource: any, entities: any[], url: string): Promise<typeorm.DataSource>;
|
|
@@ -1,18 +1,149 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
/** The transactional context (`session` and/or `entityManager`) established by `@Transactional`, if any. */
|
|
3
|
+
export interface TransactionContext {
|
|
4
|
+
/** The MongoDB-specific session object to pass in to MongoRepository for each operation. */
|
|
5
|
+
session?: any;
|
|
6
|
+
/** The TypeORM-specific entity manager to perform all operations with. */
|
|
7
|
+
entityManager?: any;
|
|
8
|
+
/** The datasource name this context's session/entityManager belongs to, used to guard merging (see `Transactional`). */
|
|
9
|
+
datasource?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Best-effort compensating actions to run if this transaction ultimately fails, populated via
|
|
12
|
+
* `registerRollbackHook()`. Owned by whichever `@Transactional` call actually opened the real transaction
|
|
13
|
+
* (nested/merged calls share the same array via the ambient context, rather than each getting their own).
|
|
14
|
+
*/
|
|
15
|
+
onRollback?: Array<() => Promise<void>>;
|
|
16
|
+
}
|
|
1
17
|
/**
|
|
2
|
-
*
|
|
18
|
+
* Carries the transactional context established by `@Transactional` through the async call chain of the
|
|
19
|
+
* decorated method, keyed to that specific invocation rather than to the object instance the method runs on.
|
|
20
|
+
*/
|
|
21
|
+
export declare const transactionContext: AsyncLocalStorage<TransactionContext>;
|
|
22
|
+
/**
|
|
23
|
+
* Registers a best-effort compensating action to run if the currently active transaction (the one owning the
|
|
24
|
+
* ambient `transactionContext`) ultimately fails. Intended for code that just committed a write on a *different*
|
|
25
|
+
* connection than the active transaction's own (e.g. one that can't be rolled back by that transaction's own
|
|
26
|
+
* abort) and needs its own explicit cleanup to avoid an orphaned write if the active transaction later fails.
|
|
27
|
+
* A no-op if there's no active transaction to register against.
|
|
3
28
|
*
|
|
4
|
-
*
|
|
29
|
+
* The hook is responsible for catching and logging its own errors; if it throws anyway, that's swallowed (via
|
|
30
|
+
* `Promise.allSettled`) rather than masking the original failure that triggered the rollback.
|
|
31
|
+
*
|
|
32
|
+
* @param hook The compensating action to run.
|
|
33
|
+
*/
|
|
34
|
+
export declare function registerRollbackHook(hook: () => Promise<void>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Apply this to a property to have the datasource connection with the given name injected at instantiation.
|
|
37
|
+
*
|
|
38
|
+
* @param name The name of the datasource or class type.
|
|
39
|
+
* @param required Set to `true` to indicate this injection must resolve, otherwise set to `false`. Default is `true`.
|
|
5
40
|
*/
|
|
6
|
-
export declare function
|
|
41
|
+
export declare function DataSource(name: string, required?: boolean): (target: any, propertyKey: string | symbol) => void;
|
|
7
42
|
/**
|
|
8
|
-
*
|
|
43
|
+
* Injects the entity manager as the value of the decorated argument.
|
|
44
|
+
*
|
|
45
|
+
* @param name The name of the datasource or class type.
|
|
46
|
+
*/
|
|
47
|
+
export declare function EntityManager(nameOrType?: string | any): (target: any, propertyKey: string, index: number) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Injects the MongoDB session (used by @Transactional) as the value of the decorated argument.
|
|
50
|
+
*/
|
|
51
|
+
export declare function MongoSession(nameOrType?: string | any): (target: any, propertyKey: string, index: number) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Apply this to a property to have the datasource repository for the given entity type injected at instantiation.
|
|
9
54
|
*
|
|
10
55
|
* @param {any} type The entity type whose repository will be injected.
|
|
56
|
+
* @param required Set to `true` to indicate this injection must resolve, otherwise set to `false`. Default is `true`.
|
|
11
57
|
*/
|
|
12
|
-
export declare function Repository(type: any): (target: any, propertyKey: string | symbol) => void;
|
|
58
|
+
export declare function Repository(type: any, required?: boolean): (target: any, propertyKey: string | symbol) => void;
|
|
13
59
|
/**
|
|
14
|
-
* Apply this to a property to have the `Redis` connection injected at instantiation.
|
|
60
|
+
* Apply this to a property to have the `Redis` connection with the given name injected at instantiation.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} name The name of the datasource connection to inject.
|
|
63
|
+
* @param required Set to `true` to indicate this injection must resolve, otherwise set to `false`. Default is `true`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function Redis(name?: string, required?: boolean): (target: any, propertyKey: string | symbol) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Describes the opertaing mode for transaction support and how existing context should be
|
|
68
|
+
* reconciled. When @Transactional is used multiple times in a single callstack, the
|
|
69
|
+
* context can either be merged in a single transaction and nested.
|
|
70
|
+
*/
|
|
71
|
+
export declare enum TransactionalMode {
|
|
72
|
+
/** Always creates a new transactional context for the current function. */
|
|
73
|
+
CREATE = 0,
|
|
74
|
+
/** Merges existing transactional context instead of creating a new one. */
|
|
75
|
+
MERGE = 1
|
|
76
|
+
}
|
|
77
|
+
export interface TransactionalOptions {
|
|
78
|
+
/** The merge mode to apply when multiple transactions are declared in the same call stack. */
|
|
79
|
+
mode: TransactionalMode;
|
|
80
|
+
/** The set of options to pass to the underlying datastore driver. */
|
|
81
|
+
driverOptions?: any;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Apply this to perform all operations in a single transaction. The specified `source` can
|
|
85
|
+
* be the name of a connection or the class type of a persistent data model. If no `source` is specified it is inferred
|
|
86
|
+
* by lookup via `this.modelClass` which is injected when `@Model` is added to a class.
|
|
87
|
+
*
|
|
88
|
+
* For MongoDB, this has the effect of creating a new session and wrapping the function call in
|
|
89
|
+
* `session.withTransaction()`. Note that you must pass in the `session` to each `MongoRepository` function you wish
|
|
90
|
+
* to use the transaction. The `session` is automatically made available for the duration of the call via
|
|
91
|
+
* `transactionContext` (an `AsyncLocalStorage` that is scoped to this call). Optionally, it can also be injected to a
|
|
92
|
+
* function argument that is decorated with `@MongoSession`.
|
|
93
|
+
*
|
|
94
|
+
* For TypeORM, this has the effect of creating a new transaction and wrapping the function call in
|
|
95
|
+
* `datasource.transaction()`. Note that you must use the provided `EntityManager` for all database actions. The
|
|
96
|
+
* `entityManager` is automatically made available for the duration of the call via `transactionContext`. Optionally,
|
|
97
|
+
* it can be injected to a function argument that is decorated with `@EntityManager`.
|
|
98
|
+
*
|
|
99
|
+
* If `@Transactional` was already in effect earlier in the current call stack (e.g. a `RepoUtils` method called
|
|
100
|
+
* from a `ModelRoute` method that's also `@Transactional`), the existing transaction is reused by default rather
|
|
101
|
+
* than opening a second, nested one. See `TransactionalOptions.mode`.
|
|
102
|
+
*
|
|
103
|
+
* Note: A `@Transactional` method *MUST* always return a promise (e.g. is async).
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* @Model(MongoModel)
|
|
108
|
+
* class MyClass {
|
|
109
|
+
* @Repository(MongoModel)
|
|
110
|
+
* private myRepo: MongoRepository<MongoModel>;
|
|
111
|
+
*
|
|
112
|
+
* @Transactional()
|
|
113
|
+
* public myFunc(obj: MongoModel, @MongoSession() session) {
|
|
114
|
+
* await this.myRepo.save(obj, { session });
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* class MyClass {
|
|
121
|
+
* @Repository(MongoModel)
|
|
122
|
+
* private myRepo: MongoRepository<MongoModel>;
|
|
123
|
+
*
|
|
124
|
+
* @Repository(MongoModel2)
|
|
125
|
+
* private myRepo2: MongoRepository<MongoModel2>;
|
|
126
|
+
*
|
|
127
|
+
* @Transactional(MongoModel)
|
|
128
|
+
* public myFunc(obj: MongoModel, @MongoSession() session) {
|
|
129
|
+
* await this.myRepo.save(obj, { session });
|
|
130
|
+
* }
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* class MyClass {
|
|
136
|
+
* @Repository(SQLModel)
|
|
137
|
+
* private myRepo: Repository<SQLModel>;
|
|
15
138
|
*
|
|
16
|
-
*
|
|
139
|
+
* @Transactional(SQLModel)
|
|
140
|
+
* public myFunc(obj: SQLModel, @EntityManager() em) {
|
|
141
|
+
* await em.save(obj);
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
* @param source The name of the datasource or the class type that a transaction will be created for. If none specified,
|
|
146
|
+
* the source is inferred using `this.modelClass`.
|
|
147
|
+
* @param options The transcation options to pass to the underlying datasource connection.
|
|
17
148
|
*/
|
|
18
|
-
export declare function
|
|
149
|
+
export declare function Transactional(source?: string | any, options?: TransactionalOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
@@ -3,7 +3,7 @@ export interface DocumentsData {
|
|
|
3
3
|
default?: any;
|
|
4
4
|
description?: string;
|
|
5
5
|
example?: any;
|
|
6
|
-
format?:
|
|
6
|
+
format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
|
|
7
7
|
summary?: string;
|
|
8
8
|
tags?: string[];
|
|
9
9
|
}
|
|
@@ -36,7 +36,7 @@ export declare function Example(value: any): (target: any, propertyKey?: string)
|
|
|
36
36
|
*
|
|
37
37
|
* @param value The format of the property's property.
|
|
38
38
|
*/
|
|
39
|
-
export declare function Format(value:
|
|
39
|
+
export declare function Format(value: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string): (target: any, propertyKey?: string) => void;
|
|
40
40
|
/**
|
|
41
41
|
* Provides a brief summary about the class, property or function.
|
|
42
42
|
*
|
|
@@ -67,3 +67,12 @@ export declare function Returns(types?: any | any[]): (target: any, propertyKey:
|
|
|
67
67
|
* becomes `[[Array, MyClass]]`).
|
|
68
68
|
*/
|
|
69
69
|
export declare function TypeInfo(types?: any | any[]): (target: any, propertyKey: string) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves the typing information of a class property or function, preferring the richer description provided by
|
|
72
|
+
* `@TypeInfo` and falling back to TypeScript's own `design:type` reflection metadata when `@TypeInfo` was not
|
|
73
|
+
* applied.
|
|
74
|
+
*
|
|
75
|
+
* @param target The class prototype (or class, for static members) to retrieve type information for.
|
|
76
|
+
* @param propertyKey The name of the property or function to retrieve type information for.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getTypeInfo(target: any, propertyKey: string): any;
|