@rapidrest/service-core 1.0.0-rc.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +382 -23
- package/README.md +79 -5
- package/dist/lib/ApiErrors.js +10 -0
- package/dist/lib/ApiErrors.js.map +1 -1
- package/dist/lib/BackgroundService.js +1 -4
- package/dist/lib/BackgroundService.js.map +1 -1
- package/dist/lib/BackgroundServiceManager.js +47 -6
- package/dist/lib/BackgroundServiceManager.js.map +1 -1
- package/dist/lib/BulkError.js +4 -0
- package/dist/lib/BulkError.js.map +1 -1
- package/dist/lib/EventListenerManager.js +53 -18
- package/dist/lib/EventListenerManager.js.map +1 -1
- package/dist/lib/NetUtils.js +1 -0
- package/dist/lib/NetUtils.js.map +1 -1
- package/dist/lib/NotificationUtils.js +27 -8
- package/dist/lib/NotificationUtils.js.map +1 -1
- package/dist/lib/ObjectFactory.js +25 -44
- package/dist/lib/ObjectFactory.js.map +1 -1
- package/dist/lib/OpenApiSpec.js +31 -11
- package/dist/lib/OpenApiSpec.js.map +1 -1
- package/dist/lib/Server.js +74 -110
- package/dist/lib/Server.js.map +1 -1
- package/dist/lib/auth/AuthMiddleware.js +11 -16
- package/dist/lib/auth/AuthMiddleware.js.map +1 -1
- package/dist/lib/auth/JWTStrategy.js +68 -17
- package/dist/lib/auth/JWTStrategy.js.map +1 -1
- package/dist/lib/auth/index.js +0 -1
- package/dist/lib/auth/index.js.map +1 -1
- package/dist/lib/database/ConnectionKinds.js +15 -0
- package/dist/lib/database/ConnectionKinds.js.map +1 -1
- package/dist/lib/database/ConnectionManager.js +140 -61
- package/dist/lib/database/ConnectionManager.js.map +1 -1
- package/dist/lib/database/MongoConnection.js +13 -3
- package/dist/lib/database/MongoConnection.js.map +1 -1
- package/dist/lib/database/MongoRepository.js +61 -15
- package/dist/lib/database/MongoRepository.js.map +1 -1
- package/dist/lib/database/MongoSchemaSync.js +3 -3
- package/dist/lib/database/MongoSchemaSync.js.map +1 -1
- package/dist/lib/database/NamingUtils.js +3 -2
- package/dist/lib/database/NamingUtils.js.map +1 -1
- package/dist/lib/database/RedisCache.js +64 -0
- package/dist/lib/database/RedisCache.js.map +1 -0
- package/dist/lib/database/TypeOrmSupport.js +53 -13
- package/dist/lib/database/TypeOrmSupport.js.map +1 -1
- package/dist/lib/database/index.js +1 -0
- package/dist/lib/database/index.js.map +1 -1
- package/dist/lib/decorators/DatabaseDecorators.js +264 -20
- package/dist/lib/decorators/DatabaseDecorators.js.map +1 -1
- package/dist/lib/decorators/DocDecorators.js +30 -9
- package/dist/lib/decorators/DocDecorators.js.map +1 -1
- package/dist/lib/decorators/EventDecorators.js +1 -0
- package/dist/lib/decorators/EventDecorators.js.map +1 -1
- package/dist/lib/decorators/ModelDecorators.js +39 -23
- package/dist/lib/decorators/ModelDecorators.js.map +1 -1
- package/dist/lib/decorators/PersistenceDecorators.js +4 -3
- package/dist/lib/decorators/PersistenceDecorators.js.map +1 -1
- package/dist/lib/decorators/RouteDecorators.js +139 -36
- package/dist/lib/decorators/RouteDecorators.js.map +1 -1
- package/dist/lib/http/IWebSocketShim.js +2 -0
- package/dist/lib/http/IWebSocketShim.js.map +1 -0
- package/dist/lib/http/MiddlewareChain.js +167 -0
- package/dist/lib/http/MiddlewareChain.js.map +1 -0
- package/dist/lib/http/RuntimeDetect.js +9 -0
- package/dist/lib/http/RuntimeDetect.js.map +1 -0
- package/dist/lib/http/bun/BunAdapters.js +326 -0
- package/dist/lib/http/bun/BunAdapters.js.map +1 -0
- package/dist/lib/http/bun/BunRouter.js +391 -0
- package/dist/lib/http/bun/BunRouter.js.map +1 -0
- package/dist/lib/http/bun/BunWebSocket.js +49 -0
- package/dist/lib/http/bun/BunWebSocket.js.map +1 -0
- package/dist/lib/http/index.js +16 -3
- package/dist/lib/http/index.js.map +1 -1
- package/dist/lib/http/session/RedisSessionStore.js +30 -0
- package/dist/lib/http/session/RedisSessionStore.js.map +1 -0
- package/dist/lib/http/session/SessionManager.js +113 -0
- package/dist/lib/http/session/SessionManager.js.map +1 -0
- package/dist/lib/http/session/SessionStore.js +6 -0
- package/dist/lib/http/session/SessionStore.js.map +1 -0
- package/dist/lib/http/session/sessionMiddleware.js +42 -0
- package/dist/lib/http/session/sessionMiddleware.js.map +1 -0
- package/dist/lib/http/types.js +0 -3
- package/dist/lib/http/types.js.map +1 -1
- package/dist/lib/http/uWS/Adapters.js +421 -0
- package/dist/lib/http/uWS/Adapters.js.map +1 -0
- package/dist/lib/http/{Router.js → uWS/Router.js} +73 -173
- package/dist/lib/http/uWS/Router.js.map +1 -0
- package/dist/lib/http/{WebSocket.js → uWS/WebSocket.js} +4 -1
- package/dist/lib/http/uWS/WebSocket.js.map +1 -0
- package/dist/lib/models/BaseEntity.js +2 -1
- package/dist/lib/models/BaseEntity.js.map +1 -1
- package/dist/lib/models/BaseMongoEntity.js +2 -2
- package/dist/lib/models/BaseMongoEntity.js.map +1 -1
- package/dist/lib/models/ModelUtils.js +248 -101
- package/dist/lib/models/ModelUtils.js.map +1 -1
- package/dist/lib/models/RecoverableBaseEntity.js +6 -1
- package/dist/lib/models/RecoverableBaseEntity.js.map +1 -1
- package/dist/lib/models/RecoverableBaseMongoEntity.js +1 -0
- package/dist/lib/models/RecoverableBaseMongoEntity.js.map +1 -1
- package/dist/lib/models/RepoUtils.js +641 -213
- package/dist/lib/models/RepoUtils.js.map +1 -1
- package/dist/lib/models/SimpleEntity.js +1 -0
- package/dist/lib/models/SimpleEntity.js.map +1 -1
- package/dist/lib/models/SimpleMongoEntity.js +2 -1
- package/dist/lib/models/SimpleMongoEntity.js.map +1 -1
- package/dist/lib/models/StatusExtraData.js +4 -0
- package/dist/lib/models/StatusExtraData.js.map +1 -1
- package/dist/lib/routes/{AdminRoute.js → BaseAdminRoute.js} +98 -80
- package/dist/lib/routes/BaseAdminRoute.js.map +1 -0
- package/dist/lib/routes/{MetricsRoute.js → BaseMetricsRoute.js} +29 -15
- package/dist/lib/routes/BaseMetricsRoute.js.map +1 -0
- package/dist/lib/routes/{OpenAPIRoute.js → BaseOpenAPIRoute.js} +32 -32
- package/dist/lib/routes/BaseOpenAPIRoute.js.map +1 -0
- package/dist/lib/routes/BasePushRoute.js +305 -0
- package/dist/lib/routes/BasePushRoute.js.map +1 -0
- package/dist/lib/routes/BaseStaticRoute.js +153 -0
- package/dist/lib/routes/BaseStaticRoute.js.map +1 -0
- package/dist/lib/routes/BaseStatusRoute.js +80 -0
- package/dist/lib/routes/BaseStatusRoute.js.map +1 -0
- package/dist/lib/routes/CRUDRoute.js +284 -0
- package/dist/lib/routes/CRUDRoute.js.map +1 -0
- package/dist/lib/routes/ModelRoute.js +84 -57
- package/dist/lib/routes/ModelRoute.js.map +1 -1
- package/dist/lib/routes/RouteUtils.js +108 -20
- package/dist/lib/routes/RouteUtils.js.map +1 -1
- package/dist/lib/routes/index.js +7 -4
- package/dist/lib/routes/index.js.map +1 -1
- package/dist/lib/security/ACLUtils.js +297 -170
- package/dist/lib/security/ACLUtils.js.map +1 -1
- package/dist/lib/security/AccessControlList.js +18 -10
- package/dist/lib/security/AccessControlList.js.map +1 -1
- package/dist/lib/security/AccessControlListMongo.js +19 -68
- package/dist/lib/security/AccessControlListMongo.js.map +1 -1
- package/dist/lib/security/AccessControlListSQL.js +21 -70
- package/dist/lib/security/AccessControlListSQL.js.map +1 -1
- package/dist/lib/security/BaseACLRoute.js +239 -0
- package/dist/lib/security/BaseACLRoute.js.map +1 -0
- package/dist/lib/security/index.js +3 -0
- package/dist/lib/security/index.js.map +1 -1
- package/dist/lib/test/request.js +62 -5
- package/dist/lib/test/request.js.map +1 -1
- package/dist/lib/test/requestws.js +34 -10
- package/dist/lib/test/requestws.js.map +1 -1
- package/dist/types/ApiErrors.d.ts +8 -2
- package/dist/types/BackgroundService.d.ts +0 -5
- package/dist/types/BackgroundServiceManager.d.ts +2 -1
- package/dist/types/EventListenerManager.d.ts +7 -6
- package/dist/types/NotificationUtils.d.ts +5 -3
- package/dist/types/OpenApiSpec.d.ts +2 -2
- package/dist/types/Server.d.ts +28 -10
- package/dist/types/auth/AuthMiddleware.d.ts +3 -3
- package/dist/types/auth/AuthStrategy.d.ts +10 -7
- package/dist/types/auth/JWTStrategy.d.ts +6 -4
- package/dist/types/auth/index.d.ts +0 -1
- package/dist/types/database/ConnectionKinds.d.ts +7 -0
- package/dist/types/database/ConnectionManager.d.ts +29 -4
- package/dist/types/database/MongoConnection.d.ts +16 -4
- package/dist/types/database/MongoRepository.d.ts +32 -11
- package/dist/types/database/RedisCache.d.ts +23 -0
- package/dist/types/database/TypeOrmSupport.d.ts +4 -4
- package/dist/types/database/index.d.ts +1 -0
- package/dist/types/decorators/DatabaseDecorators.d.ts +139 -8
- package/dist/types/decorators/DocDecorators.d.ts +11 -2
- package/dist/types/decorators/ModelDecorators.d.ts +12 -5
- package/dist/types/decorators/PersistenceDecorators.d.ts +11 -4
- package/dist/types/decorators/RouteDecorators.d.ts +36 -6
- package/dist/types/http/IWebSocketShim.d.ts +11 -0
- package/dist/types/http/MiddlewareChain.d.ts +47 -0
- package/dist/types/http/RuntimeDetect.d.ts +2 -0
- package/dist/types/http/bun/BunAdapters.d.ts +139 -0
- package/dist/types/http/bun/BunRouter.d.ts +79 -0
- package/dist/types/http/bun/BunWebSocket.d.ts +35 -0
- package/dist/types/http/index.d.ts +16 -6
- package/dist/types/http/session/RedisSessionStore.d.ts +15 -0
- package/dist/types/http/session/SessionManager.d.ts +35 -0
- package/dist/types/http/session/SessionStore.d.ts +12 -0
- package/dist/types/http/session/sessionMiddleware.d.ts +10 -0
- package/dist/types/http/types.d.ts +42 -3
- package/dist/types/http/uWS/Adapters.d.ts +129 -0
- package/dist/types/http/{Router.d.ts → uWS/Router.d.ts} +14 -38
- package/dist/types/http/{WebSocket.d.ts → uWS/WebSocket.d.ts} +6 -5
- package/dist/types/models/BaseEntity.d.ts +1 -1
- package/dist/types/models/ModelUtils.d.ts +47 -14
- package/dist/types/models/RecoverableBaseEntity.d.ts +3 -1
- package/dist/types/models/RepoUtils.d.ts +84 -14
- package/dist/types/routes/BaseAdminRoute.d.ts +65 -0
- package/dist/types/routes/BaseMetricsRoute.d.ts +37 -0
- package/dist/types/routes/BaseOpenAPIRoute.d.ts +33 -0
- package/dist/types/routes/BasePushRoute.d.ts +53 -0
- package/dist/types/routes/BaseStaticRoute.d.ts +44 -0
- package/dist/types/routes/BaseStatusRoute.d.ts +37 -0
- package/dist/types/routes/CRUDRoute.d.ts +57 -0
- package/dist/types/routes/ModelRoute.d.ts +39 -36
- package/dist/types/routes/RouteUtils.d.ts +19 -0
- package/dist/types/routes/index.d.ts +7 -4
- package/dist/types/security/ACLUtils.d.ts +94 -18
- package/dist/types/security/AccessControlList.d.ts +37 -59
- package/dist/types/security/AccessControlListMongo.d.ts +3 -8
- package/dist/types/security/AccessControlListSQL.d.ts +3 -8
- package/dist/types/security/BaseACLRoute.d.ts +73 -0
- package/dist/types/security/index.d.ts +3 -0
- package/dist/types/test/request.d.ts +18 -1
- package/package.json +135 -129
- package/tsconfig.export.json +17 -0
- package/dist/lib/auth/BasicStrategy.js +0 -113
- package/dist/lib/auth/BasicStrategy.js.map +0 -1
- package/dist/lib/http/Adapters.js +0 -241
- package/dist/lib/http/Adapters.js.map +0 -1
- package/dist/lib/http/Router.js.map +0 -1
- package/dist/lib/http/WebSocket.js.map +0 -1
- package/dist/lib/routes/AdminRoute.js.map +0 -1
- package/dist/lib/routes/MetricsRoute.js.map +0 -1
- package/dist/lib/routes/OpenAPIRoute.js.map +0 -1
- package/dist/lib/routes/StatusRoute.js +0 -55
- package/dist/lib/routes/StatusRoute.js.map +0 -1
- package/dist/lib/security/ACLRouteMongo.js +0 -194
- package/dist/lib/security/ACLRouteMongo.js.map +0 -1
- package/dist/lib/security/ACLRouteSQL.js +0 -193
- package/dist/lib/security/ACLRouteSQL.js.map +0 -1
- package/dist/types/auth/BasicStrategy.d.ts +0 -37
- package/dist/types/http/Adapters.d.ts +0 -68
- package/dist/types/routes/AdminRoute.d.ts +0 -47
- package/dist/types/routes/MetricsRoute.d.ts +0 -15
- package/dist/types/routes/OpenAPIRoute.d.ts +0 -17
- package/dist/types/routes/StatusRoute.d.ts +0 -11
- package/dist/types/security/ACLRouteMongo.d.ts +0 -19
- package/dist/types/security/ACLRouteSQL.d.ts +0 -19
- package/docs/Makefile +0 -20
- package/docs/conf.py +0 -58
- package/docs/index.rst +0 -17
- package/docs/make.bat +0 -35
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/README.md +0 -13
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/MongoRepository.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/RedisConnection.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/Repository.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/README.md +0 -23
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Default.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Description.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Document.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Example.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Format.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Returns.md +0 -28
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Summary.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Tags.md +0 -25
- package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/TypeInfo.md +0 -28
- package/docs/reference/@rapidrest/namespaces/DocDecorators/interfaces/DocumentsData.md +0 -57
- package/docs/reference/@rapidrest/namespaces/EventDecorators/README.md +0 -12
- package/docs/reference/@rapidrest/namespaces/EventDecorators/functions/EventListener.md +0 -17
- package/docs/reference/@rapidrest/namespaces/EventDecorators/functions/OnEvent.md +0 -26
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/README.md +0 -26
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Cache.md +0 -25
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/ChildEntity.md +0 -18
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/DataStore.md +0 -25
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Identifier.md +0 -27
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Protect.md +0 -35
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Reference.md +0 -25
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Shard.md +0 -27
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/TrackChanges.md +0 -26
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/interfaces/PendingTypeOrmColumn.md +0 -45
- package/docs/reference/@rapidrest/namespaces/ModelDecorators/variables/pendingTypeOrmColumns.md +0 -14
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/README.md +0 -27
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Column.md +0 -25
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Entity.md +0 -25
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Index.md +0 -119
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/PrimaryColumn.md +0 -25
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Unique.md +0 -68
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getColumnMetadata.md +0 -26
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getEntityName.md +0 -26
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getIndexMetadata.md +0 -27
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/CollationOptions.md +0 -79
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/ColumnInfo.md +0 -41
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/ColumnOptions.md +0 -51
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/EntityOptions.md +0 -32
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/IndexInfo.md +0 -41
- package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/IndexOptions.md +0 -61
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/README.md +0 -36
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/After.md +0 -26
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Auth.md +0 -33
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/AuthResult.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Before.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/ContentType.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Delete.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Get.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Head.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Header.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Method.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Model.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Options.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Param.md +0 -26
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Patch.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Post.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Protect.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Put.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Query.md +0 -26
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Request.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/RequiresRole.md +0 -26
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Response.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Route.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Socket.md +0 -33
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/User.md +0 -31
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Validate.md +0 -25
- package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/WebSocket.md +0 -25
- package/docs/reference/README.md +0 -20
- package/docs/reference/classes/ACLUtils.md +0 -263
- package/docs/reference/classes/AdminRoute.md +0 -51
- package/docs/reference/classes/AuthMiddleware.md +0 -173
- package/docs/reference/classes/BackgroundService.md +0 -117
- package/docs/reference/classes/BackgroundServiceManager.md +0 -172
- package/docs/reference/classes/BaseEntity.md +0 -82
- package/docs/reference/classes/BaseMongoEntity.md +0 -107
- package/docs/reference/classes/BasicStrategy.md +0 -131
- package/docs/reference/classes/BasicStrategyOptions.md +0 -115
- package/docs/reference/classes/BulkError.md +0 -271
- package/docs/reference/classes/ConnectionManager.md +0 -75
- package/docs/reference/classes/EventListenerManager.md +0 -88
- package/docs/reference/classes/HttpRouter.md +0 -343
- package/docs/reference/classes/JWTStrategy.md +0 -100
- package/docs/reference/classes/JWTStrategyOptions.md +0 -97
- package/docs/reference/classes/MetricsRoute.md +0 -27
- package/docs/reference/classes/ModelRoute.md +0 -527
- package/docs/reference/classes/ModelUtils.md +0 -446
- package/docs/reference/classes/MongoConnection.md +0 -218
- package/docs/reference/classes/MongoRepository.md +0 -390
- package/docs/reference/classes/MongoSchemaSync.md +0 -97
- package/docs/reference/classes/NetUtils.md +0 -90
- package/docs/reference/classes/NotificationUtils.md +0 -77
- package/docs/reference/classes/ObjectFactory.md +0 -336
- package/docs/reference/classes/OpenAPIRoute.md +0 -77
- package/docs/reference/classes/OpenApiSpec.md +0 -892
- package/docs/reference/classes/RecoverableBaseEntity.md +0 -114
- package/docs/reference/classes/RecoverableBaseMongoEntity.md +0 -124
- package/docs/reference/classes/RedisTransport.md +0 -2202
- package/docs/reference/classes/RepoUtils.md +0 -482
- package/docs/reference/classes/RouteUtils.md +0 -191
- package/docs/reference/classes/Server.md +0 -408
- package/docs/reference/classes/SimpleEntity.md +0 -48
- package/docs/reference/classes/SimpleMongoEntity.md +0 -66
- package/docs/reference/classes/StatusExtraData.md +0 -57
- package/docs/reference/classes/StatusRoute.md +0 -26
- package/docs/reference/classes/UWSRequest.md +0 -226
- package/docs/reference/classes/UWSResponse.md +0 -257
- package/docs/reference/classes/UWSWebSocketShim.md +0 -958
- package/docs/reference/enumerations/ACLAction.md +0 -63
- package/docs/reference/enumerations/ApiErrorMessages.md +0 -123
- package/docs/reference/enumerations/ApiErrors.md +0 -123
- package/docs/reference/functions/createWebSocketStream.md +0 -27
- package/docs/reference/functions/isSqlDataSource.md +0 -26
- package/docs/reference/functions/readBody.md +0 -29
- package/docs/reference/functions/resolveCollectionName.md +0 -33
- package/docs/reference/functions/runChain.md +0 -40
- package/docs/reference/functions/snakeCase.md +0 -28
- package/docs/reference/globals.md +0 -106
- package/docs/reference/interfaces/ACLRecord.md +0 -96
- package/docs/reference/interfaces/AccessControlList.md +0 -76
- package/docs/reference/interfaces/AuthResult.md +0 -55
- package/docs/reference/interfaces/AuthStrategy.md +0 -95
- package/docs/reference/interfaces/CreateRequestOptions.md +0 -121
- package/docs/reference/interfaces/DeleteRequestOptions.md +0 -137
- package/docs/reference/interfaces/FindRequestOptions.md +0 -133
- package/docs/reference/interfaces/HttpRequest.md +0 -147
- package/docs/reference/interfaces/HttpResponse.md +0 -164
- package/docs/reference/interfaces/JWTAuthResult.md +0 -84
- package/docs/reference/interfaces/RepoCreateOptions.md +0 -95
- package/docs/reference/interfaces/RepoDeleteOptions.md +0 -105
- package/docs/reference/interfaces/RepoFindOptions.md +0 -125
- package/docs/reference/interfaces/RepoOperationOptions.md +0 -69
- package/docs/reference/interfaces/RepoUpdateOptions.md +0 -101
- package/docs/reference/interfaces/RequestOptions.md +0 -112
- package/docs/reference/interfaces/RequestWS.md +0 -225
- package/docs/reference/interfaces/TruncateRequestOptions.md +0 -161
- package/docs/reference/interfaces/UpdateRequestOptions.md +0 -139
- package/docs/reference/type-aliases/ErrorHandler.md +0 -35
- package/docs/reference/type-aliases/NextFunction.md +0 -23
- package/docs/reference/type-aliases/OneOrMany.md +0 -19
- package/docs/reference/type-aliases/OneOrNull.md +0 -19
- package/docs/reference/type-aliases/PartialBaseEntity.md +0 -17
- package/docs/reference/type-aliases/PartialSimpleEntity.md +0 -17
- package/docs/reference/type-aliases/RequestHandler.md +0 -31
- package/docs/reference/type-aliases/UpdateObject.md +0 -19
- package/docs/reference/type-aliases/WsUpgradeAuth.md +0 -27
- package/docs/reference/type-aliases/WsUpgradeAuthResult.md +0 -47
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { AccessControlList } from "../security/AccessControlList.js";
|
|
2
|
+
import { type AccessControlList } from "../security/AccessControlList.js";
|
|
3
3
|
/**
|
|
4
4
|
* Describes a column registration that must be bridged into TypeORM's metadata storage when (and only when) a SQL
|
|
5
5
|
* connection is established. Entries are queued here by decorators so that this module does not depend on the
|
|
@@ -23,7 +23,7 @@ export declare const pendingTypeOrmColumns: PendingTypeOrmColumn[];
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function Cache(ttl?: number): (target: any) => void;
|
|
25
25
|
/**
|
|
26
|
-
* Indicates that a class is a child entity to some parent. Child entities will inherit all
|
|
26
|
+
* Indicates that a class is a child entity to some parent. Child entities will inherit all datasource configuration
|
|
27
27
|
* of the parent, including cache settings.
|
|
28
28
|
*/
|
|
29
29
|
export declare function ChildEntity(): <T extends {
|
|
@@ -35,15 +35,22 @@ export declare function ChildEntity(): <T extends {
|
|
|
35
35
|
};
|
|
36
36
|
} & T;
|
|
37
37
|
/**
|
|
38
|
-
* Indicates that the class describes an entity that will be persisted in the
|
|
38
|
+
* Indicates that the class describes an entity that will be persisted in the datasource with the given name.
|
|
39
39
|
*
|
|
40
|
-
* @param
|
|
40
|
+
* @param datasource The name of the datasource to store records of the decorated class.
|
|
41
41
|
*/
|
|
42
|
-
export declare function DataStore(
|
|
42
|
+
export declare function DataStore(datasource: string): (target: any) => void;
|
|
43
43
|
/**
|
|
44
44
|
* Apply this to a property that is considered a unique identifier.
|
|
45
45
|
*/
|
|
46
46
|
export declare function Identifier(target: any, propertyKey: string | symbol): void;
|
|
47
|
+
/**
|
|
48
|
+
* Apply this to a property that must never be settable by a client. `RepoUtils.create()`/`update()` strip any
|
|
49
|
+
* client-supplied value for a `@ReadOnly` property before persisting — the property's existing/declared-default
|
|
50
|
+
* value is kept instead, regardless of what the request body contains. Use this for fields that should only ever
|
|
51
|
+
* be changed by application/business logic (e.g. `roles`, ownership fields, computed/derived state).
|
|
52
|
+
*/
|
|
53
|
+
export declare function ReadOnly(target: any, propertyKey: string | symbol): void;
|
|
47
54
|
type PartialACL = Partial<AccessControlList> & Pick<AccessControlList, "records">;
|
|
48
55
|
/**
|
|
49
56
|
* Apply this to a model class to indicate that it should be protected by the AccessControlList security system.
|
|
@@ -18,7 +18,7 @@ export interface CollationOptions {
|
|
|
18
18
|
* The set of options available when declaring a persisted column/property via the `@Column` decorator.
|
|
19
19
|
*/
|
|
20
20
|
export interface ColumnOptions {
|
|
21
|
-
/** The name of the column in the
|
|
21
|
+
/** The name of the column in the datasource. Defaults to the property name. */
|
|
22
22
|
name?: string;
|
|
23
23
|
/** Set to `true` if the column may store `null`/`undefined` values. */
|
|
24
24
|
nullable?: boolean;
|
|
@@ -26,6 +26,13 @@ export interface ColumnOptions {
|
|
|
26
26
|
primary?: boolean;
|
|
27
27
|
/** Set to `true` if the column stores a MongoDB `ObjectId` value. */
|
|
28
28
|
isObjectId?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Explicitly declares the SQL column type, overriding the type that would otherwise be inferred from
|
|
31
|
+
* TypeScript's reflected property type. Required whenever the design-time type cannot be reliably inferred,
|
|
32
|
+
* such as nullable/union-typed properties (which TypeScript reflects as `Object`) or properties whose value is
|
|
33
|
+
* a complex/nested structure that has no direct SQL column equivalent (e.g. `"simple-json"`).
|
|
34
|
+
*/
|
|
35
|
+
type?: string | Function;
|
|
29
36
|
}
|
|
30
37
|
/**
|
|
31
38
|
* The set of options to use when declaring a persistent class type via the `@Entity` decorator.
|
|
@@ -75,13 +82,13 @@ export interface IndexInfo {
|
|
|
75
82
|
options: IndexOptions;
|
|
76
83
|
}
|
|
77
84
|
/**
|
|
78
|
-
* Indicates that the decorated property will be persisted as a column/property in the
|
|
85
|
+
* Indicates that the decorated property will be persisted as a column/property in the datasource.
|
|
79
86
|
*
|
|
80
87
|
* @param options The options describing the column.
|
|
81
88
|
*/
|
|
82
89
|
export declare function Column(options?: ColumnOptions): (target: any, propertyKey: string | symbol) => void;
|
|
83
90
|
/**
|
|
84
|
-
* Indicates that the decorated property is a primary key column in the
|
|
91
|
+
* Indicates that the decorated property is a primary key column in the datasource.
|
|
85
92
|
*
|
|
86
93
|
* @param options The options describing the column.
|
|
87
94
|
*/
|
|
@@ -114,7 +121,7 @@ export declare function Unique(name?: string): PropertyDecorator;
|
|
|
114
121
|
export declare function Unique(fields: string[]): ClassDecorator;
|
|
115
122
|
export declare function Unique(name: string, fields: string[]): ClassDecorator;
|
|
116
123
|
/**
|
|
117
|
-
* Indicates that the class describes an entity that is persisted to a
|
|
124
|
+
* Indicates that the class describes an entity that is persisted to a datasource.
|
|
118
125
|
*
|
|
119
126
|
* @param options The options to set.
|
|
120
127
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { AccessControlList } from "../security/AccessControlList.js";
|
|
2
|
+
import { type AccessControlList } from "../security/AccessControlList.js";
|
|
3
3
|
/**
|
|
4
4
|
* Indicates a provided function or list of functions to execute *after* the decorated function and before the response
|
|
5
5
|
* is sent to a client. Note that the function must call `next()` in order for this decorator to work.
|
|
@@ -8,10 +8,19 @@ import { AccessControlList } from "../security/AccessControlList.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function After(func: Function | string | (Function | string)[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Indicates that the decorated class contains route definitions. This prepends `/api` or `/api/v{version}` to
|
|
12
|
+
* all provided path(s). e.g. `@ApiRoute('my-api')` results in `/api/my-api`. `@ApiRoute('my-api',2) results in
|
|
13
|
+
* `/api/v2/my-api`.
|
|
14
|
+
*
|
|
15
|
+
* @param paths The base path(s) that all route definitions will use.
|
|
16
|
+
* @param version The optional version number to prepend the path with. Prefixes the provided version with `v` in the path.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ApiRoute(paths: string | string[], version?: string | number): (target: Function) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Applies authentication to the decorated route or method for the provided strategy or list of strategies
|
|
12
21
|
* should be attempted before processing the route.
|
|
13
22
|
*
|
|
14
|
-
* @param strategies The
|
|
23
|
+
* @param strategies The strategies that will be applied when incoming requests are processed.
|
|
15
24
|
* @param require Set to `true` to indicate that at least one of the specified authentication strategies must pass to
|
|
16
25
|
* proceed, otherwise set to `false`. Default is `true`.
|
|
17
26
|
*/
|
|
@@ -127,13 +136,19 @@ export declare function Protect(acl?: PartialACL): (target: any, propertyKey?: s
|
|
|
127
136
|
*/
|
|
128
137
|
export declare function Query(name?: string | undefined): (target: any, propertyKey: string, index: number) => void;
|
|
129
138
|
/**
|
|
130
|
-
* Injects the
|
|
139
|
+
* Injects the HTTP request object as the value of the decorated argument.
|
|
131
140
|
*/
|
|
132
141
|
export declare function Request(target: any, propertyKey: string, index: number): void;
|
|
133
142
|
/**
|
|
134
|
-
* Injects the
|
|
143
|
+
* Injects the HTTP response object as the value of the decorated argument.
|
|
135
144
|
*/
|
|
136
145
|
export declare function Response(target: any, propertyKey: string, index: number): void;
|
|
146
|
+
/**
|
|
147
|
+
* Indicates that elevated user permissions is required to perform the action. Optionally, set a `lastStart` which is the number
|
|
148
|
+
* of seconds that the user has most recently confirmed elevation. A negative value indicates until the end of the elevated
|
|
149
|
+
* window. Default is `-1`.
|
|
150
|
+
*/
|
|
151
|
+
export declare function RequiresElevation(lastStart?: number): (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void;
|
|
137
152
|
/**
|
|
138
153
|
* Indicates that the client must be an authenticated user with at least one of the specified role(s) to process the
|
|
139
154
|
* request.
|
|
@@ -142,7 +157,22 @@ export declare function Response(target: any, propertyKey: string, index: number
|
|
|
142
157
|
*/
|
|
143
158
|
export declare function RequiresRole(roles: string | string[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
144
159
|
/**
|
|
145
|
-
* Indicates that the
|
|
160
|
+
* Indicates that the client's token must carry at least one of the specified OAuth-style scope(s) to process the
|
|
161
|
+
* request. This is a coarse, token-level pre-check performed before the per-resource `AccessControlList` check —
|
|
162
|
+
* it answers "can this token ever perform this class of action" rather than "can this user perform this action on
|
|
163
|
+
* this specific resource".
|
|
164
|
+
*
|
|
165
|
+
* @param scopes The scope(s) that the authenticated user's token must carry to make the request. The sentinel
|
|
166
|
+
* value `ACLAction.FULL` (`"*"`) also satisfies any required scope.
|
|
167
|
+
*/
|
|
168
|
+
export declare function RequiresScope(scopes: string | string[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
169
|
+
/**
|
|
170
|
+
* Indicates that the client must be an authenticated user with at least one trusted role(s) to process the
|
|
171
|
+
* request.
|
|
172
|
+
*/
|
|
173
|
+
export declare function RequiresTrustedRole(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
174
|
+
/**
|
|
175
|
+
* Indicates that the decorated class contains route definitions.
|
|
146
176
|
*
|
|
147
177
|
* @param paths The base path(s) that all route definitions will use.
|
|
148
178
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
/**
|
|
3
|
+
* Framework-agnostic WebSocket shim surface. Both the uWS-backed and Bun-backed WebSocket shims
|
|
4
|
+
* implement this, so route/middleware code (e.g. `BaseAdminRoute`, `AuthMiddleware.authWebSocket`)
|
|
5
|
+
* never depends on the concrete runtime implementation.
|
|
6
|
+
*/
|
|
7
|
+
export interface IWebSocketShim extends EventEmitter {
|
|
8
|
+
readyState: number;
|
|
9
|
+
send(data: any, cb?: (err?: Error) => void): void;
|
|
10
|
+
close(code?: number, reason?: string): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { HttpRequest, HttpResponse, RequestHandler } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runs an ordered array of middleware handlers sequentially, Express-style.
|
|
4
|
+
* Supports both 3-param `(req, res, next)` handlers and 4-param `(err, req, res, next)`
|
|
5
|
+
* error handlers. On error, execution skips to the next error handler.
|
|
6
|
+
*
|
|
7
|
+
* Each handler is awaited via a Promise that resolves when next() is called, not when
|
|
8
|
+
* the handler's return value resolves. This correctly handles: (1) sync handlers that
|
|
9
|
+
* call next() synchronously, (2) async handlers that return next() or await before
|
|
10
|
+
* calling it, and (3) sync handlers that schedule next() via callbacks such as
|
|
11
|
+
* setTimeout or socket.once. The chain terminates early when a handler ends the
|
|
12
|
+
* response without calling next().
|
|
13
|
+
*
|
|
14
|
+
* Framework-agnostic — used by both the uWS-backed and Bun-backed routers.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runChain(handlers: RequestHandler[], req: HttpRequest, res: HttpResponse): Promise<void>;
|
|
17
|
+
/** Result returned by a pre-upgrade WebSocket auth function. */
|
|
18
|
+
export type WsUpgradeAuthResult = {
|
|
19
|
+
user?: any;
|
|
20
|
+
authPayload?: any;
|
|
21
|
+
authToken?: string;
|
|
22
|
+
/** Set to `true` to reject the connection with HTTP 401 before the WebSocket handshake. */
|
|
23
|
+
reject?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Optional pre-upgrade auth function for WebSocket routes. Called synchronously before the
|
|
27
|
+
* WebSocket handshake completes. Returning `{ reject: true }` sends an HTTP 401 and skips the
|
|
28
|
+
* upgrade entirely. Returning `{}` falls through to the post-upgrade message-based LOGIN flow.
|
|
29
|
+
* Returning `{ user, ... }` pre-authenticates the connection so clients that can send an
|
|
30
|
+
* Authorization header skip the LOGIN step.
|
|
31
|
+
*/
|
|
32
|
+
export type WsUpgradeAuth = (req: HttpRequest) => WsUpgradeAuthResult;
|
|
33
|
+
/** Parses `:param` names out of a route pattern (e.g. `/users/:uid/:version` → `["uid","version"]`). */
|
|
34
|
+
export declare function extractParamNames(routePath: string): string[];
|
|
35
|
+
/**
|
|
36
|
+
* Builds a stub `HttpResponse` used for WebSocket routes: the framework middleware chain runs
|
|
37
|
+
* against a WebSocket "request" that has no real HTTP response to write to, so all writes are
|
|
38
|
+
* no-ops other than tracking `writableEnded`.
|
|
39
|
+
*
|
|
40
|
+
* @param onUnhandledError Invoked when `runChain()` reaches the end of the chain with an
|
|
41
|
+
* unhandled error and falls back to `res.status(...).json(...)` — the only way that fallback
|
|
42
|
+
* (or any other middleware) can signal an error for a WS connection, since there is no real
|
|
43
|
+
* response to write to. The router's `ws()` open handler uses this to close the socket the same
|
|
44
|
+
* way route handlers do themselves (a `1002` close carrying the error's short code), instead of
|
|
45
|
+
* silently doing nothing.
|
|
46
|
+
*/
|
|
47
|
+
export declare function makeWsStubResponse(onUnhandledError?: (status: number, payload: any) => void): HttpResponse;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { HttpRequest, HttpResponse } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal structural slice of Bun's `Server` used by `BunRequest`. Deliberately NOT typed as
|
|
4
|
+
* `Bun.Server` — a public constructor parameter typed against the ambient `Bun` namespace would
|
|
5
|
+
* leak into this package's emitted `.d.ts`, breaking `tsc` for downstream consumers who don't have
|
|
6
|
+
* `@types/bun` installed even though they never touch the Bun adapter (confirmed: without this,
|
|
7
|
+
* the emitted declaration file contains a bare unresolvable `Bun.Server<any>` reference). Bun's
|
|
8
|
+
* real `Server` structurally satisfies this interface, so `bun/BunRouter.ts` (which has its own
|
|
9
|
+
* `/// <reference types="bun" />`) can pass a real instance unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export interface RequestIPSource {
|
|
12
|
+
requestIP(req: Request): {
|
|
13
|
+
address?: string;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Adapts a Bun/Fetch API `Request` to the framework-agnostic `HttpRequest` interface.
|
|
18
|
+
*
|
|
19
|
+
* Unlike uWS's stack-allocated request, a Fetch API `Request` stays valid across `await`, so there
|
|
20
|
+
* is no urgency to capture everything synchronously in the constructor the way `UWSRequest` must —
|
|
21
|
+
* this is done here purely for parity/simplicity, not correctness.
|
|
22
|
+
*/
|
|
23
|
+
export declare class BunRequest implements HttpRequest {
|
|
24
|
+
readonly method: string;
|
|
25
|
+
readonly url: string;
|
|
26
|
+
readonly path: string;
|
|
27
|
+
readonly headers: Record<string, string>;
|
|
28
|
+
params: Record<string, string>;
|
|
29
|
+
readonly query: Record<string, string | string[]>;
|
|
30
|
+
body: any;
|
|
31
|
+
rawBody?: Buffer;
|
|
32
|
+
readonly cookies: Record<string, string>;
|
|
33
|
+
readonly signedCookies: Record<string, string>;
|
|
34
|
+
readonly socket: {
|
|
35
|
+
remoteAddress?: string;
|
|
36
|
+
};
|
|
37
|
+
user?: any;
|
|
38
|
+
authPayload?: any;
|
|
39
|
+
authToken?: string;
|
|
40
|
+
/** Allow arbitrary per-request properties (websocket, wsHandled, etc.) */
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
constructor(req: Request, server: RequestIPSource);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Adapts a buffered/streamed set of response calls to the framework-agnostic `HttpResponse`
|
|
46
|
+
* interface, bridging them into a Fetch API `Response` that `Bun.serve()`'s `fetch()` handler
|
|
47
|
+
* resolves and returns.
|
|
48
|
+
*
|
|
49
|
+
* Two modes:
|
|
50
|
+
* - Buffered (default): `end()`/`json()`/`send()` finalize the body and resolve `responseReady`
|
|
51
|
+
* with a single complete `Response`.
|
|
52
|
+
* - Streaming: `flushHeaders()`/`write()` construct a `ReadableStream`-backed `Response` and
|
|
53
|
+
* resolve `responseReady` immediately (before the body is fully known) so the client starts
|
|
54
|
+
* receiving bytes right away; further `write()` calls enqueue chunks, `end()` closes the stream.
|
|
55
|
+
*/
|
|
56
|
+
export declare class BunResponse implements HttpResponse {
|
|
57
|
+
private _statusCode;
|
|
58
|
+
private _headers;
|
|
59
|
+
private _headersSent;
|
|
60
|
+
private _writableEnded;
|
|
61
|
+
private _streaming;
|
|
62
|
+
private _aborted;
|
|
63
|
+
private _abortHandlers;
|
|
64
|
+
private _finished;
|
|
65
|
+
private _finishHandlers;
|
|
66
|
+
/** Set to true for HEAD requests — body bytes must not be sent. */
|
|
67
|
+
isHead: boolean;
|
|
68
|
+
/** Intermediate result passed between middleware. */
|
|
69
|
+
result?: any;
|
|
70
|
+
/** Allow arbitrary per-response properties. */
|
|
71
|
+
[key: string]: any;
|
|
72
|
+
private _body;
|
|
73
|
+
private _controller;
|
|
74
|
+
private _stream;
|
|
75
|
+
private _resolveReady;
|
|
76
|
+
/** Resolves once headers are known — either the full buffered Response, or a streaming one. */
|
|
77
|
+
readonly responseReady: Promise<Response>;
|
|
78
|
+
constructor(rawRequest: Request);
|
|
79
|
+
get statusCode(): number;
|
|
80
|
+
get headersSent(): boolean;
|
|
81
|
+
get writableEnded(): boolean;
|
|
82
|
+
status(code: number): this;
|
|
83
|
+
setHeader(key: string, value: string | number | string[]): this;
|
|
84
|
+
appendHeader(key: string, value: string | number): this;
|
|
85
|
+
getHeader(key: string): string | string[] | undefined;
|
|
86
|
+
json(data: any): void;
|
|
87
|
+
send(data?: any): void;
|
|
88
|
+
end(data?: any): void;
|
|
89
|
+
/**
|
|
90
|
+
* Flushes status and headers to the wire immediately without ending the response, via a
|
|
91
|
+
* `ReadableStream`, and resolves `responseReady` right away so the client starts receiving
|
|
92
|
+
* bytes before the rest of the middleware chain finishes. Required before streaming data
|
|
93
|
+
* (e.g. SSE). Safe to call multiple times — only acts on the first call.
|
|
94
|
+
*/
|
|
95
|
+
flushHeaders(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Writes a chunk to the response without ending it (streaming / SSE).
|
|
98
|
+
* Flushes headers on the first call if they haven't been sent yet.
|
|
99
|
+
*/
|
|
100
|
+
write(data: string | Buffer): void;
|
|
101
|
+
/**
|
|
102
|
+
* Registers a callback to run when the client aborts the connection — either before any
|
|
103
|
+
* response was sent (via the request's `AbortSignal`) or mid-stream (via the `ReadableStream`'s
|
|
104
|
+
* `cancel` callback).
|
|
105
|
+
*/
|
|
106
|
+
onAbort(callback: () => void): void;
|
|
107
|
+
/**
|
|
108
|
+
* Registers a callback fired exactly once when the response lifecycle ends — a normal end(),
|
|
109
|
+
* a client abort, or a streaming abort. Fires immediately if the response has already finished.
|
|
110
|
+
* Handlers run fire-and-forget (via a resolved microtask) so slow/async work (e.g. a Redis
|
|
111
|
+
* write) never delays or blocks the actual response flush.
|
|
112
|
+
*/
|
|
113
|
+
onFinish(handler: () => void | Promise<void>): void;
|
|
114
|
+
private _fireFinish;
|
|
115
|
+
/**
|
|
116
|
+
* Errors the underlying stream if it's still open. Used when a middleware chain throws after
|
|
117
|
+
* streaming has already started and the `Response` has already been handed back to the client.
|
|
118
|
+
*/
|
|
119
|
+
abortStream(err: any): void;
|
|
120
|
+
private _enqueue;
|
|
121
|
+
private _buildHeaders;
|
|
122
|
+
private _buildResponse;
|
|
123
|
+
private _buildStreamingResponse;
|
|
124
|
+
}
|
|
125
|
+
export type ReadBunBodyResult = {
|
|
126
|
+
ok: true;
|
|
127
|
+
} | {
|
|
128
|
+
ok: false;
|
|
129
|
+
response: Response;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Reads the full request body from a Bun `Request` into a Buffer, mirroring `readBody()`'s uWS
|
|
133
|
+
* behavior exactly: body parsing (JSON / URL-encoded) is applied based on content-type and the
|
|
134
|
+
* result is cached on `req.body` / `req.rawBody`. Rejects with a 413 JSON `Response` if the body
|
|
135
|
+
* exceeds `maxBodySize` — checked both against the declared `Content-Length` up front (fast path)
|
|
136
|
+
* and against the actual accumulated byte count as chunks arrive, so chunked/unknown-length bodies
|
|
137
|
+
* that lie about or omit `Content-Length` are still caught, matching uWS's guarantee.
|
|
138
|
+
*/
|
|
139
|
+
export declare function readBunBody(req: BunRequest, rawRequest: Request, maxBodySize?: number): Promise<ReadBunBodyResult>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { IHttpRouter, RequestHandler } from "../types.js";
|
|
2
|
+
import { type WsUpgradeAuth } from "../MiddlewareChain.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bun-native HTTP/WebSocket router built on `Bun.serve()`. Exposes the same public surface as the
|
|
5
|
+
* uWS-backed `HttpRouter` (`use/get/post/put/delete/patch/head/options/ws/listen/close/isListening/
|
|
6
|
+
* listenPort`) so `RouteUtils.registerRoute()` and `Server.ts` work against either implementation
|
|
7
|
+
* unchanged.
|
|
8
|
+
*
|
|
9
|
+
* Unlike uWS, `Bun.serve()` has no built-in dynamic router, so this class maintains its own route
|
|
10
|
+
* table matched inside a single `fetch()` callback, with static-segment > `:param` > `/*` wildcard
|
|
11
|
+
* precedence — replicating uWS's specificity-based matching.
|
|
12
|
+
*/
|
|
13
|
+
export declare class BunRouter implements IHttpRouter {
|
|
14
|
+
private readonly routesByMethod;
|
|
15
|
+
private readonly wsRoutes;
|
|
16
|
+
private readonly globalMiddleware;
|
|
17
|
+
private preRouteCount;
|
|
18
|
+
private readonly rootWildcardVerbs;
|
|
19
|
+
private readonly maxBodySize;
|
|
20
|
+
private readonly sslConfig;
|
|
21
|
+
private _bunServer;
|
|
22
|
+
/** The port the server is currently listening on (set after a successful `listen()` call). */
|
|
23
|
+
listenPort: number;
|
|
24
|
+
constructor(maxBodySize?: number, sslConfig?: any);
|
|
25
|
+
/** Returns `true` if the server is currently listening. */
|
|
26
|
+
get isListening(): boolean;
|
|
27
|
+
/** Register global middleware that runs before every route handler. */
|
|
28
|
+
use(...handlers: RequestHandler[]): this;
|
|
29
|
+
/**
|
|
30
|
+
* Freezes the pre-route middleware count the first time a route is registered.
|
|
31
|
+
* All global middleware registered BEFORE this call is "pre-route" middleware;
|
|
32
|
+
* everything added after is "post-route" (error handlers, metrics, etc.).
|
|
33
|
+
*/
|
|
34
|
+
private capturePreRouteCount;
|
|
35
|
+
private pushRoute;
|
|
36
|
+
private register;
|
|
37
|
+
get(routePath: string, ...handlers: RequestHandler[]): this;
|
|
38
|
+
post(routePath: string, ...handlers: RequestHandler[]): this;
|
|
39
|
+
put(routePath: string, ...handlers: RequestHandler[]): this;
|
|
40
|
+
delete(routePath: string, ...handlers: RequestHandler[]): this;
|
|
41
|
+
patch(routePath: string, ...handlers: RequestHandler[]): this;
|
|
42
|
+
head(routePath: string, ...handlers: RequestHandler[]): this;
|
|
43
|
+
options(routePath: string, ...handlers: RequestHandler[]): this;
|
|
44
|
+
/**
|
|
45
|
+
* Registers a WebSocket route. Handlers follow the same `(req, res, next)` pattern as HTTP
|
|
46
|
+
* routes; they receive `req.websocket` containing the Bun WebSocket shim.
|
|
47
|
+
*
|
|
48
|
+
* `upgradeAuth` is an optional pre-upgrade auth function, run synchronously inside `fetch()`
|
|
49
|
+
* before the handshake. If it returns `{ reject: true }`, an HTTP 401 is sent and the upgrade
|
|
50
|
+
* is aborted. If it returns `{ user, ... }`, those credentials are attached to the request so
|
|
51
|
+
* downstream middleware sees an authenticated user. If it returns `{}`, auth falls through to
|
|
52
|
+
* the post-upgrade message-based LOGIN flow.
|
|
53
|
+
*/
|
|
54
|
+
ws(routePath: string, handlers: RequestHandler[], _wsOptions?: any, upgradeAuth?: WsUpgradeAuth): this;
|
|
55
|
+
/**
|
|
56
|
+
* Matches a request against the route table. Exact-length static/param routes always outrank
|
|
57
|
+
* wildcard-suffixed routes, matching uWS's `best ?? wildcard` fallback behavior. Among wildcard
|
|
58
|
+
* candidates, the one with the longest (most specific) matching prefix wins — e.g. `/static/*`
|
|
59
|
+
* beats a bare `/*` for requests under `/static`.
|
|
60
|
+
*
|
|
61
|
+
* `reqHasTrailingSlash` is required to replicate uWS's own wildcard boundary rule, verified
|
|
62
|
+
* empirically against real uWS: a `<prefix>/*` route matches `<prefix>/` and anything nested
|
|
63
|
+
* under it, but NOT the bare `<prefix>` with no trailing slash — a distinction that's lost if
|
|
64
|
+
* matching were done on segment arrays alone, since `/static` and `/static/` produce the same
|
|
65
|
+
* segment list once empty segments are filtered out.
|
|
66
|
+
*/
|
|
67
|
+
private matchRoute;
|
|
68
|
+
private matchWsRoute;
|
|
69
|
+
private readonly fetchHandler;
|
|
70
|
+
private readonly websocketConfig;
|
|
71
|
+
/**
|
|
72
|
+
* Starts listening on the given host and port.
|
|
73
|
+
* Resolves when the server is ready; rejects if the port cannot be bound.
|
|
74
|
+
*/
|
|
75
|
+
listen(host: string, port: number): Promise<void>;
|
|
76
|
+
/** Stops the server, closing the listen socket. */
|
|
77
|
+
close(): void;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import type { IWebSocketShim } from "../IWebSocketShim.js";
|
|
3
|
+
/**
|
|
4
|
+
* Minimal structural slice of Bun's `ServerWebSocket` used by this shim. Deliberately NOT typed as
|
|
5
|
+
* `Bun.ServerWebSocket` — a public constructor parameter typed against the ambient `Bun` namespace
|
|
6
|
+
* would leak into this package's emitted `.d.ts`, breaking `tsc` for downstream consumers who don't
|
|
7
|
+
* have `@types/bun` installed even though they never touch the Bun adapter. Bun's real
|
|
8
|
+
* `ServerWebSocket` structurally satisfies this interface, so `bun/BunRouter.ts` (which has its own
|
|
9
|
+
* `/// <reference types="bun" />`) can pass a real instance unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export interface WebSocketSendTarget {
|
|
12
|
+
send(data: string | Uint8Array): number;
|
|
13
|
+
close(code?: number, reason?: string): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Wraps a Bun `ServerWebSocket` handle and exposes an EventEmitter-based API compatible with
|
|
17
|
+
* `IWebSocketShim`, mirroring `UWSWebSocketShim`'s behavior for the uWS-backed router so that
|
|
18
|
+
* route handlers (e.g. `BaseAdminRoute`) and `AuthMiddleware.authWebSocket()` work unchanged
|
|
19
|
+
* regardless of which runtime is active.
|
|
20
|
+
*/
|
|
21
|
+
export declare class BunWebSocketShim extends EventEmitter implements IWebSocketShim {
|
|
22
|
+
private readonly _ws;
|
|
23
|
+
readyState: number;
|
|
24
|
+
constructor(ws: WebSocketSendTarget);
|
|
25
|
+
/**
|
|
26
|
+
* Sends data over the WebSocket connection.
|
|
27
|
+
* @param data The data to send.
|
|
28
|
+
* @param cb Optional callback invoked on completion or error.
|
|
29
|
+
*/
|
|
30
|
+
send(data: any, cb?: (err?: Error) => void): void;
|
|
31
|
+
/**
|
|
32
|
+
* Closes the WebSocket connection with an optional code and reason.
|
|
33
|
+
*/
|
|
34
|
+
close(code?: number, reason?: string): void;
|
|
35
|
+
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
export type { HttpRequest, HttpResponse, NextFunction, RequestHandler
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export type {
|
|
6
|
-
export {
|
|
1
|
+
export type { ErrorHandler, HttpRequest, HttpResponse, IHttpRouter, NextFunction, RequestHandler } from "./types.js";
|
|
2
|
+
export { isBunRuntime } from "./RuntimeDetect.js";
|
|
3
|
+
export type { IWebSocketShim } from "./IWebSocketShim.js";
|
|
4
|
+
export { extractParamNames, makeWsStubResponse, runChain } from "./MiddlewareChain.js";
|
|
5
|
+
export type { WsUpgradeAuth, WsUpgradeAuthResult } from "./MiddlewareChain.js";
|
|
6
|
+
export type { SessionStore } from "./session/SessionStore.js";
|
|
7
|
+
export { RedisSessionStore } from "./session/RedisSessionStore.js";
|
|
8
|
+
export { SessionManager } from "./session/SessionManager.js";
|
|
9
|
+
export { createSessionMiddleware } from "./session/sessionMiddleware.js";
|
|
10
|
+
export { UWSRequest, UWSResponse, readBody } from "./uWS/Adapters.js";
|
|
11
|
+
export type { HttpRouter } from "./uWS/Router.js";
|
|
12
|
+
export type { RequestWS } from "./uWS/WebSocket.js";
|
|
13
|
+
export { UWSWebSocketShim, createWebSocketStream } from "./uWS/WebSocket.js";
|
|
14
|
+
export { BunRequest, BunResponse, readBunBody } from "./bun/BunAdapters.js";
|
|
15
|
+
export { BunRouter } from "./bun/BunRouter.js";
|
|
16
|
+
export { BunWebSocketShim } from "./bun/BunWebSocket.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RedisClientType } from "redis";
|
|
2
|
+
import type { SessionStore } from "./SessionStore.js";
|
|
3
|
+
/**
|
|
4
|
+
* Redis-backed session store for multi-instance/production deployments, where an in-process
|
|
5
|
+
* `MemorySessionStore` would not be shared across horizontally-scaled instances.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RedisSessionStore implements SessionStore {
|
|
8
|
+
private client;
|
|
9
|
+
/** The default record TTL (in seconds). */
|
|
10
|
+
defaultTTL: number;
|
|
11
|
+
constructor(client: RedisClientType);
|
|
12
|
+
load(sessionId: string): Promise<Record<string, any> | undefined>;
|
|
13
|
+
save(sessionId: string, data: Record<string, any>, ttlSeconds?: number): Promise<void>;
|
|
14
|
+
delete(sessionId: string): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owns session-ID generation/signing and store selection (in-memory by default, Redis-backed when
|
|
3
|
+
* a `cache` datasource connection is available and `session.store` isn't forced to `"memory"`).
|
|
4
|
+
* Registered by `Server.ts` only when a `session` config block is present.
|
|
5
|
+
*
|
|
6
|
+
* @author Jean-Philippe Steinmetz
|
|
7
|
+
*/
|
|
8
|
+
export declare class SessionManager {
|
|
9
|
+
private _objectFactory?;
|
|
10
|
+
private options;
|
|
11
|
+
private globalCookieSecret?;
|
|
12
|
+
/** The redis client used as a session store when configured. Special-cased to not throw if absent. */
|
|
13
|
+
private cacheClient?;
|
|
14
|
+
private logger?;
|
|
15
|
+
private store;
|
|
16
|
+
private secret;
|
|
17
|
+
cookieName: string;
|
|
18
|
+
ttlSeconds: number;
|
|
19
|
+
cookieSecure: boolean;
|
|
20
|
+
cookieSameSite: string;
|
|
21
|
+
cookiePath: string;
|
|
22
|
+
private init;
|
|
23
|
+
/** Generates a new, cryptographically random session ID. */
|
|
24
|
+
generateId(): string;
|
|
25
|
+
/** Signs a session ID for safe storage in a cookie value. */
|
|
26
|
+
signId(id: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Verifies a signed session ID cookie value, returning the original session ID if the
|
|
29
|
+
* signature is valid, or `undefined` if it's missing, malformed, or tampered with.
|
|
30
|
+
*/
|
|
31
|
+
verifyId(signed: string): string | undefined;
|
|
32
|
+
load(sessionId: string): Promise<Record<string, any> | undefined>;
|
|
33
|
+
save(sessionId: string, data: Record<string, any>): Promise<void>;
|
|
34
|
+
delete(sessionId: string): Promise<void>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pluggable backing store for session data, keyed by session ID. Implementations must be safe
|
|
3
|
+
* to call from concurrent requests.
|
|
4
|
+
*/
|
|
5
|
+
export interface SessionStore {
|
|
6
|
+
/** Loads the session data for the given session ID, or `undefined` if none exists (or has expired). */
|
|
7
|
+
load(sessionId: string): Promise<Record<string, any> | undefined>;
|
|
8
|
+
/** Persists the given session data, resetting its expiration to `ttlSeconds` from now. */
|
|
9
|
+
save(sessionId: string, data: Record<string, any>, ttlSeconds?: number): Promise<void>;
|
|
10
|
+
/** Removes the session data for the given session ID, if any. */
|
|
11
|
+
delete(sessionId: string): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RequestHandler } from "../types.js";
|
|
2
|
+
import type { SessionManager } from "./SessionManager.js";
|
|
3
|
+
/**
|
|
4
|
+
* Builds a global, framework-agnostic session middleware backed by the given `SessionManager`.
|
|
5
|
+
* Lazily loads-or-creates `req.session` and persists any mutations back to the store once the
|
|
6
|
+
* response finishes. Cheap for requests that never touch sessions: no store round-trip unless a
|
|
7
|
+
* valid session cookie was actually sent, and no `Set-Cookie`/store write for sessions that end up
|
|
8
|
+
* empty.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createSessionMiddleware(mgr: SessionManager): RequestHandler;
|