@rapidrest/service-core 1.0.0-beta.1

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.
Files changed (332) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +16 -0
  3. package/dist/lib/ApiErrors.js +41 -0
  4. package/dist/lib/ApiErrors.js.map +1 -0
  5. package/dist/lib/BackgroundService.js +16 -0
  6. package/dist/lib/BackgroundService.js.map +1 -0
  7. package/dist/lib/BackgroundServiceManager.js +135 -0
  8. package/dist/lib/BackgroundServiceManager.js.map +1 -0
  9. package/dist/lib/BulkError.js +24 -0
  10. package/dist/lib/BulkError.js.map +1 -0
  11. package/dist/lib/EventListenerManager.js +161 -0
  12. package/dist/lib/EventListenerManager.js.map +1 -0
  13. package/dist/lib/NetUtils.js +103 -0
  14. package/dist/lib/NetUtils.js.map +1 -0
  15. package/dist/lib/NotificationUtils.js +34 -0
  16. package/dist/lib/NotificationUtils.js.map +1 -0
  17. package/dist/lib/ObjectFactory.js +90 -0
  18. package/dist/lib/ObjectFactory.js.map +1 -0
  19. package/dist/lib/OpenApiSpec.js +748 -0
  20. package/dist/lib/OpenApiSpec.js.map +1 -0
  21. package/dist/lib/Server.js +549 -0
  22. package/dist/lib/Server.js.map +1 -0
  23. package/dist/lib/Types.js +2 -0
  24. package/dist/lib/Types.js.map +1 -0
  25. package/dist/lib/auth/AuthMiddleware.js +229 -0
  26. package/dist/lib/auth/AuthMiddleware.js.map +1 -0
  27. package/dist/lib/auth/AuthStrategy.js +2 -0
  28. package/dist/lib/auth/AuthStrategy.js.map +1 -0
  29. package/dist/lib/auth/BasicStrategy.js +106 -0
  30. package/dist/lib/auth/BasicStrategy.js.map +1 -0
  31. package/dist/lib/auth/JWTStrategy.js +161 -0
  32. package/dist/lib/auth/JWTStrategy.js.map +1 -0
  33. package/dist/lib/auth/index.js +5 -0
  34. package/dist/lib/auth/index.js.map +1 -0
  35. package/dist/lib/database/ConnectionKinds.js +14 -0
  36. package/dist/lib/database/ConnectionKinds.js.map +1 -0
  37. package/dist/lib/database/ConnectionManager.js +161 -0
  38. package/dist/lib/database/ConnectionManager.js.map +1 -0
  39. package/dist/lib/database/MongoConnection.js +86 -0
  40. package/dist/lib/database/MongoConnection.js.map +1 -0
  41. package/dist/lib/database/MongoRepository.js +136 -0
  42. package/dist/lib/database/MongoRepository.js.map +1 -0
  43. package/dist/lib/database/MongoSchemaSync.js +136 -0
  44. package/dist/lib/database/MongoSchemaSync.js.map +1 -0
  45. package/dist/lib/database/NamingUtils.js +52 -0
  46. package/dist/lib/database/NamingUtils.js.map +1 -0
  47. package/dist/lib/database/TypeOrmSupport.js +146 -0
  48. package/dist/lib/database/TypeOrmSupport.js.map +1 -0
  49. package/dist/lib/database/index.js +7 -0
  50. package/dist/lib/database/index.js.map +1 -0
  51. package/dist/lib/decorators/DatabaseDecorators.js +52 -0
  52. package/dist/lib/decorators/DatabaseDecorators.js.map +1 -0
  53. package/dist/lib/decorators/DocDecorators.js +120 -0
  54. package/dist/lib/decorators/DocDecorators.js.map +1 -0
  55. package/dist/lib/decorators/EventDecorators.js +24 -0
  56. package/dist/lib/decorators/EventDecorators.js.map +1 -0
  57. package/dist/lib/decorators/ModelDecorators.js +173 -0
  58. package/dist/lib/decorators/ModelDecorators.js.map +1 -0
  59. package/dist/lib/decorators/PersistenceDecorators.js +177 -0
  60. package/dist/lib/decorators/PersistenceDecorators.js.map +1 -0
  61. package/dist/lib/decorators/RouteDecorators.js +324 -0
  62. package/dist/lib/decorators/RouteDecorators.js.map +1 -0
  63. package/dist/lib/decorators/index.js +7 -0
  64. package/dist/lib/decorators/index.js.map +1 -0
  65. package/dist/lib/http/Adapters.js +230 -0
  66. package/dist/lib/http/Adapters.js.map +1 -0
  67. package/dist/lib/http/Router.js +403 -0
  68. package/dist/lib/http/Router.js.map +1 -0
  69. package/dist/lib/http/WebSocket.js +82 -0
  70. package/dist/lib/http/WebSocket.js.map +1 -0
  71. package/dist/lib/http/index.js +4 -0
  72. package/dist/lib/http/index.js.map +1 -0
  73. package/dist/lib/http/types.js +5 -0
  74. package/dist/lib/http/types.js.map +1 -0
  75. package/dist/lib/index.js +18 -0
  76. package/dist/lib/index.js.map +1 -0
  77. package/dist/lib/models/BaseEntity.js +83 -0
  78. package/dist/lib/models/BaseEntity.js.map +1 -0
  79. package/dist/lib/models/BaseMongoEntity.js +40 -0
  80. package/dist/lib/models/BaseMongoEntity.js.map +1 -0
  81. package/dist/lib/models/ModelUtils.js +645 -0
  82. package/dist/lib/models/ModelUtils.js.map +1 -0
  83. package/dist/lib/models/RecoverableBaseEntity.js +39 -0
  84. package/dist/lib/models/RecoverableBaseEntity.js.map +1 -0
  85. package/dist/lib/models/RecoverableBaseMongoEntity.js +40 -0
  86. package/dist/lib/models/RecoverableBaseMongoEntity.js.map +1 -0
  87. package/dist/lib/models/RepoUtils.js +717 -0
  88. package/dist/lib/models/RepoUtils.js.map +1 -0
  89. package/dist/lib/models/SimpleEntity.js +42 -0
  90. package/dist/lib/models/SimpleEntity.js.map +1 -0
  91. package/dist/lib/models/SimpleMongoEntity.js +38 -0
  92. package/dist/lib/models/SimpleMongoEntity.js.map +1 -0
  93. package/dist/lib/models/StatusExtraData.js +15 -0
  94. package/dist/lib/models/StatusExtraData.js.map +1 -0
  95. package/dist/lib/models/index.js +10 -0
  96. package/dist/lib/models/index.js.map +1 -0
  97. package/dist/lib/routes/AdminRoute.js +268 -0
  98. package/dist/lib/routes/AdminRoute.js.map +1 -0
  99. package/dist/lib/routes/MetricsRoute.js +86 -0
  100. package/dist/lib/routes/MetricsRoute.js.map +1 -0
  101. package/dist/lib/routes/ModelRoute.js +481 -0
  102. package/dist/lib/routes/ModelRoute.js.map +1 -0
  103. package/dist/lib/routes/OpenAPIRoute.js +115 -0
  104. package/dist/lib/routes/OpenAPIRoute.js.map +1 -0
  105. package/dist/lib/routes/RouteUtils.js +445 -0
  106. package/dist/lib/routes/RouteUtils.js.map +1 -0
  107. package/dist/lib/routes/StatusRoute.js +55 -0
  108. package/dist/lib/routes/StatusRoute.js.map +1 -0
  109. package/dist/lib/routes/index.js +7 -0
  110. package/dist/lib/routes/index.js.map +1 -0
  111. package/dist/lib/security/ACLRouteMongo.js +194 -0
  112. package/dist/lib/security/ACLRouteMongo.js.map +1 -0
  113. package/dist/lib/security/ACLRouteSQL.js +193 -0
  114. package/dist/lib/security/ACLRouteSQL.js.map +1 -0
  115. package/dist/lib/security/ACLUtils.js +457 -0
  116. package/dist/lib/security/ACLUtils.js.map +1 -0
  117. package/dist/lib/security/AccessControlList.js +18 -0
  118. package/dist/lib/security/AccessControlList.js.map +1 -0
  119. package/dist/lib/security/AccessControlListMongo.js +155 -0
  120. package/dist/lib/security/AccessControlListMongo.js.map +1 -0
  121. package/dist/lib/security/AccessControlListSQL.js +149 -0
  122. package/dist/lib/security/AccessControlListSQL.js.map +1 -0
  123. package/dist/lib/security/index.js +3 -0
  124. package/dist/lib/security/index.js.map +1 -0
  125. package/dist/lib/test/index.js +3 -0
  126. package/dist/lib/test/index.js.map +1 -0
  127. package/dist/lib/test/request.js +99 -0
  128. package/dist/lib/test/request.js.map +1 -0
  129. package/dist/lib/test/requestws.js +173 -0
  130. package/dist/lib/test/requestws.js.map +1 -0
  131. package/dist/types/ApiErrors.d.ts +38 -0
  132. package/dist/types/BackgroundService.d.ts +30 -0
  133. package/dist/types/BackgroundServiceManager.d.ts +66 -0
  134. package/dist/types/BulkError.d.ts +11 -0
  135. package/dist/types/EventListenerManager.d.ts +36 -0
  136. package/dist/types/NetUtils.d.ts +29 -0
  137. package/dist/types/NotificationUtils.d.ts +25 -0
  138. package/dist/types/ObjectFactory.d.ts +17 -0
  139. package/dist/types/OpenApiSpec.d.ts +114 -0
  140. package/dist/types/Server.d.ts +180 -0
  141. package/dist/types/Types.d.ts +8 -0
  142. package/dist/types/auth/AuthMiddleware.d.ts +42 -0
  143. package/dist/types/auth/AuthStrategy.d.ts +32 -0
  144. package/dist/types/auth/BasicStrategy.d.ts +33 -0
  145. package/dist/types/auth/JWTStrategy.d.ts +61 -0
  146. package/dist/types/auth/index.d.ts +4 -0
  147. package/dist/types/database/ConnectionKinds.d.ts +7 -0
  148. package/dist/types/database/ConnectionManager.d.ts +35 -0
  149. package/dist/types/database/MongoConnection.d.ts +54 -0
  150. package/dist/types/database/MongoRepository.d.ts +92 -0
  151. package/dist/types/database/MongoSchemaSync.d.ts +41 -0
  152. package/dist/types/database/NamingUtils.d.ts +24 -0
  153. package/dist/types/database/TypeOrmSupport.d.ts +20 -0
  154. package/dist/types/database/index.d.ts +6 -0
  155. package/dist/types/decorators/DatabaseDecorators.d.ts +18 -0
  156. package/dist/types/decorators/DocDecorators.d.ts +69 -0
  157. package/dist/types/decorators/EventDecorators.d.ts +12 -0
  158. package/dist/types/decorators/ModelDecorators.d.ts +80 -0
  159. package/dist/types/decorators/PersistenceDecorators.d.ts +117 -0
  160. package/dist/types/decorators/RouteDecorators.d.ts +172 -0
  161. package/dist/types/decorators/index.d.ts +6 -0
  162. package/dist/types/http/Adapters.d.ts +68 -0
  163. package/dist/types/http/Router.d.ts +99 -0
  164. package/dist/types/http/WebSocket.d.ts +56 -0
  165. package/dist/types/http/index.d.ts +6 -0
  166. package/dist/types/http/types.d.ts +54 -0
  167. package/dist/types/index.d.ts +17 -0
  168. package/dist/types/models/BaseEntity.d.ts +29 -0
  169. package/dist/types/models/BaseMongoEntity.d.ts +13 -0
  170. package/dist/types/models/ModelUtils.d.ts +166 -0
  171. package/dist/types/models/RecoverableBaseEntity.d.ts +16 -0
  172. package/dist/types/models/RecoverableBaseMongoEntity.d.ts +16 -0
  173. package/dist/types/models/RepoUtils.d.ts +154 -0
  174. package/dist/types/models/SimpleEntity.d.ts +14 -0
  175. package/dist/types/models/SimpleMongoEntity.d.ts +15 -0
  176. package/dist/types/models/StatusExtraData.d.ts +6 -0
  177. package/dist/types/models/index.d.ts +9 -0
  178. package/dist/types/routes/AdminRoute.d.ts +47 -0
  179. package/dist/types/routes/MetricsRoute.d.ts +15 -0
  180. package/dist/types/routes/ModelRoute.d.ts +226 -0
  181. package/dist/types/routes/OpenAPIRoute.d.ts +17 -0
  182. package/dist/types/routes/RouteUtils.d.ts +55 -0
  183. package/dist/types/routes/StatusRoute.d.ts +11 -0
  184. package/dist/types/routes/index.d.ts +6 -0
  185. package/dist/types/security/ACLRouteMongo.d.ts +19 -0
  186. package/dist/types/security/ACLRouteSQL.d.ts +19 -0
  187. package/dist/types/security/ACLUtils.d.ts +94 -0
  188. package/dist/types/security/AccessControlList.d.ts +103 -0
  189. package/dist/types/security/AccessControlListMongo.d.ts +24 -0
  190. package/dist/types/security/AccessControlListSQL.d.ts +24 -0
  191. package/dist/types/security/index.d.ts +2 -0
  192. package/dist/types/test/index.d.ts +2 -0
  193. package/dist/types/test/request.d.ts +24 -0
  194. package/dist/types/test/requestws.d.ts +21 -0
  195. package/docs/Makefile +20 -0
  196. package/docs/conf.py +58 -0
  197. package/docs/index.rst +17 -0
  198. package/docs/make.bat +35 -0
  199. package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/README.md +13 -0
  200. package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/MongoRepository.md +25 -0
  201. package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/RedisConnection.md +25 -0
  202. package/docs/reference/@rapidrest/namespaces/DatabaseDecorators/functions/Repository.md +25 -0
  203. package/docs/reference/@rapidrest/namespaces/DocDecorators/README.md +23 -0
  204. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Default.md +25 -0
  205. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Description.md +25 -0
  206. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Document.md +25 -0
  207. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Example.md +25 -0
  208. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Format.md +25 -0
  209. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Returns.md +28 -0
  210. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Summary.md +25 -0
  211. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/Tags.md +25 -0
  212. package/docs/reference/@rapidrest/namespaces/DocDecorators/functions/TypeInfo.md +28 -0
  213. package/docs/reference/@rapidrest/namespaces/DocDecorators/interfaces/DocumentsData.md +57 -0
  214. package/docs/reference/@rapidrest/namespaces/EventDecorators/README.md +12 -0
  215. package/docs/reference/@rapidrest/namespaces/EventDecorators/functions/EventListener.md +17 -0
  216. package/docs/reference/@rapidrest/namespaces/EventDecorators/functions/OnEvent.md +26 -0
  217. package/docs/reference/@rapidrest/namespaces/ModelDecorators/README.md +26 -0
  218. package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Cache.md +25 -0
  219. package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/ChildEntity.md +18 -0
  220. package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/DataStore.md +25 -0
  221. package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Identifier.md +27 -0
  222. package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Protect.md +35 -0
  223. package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Reference.md +25 -0
  224. package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/Shard.md +27 -0
  225. package/docs/reference/@rapidrest/namespaces/ModelDecorators/functions/TrackChanges.md +26 -0
  226. package/docs/reference/@rapidrest/namespaces/ModelDecorators/interfaces/PendingTypeOrmColumn.md +45 -0
  227. package/docs/reference/@rapidrest/namespaces/ModelDecorators/variables/pendingTypeOrmColumns.md +14 -0
  228. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/README.md +25 -0
  229. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Column.md +25 -0
  230. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Entity.md +26 -0
  231. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Index.md +119 -0
  232. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/PrimaryColumn.md +25 -0
  233. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/Unique.md +68 -0
  234. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getColumnMetadata.md +26 -0
  235. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getEntityName.md +26 -0
  236. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/functions/getIndexMetadata.md +27 -0
  237. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/ColumnInfo.md +41 -0
  238. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/ColumnOptions.md +51 -0
  239. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/IndexInfo.md +41 -0
  240. package/docs/reference/@rapidrest/namespaces/PersistenceDecorators/interfaces/IndexOptions.md +51 -0
  241. package/docs/reference/@rapidrest/namespaces/RouteDecorators/README.md +36 -0
  242. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/After.md +26 -0
  243. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Auth.md +33 -0
  244. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/AuthResult.md +31 -0
  245. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Before.md +25 -0
  246. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/ContentType.md +25 -0
  247. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Delete.md +25 -0
  248. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Get.md +25 -0
  249. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Head.md +25 -0
  250. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Header.md +25 -0
  251. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Method.md +31 -0
  252. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Model.md +25 -0
  253. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Options.md +25 -0
  254. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Param.md +26 -0
  255. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Patch.md +25 -0
  256. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Post.md +25 -0
  257. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Protect.md +31 -0
  258. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Put.md +25 -0
  259. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Query.md +26 -0
  260. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Request.md +31 -0
  261. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/RequiresRole.md +26 -0
  262. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Response.md +31 -0
  263. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Route.md +25 -0
  264. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Socket.md +33 -0
  265. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/User.md +31 -0
  266. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/Validate.md +25 -0
  267. package/docs/reference/@rapidrest/namespaces/RouteDecorators/functions/WebSocket.md +25 -0
  268. package/docs/reference/README.md +20 -0
  269. package/docs/reference/classes/ACLUtils.md +251 -0
  270. package/docs/reference/classes/AdminRoute.md +51 -0
  271. package/docs/reference/classes/AuthMiddleware.md +131 -0
  272. package/docs/reference/classes/BackgroundService.md +117 -0
  273. package/docs/reference/classes/BackgroundServiceManager.md +172 -0
  274. package/docs/reference/classes/BaseEntity.md +82 -0
  275. package/docs/reference/classes/BaseMongoEntity.md +107 -0
  276. package/docs/reference/classes/BasicStrategy.md +89 -0
  277. package/docs/reference/classes/BasicStrategyOptions.md +91 -0
  278. package/docs/reference/classes/BulkError.md +271 -0
  279. package/docs/reference/classes/ConnectionManager.md +75 -0
  280. package/docs/reference/classes/EventListenerManager.md +88 -0
  281. package/docs/reference/classes/JWTStrategy.md +77 -0
  282. package/docs/reference/classes/JWTStrategyOptions.md +97 -0
  283. package/docs/reference/classes/MetricsRoute.md +27 -0
  284. package/docs/reference/classes/ModelRoute.md +527 -0
  285. package/docs/reference/classes/ModelUtils.md +448 -0
  286. package/docs/reference/classes/MongoConnection.md +218 -0
  287. package/docs/reference/classes/MongoRepository.md +354 -0
  288. package/docs/reference/classes/MongoSchemaSync.md +67 -0
  289. package/docs/reference/classes/NetUtils.md +90 -0
  290. package/docs/reference/classes/NotificationUtils.md +77 -0
  291. package/docs/reference/classes/ObjectFactory.md +336 -0
  292. package/docs/reference/classes/OpenAPIRoute.md +77 -0
  293. package/docs/reference/classes/OpenApiSpec.md +892 -0
  294. package/docs/reference/classes/RecoverableBaseEntity.md +114 -0
  295. package/docs/reference/classes/RecoverableBaseMongoEntity.md +124 -0
  296. package/docs/reference/classes/RedisTransport.md +2202 -0
  297. package/docs/reference/classes/RepoUtils.md +486 -0
  298. package/docs/reference/classes/RouteUtils.md +191 -0
  299. package/docs/reference/classes/Server.md +408 -0
  300. package/docs/reference/classes/SimpleEntity.md +48 -0
  301. package/docs/reference/classes/SimpleMongoEntity.md +66 -0
  302. package/docs/reference/classes/StatusExtraData.md +57 -0
  303. package/docs/reference/classes/StatusRoute.md +26 -0
  304. package/docs/reference/enumerations/ACLAction.md +63 -0
  305. package/docs/reference/enumerations/ApiErrorMessages.md +123 -0
  306. package/docs/reference/enumerations/ApiErrors.md +123 -0
  307. package/docs/reference/functions/isSqlDataSource.md +26 -0
  308. package/docs/reference/functions/resolveCollectionName.md +33 -0
  309. package/docs/reference/functions/snakeCase.md +28 -0
  310. package/docs/reference/globals.md +91 -0
  311. package/docs/reference/interfaces/ACLRecord.md +96 -0
  312. package/docs/reference/interfaces/AccessControlList.md +76 -0
  313. package/docs/reference/interfaces/AuthResult.md +55 -0
  314. package/docs/reference/interfaces/AuthStrategy.md +57 -0
  315. package/docs/reference/interfaces/CreateRequestOptions.md +121 -0
  316. package/docs/reference/interfaces/DeleteRequestOptions.md +147 -0
  317. package/docs/reference/interfaces/FindRequestOptions.md +133 -0
  318. package/docs/reference/interfaces/JWTAuthResult.md +84 -0
  319. package/docs/reference/interfaces/RepoCreateOptions.md +95 -0
  320. package/docs/reference/interfaces/RepoDeleteOptions.md +115 -0
  321. package/docs/reference/interfaces/RepoFindOptions.md +135 -0
  322. package/docs/reference/interfaces/RepoOperationOptions.md +69 -0
  323. package/docs/reference/interfaces/RepoUpdateOptions.md +111 -0
  324. package/docs/reference/interfaces/RequestOptions.md +112 -0
  325. package/docs/reference/interfaces/TruncateRequestOptions.md +175 -0
  326. package/docs/reference/interfaces/UpdateRequestOptions.md +149 -0
  327. package/docs/reference/type-aliases/OneOrMany.md +19 -0
  328. package/docs/reference/type-aliases/OneOrNull.md +19 -0
  329. package/docs/reference/type-aliases/PartialBaseEntity.md +17 -0
  330. package/docs/reference/type-aliases/PartialSimpleEntity.md +17 -0
  331. package/docs/reference/type-aliases/UpdateObject.md +19 -0
  332. package/package.json +125 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2020-2026 Jean-Philippe Steinmetz <caskater47@gmail.com>
4
+ Copyright (C) 2020-2026 Arthur Thompson
5
+ Copyright (C) 2024 Thomas Buscaglia
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # RapidREST: service-core
2
+
3
+ [![pipeline status](https://gitlab.rapidrest.com/rapidrest/rapidrestjs/service-core/badges/master/pipeline.svg)](https://gitlab.rapidrest.com/rapidrest/rapidrestjs/service-core/-/commits/master)
4
+ [![coverage report](https://gitlab.rapidrest.com/rapidrest/rapidrestjs/service-core/badges/master/coverage.svg)](https://gitlab.rapidrest.com/rapidrest/rapidrestjs/service-core/-/commits/master)
5
+
6
+ Provides common functionality and utilities for RapidREST based REST API service projects.
7
+
8
+ ## NPM
9
+ ```
10
+ npm i @rapidrest/service-core
11
+ ```
12
+
13
+ ## Yarn
14
+ ```
15
+ yarn add @rapidrest/service-core
16
+ ```
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Defines the unique codes for all common API errors.
3
+ */
4
+ export var ApiErrors;
5
+ (function (ApiErrors) {
6
+ ApiErrors["UNKNOWN"] = "api-001";
7
+ ApiErrors["INTERNAL_ERROR"] = "api-002";
8
+ ApiErrors["INVALID_REQUEST"] = "api-003";
9
+ ApiErrors["NOT_FOUND"] = "api-010";
10
+ ApiErrors["IDENTIFIER_EXISTS"] = "api-011";
11
+ ApiErrors["INVALID_OBJECT_VERSION"] = "api-012";
12
+ ApiErrors["OBJECT_ID_MISMATCH"] = "api-013";
13
+ ApiErrors["SEARCH_INVALID_RANGE"] = "api-014";
14
+ ApiErrors["SEARCH_INVALID_ME_REFERENCE"] = "api-015";
15
+ ApiErrors["BULK_CREATE_FAILURE"] = "api-021";
16
+ ApiErrors["BULK_UPDATE_FAILURE"] = "api-022";
17
+ ApiErrors["AUTH_REQUIRED"] = "api-100";
18
+ ApiErrors["AUTH_FAILED"] = "api-101";
19
+ ApiErrors["AUTH_PERMISSION_FAILURE"] = "api-102";
20
+ })(ApiErrors || (ApiErrors = {}));
21
+ /**
22
+ * Defines the default message of all common API errors.
23
+ */
24
+ export var ApiErrorMessages;
25
+ (function (ApiErrorMessages) {
26
+ ApiErrorMessages["UNKNOWN"] = "An unknown error has occurred. Please try again.";
27
+ ApiErrorMessages["INTERNAL_ERROR"] = "An internal error has occurred. Please contact the adminstrator.";
28
+ ApiErrorMessages["INVALID_REQUEST"] = "Invalid message or request.";
29
+ ApiErrorMessages["NOT_FOUND"] = "No resource could be found with the specified identifier.";
30
+ ApiErrorMessages["IDENTIFIER_EXISTS"] = "A resource with that identifier already exists.";
31
+ ApiErrorMessages["INVALID_OBJECT_VERSION"] = "Invalid object version. Do you have the latest version?";
32
+ ApiErrorMessages["OBJECT_ID_MISMATCH"] = "The object provided does not match the identifier given.";
33
+ ApiErrorMessages["SEARCH_INVALID_RANGE"] = "Invalid range value: '{{value}}'. Expected 2 arguments, got {{length}}";
34
+ ApiErrorMessages["SEARCH_INVALID_ME_REFERENCE"] = "Use of the `me` reference requires authentication.";
35
+ ApiErrorMessages["BULK_CREATE_FAILURE"] = "Failed to create one or more objects.";
36
+ ApiErrorMessages["BULK_UPDATE_FAILURE"] = "Failed to update one or more objects.";
37
+ ApiErrorMessages["AUTH_REQUIRED"] = "Authorization is required to access this resource.";
38
+ ApiErrorMessages["AUTH_FAILED"] = "Invalid or missing authentication token.";
39
+ ApiErrorMessages["AUTH_PERMISSION_FAILURE"] = "User does not have permission to perform this action.";
40
+ })(ApiErrorMessages || (ApiErrorMessages = {}));
41
+ //# sourceMappingURL=ApiErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiErrors.js","sourceRoot":"","sources":["../../src/ApiErrors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,SAeX;AAfD,WAAY,SAAS;IACjB,gCAAmB,CAAA;IACnB,uCAA0B,CAAA;IAC1B,wCAA2B,CAAA;IAC3B,kCAAqB,CAAA;IACrB,0CAA6B,CAAA;IAC7B,+CAAkC,CAAA;IAClC,2CAA8B,CAAA;IAC9B,6CAAgC,CAAA;IAChC,oDAAuC,CAAA;IACvC,4CAA+B,CAAA;IAC/B,4CAA+B,CAAA;IAC/B,sCAAyB,CAAA;IACzB,oCAAuB,CAAA;IACvB,gDAAmC,CAAA;AACvC,CAAC,EAfW,SAAS,KAAT,SAAS,QAepB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,gBAeX;AAfD,WAAY,gBAAgB;IACxB,gFAA4D,CAAA;IAC5D,uGAAmF,CAAA;IACnF,mEAA+C,CAAA;IAC/C,2FAAuE,CAAA;IACvE,yFAAqE,CAAA;IACrE,sGAAkF,CAAA;IAClF,mGAA+E,CAAA;IAC/E,mHAA+F,CAAA;IAC/F,sGAAkF,CAAA;IAClF,iFAA6D,CAAA;IAC7D,iFAA6D,CAAA;IAC7D,wFAAoE,CAAA;IACpE,4EAAwD,CAAA;IACxD,qGAAiF,CAAA;AACrF,CAAC,EAfW,gBAAgB,KAAhB,gBAAgB,QAe3B"}
@@ -0,0 +1,16 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2020-2026 Jean-Philippe Steinmetz
3
+ ///////////////////////////////////////////////////////////////////////////////
4
+ /**
5
+ * The `BackgroundService` is an abstract base class for defining scheduled background services. A background service
6
+ * executes in the background once on startup or on a set schedule (like a cron job) and performs additional processing.
7
+ *
8
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
9
+ */
10
+ export class BackgroundService {
11
+ constructor(config, logger) {
12
+ this.config = config;
13
+ this.logger = logger;
14
+ }
15
+ }
16
+ //# sourceMappingURL=BackgroundService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackgroundService.js","sourceRoot":"","sources":["../../src/BackgroundService.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,kDAAkD;AAClD,+EAA+E;AAC/E;;;;;GAKG;AACH,MAAM,OAAgB,iBAAiB;IAMnC,YAAY,MAAW,EAAE,MAAW;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CAsBJ"}
@@ -0,0 +1,135 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2020-2026 Jean-Philippe Steinmetz
3
+ ///////////////////////////////////////////////////////////////////////////////
4
+ import { BackgroundService } from "./BackgroundService.js";
5
+ import * as schedule from "node-schedule";
6
+ /**
7
+ * The `BackgroundServiceManager` manages all configured background services in the application. It is responsible for
8
+ * initializing the jobs, scheduling them and performing any related shutdown tasks. See the `BackgroundService`
9
+ * class for details on how to create a background service class to be used by this manager.
10
+ *
11
+ * ## Usage
12
+ * To use the manager instantiate a new object and provide the required constructor arguments. Then simply call the
13
+ * `startAll` function. When shutting your application down you should call the `stopAll` function.
14
+ *
15
+ * ```
16
+ * import { BackgroundServiceManager } from "@rapidrest/service-core";
17
+ *
18
+ * const manager: BackgroundServiceManager = new BackgroundServiceManager(objectFactory, serviceClasses, config, logger);
19
+ * await manager.startAll();
20
+ * ...
21
+ * await manager.stopAll();
22
+ * ```
23
+ *
24
+ * You may optionally start and stop individual services using the `start` and `stop` functions respectively.
25
+ *
26
+ * ```
27
+ * await manager.start("MyService");
28
+ * ...
29
+ * await manger.stop("MyService");
30
+ * ```
31
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
32
+ */
33
+ export class BackgroundServiceManager {
34
+ constructor(objectFactory, classes, config, logger) {
35
+ this.jobs = {};
36
+ this.services = {};
37
+ this.classes = classes;
38
+ this.config = config;
39
+ this.logger = logger;
40
+ this.objectFactory = objectFactory;
41
+ }
42
+ /**
43
+ * Returns the service instance with the given name.
44
+ *
45
+ * @param name The name of the background service to retrieve.
46
+ */
47
+ getService(name) {
48
+ return this.services[name];
49
+ }
50
+ /**
51
+ * Starts all configured background services.
52
+ */
53
+ async startAll() {
54
+ // Go through all loaded background job classes and start each one
55
+ if (this.classes) {
56
+ for (const name in this.classes) {
57
+ const clazz = this.classes[name];
58
+ if (clazz.prototype instanceof BackgroundService) {
59
+ await this.start(name, clazz);
60
+ }
61
+ }
62
+ }
63
+ }
64
+ /**
65
+ * Starts the background service with the given name.
66
+ *
67
+ * @param serviceName The name of the background service to start.
68
+ * @param clazz The class type of the service to start. If not specified the name is used to lookup the class type.
69
+ * @param args The list of arguments to pass into the service constructor
70
+ */
71
+ async start(serviceName, clazz, ...args) {
72
+ // Check that the job hasn't already been started
73
+ if (this.jobs[serviceName]) {
74
+ return;
75
+ }
76
+ // Look for the class definition with the given name if not already given
77
+ clazz = clazz ? clazz : this.classes[serviceName];
78
+ if (clazz) {
79
+ try {
80
+ this.logger.info("Starting service " + serviceName + "...");
81
+ // Instantiate the service class
82
+ const service = await this.objectFactory.newInstance(clazz, {
83
+ name: serviceName,
84
+ initialize: true,
85
+ args: [this.config, this.logger, ...args],
86
+ });
87
+ this.services[serviceName] = service;
88
+ // Initialize the service
89
+ await service.start();
90
+ // Schedule the service for background execution
91
+ if (service.schedule) {
92
+ this.jobs[serviceName] = schedule.scheduleJob(service.schedule, service.run.bind(service));
93
+ }
94
+ else {
95
+ // One time execution services are run once and then immediately cleaned up
96
+ await service.run();
97
+ await service.stop();
98
+ await this.objectFactory.destroy(service);
99
+ }
100
+ }
101
+ catch (err) {
102
+ this.logger.error(`Failed to start service: ${serviceName}`);
103
+ this.logger.debug(err);
104
+ }
105
+ }
106
+ }
107
+ /**
108
+ * Stops all currently active background services that are owned by the manager.
109
+ */
110
+ async stopAll() {
111
+ for (const jobName in this.jobs) {
112
+ await this.stop(jobName);
113
+ }
114
+ // Clear the local state
115
+ this.jobs = {};
116
+ this.services = {};
117
+ }
118
+ /**
119
+ * Stops the background service with the given name.
120
+ *
121
+ * @param serviceName The name of the background service to stop.
122
+ */
123
+ async stop(serviceName) {
124
+ this.logger.info("Stopping background service " + serviceName + "...");
125
+ // Cancel the background execution schedule
126
+ if (this.jobs[serviceName]) {
127
+ this.jobs[serviceName].cancel(false);
128
+ }
129
+ // Shut it down
130
+ if (this.services[serviceName]) {
131
+ await this.services[serviceName].stop();
132
+ }
133
+ }
134
+ }
135
+ //# sourceMappingURL=BackgroundServiceManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackgroundServiceManager.js","sourceRoot":"","sources":["../../src/BackgroundServiceManager.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,kDAAkD;AAClD,+EAA+E;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,wBAAwB;IAQjC,YAAY,aAA4B,EAAE,OAAW,EAAE,MAAW,EAAE,MAAW;QALvE,SAAI,GAAQ,EAAE,CAAC;QAGf,aAAQ,GAAQ,EAAE,CAAC;QAGvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACI,UAAU,CAAC,IAAY;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACjB,kEAAkE;QAClE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC9B,MAAM,KAAK,GAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACtC,IAAI,KAAK,CAAC,SAAS,YAAY,iBAAiB,EAAE,CAAC;oBAC/C,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,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E,CAAC;oBACrB,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC9C,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,WAAW,EAAE,CAAC,CAAC;gBAC7D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO;QAChB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QAED,wBAAwB;QACxB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CAAC,WAAmB;QACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,GAAG,WAAW,GAAG,KAAK,CAAC,CAAC;QAEvE,2CAA2C;QAC3C,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;QAED,eAAe;QACf,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5C,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,24 @@
1
+ import { ApiError } from "@rapidrest/core";
2
+ /**
3
+ * An error take that takes an array of other errors.
4
+ */
5
+ export class BulkError extends ApiError {
6
+ constructor(errs, code, defaultStatus, message) {
7
+ super(code, defaultStatus, message);
8
+ /**
9
+ * The list of errors that have been thrown.
10
+ */
11
+ this.errors = [];
12
+ // Per: https://github.com/microsoft/TypeScript-wiki/blob/81fe7b91664de43c02ea209492ec1cea7f3661d0/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
13
+ Object.setPrototypeOf(this, BulkError.prototype);
14
+ this.errors = errs;
15
+ // Override default from the first valid status code
16
+ for (const err of errs) {
17
+ if (err && "status" in err) {
18
+ this.status = err.status;
19
+ break;
20
+ }
21
+ }
22
+ }
23
+ }
24
+ //# sourceMappingURL=BulkError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BulkError.js","sourceRoot":"","sources":["../../src/BulkError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,QAAQ;IAMnC,YAAY,IAAsB,EAAE,IAAY,EAAE,aAAqB,EAAE,OAAgB;QACrF,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QANxC;;WAEG;QACa,WAAM,GAAqB,EAAE,CAAC;QAI1C,sLAAsL;QACtL,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,oDAAoD;QACpD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,EAAE,CAAC;gBACzB,IAAI,CAAC,MAAM,GAAI,GAAW,CAAC,MAAM,CAAC;gBAClC,MAAM;YACV,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,161 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { ObjectDecorators } from "@rapidrest/core";
11
+ const { Config, Destroy, Init, Logger } = ObjectDecorators;
12
+ /**
13
+ * The `EventListenerManager` is responsible for managing event handlers and processing of incoming
14
+ * events from the configured redis pubsub channels. An event handler is any function that has been
15
+ * decorated with the `@OnEvent` decorator and registered with this manager. Once registered, any event
16
+ * that is received corresponding to the list of types specified in the decorator arguments will be
17
+ * sent to the designated function(s). If no type is specified, the handler function will be called
18
+ * for any event that is received.
19
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
20
+ */
21
+ export class EventListenerManager {
22
+ constructor(objectFactory, redis) {
23
+ this.channels = [];
24
+ this.handlers = new Map();
25
+ this.objectFactory = objectFactory;
26
+ this.redis = redis;
27
+ }
28
+ async init() {
29
+ try {
30
+ await this.redis.subscribe(...this.channels);
31
+ }
32
+ catch (err) {
33
+ this.logger.error("EventManager: Failed to subscribe to pubsub channels: " + this.channels);
34
+ this.logger.debug(err);
35
+ }
36
+ this.redis.on("message", (channel, message) => {
37
+ try {
38
+ const decoded = JSON.parse(message);
39
+ this.onEvent(decoded);
40
+ }
41
+ catch (err) {
42
+ this.logger.error("EventManager: Received event but could not parse it.");
43
+ this.logger.debug(`EventManager: Channel=${channel}, Event=${message}, Error=${err}`);
44
+ }
45
+ });
46
+ // Go through each class in the ObjectFactory and create any with event listener decorator.
47
+ const classes = this.objectFactory.classes;
48
+ if (classes) {
49
+ for (const clazz of classes.values()) {
50
+ try {
51
+ if (Reflect.hasOwnMetadata("rrst:eventListeners", clazz) &&
52
+ clazz.prototype.constructor.length === 0) {
53
+ const obj = await this.objectFactory.newInstance(clazz, { name: "default" });
54
+ this.register(obj);
55
+ }
56
+ }
57
+ catch (err) {
58
+ this.logger.debug(`EventListeners: Unable to process class[${clazz}], Error=${err}`);
59
+ }
60
+ }
61
+ }
62
+ // Go through each object instance in the ObjectFactory that is an event processor.
63
+ const objs = this.objectFactory.instances;
64
+ if (objs) {
65
+ for (const obj of objs.values()) {
66
+ this.register(obj);
67
+ }
68
+ }
69
+ }
70
+ async destroy() {
71
+ await this.redis.unsubscribe(...this.channels);
72
+ this.handlers.clear();
73
+ }
74
+ /**
75
+ * Handler function for events that arrive from redis.
76
+ */
77
+ onEvent(evt) {
78
+ // The registered event types can be regular expression patterns so we
79
+ // need to test each one against our type in order to idenity which
80
+ // handlers to send to.
81
+ for (const entry of this.handlers.entries()) {
82
+ // We'll perform regex comparisons with case-insentivity to make it easier
83
+ if (evt.type.match(new RegExp(entry[0], "i"))) {
84
+ const handlers = entry[1];
85
+ if (handlers) {
86
+ for (const handler of handlers) {
87
+ handler(evt);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+ /**
94
+ * Adds the given function to the list of designated event handlers for the specified type.
95
+ * @param event The type of event to add a handler for
96
+ * @param func The function to add
97
+ */
98
+ addEventHandler(event, func) {
99
+ let handlers = this.handlers.get(event);
100
+ // Create the list if not already exists
101
+ if (!handlers) {
102
+ handlers = [];
103
+ }
104
+ // Add the handler to the list if not already registered
105
+ if (!handlers.includes(func)) {
106
+ handlers.push(func);
107
+ }
108
+ // Update the list in the map
109
+ this.handlers.set(event, handlers);
110
+ }
111
+ /**
112
+ * Registers the given object to be notified of events that arrive.
113
+ * @param obj The object to register for event handling.
114
+ */
115
+ register(obj) {
116
+ const members = [];
117
+ // Search through the object looking for all functions that have
118
+ // the @Event decorator.
119
+ let proto = Object.getPrototypeOf(obj);
120
+ while (proto) {
121
+ for (const member of Object.getOwnPropertyNames(proto)) {
122
+ const events = Reflect.getMetadata("rrst:events", proto, member);
123
+ // Don't register the same member more than once
124
+ if (events && !members.includes(member)) {
125
+ const func = obj[member].bind(obj);
126
+ if (Array.isArray(events)) {
127
+ for (const event of events) {
128
+ this.addEventHandler(event, func);
129
+ }
130
+ }
131
+ else {
132
+ this.addEventHandler(events, func);
133
+ }
134
+ members.push(member);
135
+ }
136
+ }
137
+ proto = Object.getPrototypeOf(proto);
138
+ }
139
+ }
140
+ }
141
+ __decorate([
142
+ Config("events:channels", []),
143
+ __metadata("design:type", Array)
144
+ ], EventListenerManager.prototype, "channels", void 0);
145
+ __decorate([
146
+ Logger,
147
+ __metadata("design:type", Object)
148
+ ], EventListenerManager.prototype, "logger", void 0);
149
+ __decorate([
150
+ Init,
151
+ __metadata("design:type", Function),
152
+ __metadata("design:paramtypes", []),
153
+ __metadata("design:returntype", Promise)
154
+ ], EventListenerManager.prototype, "init", null);
155
+ __decorate([
156
+ Destroy,
157
+ __metadata("design:type", Function),
158
+ __metadata("design:paramtypes", []),
159
+ __metadata("design:returntype", Promise)
160
+ ], EventListenerManager.prototype, "destroy", null);
161
+ //# sourceMappingURL=EventListenerManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventListenerManager.js","sourceRoot":"","sources":["../../src/EventListenerManager.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAS,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,OAAO,oBAAoB;IAS7B,YAAY,aAA4B,EAAE,KAAY;QAP9C,aAAQ,GAAa,EAAE,CAAC;QAIxB,aAAQ,GAA4B,IAAI,GAAG,EAAE,CAAC;QAIlD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAGY,AAAN,KAAK,CAAC,IAAI;QACb,IAAI,CAAC;YACD,MAA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AAC;oBACvC,CAAC;oBACD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACzB,CAAC;YACL,CAAC;YAED,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;IACL,CAAC;CACJ;AArIW;IADP,MAAM,CAAC,iBAAiB,EAAE,EAAE,CAAC;;sDACE;AAExB;IADP,MAAM;;oDACa;AAWP;IADZ,IAAI;;;;gDA0CJ;AAGY;IADZ,OAAO;;;;mDAIP"}
@@ -0,0 +1,103 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2020-2026 Jean-Philippe Steinmetz
3
+ ///////////////////////////////////////////////////////////////////////////////
4
+ import { promises as dns } from "dns";
5
+ /**
6
+ * Provides common utilities and functions for working with networking related problems.
7
+ *
8
+ * @author Jean-Philippe Steinmetz <rapidrests@gmail.com>
9
+ */
10
+ export class NetUtils {
11
+ /**
12
+ * Performs DNS lookup of the IP address from a given url.
13
+ *
14
+ * @param url The url to lookup the IP from.
15
+ * @param family ip family used for dns lookup
16
+ * @returns A `string` containing the IP address if found, otherwise `undefined`.
17
+ */
18
+ static async lookupIPAddress(url, family = 4) {
19
+ let result = undefined;
20
+ try {
21
+ const tmp = new URL(url);
22
+ // Check that the host isn't already an IPv4/IPv6 address
23
+ let matches = null;
24
+ if ((matches = tmp.host.match(/^((?:[0-9]{1,3}\.){3}[0-9]{1,3}):?([0-9]+)?$/)) ||
25
+ (matches = tmp.host.match(/^\[?((::)?([0-9a-fA-F]{1,4}:){0,7}:?([0-9a-fA-F]{1,4}:?){1,7})\]?:?([0-9]+)?$/))) {
26
+ result = matches[1];
27
+ }
28
+ else {
29
+ // Attempt to resolve the domain name
30
+ matches = tmp.host.match(/^((?:[A-Za-z0-9-]+\.?)+[A-Za-z0-9]{1,3})(:\d{1,5})?$/);
31
+ if (matches) {
32
+ const lookup = await dns.lookup(matches[1], family);
33
+ result = lookup.address;
34
+ }
35
+ }
36
+ }
37
+ catch (err) {
38
+ // Do nothing
39
+ }
40
+ return result;
41
+ }
42
+ /**
43
+ * Extracts the IP address from a given url or HTTP request.
44
+ *
45
+ * When `trustedProxies` is provided, forwarding headers (`X-Forwarded-For`, etc.) are
46
+ * only trusted when the direct connection's `remoteAddress` is in that list. Without a
47
+ * trusted-proxy list the headers are ignored and the socket address is returned directly,
48
+ * preventing clients from spoofing their IP in audit logs.
49
+ *
50
+ * @param urlOrRequest The url or HTTP request to extract the IP from.
51
+ * @param trustedProxies Optional list of proxy IP addresses whose forwarding headers should be trusted.
52
+ * @returns A `string` containing the IP address if found, otherwise `undefined`.
53
+ */
54
+ static getIPAddress(urlOrRequest, trustedProxies) {
55
+ let result = undefined;
56
+ if (typeof urlOrRequest === "string") {
57
+ // Check that for IPv4/IPv6 addresses
58
+ let matches = null;
59
+ if ((matches = urlOrRequest.match(/^((?:[0-9]{1,3}\.){3}[0-9]{1,3}):?([0-9]+)?$/)) ||
60
+ (matches = urlOrRequest.match(/^\[?((::)?([0-9a-fA-F]{1,4}:){0,7}:?([0-9a-fA-F]{1,4}:?){1,7})\]?:?([0-9]+)?$/))) {
61
+ result = matches[1];
62
+ }
63
+ // Maybe it's a URL?
64
+ else {
65
+ try {
66
+ const tmp = new URL(urlOrRequest);
67
+ // Check that the host isn't already an IPv4/IPv6 address
68
+ let matches = null;
69
+ if ((matches = tmp.host.match(/^((?:[0-9]{1,3}\.){3}[0-9]{1,3}):?([0-9]+)?$/)) ||
70
+ (matches = tmp.host.match(/^\[?((::)?([0-9a-fA-F]{1,4}:){0,7}:?([0-9a-fA-F]{1,4}:?){1,7})\]?:?([0-9]+)?$/))) {
71
+ result = matches[1];
72
+ }
73
+ else {
74
+ result = tmp.host;
75
+ }
76
+ }
77
+ catch (err) {
78
+ // Do nothing
79
+ }
80
+ }
81
+ }
82
+ else {
83
+ const remoteAddr = urlOrRequest.socket?.remoteAddress;
84
+ const proxyTrusted = trustedProxies && trustedProxies.length > 0
85
+ ? remoteAddr !== undefined && trustedProxies.includes(remoteAddr)
86
+ : false;
87
+ if (proxyTrusted) {
88
+ if (urlOrRequest.headers["x-original-forwarded-for"]) {
89
+ result = urlOrRequest.headers["x-original-forwarded-for"];
90
+ }
91
+ else if (urlOrRequest.headers["x-forwarded-for"]) {
92
+ result = urlOrRequest.headers["x-forwarded-for"];
93
+ }
94
+ else if (urlOrRequest.headers["x-real-ip"]) {
95
+ result = urlOrRequest.headers["x-real-ip"];
96
+ }
97
+ }
98
+ result = result ?? remoteAddr;
99
+ }
100
+ return result;
101
+ }
102
+ }
103
+ //# sourceMappingURL=NetUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NetUtils.js","sourceRoot":"","sources":["../../src/NetUtils.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,kDAAkD;AAClD,+EAA+E;AAC/E,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAiB,MAAM,KAAK,CAAC;AAGrD;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACjB;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,GAAW,EAAE,SAAiB,CAAC;QAC/D,IAAI,MAAM,GAAuB,SAAS,CAAC;QAE3C,IAAI,CAAC;YACD,MAAM,GAAG,GAAQ,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAC9B,yDAAyD;YACzD,IAAI,OAAO,GAA4B,IAAI,CAAC;YAC5C,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;gBAC1E,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,+EAA+E,CAAC,CAAC,EAAE,CAAC;gBAC9G,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACJ,qCAAqC;gBACrC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;gBACjF,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G,EAAE,CAAC;oBACX,aAAa;gBACjB,CAAC;YACL,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,MAAM,UAAU,GAAG,YAAY,CAAC,MAAM,EAAE,aAAa,CAAC;YACtD,MAAM,YAAY,GACd,cAAc,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC;gBACvC,CAAC,CAAC,UAAU,KAAK,SAAS,IAAI,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC;gBACjE,CAAC,CAAC,KAAK,CAAC;YAEhB,IAAI,YAAY,EAAE,CAAC;gBACf,IAAI,YAAY,CAAC,OAAO,CAAC,0BAA0B,CAAC,EAAE,CAAC;oBACnD,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,0BAA0B,CAAW,CAAC;gBACxE,CAAC;qBAAM,IAAI,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;oBACjD,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAW,CAAC;gBAC/D,CAAC;qBAAM,IAAI,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;oBAC3C,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,CAAW,CAAC;gBACzD,CAAC;YACL,CAAC;YAED,MAAM,GAAG,MAAM,IAAI,UAAU,CAAC;QAClC,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Utility functions for sending push notifications to registered clients.
3
+ *
4
+ * @author Jean-Philippe Steinmetz
5
+ */
6
+ export class NotificationUtils {
7
+ /**
8
+ * Initializes the utility using the given redis connection.
9
+ *
10
+ * @param {any} redis The redis connection to publish to.
11
+ */
12
+ constructor(redis) {
13
+ this.redis = redis;
14
+ }
15
+ /**
16
+ * Sends a given message to the room or user with the specified uid(s).
17
+ *
18
+ * @param {string} uids The universally unique identifier of the room or user to send the message to.
19
+ * @param {string} type The type of message being sent.
20
+ * @param {string} action The action performed on the data (if applicable).
21
+ * @param {string} data The contents of the message to send to the room or user.
22
+ */
23
+ sendMessage(uids, type, action, data) {
24
+ if (Array.isArray(uids)) {
25
+ for (const uid of uids) {
26
+ void this.redis?.publish(uid, JSON.stringify({ type, action, data }));
27
+ }
28
+ }
29
+ else {
30
+ void this.redis?.publish(uids, JSON.stringify({ type, action, data }));
31
+ }
32
+ }
33
+ }
34
+ //# sourceMappingURL=NotificationUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationUtils.js","sourceRoot":"","sources":["../../src/NotificationUtils.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAI1B;;;;OAIG;IACH,YAAY,KAAY;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACI,WAAW,CAAC,IAAuB,EAAE,IAAY,EAAE,MAAc,EAAE,IAAS;QAC/E,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACrB,KAAK,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC1E,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,KAAK,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;IACL,CAAC;CACJ"}