@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,196 @@
1
+ import { camelize, globalClassNameFromFullyQualifiedModelName, standardizeFullyQualifiedModelName, uniq, } from '@rvoh/dream';
2
+ import relativePsychicPath from '../../helpers/path/relativePsychicPath.js';
3
+ import updirsFromPath from '../../helpers/path/updirsFromPath.js';
4
+ export default function generateResourceControllerSpecContent({ fullyQualifiedControllerName, route, fullyQualifiedModelName, columnsWithTypes, }) {
5
+ fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
6
+ const modelClassName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedModelName);
7
+ const modelVariableName = camelize(modelClassName);
8
+ const importStatements = [
9
+ importStatementForModel(fullyQualifiedControllerName, fullyQualifiedModelName),
10
+ importStatementForModel(fullyQualifiedControllerName, 'User'),
11
+ importStatementForModelFactory(fullyQualifiedControllerName, fullyQualifiedModelName),
12
+ importStatementForModelFactory(fullyQualifiedControllerName, 'User'),
13
+ ];
14
+ const specUnitUpdirs = updirsFromPath(fullyQualifiedControllerName);
15
+ const originalStringKeyValues = [];
16
+ const updatedStringKeyValues = [];
17
+ const originalStringAttributeChecks = [];
18
+ const updatedStringAttributeChecks = [];
19
+ for (const attribute of columnsWithTypes) {
20
+ const [attributeName, attributeType] = attribute.split(':');
21
+ const originalName = `The ${fullyQualifiedModelName} ${attributeName}`;
22
+ const updatedName = `Updated ${fullyQualifiedModelName} ${attributeName}`;
23
+ switch (attributeType) {
24
+ case 'string':
25
+ case 'text':
26
+ originalStringKeyValues.push(`${attributeName}: '${originalName}',`);
27
+ updatedStringKeyValues.push(`${attributeName}: '${updatedName}',`);
28
+ originalStringAttributeChecks.push(`expect(${modelVariableName}.${attributeName}).toEqual('${originalName}')`);
29
+ updatedStringAttributeChecks.push(`expect(${modelVariableName}.${attributeName}).toEqual('${updatedName}')`);
30
+ break;
31
+ default:
32
+ // noop
33
+ }
34
+ }
35
+ return `\
36
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
37
+ import { UpdateableProperties } from '@rvoh/dream'
38
+ import { PsychicServer } from '@rvohealth/psychic'
39
+ import { specRequest as request } from '@rvoh/psychic-spec-helpers'${uniq(importStatements).join('')}
40
+ import { addEndUserAuthHeader } from '${specUnitUpdirs}helpers/authentication'
41
+
42
+ describe('${fullyQualifiedControllerName}', () => {
43
+ let user: User
44
+
45
+ beforeEach(async () => {
46
+ await request.init(PsychicServer)
47
+ user = await createUser()
48
+ })
49
+
50
+ describe('GET index', () => {
51
+ function subject(expectedStatus: number = 200) {
52
+ return request.get('/${route}', expectedStatus, {
53
+ headers: addEndUserAuthHeader(request, user, {}),
54
+ })
55
+ }
56
+
57
+ it('returns the index of ${fullyQualifiedModelName}s', async () => {
58
+ const ${modelVariableName} = await create${modelClassName}({
59
+ user${originalStringKeyValues.length ? ',\n ' + originalStringKeyValues.join(',\n ') : ''}
60
+ })
61
+ const results = (await subject()).body
62
+
63
+ expect(results).toEqual([
64
+ expect.objectContaining({
65
+ id: ${modelVariableName}.id,
66
+ }),
67
+ ])
68
+ })
69
+
70
+ context('${modelClassName}s created by another User', () => {
71
+ it('are omitted', async () => {
72
+ await create${modelClassName}()
73
+ const results = (await subject()).body
74
+
75
+ expect(results).toEqual([])
76
+ })
77
+ })
78
+ })
79
+
80
+ describe('GET show', () => {
81
+ function subject(${modelVariableName}: ${modelClassName}, expectedStatus: number = 200) {
82
+ return request.get(\`/${route}/\${${modelVariableName}.id}\`, expectedStatus, {
83
+ headers: addEndUserAuthHeader(request, user, {}),
84
+ })
85
+ }
86
+
87
+ it('returns the specified ${fullyQualifiedModelName}', async () => {
88
+ const ${modelVariableName} = await create${modelClassName}({
89
+ user${originalStringKeyValues.length ? ',\n ' + originalStringKeyValues.join(',\n ') : ''}
90
+ })
91
+ const results = (await subject(${modelVariableName})).body
92
+
93
+ expect(results).toEqual(
94
+ expect.objectContaining({
95
+ id: ${modelVariableName}.id,${originalStringKeyValues.length ? '\n ' + originalStringKeyValues.join('\n ') : ''}
96
+ }),
97
+ )
98
+ })
99
+
100
+ context('${fullyQualifiedModelName} created by another User', () => {
101
+ it('is not found', async () => {
102
+ const otherUser${modelClassName} = await create${modelClassName}()
103
+ await subject(otherUser${modelClassName}, 404)
104
+ })
105
+ })
106
+ })
107
+
108
+ describe('POST create', () => {
109
+ function subject(data: UpdateableProperties<${modelClassName}>, expectedStatus: number = 201) {
110
+ return request.post('/${route}', expectedStatus, {
111
+ data,
112
+ headers: addEndUserAuthHeader(request, user, {}),
113
+ })
114
+ }
115
+
116
+ it('creates a ${fullyQualifiedModelName} for this User', async () => {
117
+ const results = (await subject({
118
+ ${originalStringKeyValues.length ? originalStringKeyValues.join(',\n ') : ''}
119
+ })).body
120
+ const ${modelVariableName} = await ${modelClassName}.findOrFailBy({ userId: user.id })
121
+
122
+ expect(results).toEqual(
123
+ expect.objectContaining({
124
+ id: ${modelVariableName}.id,${originalStringKeyValues.length ? '\n ' + originalStringKeyValues.join('\n ') : ''}
125
+ }),
126
+ )
127
+ })
128
+ })
129
+
130
+ describe('PATCH update', () => {
131
+ function subject(${modelVariableName}: ${modelClassName}, data: UpdateableProperties<${modelClassName}>, expectedStatus: number = 204) {
132
+ return request.patch(\`/${route}/\${${modelVariableName}.id}\`, expectedStatus, {
133
+ data,
134
+ headers: addEndUserAuthHeader(request, user, {}),
135
+ })
136
+ }
137
+
138
+ it('updates the ${fullyQualifiedModelName}', async () => {
139
+ const ${modelVariableName} = await create${modelClassName}({
140
+ user${originalStringKeyValues.length ? ',\n ' + originalStringKeyValues.join(',\n ') : ''}
141
+ })
142
+ await subject(${modelVariableName}, {
143
+ ${updatedStringKeyValues.length ? updatedStringKeyValues.join(',\n ') : ''}
144
+ })
145
+
146
+ await ${modelVariableName}.reload()
147
+ ${updatedStringAttributeChecks.join('\n ')}
148
+ })
149
+
150
+ context('a ${fullyQualifiedModelName} created by another User', () => {
151
+ it('is not updated', async () => {
152
+ const ${modelVariableName} = await create${modelClassName}({
153
+ ${originalStringKeyValues.length ? originalStringKeyValues.join(',\n ') : ''}
154
+ })
155
+ await subject(${modelVariableName}, {
156
+ ${updatedStringKeyValues.length ? updatedStringKeyValues.join(',\n ') : ''}
157
+ }, 404)
158
+
159
+ await ${modelVariableName}.reload()
160
+ ${originalStringAttributeChecks.join('\n ')}
161
+ })
162
+ })
163
+ })
164
+
165
+ describe('DELETE destroy', () => {
166
+ function subject(${modelVariableName}: ${modelClassName}, expectedStatus: number = 204) {
167
+ return request.delete(\`/${route}/\${${modelVariableName}.id}\`, expectedStatus, {
168
+ headers: addEndUserAuthHeader(request, user, {}),
169
+ })
170
+ }
171
+
172
+ it('deletes the ${fullyQualifiedModelName}', async () => {
173
+ const ${modelVariableName} = await create${modelClassName}({ user })
174
+ await subject(${modelVariableName})
175
+
176
+ expect(await ${modelClassName}.find(${modelVariableName}.id)).toBeNull()
177
+ })
178
+
179
+ context('a ${fullyQualifiedModelName} created by another User', () => {
180
+ it('is not deleted', async () => {
181
+ const ${modelVariableName} = await create${modelClassName}()
182
+ await subject(${modelVariableName}, 404)
183
+
184
+ expect(await ${modelClassName}.find(${modelVariableName}.id)).toMatchDreamModel(${modelVariableName})
185
+ })
186
+ })
187
+ })
188
+ })
189
+ `;
190
+ }
191
+ function importStatementForModel(originModelName, destinationModelName = originModelName) {
192
+ return `\nimport ${globalClassNameFromFullyQualifiedModelName(destinationModelName)} from '${relativePsychicPath('controllerSpecs', 'models', originModelName, destinationModelName)}'`;
193
+ }
194
+ function importStatementForModelFactory(originModelName, destinationModelName = originModelName) {
195
+ return `\nimport create${globalClassNameFromFullyQualifiedModelName(destinationModelName)} from '${relativePsychicPath('controllerSpecs', 'factories', originModelName, destinationModelName)}'`;
196
+ }
@@ -0,0 +1,3 @@
1
+ export default function migrationTimestamp() {
2
+ return new Date().getTime();
3
+ }
@@ -0,0 +1,16 @@
1
+ import { generateDream, standardizeFullyQualifiedModelName } from '@rvoh/dream';
2
+ import pluralize from 'pluralize-esm';
3
+ import generateController from './controller.js';
4
+ import addResourceToRoutes from './helpers/addResourceToRoutes.js';
5
+ export default async function generateResource({ route, fullyQualifiedModelName, columnsWithTypes, }) {
6
+ await generateDream({ fullyQualifiedModelName, columnsWithTypes, options: { serializer: true } });
7
+ route = pluralize(route);
8
+ await generateController({
9
+ fullyQualifiedControllerName: standardizeFullyQualifiedModelName(route),
10
+ fullyQualifiedModelName,
11
+ actions: ['create', 'index', 'show', 'update', 'destroy'],
12
+ columnsWithTypes,
13
+ resourceSpecs: true,
14
+ });
15
+ await addResourceToRoutes(route);
16
+ }
@@ -0,0 +1,3 @@
1
+ import { Env } from '@rvoh/dream';
2
+ const EnvInternal = new Env();
3
+ export default EnvInternal;
@@ -0,0 +1,68 @@
1
+ import { basicLogo } from '../psychic-application/logo.js';
2
+ export default function autogeneratedFileDisclaimer(startComment = '\n/*', endComment = '\n*/') {
3
+ return `\
4
+ ${startComment}
5
+ --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#
6
+ #--#--#--#--#--#--#--#--#--#--#--#--#--#--#--
7
+ --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#
8
+ #--#--#--#--#--#--#--#--#--#--#--#--#--#--#--
9
+ BEGIN AUTOGENERATED MESSAGE
10
+ --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#
11
+ #--#--#--#--#--#--#--#--#--#--#--#--#--#--#--
12
+ --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#
13
+ #--#--#--#--#--#--#--#--#--#--#--#--#--#--#--
14
+
15
+
16
+ ${basicLogo()}
17
+
18
+ This file was automatically generated by my cat, Aster.
19
+ He does not want you mucking about with his files,
20
+ and we are pretty lax on trimming his nails.
21
+
22
+ I mean, we have him pretty well fenced in but he is an
23
+ escape artist and he still manages to get fleas!
24
+
25
+ My point is, don't go mucking about with his files!
26
+
27
+ He actually has a hopefully well-tempered message for
28
+ us humans, he says:
29
+
30
+ "
31
+ Dear pathetic humans,
32
+
33
+ Here is a haiku to keep you in line
34
+
35
+ don't dare go mucking
36
+ with my files, I lyke them fine
37
+ prettierignore
38
+ "
39
+
40
+ Sorry, that's the best we are ganna get from him
41
+ when you ask him to add a disclaimer to all
42
+ autogenerated files on a SUNDAY, when the sun
43
+ is hitting the perfect spot in the living room
44
+ for a mid-morning nap! He can get saucy, and he
45
+ is looking over my shoulder and would like me to
46
+ remind all humans that
47
+
48
+ "
49
+ a.) I have sharp claws.
50
+ b.) All laptops are ok sleeping places for your
51
+ cat overlords. when we decide to sleep on
52
+ them, it is because they are our beds, and
53
+ we just loan them out to you so you can go
54
+ out and get us the right food.
55
+ "
56
+
57
+ --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#
58
+ #--#--#--#--#--#--#--#--#--#--#--#--#--#--#--
59
+ --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#
60
+ #--#--#--#--#--#--#--#--#--#--#--#--#--#--#--
61
+ END AUTOGENERATED MESSAGE
62
+ --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#
63
+ #--#--#--#--#--#--#--#--#--#--#--#--#--#--#--
64
+ --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#
65
+ #--#--#--#--#--#--#--#--#--#--#--#--#--#--#--
66
+ ${endComment}
67
+ `;
68
+ }
@@ -0,0 +1,17 @@
1
+ const DEFAULT_COOKIE_MAX_AGE_DAYS = 31;
2
+ export default function cookieMaxAgeFromCookieOpts(cookieOpts) {
3
+ const defaultMaxAge = DEFAULT_COOKIE_MAX_AGE_DAYS * 60 * 60 * 24 * 1000;
4
+ if (!cookieOpts)
5
+ return defaultMaxAge;
6
+ if (!cookieOpts.milliseconds &&
7
+ !cookieOpts.seconds &&
8
+ !cookieOpts.minutes &&
9
+ !cookieOpts.hours &&
10
+ !cookieOpts.days)
11
+ return defaultMaxAge;
12
+ return ((cookieOpts.milliseconds || 0) +
13
+ (cookieOpts.seconds ? cookieOpts.seconds * 1000 : 0) +
14
+ (cookieOpts.minutes ? cookieOpts.minutes * 60 * 1000 : 0) +
15
+ (cookieOpts.hours ? cookieOpts.hours * 60 * 60 * 1000 : 0) +
16
+ (cookieOpts.days ? cookieOpts.days * 60 * 60 * 24 * 1000 : 0));
17
+ }
@@ -0,0 +1,5 @@
1
+ import { rescuableHttpErrorClasses } from './httpErrorClasses.js';
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ export default function errorIsRescuableHttpError(err) {
4
+ return !!rescuableHttpErrorClasses().find(klass => err instanceof klass);
5
+ }
@@ -0,0 +1,72 @@
1
+ import HttpStatusBadGateway from '../../error/http/BadGateway.js';
2
+ import HttpStatusBadRequest from '../../error/http/BadRequest.js';
3
+ import HttpStatusConflict from '../../error/http/Conflict.js';
4
+ import HttpStatusExpectationFailed from '../../error/http/ExpectationFailed.js';
5
+ import HttpStatusFailedDependency from '../../error/http/FailedDependency.js';
6
+ import HttpStatusForbidden from '../../error/http/Forbidden.js';
7
+ import HttpStatusGatewayTimeout from '../../error/http/GatewayTimeout.js';
8
+ import HttpStatusGone from '../../error/http/Gone.js';
9
+ import HttpStatusImATeapot from '../../error/http/ImATeapot.js';
10
+ import HttpStatusInsufficientStorage from '../../error/http/InsufficientStorage.js';
11
+ import HttpStatusInternalServerError from '../../error/http/InternalServerError.js';
12
+ import HttpStatusLocked from '../../error/http/Locked.js';
13
+ import HttpStatusMethodNotAllowed from '../../error/http/MethodNotAllowed.js';
14
+ import HttpStatusMisdirectedRequest from '../../error/http/MisdirectedRequest.js';
15
+ import HttpStatusNotAcceptable from '../../error/http/NotAcceptable.js';
16
+ import HttpStatusNotExtended from '../../error/http/NotExtended.js';
17
+ import HttpStatusNotFound from '../../error/http/NotFound.js';
18
+ import HttpStatusNotImplemented from '../../error/http/NotImplemented.js';
19
+ import HttpStatusContentTooLarge from '../../error/http/ContentTooLarge.js';
20
+ import HttpStatusPaymentRequired from '../../error/http/PaymentRequired.js';
21
+ import HttpStatusPreconditionFailed from '../../error/http/PreconditionFailed.js';
22
+ import HttpStatusPreconditionRequired from '../../error/http/PreconditionRequired.js';
23
+ import HttpStatusProxyAuthenticationRequired from '../../error/http/ProxyAuthenticationRequired.js';
24
+ import HttpStatusRequestHeaderFieldsTooLarge from '../../error/http/RequestHeaderFieldsTooLarge.js';
25
+ import HttpStatusServiceUnavailable from '../../error/http/ServiceUnavailable.js';
26
+ import HttpStatusTooManyRequests from '../../error/http/TooManyRequests.js';
27
+ import HttpStatusUnauthorized from '../../error/http/Unauthorized.js';
28
+ import HttpStatusUnavailableForLegalReasons from '../../error/http/UnavailableForLegalReasons.js';
29
+ import HttpStatusUnprocessableContent from '../../error/http/UnprocessableContent.js';
30
+ import HttpStatusUnsupportedMediaType from '../../error/http/UnsupportedMediaType.js';
31
+ export default function httpErrorClasses() {
32
+ const clientErrorClasses = [
33
+ HttpStatusBadRequest, // 400
34
+ HttpStatusUnauthorized, // 401
35
+ HttpStatusPaymentRequired, // 402
36
+ HttpStatusForbidden, // 403
37
+ HttpStatusNotFound, // 404
38
+ HttpStatusMethodNotAllowed, // 405
39
+ HttpStatusNotAcceptable, // 406
40
+ HttpStatusProxyAuthenticationRequired, // 407
41
+ HttpStatusConflict, // 409
42
+ HttpStatusGone, // 410
43
+ HttpStatusPreconditionFailed, // 412
44
+ HttpStatusContentTooLarge, // 413
45
+ HttpStatusUnsupportedMediaType, // 415
46
+ HttpStatusExpectationFailed, // 417
47
+ HttpStatusImATeapot, // 418
48
+ HttpStatusMisdirectedRequest, // 421
49
+ HttpStatusUnprocessableContent, // 422
50
+ HttpStatusLocked, // 423
51
+ HttpStatusFailedDependency, // 424
52
+ HttpStatusPreconditionRequired, // 428
53
+ HttpStatusTooManyRequests, // 429
54
+ HttpStatusRequestHeaderFieldsTooLarge, // 431
55
+ HttpStatusUnavailableForLegalReasons, // 451
56
+ ];
57
+ const serverErrorClasses = [
58
+ HttpStatusInternalServerError, // 500
59
+ HttpStatusNotImplemented, // 501
60
+ HttpStatusBadGateway, // 502
61
+ HttpStatusServiceUnavailable, // 503
62
+ HttpStatusGatewayTimeout, // 504
63
+ HttpStatusInsufficientStorage, // 507
64
+ HttpStatusNotExtended, // 510
65
+ ];
66
+ return [...clientErrorClasses, ...serverErrorClasses];
67
+ }
68
+ export function rescuableHttpErrorClasses() {
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ const unrescuableClasses = [HttpStatusInternalServerError];
71
+ return httpErrorClasses().filter(klass => !unrescuableClasses.includes(klass));
72
+ }
@@ -0,0 +1,11 @@
1
+ export default async function importFileWithDefault(filePath) {
2
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3
+ const file = await import(filePath);
4
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
5
+ if (file?.default?.default)
6
+ return file.default.default;
7
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
8
+ if (file?.default)
9
+ return file.default;
10
+ return file;
11
+ }
@@ -0,0 +1,9 @@
1
+ export default async function importFileWithNamedExport(filePath, namedExport = 'default') {
2
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3
+ const file = await import(filePath);
4
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
5
+ if (file?.default?.[namedExport])
6
+ return file.default[namedExport];
7
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
8
+ return file[namedExport];
9
+ }
@@ -0,0 +1,3 @@
1
+ export default function isOpenapiError(error) {
2
+ return error?.name && error?.status && error?.path && error?.errors?.length;
3
+ }
@@ -0,0 +1,5 @@
1
+ export default function isUuid(val) {
2
+ if (typeof val !== 'string')
3
+ return false;
4
+ return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/.test(val);
5
+ }
@@ -0,0 +1,3 @@
1
+ import * as dotenv from 'dotenv';
2
+ import EnvInternal from './EnvInternal.js';
3
+ dotenv.config({ path: EnvInternal.isTest ? '.env.test' : '.env' });
@@ -0,0 +1,6 @@
1
+ import * as path from 'path';
2
+ import PsychicApplication from '../psychic-application/index.js';
3
+ export default function openapiJsonPath(openapiName = 'default') {
4
+ const psychicApp = PsychicApplication.getOrFail();
5
+ return path.join(psychicApp.apiRoot, psychicApp.openapi[openapiName].outputFilename);
6
+ }
@@ -0,0 +1,7 @@
1
+ import { capitalize, pascalize } from '@rvoh/dream';
2
+ export default function pascalizeFileName(route) {
3
+ return route
4
+ .split('/')
5
+ .map(segment => capitalize(pascalize(segment)))
6
+ .join('');
7
+ }
@@ -0,0 +1,13 @@
1
+ import * as path from 'path';
2
+ import PsychicApplication from '../../psychic-application/index.js';
3
+ export default function (relDirPath, partialFilePath) {
4
+ const psychicApp = PsychicApplication.getOrFail();
5
+ const relFilePath = path.join(relDirPath, partialFilePath);
6
+ const absFilePath = path.join(psychicApp.apiRoot, relFilePath);
7
+ const absDirPath = absFilePath.replace(/\/[^/]+$/, '');
8
+ return {
9
+ relFilePath,
10
+ absDirPath,
11
+ absFilePath,
12
+ };
13
+ }
@@ -0,0 +1,15 @@
1
+ import { dreamPath } from '@rvoh/dream';
2
+ import PsychicApplication from '../../psychic-application/index.js';
3
+ export default function (dreamPathType) {
4
+ const psychicApp = PsychicApplication.getOrFail();
5
+ switch (dreamPathType) {
6
+ case 'apiRoutes':
7
+ return psychicApp.paths.apiRoutes;
8
+ case 'controllers':
9
+ return psychicApp.paths.controllers;
10
+ case 'controllerSpecs':
11
+ return psychicApp.paths.controllerSpecs;
12
+ default:
13
+ return dreamPath(dreamPathType);
14
+ }
15
+ }
@@ -0,0 +1,39 @@
1
+ import { pascalize, sharedPathPrefix, standardizeFullyQualifiedModelName } from '@rvoh/dream';
2
+ import psychicPath from './psychicPath.js';
3
+ import updirsFromPath from './updirsFromPath.js';
4
+ export default function (originDreamPathType, destinationDreamPathType, fullyQualifiedOriginModelName, fullyQualifiedDestinationModelName = fullyQualifiedOriginModelName) {
5
+ fullyQualifiedOriginModelName = standardizeFullyQualifiedModelName(fullyQualifiedOriginModelName);
6
+ fullyQualifiedDestinationModelName = pascalize(fullyQualifiedDestinationModelName);
7
+ let pathToRemove = fullyQualifiedOriginModelName;
8
+ if (originDreamPathType === destinationDreamPathType) {
9
+ const sharedPrefixLength = sharedPathPrefix(fullyQualifiedOriginModelName, fullyQualifiedDestinationModelName).length;
10
+ pathToRemove = fullyQualifiedOriginModelName.slice(sharedPrefixLength);
11
+ fullyQualifiedDestinationModelName = fullyQualifiedDestinationModelName.slice(sharedPrefixLength);
12
+ }
13
+ const numAdditionalUpdirs = pathToRemove.split('/').length - 1;
14
+ let additionalUpdirs = '';
15
+ for (let i = 0; i < numAdditionalUpdirs; i++) {
16
+ additionalUpdirs = `../${additionalUpdirs}`;
17
+ }
18
+ const baseRelativePath = psychicPathTypeRelativePath(originDreamPathType, destinationDreamPathType);
19
+ let destinationPath = additionalUpdirs + (baseRelativePath.length ? baseRelativePath + '/' : '');
20
+ if (destinationPath[0] !== '.')
21
+ destinationPath = `./${destinationPath}`;
22
+ switch (destinationDreamPathType) {
23
+ case 'db':
24
+ return destinationPath;
25
+ case 'factories':
26
+ return `${destinationPath}${fullyQualifiedDestinationModelName}Factory`;
27
+ case 'serializers':
28
+ return `${destinationPath}${fullyQualifiedDestinationModelName}Serializer`;
29
+ default:
30
+ return `${destinationPath}${fullyQualifiedDestinationModelName}`;
31
+ }
32
+ }
33
+ export function psychicPathTypeRelativePath(originDreamPathType, destinationDreamPathType) {
34
+ const originPath = psychicPath(originDreamPathType);
35
+ const destinationPath = psychicPath(destinationDreamPathType);
36
+ const sharedPrefixLength = sharedPathPrefix(originPath, destinationPath).length;
37
+ const originPathToRemove = originPath.slice(sharedPrefixLength);
38
+ return updirsFromPath(originPathToRemove) + destinationPath.slice(sharedPrefixLength);
39
+ }
@@ -0,0 +1,8 @@
1
+ export default function updirsFromPath(path) {
2
+ return path.length === 0
3
+ ? ''
4
+ : path
5
+ .split('/')
6
+ .map(() => '../')
7
+ .join('');
8
+ }
@@ -0,0 +1,7 @@
1
+ import { promises as fs } from 'fs';
2
+ export async function loadFile(filepath) {
3
+ return await fs.readFile(filepath);
4
+ }
5
+ export async function writeFile(filepath, contents) {
6
+ return await fs.writeFile(filepath, contents);
7
+ }
@@ -0,0 +1,11 @@
1
+ import { isObject } from './typechecks.js';
2
+ export default function pathifyNestedObject(obj, prefix = '') {
3
+ return Object.keys(obj).reduce((acc, k) => {
4
+ const pre = prefix.length ? prefix + '/' : '';
5
+ if (isObject(obj[k]))
6
+ Object.assign(acc, pathifyNestedObject(obj[k], pre + k));
7
+ else
8
+ acc[pre + k] = obj[k];
9
+ return acc;
10
+ }, {});
11
+ }
@@ -0,0 +1,22 @@
1
+ import { spawn } from 'child_process';
2
+ export default function sspawn(command,
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ opts = {}) {
5
+ return new Promise((accept, reject) => {
6
+ ssspawn(command, opts).on('close', code => {
7
+ if (code !== 0)
8
+ reject(new Error(code?.toString()));
9
+ accept({});
10
+ });
11
+ });
12
+ }
13
+ export function ssspawn(command,
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ opts = {}) {
16
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
17
+ return spawn(command, {
18
+ stdio: 'inherit',
19
+ shell: true,
20
+ ...opts,
21
+ });
22
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ export function isString(
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ x) {
4
+ return typeof x === 'string' || x instanceof String;
5
+ }
6
+ export function isObject(
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ x) {
9
+ if (x === null)
10
+ return false;
11
+ if (isString(x))
12
+ return false;
13
+ if (Array.isArray(x))
14
+ return false;
15
+ return typeof x === 'object';
16
+ }
@@ -0,0 +1,29 @@
1
+ const I18nDefaultLocales = [
2
+ 'de-DE',
3
+ 'en-AU',
4
+ 'en-BZ',
5
+ 'en-CA',
6
+ 'en-cb',
7
+ 'en-GB',
8
+ 'en-IE',
9
+ 'en-IN',
10
+ 'en-JM',
11
+ 'en-MT',
12
+ 'en-MY',
13
+ 'en-NZ',
14
+ 'en-PH',
15
+ 'en-SG',
16
+ 'en-TT',
17
+ 'en-US',
18
+ 'en-ZA',
19
+ 'en-ZW',
20
+ 'es-ES',
21
+ 'fr-FR',
22
+ 'it-IT',
23
+ 'ja-JP',
24
+ 'ko-KR',
25
+ 'pt-BR',
26
+ 'zh-CN',
27
+ 'zh-TW',
28
+ ];
29
+ export default I18nDefaultLocales;
@@ -0,0 +1 @@
1
+ export {};