@rvoh/psychic 0.24.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 (354) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/dist/cjs/src/bin/helpers/enumsAndTheirValues.js +17 -0
  4. package/dist/cjs/src/bin/helpers/enumsFileStr.js +21 -0
  5. package/dist/cjs/src/bin/helpers/generateRouteTypes.js +16 -0
  6. package/dist/cjs/src/bin/helpers/printRoutes.js +54 -0
  7. package/dist/cjs/src/bin/index.js +79 -0
  8. package/dist/cjs/src/cli/helpers/TypesBuilder.js +26 -0
  9. package/dist/cjs/src/cli/index.js +76 -0
  10. package/dist/cjs/src/controller/decorators.js +85 -0
  11. package/dist/cjs/src/controller/hooks.js +29 -0
  12. package/dist/cjs/src/controller/index.js +571 -0
  13. package/dist/cjs/src/encrypt/internal-encrypt.js +43 -0
  14. package/dist/cjs/src/env/Loader.js +26 -0
  15. package/dist/cjs/src/error/db/failed-to-connect.js +17 -0
  16. package/dist/cjs/src/error/db/index.js +16 -0
  17. package/dist/cjs/src/error/db/missing-options.js +17 -0
  18. package/dist/cjs/src/error/encrypt/missing-cookie-encryption-options.js +27 -0
  19. package/dist/cjs/src/error/http/BadGateway.js +9 -0
  20. package/dist/cjs/src/error/http/BadRequest.js +9 -0
  21. package/dist/cjs/src/error/http/Conflict.js +9 -0
  22. package/dist/cjs/src/error/http/ContentTooLarge.js +9 -0
  23. package/dist/cjs/src/error/http/ExpectationFailed.js +9 -0
  24. package/dist/cjs/src/error/http/FailedDependency.js +9 -0
  25. package/dist/cjs/src/error/http/Forbidden.js +9 -0
  26. package/dist/cjs/src/error/http/GatewayTimeout.js +9 -0
  27. package/dist/cjs/src/error/http/Gone.js +9 -0
  28. package/dist/cjs/src/error/http/ImATeapot.js +9 -0
  29. package/dist/cjs/src/error/http/InsufficientStorage.js +9 -0
  30. package/dist/cjs/src/error/http/InternalServerError.js +9 -0
  31. package/dist/cjs/src/error/http/Locked.js +9 -0
  32. package/dist/cjs/src/error/http/MethodNotAllowed.js +9 -0
  33. package/dist/cjs/src/error/http/MisdirectedRequest.js +9 -0
  34. package/dist/cjs/src/error/http/NotAcceptable.js +9 -0
  35. package/dist/cjs/src/error/http/NotExtended.js +9 -0
  36. package/dist/cjs/src/error/http/NotFound.js +9 -0
  37. package/dist/cjs/src/error/http/NotImplemented.js +9 -0
  38. package/dist/cjs/src/error/http/PaymentRequired.js +9 -0
  39. package/dist/cjs/src/error/http/PreconditionFailed.js +9 -0
  40. package/dist/cjs/src/error/http/PreconditionRequired.js +9 -0
  41. package/dist/cjs/src/error/http/ProxyAuthenticationRequired.js +9 -0
  42. package/dist/cjs/src/error/http/RequestHeaderFieldsTooLarge.js +9 -0
  43. package/dist/cjs/src/error/http/ServiceUnavailable.js +9 -0
  44. package/dist/cjs/src/error/http/TooManyRequests.js +9 -0
  45. package/dist/cjs/src/error/http/Unauthorized.js +9 -0
  46. package/dist/cjs/src/error/http/UnavailableForLegalReasons.js +9 -0
  47. package/dist/cjs/src/error/http/UnprocessableContent.js +9 -0
  48. package/dist/cjs/src/error/http/UnsupportedMediaType.js +9 -0
  49. package/dist/cjs/src/error/http/index.js +22 -0
  50. package/dist/cjs/src/error/http/router/index.js +18 -0
  51. package/dist/cjs/src/error/http/router/missing-controller-method.js +20 -0
  52. package/dist/cjs/src/error/http/router/missing-controller.js +17 -0
  53. package/dist/cjs/src/error/http/status-codes.js +311 -0
  54. package/dist/cjs/src/error/model/index.js +5 -0
  55. package/dist/cjs/src/error/openapi/CannotFlattenMultiplePolymorphicRendersOneAssociations.js +22 -0
  56. package/dist/cjs/src/error/psychic-application/init-missing-api-root.js +21 -0
  57. package/dist/cjs/src/error/psychic-application/init-missing-call-to-load-controllers.js +21 -0
  58. package/dist/cjs/src/error/psychic-application/init-missing-routes-callback.js +23 -0
  59. package/dist/cjs/src/error/psychic-application/invalid-encryption-key.js +20 -0
  60. package/dist/cjs/src/error/router/cannot-find-inferred-controller-from-provided-namespace.js +42 -0
  61. package/dist/cjs/src/error/router/cannot-infer-controller-from-top-level-route.js +39 -0
  62. package/dist/cjs/src/error/ws/MissingWsRedisConnection.js +32 -0
  63. package/dist/cjs/src/generate/controller.js +107 -0
  64. package/dist/cjs/src/generate/helpers/addResourceToRoutes.js +64 -0
  65. package/dist/cjs/src/generate/helpers/generateControllerContent.js +191 -0
  66. package/dist/cjs/src/generate/helpers/generateControllerSpecContent.js +9 -0
  67. package/dist/cjs/src/generate/helpers/generateResourceControllerSpecContent.js +199 -0
  68. package/dist/cjs/src/generate/helpers/migrationTimestamp.js +6 -0
  69. package/dist/cjs/src/generate/resource.js +19 -0
  70. package/dist/cjs/src/helpers/EnvInternal.js +5 -0
  71. package/dist/cjs/src/helpers/autogeneratedFileDisclaimer.js +71 -0
  72. package/dist/cjs/src/helpers/cookieMaxAgeFromCookieOpts.js +20 -0
  73. package/dist/cjs/src/helpers/error/errorIsRescuableHttpError.js +8 -0
  74. package/dist/cjs/src/helpers/error/httpErrorClasses.js +76 -0
  75. package/dist/cjs/src/helpers/importFileWithDefault.js +14 -0
  76. package/dist/cjs/src/helpers/importFileWithNamedExport.js +12 -0
  77. package/dist/cjs/src/helpers/isOpenapiError.js +6 -0
  78. package/dist/cjs/src/helpers/isUuid.js +8 -0
  79. package/dist/cjs/src/helpers/loadEnv.js +5 -0
  80. package/dist/cjs/src/helpers/openapiJsonPath.js +9 -0
  81. package/dist/cjs/src/helpers/pascalizeFileName.js +10 -0
  82. package/dist/cjs/src/helpers/path/psychicFileAndDirPaths.js +16 -0
  83. package/dist/cjs/src/helpers/path/psychicPath.js +18 -0
  84. package/dist/cjs/src/helpers/path/relativePsychicPath.js +43 -0
  85. package/dist/cjs/src/helpers/path/updirsFromPath.js +11 -0
  86. package/dist/cjs/src/helpers/path.js +11 -0
  87. package/dist/cjs/src/helpers/pathifyNestedObject.js +14 -0
  88. package/dist/cjs/src/helpers/sspawn.js +26 -0
  89. package/dist/cjs/src/helpers/typeHelpers.js +2 -0
  90. package/dist/cjs/src/helpers/typechecks.js +20 -0
  91. package/dist/cjs/src/i18n/conf/I18nDefaultLocales.js +31 -0
  92. package/dist/cjs/src/i18n/conf/types.js +2 -0
  93. package/dist/cjs/src/i18n/provider.js +96 -0
  94. package/dist/cjs/src/index.js +104 -0
  95. package/dist/cjs/src/openapi-renderer/app.js +153 -0
  96. package/dist/cjs/src/openapi-renderer/body-segment.js +514 -0
  97. package/dist/cjs/src/openapi-renderer/defaults.js +84 -0
  98. package/dist/cjs/src/openapi-renderer/endpoint.js +930 -0
  99. package/dist/cjs/src/openapi-renderer/helpers/isBlankDescription.js +13 -0
  100. package/dist/cjs/src/openapi-renderer/helpers/openapiRoute.js +7 -0
  101. package/dist/cjs/src/openapi-renderer/serializer.js +321 -0
  102. package/dist/cjs/src/psychic-application/cache.js +17 -0
  103. package/dist/cjs/src/psychic-application/helpers/PsychicImporter.js +15 -0
  104. package/dist/cjs/src/psychic-application/helpers/globalControllerKeyFromPath.js +11 -0
  105. package/dist/cjs/src/psychic-application/helpers/import/importControllers.js +56 -0
  106. package/dist/cjs/src/psychic-application/helpers/loadAppEnv.js +5 -0
  107. package/dist/cjs/src/psychic-application/helpers/lookupClassByGlobalName.js +16 -0
  108. package/dist/cjs/src/psychic-application/index.js +346 -0
  109. package/dist/cjs/src/psychic-application/logo.js +77 -0
  110. package/dist/cjs/src/psychic-application/types.js +2 -0
  111. package/dist/cjs/src/router/helpers.js +138 -0
  112. package/dist/cjs/src/router/index.js +282 -0
  113. package/dist/cjs/src/router/route-manager.js +14 -0
  114. package/dist/cjs/src/router/types.js +6 -0
  115. package/dist/cjs/src/server/front-end-client.js +15 -0
  116. package/dist/cjs/src/server/helpers/startPsychicServer.js +39 -0
  117. package/dist/cjs/src/server/index.js +192 -0
  118. package/dist/cjs/src/server/params.js +370 -0
  119. package/dist/cjs/src/session/index.js +38 -0
  120. package/dist/esm/src/bin/helpers/enumsAndTheirValues.js +14 -0
  121. package/dist/esm/src/bin/helpers/enumsFileStr.js +18 -0
  122. package/dist/esm/src/bin/helpers/generateRouteTypes.js +13 -0
  123. package/dist/esm/src/bin/helpers/printRoutes.js +51 -0
  124. package/dist/esm/src/bin/index.js +76 -0
  125. package/dist/esm/src/cli/helpers/TypesBuilder.js +23 -0
  126. package/dist/esm/src/cli/index.js +73 -0
  127. package/dist/esm/src/controller/decorators.js +81 -0
  128. package/dist/esm/src/controller/hooks.js +25 -0
  129. package/dist/esm/src/controller/index.js +566 -0
  130. package/dist/esm/src/encrypt/internal-encrypt.js +40 -0
  131. package/dist/esm/src/env/Loader.js +24 -0
  132. package/dist/esm/src/error/db/failed-to-connect.js +14 -0
  133. package/dist/esm/src/error/db/index.js +13 -0
  134. package/dist/esm/src/error/db/missing-options.js +14 -0
  135. package/dist/esm/src/error/encrypt/missing-cookie-encryption-options.js +24 -0
  136. package/dist/esm/src/error/http/BadGateway.js +6 -0
  137. package/dist/esm/src/error/http/BadRequest.js +6 -0
  138. package/dist/esm/src/error/http/Conflict.js +6 -0
  139. package/dist/esm/src/error/http/ContentTooLarge.js +6 -0
  140. package/dist/esm/src/error/http/ExpectationFailed.js +6 -0
  141. package/dist/esm/src/error/http/FailedDependency.js +6 -0
  142. package/dist/esm/src/error/http/Forbidden.js +6 -0
  143. package/dist/esm/src/error/http/GatewayTimeout.js +6 -0
  144. package/dist/esm/src/error/http/Gone.js +6 -0
  145. package/dist/esm/src/error/http/ImATeapot.js +6 -0
  146. package/dist/esm/src/error/http/InsufficientStorage.js +6 -0
  147. package/dist/esm/src/error/http/InternalServerError.js +6 -0
  148. package/dist/esm/src/error/http/Locked.js +6 -0
  149. package/dist/esm/src/error/http/MethodNotAllowed.js +6 -0
  150. package/dist/esm/src/error/http/MisdirectedRequest.js +6 -0
  151. package/dist/esm/src/error/http/NotAcceptable.js +6 -0
  152. package/dist/esm/src/error/http/NotExtended.js +6 -0
  153. package/dist/esm/src/error/http/NotFound.js +6 -0
  154. package/dist/esm/src/error/http/NotImplemented.js +6 -0
  155. package/dist/esm/src/error/http/PaymentRequired.js +6 -0
  156. package/dist/esm/src/error/http/PreconditionFailed.js +6 -0
  157. package/dist/esm/src/error/http/PreconditionRequired.js +6 -0
  158. package/dist/esm/src/error/http/ProxyAuthenticationRequired.js +6 -0
  159. package/dist/esm/src/error/http/RequestHeaderFieldsTooLarge.js +6 -0
  160. package/dist/esm/src/error/http/ServiceUnavailable.js +6 -0
  161. package/dist/esm/src/error/http/TooManyRequests.js +6 -0
  162. package/dist/esm/src/error/http/Unauthorized.js +6 -0
  163. package/dist/esm/src/error/http/UnavailableForLegalReasons.js +6 -0
  164. package/dist/esm/src/error/http/UnprocessableContent.js +6 -0
  165. package/dist/esm/src/error/http/UnsupportedMediaType.js +6 -0
  166. package/dist/esm/src/error/http/index.js +19 -0
  167. package/dist/esm/src/error/http/router/index.js +15 -0
  168. package/dist/esm/src/error/http/router/missing-controller-method.js +17 -0
  169. package/dist/esm/src/error/http/router/missing-controller.js +14 -0
  170. package/dist/esm/src/error/http/status-codes.js +309 -0
  171. package/dist/esm/src/error/model/index.js +2 -0
  172. package/dist/esm/src/error/openapi/CannotFlattenMultiplePolymorphicRendersOneAssociations.js +19 -0
  173. package/dist/esm/src/error/psychic-application/init-missing-api-root.js +18 -0
  174. package/dist/esm/src/error/psychic-application/init-missing-call-to-load-controllers.js +18 -0
  175. package/dist/esm/src/error/psychic-application/init-missing-routes-callback.js +20 -0
  176. package/dist/esm/src/error/psychic-application/invalid-encryption-key.js +17 -0
  177. package/dist/esm/src/error/router/cannot-find-inferred-controller-from-provided-namespace.js +39 -0
  178. package/dist/esm/src/error/router/cannot-infer-controller-from-top-level-route.js +36 -0
  179. package/dist/esm/src/error/ws/MissingWsRedisConnection.js +29 -0
  180. package/dist/esm/src/generate/controller.js +104 -0
  181. package/dist/esm/src/generate/helpers/addResourceToRoutes.js +60 -0
  182. package/dist/esm/src/generate/helpers/generateControllerContent.js +188 -0
  183. package/dist/esm/src/generate/helpers/generateControllerSpecContent.js +6 -0
  184. package/dist/esm/src/generate/helpers/generateResourceControllerSpecContent.js +196 -0
  185. package/dist/esm/src/generate/helpers/migrationTimestamp.js +3 -0
  186. package/dist/esm/src/generate/resource.js +16 -0
  187. package/dist/esm/src/helpers/EnvInternal.js +3 -0
  188. package/dist/esm/src/helpers/autogeneratedFileDisclaimer.js +68 -0
  189. package/dist/esm/src/helpers/cookieMaxAgeFromCookieOpts.js +17 -0
  190. package/dist/esm/src/helpers/error/errorIsRescuableHttpError.js +5 -0
  191. package/dist/esm/src/helpers/error/httpErrorClasses.js +72 -0
  192. package/dist/esm/src/helpers/importFileWithDefault.js +11 -0
  193. package/dist/esm/src/helpers/importFileWithNamedExport.js +9 -0
  194. package/dist/esm/src/helpers/isOpenapiError.js +3 -0
  195. package/dist/esm/src/helpers/isUuid.js +5 -0
  196. package/dist/esm/src/helpers/loadEnv.js +3 -0
  197. package/dist/esm/src/helpers/openapiJsonPath.js +6 -0
  198. package/dist/esm/src/helpers/pascalizeFileName.js +7 -0
  199. package/dist/esm/src/helpers/path/psychicFileAndDirPaths.js +13 -0
  200. package/dist/esm/src/helpers/path/psychicPath.js +15 -0
  201. package/dist/esm/src/helpers/path/relativePsychicPath.js +39 -0
  202. package/dist/esm/src/helpers/path/updirsFromPath.js +8 -0
  203. package/dist/esm/src/helpers/path.js +7 -0
  204. package/dist/esm/src/helpers/pathifyNestedObject.js +11 -0
  205. package/dist/esm/src/helpers/sspawn.js +22 -0
  206. package/dist/esm/src/helpers/typeHelpers.js +1 -0
  207. package/dist/esm/src/helpers/typechecks.js +16 -0
  208. package/dist/esm/src/i18n/conf/I18nDefaultLocales.js +29 -0
  209. package/dist/esm/src/i18n/conf/types.js +1 -0
  210. package/dist/esm/src/i18n/provider.js +89 -0
  211. package/dist/esm/src/index.js +50 -0
  212. package/dist/esm/src/openapi-renderer/app.js +150 -0
  213. package/dist/esm/src/openapi-renderer/body-segment.js +511 -0
  214. package/dist/esm/src/openapi-renderer/defaults.js +81 -0
  215. package/dist/esm/src/openapi-renderer/endpoint.js +925 -0
  216. package/dist/esm/src/openapi-renderer/helpers/isBlankDescription.js +10 -0
  217. package/dist/esm/src/openapi-renderer/helpers/openapiRoute.js +4 -0
  218. package/dist/esm/src/openapi-renderer/serializer.js +318 -0
  219. package/dist/esm/src/psychic-application/cache.js +12 -0
  220. package/dist/esm/src/psychic-application/helpers/PsychicImporter.js +12 -0
  221. package/dist/esm/src/psychic-application/helpers/globalControllerKeyFromPath.js +8 -0
  222. package/dist/esm/src/psychic-application/helpers/import/importControllers.js +51 -0
  223. package/dist/esm/src/psychic-application/helpers/loadAppEnv.js +3 -0
  224. package/dist/esm/src/psychic-application/helpers/lookupClassByGlobalName.js +13 -0
  225. package/dist/esm/src/psychic-application/index.js +343 -0
  226. package/dist/esm/src/psychic-application/logo.js +73 -0
  227. package/dist/esm/src/psychic-application/types.js +1 -0
  228. package/dist/esm/src/router/helpers.js +127 -0
  229. package/dist/esm/src/router/index.js +277 -0
  230. package/dist/esm/src/router/route-manager.js +11 -0
  231. package/dist/esm/src/router/types.js +3 -0
  232. package/dist/esm/src/server/front-end-client.js +12 -0
  233. package/dist/esm/src/server/helpers/startPsychicServer.js +35 -0
  234. package/dist/esm/src/server/index.js +189 -0
  235. package/dist/esm/src/server/params.js +365 -0
  236. package/dist/esm/src/session/index.js +35 -0
  237. package/dist/types/src/bin/helpers/enumsAndTheirValues.d.ts +1 -0
  238. package/dist/types/src/bin/helpers/enumsFileStr.d.ts +1 -0
  239. package/dist/types/src/bin/helpers/generateRouteTypes.d.ts +2 -0
  240. package/dist/types/src/bin/helpers/printRoutes.d.ts +1 -0
  241. package/dist/types/src/bin/index.d.ts +12 -0
  242. package/dist/types/src/cli/helpers/TypesBuilder.d.ts +7 -0
  243. package/dist/types/src/cli/index.d.ts +8 -0
  244. package/dist/types/src/controller/decorators.d.ts +28 -0
  245. package/dist/types/src/controller/hooks.d.ts +13 -0
  246. package/dist/types/src/controller/index.d.ts +209 -0
  247. package/dist/types/src/encrypt/internal-encrypt.d.ts +6 -0
  248. package/dist/types/src/env/Loader.d.ts +8 -0
  249. package/dist/types/src/error/db/failed-to-connect.d.ts +4 -0
  250. package/dist/types/src/error/db/index.d.ts +5 -0
  251. package/dist/types/src/error/db/missing-options.d.ts +4 -0
  252. package/dist/types/src/error/encrypt/missing-cookie-encryption-options.d.ts +3 -0
  253. package/dist/types/src/error/http/BadGateway.d.ts +4 -0
  254. package/dist/types/src/error/http/BadRequest.d.ts +4 -0
  255. package/dist/types/src/error/http/Conflict.d.ts +4 -0
  256. package/dist/types/src/error/http/ContentTooLarge.d.ts +4 -0
  257. package/dist/types/src/error/http/ExpectationFailed.d.ts +4 -0
  258. package/dist/types/src/error/http/FailedDependency.d.ts +4 -0
  259. package/dist/types/src/error/http/Forbidden.d.ts +4 -0
  260. package/dist/types/src/error/http/GatewayTimeout.d.ts +4 -0
  261. package/dist/types/src/error/http/Gone.d.ts +4 -0
  262. package/dist/types/src/error/http/ImATeapot.d.ts +4 -0
  263. package/dist/types/src/error/http/InsufficientStorage.d.ts +4 -0
  264. package/dist/types/src/error/http/InternalServerError.d.ts +4 -0
  265. package/dist/types/src/error/http/Locked.d.ts +4 -0
  266. package/dist/types/src/error/http/MethodNotAllowed.d.ts +4 -0
  267. package/dist/types/src/error/http/MisdirectedRequest.d.ts +4 -0
  268. package/dist/types/src/error/http/NotAcceptable.d.ts +4 -0
  269. package/dist/types/src/error/http/NotExtended.d.ts +4 -0
  270. package/dist/types/src/error/http/NotFound.d.ts +4 -0
  271. package/dist/types/src/error/http/NotImplemented.d.ts +4 -0
  272. package/dist/types/src/error/http/PaymentRequired.d.ts +4 -0
  273. package/dist/types/src/error/http/PreconditionFailed.d.ts +4 -0
  274. package/dist/types/src/error/http/PreconditionRequired.d.ts +4 -0
  275. package/dist/types/src/error/http/ProxyAuthenticationRequired.d.ts +4 -0
  276. package/dist/types/src/error/http/RequestHeaderFieldsTooLarge.d.ts +4 -0
  277. package/dist/types/src/error/http/ServiceUnavailable.d.ts +4 -0
  278. package/dist/types/src/error/http/TooManyRequests.d.ts +4 -0
  279. package/dist/types/src/error/http/Unauthorized.d.ts +4 -0
  280. package/dist/types/src/error/http/UnavailableForLegalReasons.d.ts +4 -0
  281. package/dist/types/src/error/http/UnprocessableContent.d.ts +4 -0
  282. package/dist/types/src/error/http/UnsupportedMediaType.d.ts +4 -0
  283. package/dist/types/src/error/http/index.d.ts +10 -0
  284. package/dist/types/src/error/http/router/index.d.ts +6 -0
  285. package/dist/types/src/error/http/router/missing-controller-method.d.ts +7 -0
  286. package/dist/types/src/error/http/router/missing-controller.d.ts +6 -0
  287. package/dist/types/src/error/http/status-codes.d.ts +312 -0
  288. package/dist/types/src/error/model/index.d.ts +2 -0
  289. package/dist/types/src/error/openapi/CannotFlattenMultiplePolymorphicRendersOneAssociations.d.ts +7 -0
  290. package/dist/types/src/error/psychic-application/init-missing-api-root.d.ts +4 -0
  291. package/dist/types/src/error/psychic-application/init-missing-call-to-load-controllers.d.ts +4 -0
  292. package/dist/types/src/error/psychic-application/init-missing-routes-callback.d.ts +4 -0
  293. package/dist/types/src/error/psychic-application/invalid-encryption-key.d.ts +4 -0
  294. package/dist/types/src/error/router/cannot-find-inferred-controller-from-provided-namespace.d.ts +15 -0
  295. package/dist/types/src/error/router/cannot-infer-controller-from-top-level-route.d.ts +8 -0
  296. package/dist/types/src/error/ws/MissingWsRedisConnection.d.ts +3 -0
  297. package/dist/types/src/generate/controller.d.ts +7 -0
  298. package/dist/types/src/generate/helpers/addResourceToRoutes.d.ts +7 -0
  299. package/dist/types/src/generate/helpers/generateControllerContent.d.ts +8 -0
  300. package/dist/types/src/generate/helpers/generateControllerSpecContent.d.ts +1 -0
  301. package/dist/types/src/generate/helpers/generateResourceControllerSpecContent.d.ts +6 -0
  302. package/dist/types/src/generate/helpers/migrationTimestamp.d.ts +1 -0
  303. package/dist/types/src/generate/resource.d.ts +5 -0
  304. package/dist/types/src/helpers/EnvInternal.d.ts +7 -0
  305. package/dist/types/src/helpers/autogeneratedFileDisclaimer.d.ts +1 -0
  306. package/dist/types/src/helpers/cookieMaxAgeFromCookieOpts.d.ts +2 -0
  307. package/dist/types/src/helpers/error/errorIsRescuableHttpError.d.ts +1 -0
  308. package/dist/types/src/helpers/error/httpErrorClasses.d.ts +3 -0
  309. package/dist/types/src/helpers/importFileWithDefault.d.ts +1 -0
  310. package/dist/types/src/helpers/importFileWithNamedExport.d.ts +1 -0
  311. package/dist/types/src/helpers/isOpenapiError.d.ts +8 -0
  312. package/dist/types/src/helpers/isUuid.d.ts +1 -0
  313. package/dist/types/src/helpers/loadEnv.d.ts +1 -0
  314. package/dist/types/src/helpers/openapiJsonPath.d.ts +1 -0
  315. package/dist/types/src/helpers/pascalizeFileName.d.ts +1 -0
  316. package/dist/types/src/helpers/path/psychicFileAndDirPaths.d.ts +5 -0
  317. package/dist/types/src/helpers/path/psychicPath.d.ts +4 -0
  318. package/dist/types/src/helpers/path/relativePsychicPath.d.ts +3 -0
  319. package/dist/types/src/helpers/path/updirsFromPath.d.ts +1 -0
  320. package/dist/types/src/helpers/path.d.ts +2 -0
  321. package/dist/types/src/helpers/pathifyNestedObject.d.ts +5 -0
  322. package/dist/types/src/helpers/sspawn.d.ts +2 -0
  323. package/dist/types/src/helpers/typeHelpers.d.ts +4 -0
  324. package/dist/types/src/helpers/typechecks.d.ts +2 -0
  325. package/dist/types/src/i18n/conf/I18nDefaultLocales.d.ts +2 -0
  326. package/dist/types/src/i18n/conf/types.d.ts +45 -0
  327. package/dist/types/src/i18n/provider.d.ts +26 -0
  328. package/dist/types/src/index.d.ts +61 -0
  329. package/dist/types/src/openapi-renderer/app.d.ts +21 -0
  330. package/dist/types/src/openapi-renderer/body-segment.d.ts +153 -0
  331. package/dist/types/src/openapi-renderer/defaults.d.ts +5 -0
  332. package/dist/types/src/openapi-renderer/endpoint.d.ts +410 -0
  333. package/dist/types/src/openapi-renderer/helpers/isBlankDescription.d.ts +1 -0
  334. package/dist/types/src/openapi-renderer/helpers/openapiRoute.d.ts +1 -0
  335. package/dist/types/src/openapi-renderer/serializer.d.ts +76 -0
  336. package/dist/types/src/psychic-application/cache.d.ts +4 -0
  337. package/dist/types/src/psychic-application/helpers/PsychicImporter.d.ts +4 -0
  338. package/dist/types/src/psychic-application/helpers/globalControllerKeyFromPath.d.ts +1 -0
  339. package/dist/types/src/psychic-application/helpers/import/importControllers.d.ts +5 -0
  340. package/dist/types/src/psychic-application/helpers/loadAppEnv.d.ts +1 -0
  341. package/dist/types/src/psychic-application/helpers/lookupClassByGlobalName.d.ts +1 -0
  342. package/dist/types/src/psychic-application/index.d.ts +164 -0
  343. package/dist/types/src/psychic-application/logo.d.ts +2 -0
  344. package/dist/types/src/psychic-application/types.d.ts +6 -0
  345. package/dist/types/src/router/helpers.d.ts +26 -0
  346. package/dist/types/src/router/index.d.ts +55 -0
  347. package/dist/types/src/router/route-manager.d.ts +17 -0
  348. package/dist/types/src/router/types.d.ts +11 -0
  349. package/dist/types/src/server/front-end-client.d.ts +5 -0
  350. package/dist/types/src/server/helpers/startPsychicServer.d.ts +14 -0
  351. package/dist/types/src/server/index.d.ts +34 -0
  352. package/dist/types/src/server/params.d.ts +80 -0
  353. package/dist/types/src/session/index.d.ts +12 -0
  354. package/package.json +98 -0
@@ -0,0 +1,571 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.controllerSerializerIndex = exports.ControllerSerializerIndex = exports.PsychicParamsPrimitiveLiterals = void 0;
4
+ const dream_1 = require("@rvoh/dream");
5
+ const BadGateway_js_1 = require("../error/http/BadGateway.js");
6
+ const BadRequest_js_1 = require("../error/http/BadRequest.js");
7
+ const Conflict_js_1 = require("../error/http/Conflict.js");
8
+ const ContentTooLarge_js_1 = require("../error/http/ContentTooLarge.js");
9
+ const ExpectationFailed_js_1 = require("../error/http/ExpectationFailed.js");
10
+ const FailedDependency_js_1 = require("../error/http/FailedDependency.js");
11
+ const Forbidden_js_1 = require("../error/http/Forbidden.js");
12
+ const GatewayTimeout_js_1 = require("../error/http/GatewayTimeout.js");
13
+ const Gone_js_1 = require("../error/http/Gone.js");
14
+ const ImATeapot_js_1 = require("../error/http/ImATeapot.js");
15
+ const InsufficientStorage_js_1 = require("../error/http/InsufficientStorage.js");
16
+ const InternalServerError_js_1 = require("../error/http/InternalServerError.js");
17
+ const Locked_js_1 = require("../error/http/Locked.js");
18
+ const MethodNotAllowed_js_1 = require("../error/http/MethodNotAllowed.js");
19
+ const MisdirectedRequest_js_1 = require("../error/http/MisdirectedRequest.js");
20
+ const NotAcceptable_js_1 = require("../error/http/NotAcceptable.js");
21
+ const NotExtended_js_1 = require("../error/http/NotExtended.js");
22
+ const NotFound_js_1 = require("../error/http/NotFound.js");
23
+ const NotImplemented_js_1 = require("../error/http/NotImplemented.js");
24
+ const PaymentRequired_js_1 = require("../error/http/PaymentRequired.js");
25
+ const PreconditionFailed_js_1 = require("../error/http/PreconditionFailed.js");
26
+ const PreconditionRequired_js_1 = require("../error/http/PreconditionRequired.js");
27
+ const ProxyAuthenticationRequired_js_1 = require("../error/http/ProxyAuthenticationRequired.js");
28
+ const RequestHeaderFieldsTooLarge_js_1 = require("../error/http/RequestHeaderFieldsTooLarge.js");
29
+ const ServiceUnavailable_js_1 = require("../error/http/ServiceUnavailable.js");
30
+ const status_codes_js_1 = require("../error/http/status-codes.js");
31
+ const TooManyRequests_js_1 = require("../error/http/TooManyRequests.js");
32
+ const Unauthorized_js_1 = require("../error/http/Unauthorized.js");
33
+ const UnavailableForLegalReasons_js_1 = require("../error/http/UnavailableForLegalReasons.js");
34
+ const UnprocessableContent_js_1 = require("../error/http/UnprocessableContent.js");
35
+ const UnsupportedMediaType_js_1 = require("../error/http/UnsupportedMediaType.js");
36
+ const params_js_1 = require("../server/params.js");
37
+ const index_js_1 = require("../session/index.js");
38
+ exports.PsychicParamsPrimitiveLiterals = [
39
+ 'bigint',
40
+ 'bigint[]',
41
+ 'boolean',
42
+ 'boolean[]',
43
+ 'date',
44
+ 'date[]',
45
+ 'datetime',
46
+ 'datetime[]',
47
+ 'integer',
48
+ 'integer[]',
49
+ 'json',
50
+ 'json[]',
51
+ 'null',
52
+ 'null[]',
53
+ 'number',
54
+ 'number[]',
55
+ 'string',
56
+ 'string[]',
57
+ 'uuid',
58
+ 'uuid[]',
59
+ ];
60
+ class InvalidDotNotationPath extends Error {
61
+ }
62
+ class PsychicController {
63
+ /**
64
+ * @internal
65
+ *
66
+ * Used internally as a helpful distinguisher between controllers
67
+ * and non-controllers
68
+ */
69
+ static get isPsychicController() {
70
+ return true;
71
+ }
72
+ /**
73
+ * @internal
74
+ *
75
+ * Certain features (e.g. building OpenAPI specs from Attribute and RendersOne/Many decorators)
76
+ * need static access to things set up by decorators. Stage 3 Decorators change the context that is available
77
+ * at decoration time such that the class of a property being decorated is only avilable during instance instantiation. In order
78
+ * to only apply static values once, on boot, `globallyInitializingDecorators` is set to true on PsychicController,
79
+ * and all controllers are instantiated.
80
+ *
81
+ */
82
+ static globallyInitializingDecorators = false;
83
+ /**
84
+ * @internal
85
+ *
86
+ * Storage for controller action metadata, set when using the association decorators like:
87
+ * @OpenAPI
88
+ */
89
+ static controllerActionMetadata = {};
90
+ /**
91
+ * @internal
92
+ *
93
+ * Used to store controller hooks, which are registered
94
+ * by using the `@BeforeAction` decorator on your controllers
95
+ */
96
+ static controllerHooks = [];
97
+ /**
98
+ * @internal
99
+ *
100
+ * Used to store openapi data, which is registered
101
+ * by using the `@Openapi` decorator on your controller methods
102
+ */
103
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
+ static openapi;
105
+ /**
106
+ * Enables you to specify specific serializers to use
107
+ * when encountering specific models, i.e.
108
+ *
109
+ * ```ts
110
+ * class MyController extends AuthedController {
111
+ * static {
112
+ * this.serializes(User).with(UserCustomSerializer)
113
+ * }
114
+ * }
115
+ * ````
116
+ */
117
+ static serializes(ModelClass) {
118
+ return {
119
+ with: (SerializerClass) => {
120
+ exports.controllerSerializerIndex.add(this, SerializerClass, ModelClass);
121
+ return this;
122
+ },
123
+ };
124
+ }
125
+ /**
126
+ * @internal
127
+ *
128
+ * Returns the global identifier for this particular controller.
129
+ * When you first initialize your application, the controllers
130
+ * you provide are organized into a map of key-value pairs,
131
+ * where the keys are global identifiers for each controller, and
132
+ * the values are the matching controllers. The key returned here
133
+ * enables a lookup of the controller from the PsychicApplication
134
+ * class.
135
+ */
136
+ static get globalName() {
137
+ if (!this._globalName)
138
+ throw new dream_1.GlobalNameNotSet(this);
139
+ return this._globalName;
140
+ }
141
+ static setGlobalName(globalName) {
142
+ this._globalName = globalName;
143
+ }
144
+ static _globalName;
145
+ /**
146
+ * @internal
147
+ *
148
+ * Used for displaying routes when running `yarn psy routes`
149
+ * cli command
150
+ */
151
+ static get disaplayName() {
152
+ return this.globalName.replace(/^controllers\//, '').replace(/Controller$/, '');
153
+ }
154
+ /**
155
+ * @internal
156
+ *
157
+ * Returns a controller-action string which is used to signify both
158
+ * the controller and the method to be called for a particular route.
159
+ * For the controller "Api/V1/UsersController" and the method "show",
160
+ * the controllerActionPath would return:
161
+ *
162
+ * "Api/V1/Users#show"
163
+ */
164
+ static controllerActionPath(methodName) {
165
+ return `${this.globalName.replace(/^controllers\//, '').replace(/Controller$/, '')}#${methodName.toString()}`;
166
+ }
167
+ static get openapiNames() {
168
+ return ['default'];
169
+ }
170
+ static get openapiConfig() {
171
+ return {};
172
+ }
173
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
174
+ get psychicTypes() {
175
+ throw new Error('Must define psychicTypes getter in ApplicationController class within your application');
176
+ }
177
+ /**
178
+ * @internal
179
+ *
180
+ * Used internally as a helpful distinguisher between controllers
181
+ * and non-controllers
182
+ */
183
+ get isPsychicControllerInstance() {
184
+ return true;
185
+ }
186
+ req;
187
+ res;
188
+ session;
189
+ config;
190
+ action;
191
+ constructor(req, res, { config, action, }) {
192
+ this.req = req;
193
+ this.res = res;
194
+ this.config = config;
195
+ this.session = new index_js_1.default(req, res);
196
+ this.action = action;
197
+ }
198
+ get params() {
199
+ const params = {
200
+ ...this.req.params,
201
+ ...this.req.body,
202
+ ...this.req.query,
203
+ };
204
+ return params;
205
+ }
206
+ param(key) {
207
+ return this.params[key];
208
+ }
209
+ castParam(key, expectedType, opts) {
210
+ try {
211
+ return this._castParam(key.split('.'), this.params, expectedType, opts);
212
+ }
213
+ catch (error) {
214
+ if (error instanceof InvalidDotNotationPath)
215
+ throw new params_js_1.ParamValidationError(`Invalid dot notation in castParam: ${key}`);
216
+ throw error;
217
+ }
218
+ }
219
+ _castParam(keys, params, expectedType, opts) {
220
+ const key = keys.shift();
221
+ if (!keys.length)
222
+ return params_js_1.default.cast(params[key], expectedType, opts);
223
+ const nestedParams = params[key];
224
+ if (nestedParams === undefined) {
225
+ if (opts?.allowNull)
226
+ return null;
227
+ throw new InvalidDotNotationPath();
228
+ }
229
+ else if (Array.isArray(nestedParams)) {
230
+ throw new InvalidDotNotationPath();
231
+ }
232
+ else if (typeof nestedParams !== 'object') {
233
+ throw new InvalidDotNotationPath();
234
+ }
235
+ return this._castParam(keys, nestedParams, expectedType, opts);
236
+ }
237
+ paramsFor(dreamClass, opts) {
238
+ return params_js_1.default.for(opts?.key ? this.params[opts.key] || {} : this.params, dreamClass, opts);
239
+ }
240
+ getCookie(name) {
241
+ return (this.session.getCookie(name) ?? null);
242
+ }
243
+ setCookie(name, data, opts = {}) {
244
+ return this.session.setCookie(name, data, opts);
245
+ }
246
+ startSession(user) {
247
+ return this.setCookie(this.config.sessionCookieName, JSON.stringify({
248
+ id: user.primaryKeyValue,
249
+ modelKey: user.constructor.globalName,
250
+ }));
251
+ }
252
+ endSession() {
253
+ return this.session.clearCookie(this.config.sessionCookieName);
254
+ }
255
+ singleObjectJson(data, opts) {
256
+ if (!data)
257
+ return data;
258
+ const dreamApp = dream_1.DreamApplication.getOrFail();
259
+ const psychicControllerClass = this.constructor;
260
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
261
+ const lookup = exports.controllerSerializerIndex.lookupModel(this.constructor, data.constructor);
262
+ if (lookup?.length) {
263
+ const serializerClass = lookup?.[1];
264
+ if (typeof serializerClass === 'function' && serializerClass.isDreamSerializer) {
265
+ return new serializerClass(data).passthrough(this.defaultSerializerPassthrough).render();
266
+ }
267
+ }
268
+ else {
269
+ const serializerKey =
270
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
271
+ data.serializers?.[opts.serializerKey ||
272
+ psychicControllerClass['controllerActionMetadata'][this.action]?.['serializerKey'] ||
273
+ 'default'];
274
+ if (serializerKey && Object.prototype.hasOwnProperty.call(dreamApp.serializers, serializerKey)) {
275
+ const serializerClass = dreamApp.serializers[serializerKey];
276
+ if (typeof serializerClass === 'function' && serializerClass.isDreamSerializer) {
277
+ return new serializerClass(data).passthrough(this.defaultSerializerPassthrough).render();
278
+ }
279
+ else {
280
+ throw new Error(`
281
+ A serializer key was detected, but the server was unable to identify an associated serializer class matching the key.
282
+ The key in question is: "${serializerKey}"`);
283
+ }
284
+ }
285
+ }
286
+ return data;
287
+ }
288
+ json(data, opts = {}) {
289
+ if (Array.isArray(data))
290
+ return this.res.json(data.map(d =>
291
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
292
+ this.singleObjectJson(d, opts)));
293
+ return this.res.json(this.singleObjectJson(data, opts));
294
+ }
295
+ defaultSerializerPassthrough = {};
296
+ serializerPassthrough(passthrough) {
297
+ this.defaultSerializerPassthrough = {
298
+ ...this.defaultSerializerPassthrough,
299
+ ...passthrough,
300
+ };
301
+ }
302
+ respond(data = {}, opts = {}) {
303
+ const openapiData = this.constructor.openapi[this.action];
304
+ this.res.status(openapiData?.['status'] || 200);
305
+ this.json(data, opts);
306
+ }
307
+ send({ status = 200, body = undefined,
308
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
309
+ } = {}) {
310
+ // enums can also do a reverse-lookup based on values, so if e.g. 200 is passed as status,
311
+ // the lookup of HttpStatusCodeMap[status as HttpStatusSymbol] would return "ok", rather than undefined.
312
+ const realStatus = (typeof status_codes_js_1.default[status] === 'string'
313
+ ? status_codes_js_1.default[status_codes_js_1.default[status]]
314
+ : status_codes_js_1.default[status]);
315
+ this.res.status(realStatus).json(body);
316
+ }
317
+ redirect(path) {
318
+ this.res.redirect(path);
319
+ }
320
+ // begin: http status codes
321
+ // 200
322
+ ok(data = {}, opts = {}) {
323
+ this.json(data, opts);
324
+ }
325
+ // 201
326
+ created(data = {}, opts = {}) {
327
+ this.res.status(201);
328
+ this.json(data, opts);
329
+ }
330
+ // 202
331
+ accepted(data = {}, opts = {}) {
332
+ this.res.status(202);
333
+ this.json(data, opts);
334
+ }
335
+ // 203
336
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
337
+ nonAuthoritativeInformation(message = undefined) {
338
+ if (message) {
339
+ this.res.status(203).json(message);
340
+ }
341
+ else {
342
+ this.res.sendStatus(203);
343
+ }
344
+ }
345
+ // 204
346
+ noContent() {
347
+ this.res.sendStatus(204);
348
+ }
349
+ // 205
350
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
351
+ resetContent(message = undefined) {
352
+ this.res.status(205).send(message);
353
+ }
354
+ // 208
355
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
356
+ alreadyReported(message = undefined) {
357
+ this.res.status(208).send(message);
358
+ }
359
+ // 301
360
+ movedPermanently(newLocation) {
361
+ this.res.redirect(301, newLocation);
362
+ }
363
+ // 302
364
+ found(newLocation) {
365
+ this.res.redirect(302, newLocation);
366
+ }
367
+ // 303
368
+ seeOther(newLocation) {
369
+ this.res.redirect(303, newLocation);
370
+ }
371
+ // 304
372
+ notModified(newLocation) {
373
+ this.res.redirect(304, newLocation);
374
+ }
375
+ // 307
376
+ temporaryRedirect(newLocation) {
377
+ this.res.redirect(307, newLocation);
378
+ }
379
+ // 308
380
+ permanentRedirect(newLocation) {
381
+ this.res.redirect(308, newLocation);
382
+ }
383
+ // 400
384
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
385
+ badRequest(data = undefined) {
386
+ throw new BadRequest_js_1.default(data);
387
+ }
388
+ // 401
389
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
390
+ unauthorized(message = undefined) {
391
+ throw new Unauthorized_js_1.default(message);
392
+ }
393
+ // 402
394
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
395
+ paymentRequired(message = undefined) {
396
+ throw new PaymentRequired_js_1.default(message);
397
+ }
398
+ // 403
399
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
400
+ forbidden(message = undefined) {
401
+ throw new Forbidden_js_1.default(message);
402
+ }
403
+ // 404
404
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
405
+ notFound(message = undefined) {
406
+ throw new NotFound_js_1.default(message);
407
+ }
408
+ // 405
409
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
410
+ methodNotAllowed(message = undefined) {
411
+ throw new MethodNotAllowed_js_1.default(message);
412
+ }
413
+ // 406
414
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
415
+ notAcceptable(message = undefined) {
416
+ throw new NotAcceptable_js_1.default(message);
417
+ }
418
+ // 407
419
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
420
+ proxyAuthenticationRequired(message = undefined) {
421
+ throw new ProxyAuthenticationRequired_js_1.default(message);
422
+ }
423
+ // 409
424
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
425
+ conflict(message = undefined) {
426
+ throw new Conflict_js_1.default(message);
427
+ }
428
+ // 410
429
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
430
+ gone(message = undefined) {
431
+ throw new Gone_js_1.default(message);
432
+ }
433
+ // 412
434
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
435
+ preconditionFailed(message = undefined) {
436
+ throw new PreconditionFailed_js_1.default(message);
437
+ }
438
+ // 413
439
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
440
+ contentTooLarge(message = undefined) {
441
+ throw new ContentTooLarge_js_1.default(message);
442
+ }
443
+ // 415
444
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
445
+ unsupportedMediaType(message = undefined) {
446
+ throw new UnsupportedMediaType_js_1.default(message);
447
+ }
448
+ // 417
449
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
450
+ expectationFailed(message = undefined) {
451
+ throw new ExpectationFailed_js_1.default(message);
452
+ }
453
+ // 418
454
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
455
+ imATeampot(message = undefined) {
456
+ throw new ImATeapot_js_1.default(message);
457
+ }
458
+ // 421
459
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
460
+ misdirectedRequest(message = undefined) {
461
+ throw new MisdirectedRequest_js_1.default(message);
462
+ }
463
+ // 422
464
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
465
+ unprocessableContent(data = undefined) {
466
+ throw new UnprocessableContent_js_1.default(data);
467
+ }
468
+ // 423
469
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
470
+ locked(message = undefined) {
471
+ throw new Locked_js_1.default(message);
472
+ }
473
+ // 424
474
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
475
+ failedDependency(message = undefined) {
476
+ throw new FailedDependency_js_1.default(message);
477
+ }
478
+ // 428
479
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
480
+ preconditionRequired(message = undefined) {
481
+ throw new PreconditionRequired_js_1.default(message);
482
+ }
483
+ // 429
484
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
485
+ tooManyRequests(message = undefined) {
486
+ throw new TooManyRequests_js_1.default(message);
487
+ }
488
+ // 431
489
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
490
+ requestHeaderFieldsTooLarge(message = undefined) {
491
+ throw new RequestHeaderFieldsTooLarge_js_1.default(message);
492
+ }
493
+ // 451
494
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
495
+ unavailableForLegalReasons(message = undefined) {
496
+ throw new UnavailableForLegalReasons_js_1.default(message);
497
+ }
498
+ // 500
499
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
500
+ internalServerError(data = undefined) {
501
+ throw new InternalServerError_js_1.default(data);
502
+ }
503
+ // 501
504
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
505
+ notImplemented(message = undefined) {
506
+ throw new NotImplemented_js_1.default(message);
507
+ }
508
+ // 502
509
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
510
+ badGateway(message = undefined) {
511
+ throw new BadGateway_js_1.default(message);
512
+ }
513
+ // 503
514
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
515
+ serviceUnavailable(message = undefined) {
516
+ throw new ServiceUnavailable_js_1.default(message);
517
+ }
518
+ // 504
519
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
520
+ gatewayTimeout(message = undefined) {
521
+ throw new GatewayTimeout_js_1.default(message);
522
+ }
523
+ // 507
524
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
525
+ insufficientStorage(message = undefined) {
526
+ throw new InsufficientStorage_js_1.default(message);
527
+ }
528
+ // 510
529
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
530
+ notExtended(message = undefined) {
531
+ throw new NotExtended_js_1.default(message);
532
+ }
533
+ // end: http status codes
534
+ async runAction(action) {
535
+ await this.runBeforeActionsFor(action);
536
+ if (this.res.headersSent)
537
+ return;
538
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
539
+ await this[action]();
540
+ }
541
+ async runBeforeActionsFor(action) {
542
+ const beforeActions = this.constructor.controllerHooks.filter(hook => hook.shouldFireForAction(action));
543
+ for (const hook of beforeActions) {
544
+ if (this.res.headersSent)
545
+ return;
546
+ if (hook.isStatic) {
547
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
548
+ await this.constructor[hook.methodName]();
549
+ }
550
+ else {
551
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
552
+ await this[hook.methodName]();
553
+ }
554
+ }
555
+ }
556
+ }
557
+ exports.default = PsychicController;
558
+ class ControllerSerializerIndex {
559
+ associations = [];
560
+ add(ControllerClass, SerializerClass, ModelClass) {
561
+ this.associations.push([ControllerClass, SerializerClass, ModelClass]);
562
+ }
563
+ lookupModel(ControllerClass, ModelClass) {
564
+ return this.associations.find(association => association[0] === ControllerClass && association[2] === ModelClass);
565
+ }
566
+ lookupSerializer(ControllerClass, SerializerClass) {
567
+ return this.associations.find(association => association[0] === ControllerClass && association[1] === SerializerClass);
568
+ }
569
+ }
570
+ exports.ControllerSerializerIndex = ControllerSerializerIndex;
571
+ exports.controllerSerializerIndex = new ControllerSerializerIndex();
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dream_1 = require("@rvoh/dream");
4
+ const missing_cookie_encryption_options_js_1 = require("../error/encrypt/missing-cookie-encryption-options.js");
5
+ const index_js_1 = require("../psychic-application/index.js");
6
+ class InternalEncrypt {
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ static encryptCookie(data) {
9
+ const psychicApp = index_js_1.default.getOrFail();
10
+ const encryptOpts = psychicApp.encryption?.cookies;
11
+ if (!encryptOpts)
12
+ throw new missing_cookie_encryption_options_js_1.default();
13
+ if (data === null || data === undefined)
14
+ return null;
15
+ return this.doEncryption(data, encryptOpts.current);
16
+ }
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ static decryptCookie(data) {
19
+ const psychicApp = index_js_1.default.getOrFail();
20
+ const encryptOpts = psychicApp.encryption?.cookies;
21
+ if (!encryptOpts)
22
+ throw new missing_cookie_encryption_options_js_1.default();
23
+ if (data === null || data === undefined)
24
+ return null;
25
+ return this.doDecryption(data, encryptOpts.current, encryptOpts.legacy);
26
+ }
27
+ static doEncryption(
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ data, encryptionOpts) {
30
+ return dream_1.Encrypt.encrypt(data, encryptionOpts);
31
+ }
32
+ static doDecryption(
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ data, encryptionOpts, legacyEncryptionOpts) {
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
36
+ let decrypted = dream_1.Encrypt.decrypt(data, encryptionOpts);
37
+ if (decrypted === null && legacyEncryptionOpts)
38
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
39
+ decrypted = dream_1.Encrypt.decrypt(data, legacyEncryptionOpts);
40
+ return decrypted;
41
+ }
42
+ }
43
+ exports.default = InternalEncrypt;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dotenv = require("dotenv");
4
+ const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
5
+ class EnvLoader {
6
+ loaded = false;
7
+ load() {
8
+ if (this.loaded)
9
+ return;
10
+ dotenv.config({ path: EnvInternal_js_1.default.isTest ? '.env.test' : '.env' });
11
+ this.check();
12
+ }
13
+ ensureLoaded() {
14
+ if (!this.loaded)
15
+ this.load();
16
+ }
17
+ check() {
18
+ // const missingEnvs: string[] = []
19
+ // if (!process.env.APP_ENCRYPTION_KEY) missingEnvs.push('APP_ENCRYPTION_KEY')
20
+ //
21
+ // if (!!missingEnvs.length)
22
+ // throw `Must make sure the following env vars are set before starting the psychic server: \n${missingEnvs.join(",\n ")}`
23
+ }
24
+ }
25
+ const envLoader = new EnvLoader();
26
+ exports.default = envLoader;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_js_1 = require("./index.js");
4
+ class DBFailedToConnect extends index_js_1.default {
5
+ constructor(error) {
6
+ super(`
7
+ Failed to connect to the database using the credentials located at:
8
+
9
+ conf/db.ts
10
+
11
+ Please check that your credentials are valid, and then try again.
12
+ The underlying error that triggered this message was:
13
+ ${error.message}
14
+ `);
15
+ }
16
+ }
17
+ exports.default = DBFailedToConnect;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class DBError extends Error {
4
+ _message;
5
+ constructor(message) {
6
+ super();
7
+ this._message = message;
8
+ }
9
+ get message() {
10
+ return `
11
+ A Database error occured, causing psychic to crash. The message recieved was:
12
+ ${this._message}
13
+ `;
14
+ }
15
+ }
16
+ exports.default = DBError;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_js_1 = require("./index.js");
4
+ class DBMissingOptions extends index_js_1.default {
5
+ constructor(error) {
6
+ super(`
7
+ Failed to locate the database options required to bootstrap your psychic app.
8
+ Please make sure the following file is present in your app:
9
+
10
+ conf/db.ts
11
+
12
+ the underlying error that triggered this message was:
13
+ ${error.message}
14
+ `);
15
+ }
16
+ }
17
+ exports.default = DBMissingOptions;