@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.
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/cjs/src/bin/helpers/enumsAndTheirValues.js +17 -0
- package/dist/cjs/src/bin/helpers/enumsFileStr.js +21 -0
- package/dist/cjs/src/bin/helpers/generateRouteTypes.js +16 -0
- package/dist/cjs/src/bin/helpers/printRoutes.js +54 -0
- package/dist/cjs/src/bin/index.js +79 -0
- package/dist/cjs/src/cli/helpers/TypesBuilder.js +26 -0
- package/dist/cjs/src/cli/index.js +76 -0
- package/dist/cjs/src/controller/decorators.js +85 -0
- package/dist/cjs/src/controller/hooks.js +29 -0
- package/dist/cjs/src/controller/index.js +571 -0
- package/dist/cjs/src/encrypt/internal-encrypt.js +43 -0
- package/dist/cjs/src/env/Loader.js +26 -0
- package/dist/cjs/src/error/db/failed-to-connect.js +17 -0
- package/dist/cjs/src/error/db/index.js +16 -0
- package/dist/cjs/src/error/db/missing-options.js +17 -0
- package/dist/cjs/src/error/encrypt/missing-cookie-encryption-options.js +27 -0
- package/dist/cjs/src/error/http/BadGateway.js +9 -0
- package/dist/cjs/src/error/http/BadRequest.js +9 -0
- package/dist/cjs/src/error/http/Conflict.js +9 -0
- package/dist/cjs/src/error/http/ContentTooLarge.js +9 -0
- package/dist/cjs/src/error/http/ExpectationFailed.js +9 -0
- package/dist/cjs/src/error/http/FailedDependency.js +9 -0
- package/dist/cjs/src/error/http/Forbidden.js +9 -0
- package/dist/cjs/src/error/http/GatewayTimeout.js +9 -0
- package/dist/cjs/src/error/http/Gone.js +9 -0
- package/dist/cjs/src/error/http/ImATeapot.js +9 -0
- package/dist/cjs/src/error/http/InsufficientStorage.js +9 -0
- package/dist/cjs/src/error/http/InternalServerError.js +9 -0
- package/dist/cjs/src/error/http/Locked.js +9 -0
- package/dist/cjs/src/error/http/MethodNotAllowed.js +9 -0
- package/dist/cjs/src/error/http/MisdirectedRequest.js +9 -0
- package/dist/cjs/src/error/http/NotAcceptable.js +9 -0
- package/dist/cjs/src/error/http/NotExtended.js +9 -0
- package/dist/cjs/src/error/http/NotFound.js +9 -0
- package/dist/cjs/src/error/http/NotImplemented.js +9 -0
- package/dist/cjs/src/error/http/PaymentRequired.js +9 -0
- package/dist/cjs/src/error/http/PreconditionFailed.js +9 -0
- package/dist/cjs/src/error/http/PreconditionRequired.js +9 -0
- package/dist/cjs/src/error/http/ProxyAuthenticationRequired.js +9 -0
- package/dist/cjs/src/error/http/RequestHeaderFieldsTooLarge.js +9 -0
- package/dist/cjs/src/error/http/ServiceUnavailable.js +9 -0
- package/dist/cjs/src/error/http/TooManyRequests.js +9 -0
- package/dist/cjs/src/error/http/Unauthorized.js +9 -0
- package/dist/cjs/src/error/http/UnavailableForLegalReasons.js +9 -0
- package/dist/cjs/src/error/http/UnprocessableContent.js +9 -0
- package/dist/cjs/src/error/http/UnsupportedMediaType.js +9 -0
- package/dist/cjs/src/error/http/index.js +22 -0
- package/dist/cjs/src/error/http/router/index.js +18 -0
- package/dist/cjs/src/error/http/router/missing-controller-method.js +20 -0
- package/dist/cjs/src/error/http/router/missing-controller.js +17 -0
- package/dist/cjs/src/error/http/status-codes.js +311 -0
- package/dist/cjs/src/error/model/index.js +5 -0
- package/dist/cjs/src/error/openapi/CannotFlattenMultiplePolymorphicRendersOneAssociations.js +22 -0
- package/dist/cjs/src/error/psychic-application/init-missing-api-root.js +21 -0
- package/dist/cjs/src/error/psychic-application/init-missing-call-to-load-controllers.js +21 -0
- package/dist/cjs/src/error/psychic-application/init-missing-routes-callback.js +23 -0
- package/dist/cjs/src/error/psychic-application/invalid-encryption-key.js +20 -0
- package/dist/cjs/src/error/router/cannot-find-inferred-controller-from-provided-namespace.js +42 -0
- package/dist/cjs/src/error/router/cannot-infer-controller-from-top-level-route.js +39 -0
- package/dist/cjs/src/error/ws/MissingWsRedisConnection.js +32 -0
- package/dist/cjs/src/generate/controller.js +107 -0
- package/dist/cjs/src/generate/helpers/addResourceToRoutes.js +64 -0
- package/dist/cjs/src/generate/helpers/generateControllerContent.js +191 -0
- package/dist/cjs/src/generate/helpers/generateControllerSpecContent.js +9 -0
- package/dist/cjs/src/generate/helpers/generateResourceControllerSpecContent.js +199 -0
- package/dist/cjs/src/generate/helpers/migrationTimestamp.js +6 -0
- package/dist/cjs/src/generate/resource.js +19 -0
- package/dist/cjs/src/helpers/EnvInternal.js +5 -0
- package/dist/cjs/src/helpers/autogeneratedFileDisclaimer.js +71 -0
- package/dist/cjs/src/helpers/cookieMaxAgeFromCookieOpts.js +20 -0
- package/dist/cjs/src/helpers/error/errorIsRescuableHttpError.js +8 -0
- package/dist/cjs/src/helpers/error/httpErrorClasses.js +76 -0
- package/dist/cjs/src/helpers/importFileWithDefault.js +14 -0
- package/dist/cjs/src/helpers/importFileWithNamedExport.js +12 -0
- package/dist/cjs/src/helpers/isOpenapiError.js +6 -0
- package/dist/cjs/src/helpers/isUuid.js +8 -0
- package/dist/cjs/src/helpers/loadEnv.js +5 -0
- package/dist/cjs/src/helpers/openapiJsonPath.js +9 -0
- package/dist/cjs/src/helpers/pascalizeFileName.js +10 -0
- package/dist/cjs/src/helpers/path/psychicFileAndDirPaths.js +16 -0
- package/dist/cjs/src/helpers/path/psychicPath.js +18 -0
- package/dist/cjs/src/helpers/path/relativePsychicPath.js +43 -0
- package/dist/cjs/src/helpers/path/updirsFromPath.js +11 -0
- package/dist/cjs/src/helpers/path.js +11 -0
- package/dist/cjs/src/helpers/pathifyNestedObject.js +14 -0
- package/dist/cjs/src/helpers/sspawn.js +26 -0
- package/dist/cjs/src/helpers/typeHelpers.js +2 -0
- package/dist/cjs/src/helpers/typechecks.js +20 -0
- package/dist/cjs/src/i18n/conf/I18nDefaultLocales.js +31 -0
- package/dist/cjs/src/i18n/conf/types.js +2 -0
- package/dist/cjs/src/i18n/provider.js +96 -0
- package/dist/cjs/src/index.js +104 -0
- package/dist/cjs/src/openapi-renderer/app.js +153 -0
- package/dist/cjs/src/openapi-renderer/body-segment.js +514 -0
- package/dist/cjs/src/openapi-renderer/defaults.js +84 -0
- package/dist/cjs/src/openapi-renderer/endpoint.js +930 -0
- package/dist/cjs/src/openapi-renderer/helpers/isBlankDescription.js +13 -0
- package/dist/cjs/src/openapi-renderer/helpers/openapiRoute.js +7 -0
- package/dist/cjs/src/openapi-renderer/serializer.js +321 -0
- package/dist/cjs/src/psychic-application/cache.js +17 -0
- package/dist/cjs/src/psychic-application/helpers/PsychicImporter.js +15 -0
- package/dist/cjs/src/psychic-application/helpers/globalControllerKeyFromPath.js +11 -0
- package/dist/cjs/src/psychic-application/helpers/import/importControllers.js +56 -0
- package/dist/cjs/src/psychic-application/helpers/loadAppEnv.js +5 -0
- package/dist/cjs/src/psychic-application/helpers/lookupClassByGlobalName.js +16 -0
- package/dist/cjs/src/psychic-application/index.js +346 -0
- package/dist/cjs/src/psychic-application/logo.js +77 -0
- package/dist/cjs/src/psychic-application/types.js +2 -0
- package/dist/cjs/src/router/helpers.js +138 -0
- package/dist/cjs/src/router/index.js +282 -0
- package/dist/cjs/src/router/route-manager.js +14 -0
- package/dist/cjs/src/router/types.js +6 -0
- package/dist/cjs/src/server/front-end-client.js +15 -0
- package/dist/cjs/src/server/helpers/startPsychicServer.js +39 -0
- package/dist/cjs/src/server/index.js +192 -0
- package/dist/cjs/src/server/params.js +370 -0
- package/dist/cjs/src/session/index.js +38 -0
- package/dist/esm/src/bin/helpers/enumsAndTheirValues.js +14 -0
- package/dist/esm/src/bin/helpers/enumsFileStr.js +18 -0
- package/dist/esm/src/bin/helpers/generateRouteTypes.js +13 -0
- package/dist/esm/src/bin/helpers/printRoutes.js +51 -0
- package/dist/esm/src/bin/index.js +76 -0
- package/dist/esm/src/cli/helpers/TypesBuilder.js +23 -0
- package/dist/esm/src/cli/index.js +73 -0
- package/dist/esm/src/controller/decorators.js +81 -0
- package/dist/esm/src/controller/hooks.js +25 -0
- package/dist/esm/src/controller/index.js +566 -0
- package/dist/esm/src/encrypt/internal-encrypt.js +40 -0
- package/dist/esm/src/env/Loader.js +24 -0
- package/dist/esm/src/error/db/failed-to-connect.js +14 -0
- package/dist/esm/src/error/db/index.js +13 -0
- package/dist/esm/src/error/db/missing-options.js +14 -0
- package/dist/esm/src/error/encrypt/missing-cookie-encryption-options.js +24 -0
- package/dist/esm/src/error/http/BadGateway.js +6 -0
- package/dist/esm/src/error/http/BadRequest.js +6 -0
- package/dist/esm/src/error/http/Conflict.js +6 -0
- package/dist/esm/src/error/http/ContentTooLarge.js +6 -0
- package/dist/esm/src/error/http/ExpectationFailed.js +6 -0
- package/dist/esm/src/error/http/FailedDependency.js +6 -0
- package/dist/esm/src/error/http/Forbidden.js +6 -0
- package/dist/esm/src/error/http/GatewayTimeout.js +6 -0
- package/dist/esm/src/error/http/Gone.js +6 -0
- package/dist/esm/src/error/http/ImATeapot.js +6 -0
- package/dist/esm/src/error/http/InsufficientStorage.js +6 -0
- package/dist/esm/src/error/http/InternalServerError.js +6 -0
- package/dist/esm/src/error/http/Locked.js +6 -0
- package/dist/esm/src/error/http/MethodNotAllowed.js +6 -0
- package/dist/esm/src/error/http/MisdirectedRequest.js +6 -0
- package/dist/esm/src/error/http/NotAcceptable.js +6 -0
- package/dist/esm/src/error/http/NotExtended.js +6 -0
- package/dist/esm/src/error/http/NotFound.js +6 -0
- package/dist/esm/src/error/http/NotImplemented.js +6 -0
- package/dist/esm/src/error/http/PaymentRequired.js +6 -0
- package/dist/esm/src/error/http/PreconditionFailed.js +6 -0
- package/dist/esm/src/error/http/PreconditionRequired.js +6 -0
- package/dist/esm/src/error/http/ProxyAuthenticationRequired.js +6 -0
- package/dist/esm/src/error/http/RequestHeaderFieldsTooLarge.js +6 -0
- package/dist/esm/src/error/http/ServiceUnavailable.js +6 -0
- package/dist/esm/src/error/http/TooManyRequests.js +6 -0
- package/dist/esm/src/error/http/Unauthorized.js +6 -0
- package/dist/esm/src/error/http/UnavailableForLegalReasons.js +6 -0
- package/dist/esm/src/error/http/UnprocessableContent.js +6 -0
- package/dist/esm/src/error/http/UnsupportedMediaType.js +6 -0
- package/dist/esm/src/error/http/index.js +19 -0
- package/dist/esm/src/error/http/router/index.js +15 -0
- package/dist/esm/src/error/http/router/missing-controller-method.js +17 -0
- package/dist/esm/src/error/http/router/missing-controller.js +14 -0
- package/dist/esm/src/error/http/status-codes.js +309 -0
- package/dist/esm/src/error/model/index.js +2 -0
- package/dist/esm/src/error/openapi/CannotFlattenMultiplePolymorphicRendersOneAssociations.js +19 -0
- package/dist/esm/src/error/psychic-application/init-missing-api-root.js +18 -0
- package/dist/esm/src/error/psychic-application/init-missing-call-to-load-controllers.js +18 -0
- package/dist/esm/src/error/psychic-application/init-missing-routes-callback.js +20 -0
- package/dist/esm/src/error/psychic-application/invalid-encryption-key.js +17 -0
- package/dist/esm/src/error/router/cannot-find-inferred-controller-from-provided-namespace.js +39 -0
- package/dist/esm/src/error/router/cannot-infer-controller-from-top-level-route.js +36 -0
- package/dist/esm/src/error/ws/MissingWsRedisConnection.js +29 -0
- package/dist/esm/src/generate/controller.js +104 -0
- package/dist/esm/src/generate/helpers/addResourceToRoutes.js +60 -0
- package/dist/esm/src/generate/helpers/generateControllerContent.js +188 -0
- package/dist/esm/src/generate/helpers/generateControllerSpecContent.js +6 -0
- package/dist/esm/src/generate/helpers/generateResourceControllerSpecContent.js +196 -0
- package/dist/esm/src/generate/helpers/migrationTimestamp.js +3 -0
- package/dist/esm/src/generate/resource.js +16 -0
- package/dist/esm/src/helpers/EnvInternal.js +3 -0
- package/dist/esm/src/helpers/autogeneratedFileDisclaimer.js +68 -0
- package/dist/esm/src/helpers/cookieMaxAgeFromCookieOpts.js +17 -0
- package/dist/esm/src/helpers/error/errorIsRescuableHttpError.js +5 -0
- package/dist/esm/src/helpers/error/httpErrorClasses.js +72 -0
- package/dist/esm/src/helpers/importFileWithDefault.js +11 -0
- package/dist/esm/src/helpers/importFileWithNamedExport.js +9 -0
- package/dist/esm/src/helpers/isOpenapiError.js +3 -0
- package/dist/esm/src/helpers/isUuid.js +5 -0
- package/dist/esm/src/helpers/loadEnv.js +3 -0
- package/dist/esm/src/helpers/openapiJsonPath.js +6 -0
- package/dist/esm/src/helpers/pascalizeFileName.js +7 -0
- package/dist/esm/src/helpers/path/psychicFileAndDirPaths.js +13 -0
- package/dist/esm/src/helpers/path/psychicPath.js +15 -0
- package/dist/esm/src/helpers/path/relativePsychicPath.js +39 -0
- package/dist/esm/src/helpers/path/updirsFromPath.js +8 -0
- package/dist/esm/src/helpers/path.js +7 -0
- package/dist/esm/src/helpers/pathifyNestedObject.js +11 -0
- package/dist/esm/src/helpers/sspawn.js +22 -0
- package/dist/esm/src/helpers/typeHelpers.js +1 -0
- package/dist/esm/src/helpers/typechecks.js +16 -0
- package/dist/esm/src/i18n/conf/I18nDefaultLocales.js +29 -0
- package/dist/esm/src/i18n/conf/types.js +1 -0
- package/dist/esm/src/i18n/provider.js +89 -0
- package/dist/esm/src/index.js +50 -0
- package/dist/esm/src/openapi-renderer/app.js +150 -0
- package/dist/esm/src/openapi-renderer/body-segment.js +511 -0
- package/dist/esm/src/openapi-renderer/defaults.js +81 -0
- package/dist/esm/src/openapi-renderer/endpoint.js +925 -0
- package/dist/esm/src/openapi-renderer/helpers/isBlankDescription.js +10 -0
- package/dist/esm/src/openapi-renderer/helpers/openapiRoute.js +4 -0
- package/dist/esm/src/openapi-renderer/serializer.js +318 -0
- package/dist/esm/src/psychic-application/cache.js +12 -0
- package/dist/esm/src/psychic-application/helpers/PsychicImporter.js +12 -0
- package/dist/esm/src/psychic-application/helpers/globalControllerKeyFromPath.js +8 -0
- package/dist/esm/src/psychic-application/helpers/import/importControllers.js +51 -0
- package/dist/esm/src/psychic-application/helpers/loadAppEnv.js +3 -0
- package/dist/esm/src/psychic-application/helpers/lookupClassByGlobalName.js +13 -0
- package/dist/esm/src/psychic-application/index.js +343 -0
- package/dist/esm/src/psychic-application/logo.js +73 -0
- package/dist/esm/src/psychic-application/types.js +1 -0
- package/dist/esm/src/router/helpers.js +127 -0
- package/dist/esm/src/router/index.js +277 -0
- package/dist/esm/src/router/route-manager.js +11 -0
- package/dist/esm/src/router/types.js +3 -0
- package/dist/esm/src/server/front-end-client.js +12 -0
- package/dist/esm/src/server/helpers/startPsychicServer.js +35 -0
- package/dist/esm/src/server/index.js +189 -0
- package/dist/esm/src/server/params.js +365 -0
- package/dist/esm/src/session/index.js +35 -0
- package/dist/types/src/bin/helpers/enumsAndTheirValues.d.ts +1 -0
- package/dist/types/src/bin/helpers/enumsFileStr.d.ts +1 -0
- package/dist/types/src/bin/helpers/generateRouteTypes.d.ts +2 -0
- package/dist/types/src/bin/helpers/printRoutes.d.ts +1 -0
- package/dist/types/src/bin/index.d.ts +12 -0
- package/dist/types/src/cli/helpers/TypesBuilder.d.ts +7 -0
- package/dist/types/src/cli/index.d.ts +8 -0
- package/dist/types/src/controller/decorators.d.ts +28 -0
- package/dist/types/src/controller/hooks.d.ts +13 -0
- package/dist/types/src/controller/index.d.ts +209 -0
- package/dist/types/src/encrypt/internal-encrypt.d.ts +6 -0
- package/dist/types/src/env/Loader.d.ts +8 -0
- package/dist/types/src/error/db/failed-to-connect.d.ts +4 -0
- package/dist/types/src/error/db/index.d.ts +5 -0
- package/dist/types/src/error/db/missing-options.d.ts +4 -0
- package/dist/types/src/error/encrypt/missing-cookie-encryption-options.d.ts +3 -0
- package/dist/types/src/error/http/BadGateway.d.ts +4 -0
- package/dist/types/src/error/http/BadRequest.d.ts +4 -0
- package/dist/types/src/error/http/Conflict.d.ts +4 -0
- package/dist/types/src/error/http/ContentTooLarge.d.ts +4 -0
- package/dist/types/src/error/http/ExpectationFailed.d.ts +4 -0
- package/dist/types/src/error/http/FailedDependency.d.ts +4 -0
- package/dist/types/src/error/http/Forbidden.d.ts +4 -0
- package/dist/types/src/error/http/GatewayTimeout.d.ts +4 -0
- package/dist/types/src/error/http/Gone.d.ts +4 -0
- package/dist/types/src/error/http/ImATeapot.d.ts +4 -0
- package/dist/types/src/error/http/InsufficientStorage.d.ts +4 -0
- package/dist/types/src/error/http/InternalServerError.d.ts +4 -0
- package/dist/types/src/error/http/Locked.d.ts +4 -0
- package/dist/types/src/error/http/MethodNotAllowed.d.ts +4 -0
- package/dist/types/src/error/http/MisdirectedRequest.d.ts +4 -0
- package/dist/types/src/error/http/NotAcceptable.d.ts +4 -0
- package/dist/types/src/error/http/NotExtended.d.ts +4 -0
- package/dist/types/src/error/http/NotFound.d.ts +4 -0
- package/dist/types/src/error/http/NotImplemented.d.ts +4 -0
- package/dist/types/src/error/http/PaymentRequired.d.ts +4 -0
- package/dist/types/src/error/http/PreconditionFailed.d.ts +4 -0
- package/dist/types/src/error/http/PreconditionRequired.d.ts +4 -0
- package/dist/types/src/error/http/ProxyAuthenticationRequired.d.ts +4 -0
- package/dist/types/src/error/http/RequestHeaderFieldsTooLarge.d.ts +4 -0
- package/dist/types/src/error/http/ServiceUnavailable.d.ts +4 -0
- package/dist/types/src/error/http/TooManyRequests.d.ts +4 -0
- package/dist/types/src/error/http/Unauthorized.d.ts +4 -0
- package/dist/types/src/error/http/UnavailableForLegalReasons.d.ts +4 -0
- package/dist/types/src/error/http/UnprocessableContent.d.ts +4 -0
- package/dist/types/src/error/http/UnsupportedMediaType.d.ts +4 -0
- package/dist/types/src/error/http/index.d.ts +10 -0
- package/dist/types/src/error/http/router/index.d.ts +6 -0
- package/dist/types/src/error/http/router/missing-controller-method.d.ts +7 -0
- package/dist/types/src/error/http/router/missing-controller.d.ts +6 -0
- package/dist/types/src/error/http/status-codes.d.ts +312 -0
- package/dist/types/src/error/model/index.d.ts +2 -0
- package/dist/types/src/error/openapi/CannotFlattenMultiplePolymorphicRendersOneAssociations.d.ts +7 -0
- package/dist/types/src/error/psychic-application/init-missing-api-root.d.ts +4 -0
- package/dist/types/src/error/psychic-application/init-missing-call-to-load-controllers.d.ts +4 -0
- package/dist/types/src/error/psychic-application/init-missing-routes-callback.d.ts +4 -0
- package/dist/types/src/error/psychic-application/invalid-encryption-key.d.ts +4 -0
- package/dist/types/src/error/router/cannot-find-inferred-controller-from-provided-namespace.d.ts +15 -0
- package/dist/types/src/error/router/cannot-infer-controller-from-top-level-route.d.ts +8 -0
- package/dist/types/src/error/ws/MissingWsRedisConnection.d.ts +3 -0
- package/dist/types/src/generate/controller.d.ts +7 -0
- package/dist/types/src/generate/helpers/addResourceToRoutes.d.ts +7 -0
- package/dist/types/src/generate/helpers/generateControllerContent.d.ts +8 -0
- package/dist/types/src/generate/helpers/generateControllerSpecContent.d.ts +1 -0
- package/dist/types/src/generate/helpers/generateResourceControllerSpecContent.d.ts +6 -0
- package/dist/types/src/generate/helpers/migrationTimestamp.d.ts +1 -0
- package/dist/types/src/generate/resource.d.ts +5 -0
- package/dist/types/src/helpers/EnvInternal.d.ts +7 -0
- package/dist/types/src/helpers/autogeneratedFileDisclaimer.d.ts +1 -0
- package/dist/types/src/helpers/cookieMaxAgeFromCookieOpts.d.ts +2 -0
- package/dist/types/src/helpers/error/errorIsRescuableHttpError.d.ts +1 -0
- package/dist/types/src/helpers/error/httpErrorClasses.d.ts +3 -0
- package/dist/types/src/helpers/importFileWithDefault.d.ts +1 -0
- package/dist/types/src/helpers/importFileWithNamedExport.d.ts +1 -0
- package/dist/types/src/helpers/isOpenapiError.d.ts +8 -0
- package/dist/types/src/helpers/isUuid.d.ts +1 -0
- package/dist/types/src/helpers/loadEnv.d.ts +1 -0
- package/dist/types/src/helpers/openapiJsonPath.d.ts +1 -0
- package/dist/types/src/helpers/pascalizeFileName.d.ts +1 -0
- package/dist/types/src/helpers/path/psychicFileAndDirPaths.d.ts +5 -0
- package/dist/types/src/helpers/path/psychicPath.d.ts +4 -0
- package/dist/types/src/helpers/path/relativePsychicPath.d.ts +3 -0
- package/dist/types/src/helpers/path/updirsFromPath.d.ts +1 -0
- package/dist/types/src/helpers/path.d.ts +2 -0
- package/dist/types/src/helpers/pathifyNestedObject.d.ts +5 -0
- package/dist/types/src/helpers/sspawn.d.ts +2 -0
- package/dist/types/src/helpers/typeHelpers.d.ts +4 -0
- package/dist/types/src/helpers/typechecks.d.ts +2 -0
- package/dist/types/src/i18n/conf/I18nDefaultLocales.d.ts +2 -0
- package/dist/types/src/i18n/conf/types.d.ts +45 -0
- package/dist/types/src/i18n/provider.d.ts +26 -0
- package/dist/types/src/index.d.ts +61 -0
- package/dist/types/src/openapi-renderer/app.d.ts +21 -0
- package/dist/types/src/openapi-renderer/body-segment.d.ts +153 -0
- package/dist/types/src/openapi-renderer/defaults.d.ts +5 -0
- package/dist/types/src/openapi-renderer/endpoint.d.ts +410 -0
- package/dist/types/src/openapi-renderer/helpers/isBlankDescription.d.ts +1 -0
- package/dist/types/src/openapi-renderer/helpers/openapiRoute.d.ts +1 -0
- package/dist/types/src/openapi-renderer/serializer.d.ts +76 -0
- package/dist/types/src/psychic-application/cache.d.ts +4 -0
- package/dist/types/src/psychic-application/helpers/PsychicImporter.d.ts +4 -0
- package/dist/types/src/psychic-application/helpers/globalControllerKeyFromPath.d.ts +1 -0
- package/dist/types/src/psychic-application/helpers/import/importControllers.d.ts +5 -0
- package/dist/types/src/psychic-application/helpers/loadAppEnv.d.ts +1 -0
- package/dist/types/src/psychic-application/helpers/lookupClassByGlobalName.d.ts +1 -0
- package/dist/types/src/psychic-application/index.d.ts +164 -0
- package/dist/types/src/psychic-application/logo.d.ts +2 -0
- package/dist/types/src/psychic-application/types.d.ts +6 -0
- package/dist/types/src/router/helpers.d.ts +26 -0
- package/dist/types/src/router/index.d.ts +55 -0
- package/dist/types/src/router/route-manager.d.ts +17 -0
- package/dist/types/src/router/types.d.ts +11 -0
- package/dist/types/src/server/front-end-client.d.ts +5 -0
- package/dist/types/src/server/helpers/startPsychicServer.d.ts +14 -0
- package/dist/types/src/server/index.d.ts +34 -0
- package/dist/types/src/server/params.d.ts +80 -0
- package/dist/types/src/session/index.d.ts +12 -0
- package/package.json +98 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsychicNestedRouter = void 0;
|
|
4
|
+
const dream_1 = require("@rvoh/dream");
|
|
5
|
+
const express_1 = require("express");
|
|
6
|
+
const pluralize_esm_1 = require("pluralize-esm");
|
|
7
|
+
const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
|
|
8
|
+
const errorIsRescuableHttpError_js_1 = require("../helpers/error/errorIsRescuableHttpError.js");
|
|
9
|
+
const index_js_1 = require("../psychic-application/index.js");
|
|
10
|
+
const helpers_js_1 = require("../router/helpers.js");
|
|
11
|
+
const params_js_1 = require("../server/params.js");
|
|
12
|
+
const route_manager_js_1 = require("./route-manager.js");
|
|
13
|
+
const types_js_1 = require("./types.js");
|
|
14
|
+
class PsychicRouter {
|
|
15
|
+
app;
|
|
16
|
+
config;
|
|
17
|
+
currentNamespaces = [];
|
|
18
|
+
routeManager = new route_manager_js_1.default();
|
|
19
|
+
constructor(app, config) {
|
|
20
|
+
this.app = app;
|
|
21
|
+
this.config = config;
|
|
22
|
+
}
|
|
23
|
+
get routingMechanism() {
|
|
24
|
+
return this.app;
|
|
25
|
+
}
|
|
26
|
+
get routes() {
|
|
27
|
+
return this.routeManager.routes;
|
|
28
|
+
}
|
|
29
|
+
get currentNamespacePaths() {
|
|
30
|
+
return this.currentNamespaces.map(n => n.namespace);
|
|
31
|
+
}
|
|
32
|
+
// this is called after all routes have been processed.
|
|
33
|
+
commit() {
|
|
34
|
+
this.routes.forEach(route => {
|
|
35
|
+
this.app[route.httpMethod]((0, helpers_js_1.routePath)(route.path), (req, res) => {
|
|
36
|
+
this.handle(route.controller, route.action, { req, res }).catch(() => { });
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
get(path, controller, action) {
|
|
41
|
+
this.crud('get', path, controller, action);
|
|
42
|
+
}
|
|
43
|
+
post(path, controller, action) {
|
|
44
|
+
this.crud('post', path, controller, action);
|
|
45
|
+
}
|
|
46
|
+
put(path, controller, action) {
|
|
47
|
+
this.crud('put', path, controller, action);
|
|
48
|
+
}
|
|
49
|
+
patch(path, controller, action) {
|
|
50
|
+
this.crud('patch', path, controller, action);
|
|
51
|
+
}
|
|
52
|
+
delete(path, controller, action) {
|
|
53
|
+
this.crud('delete', path, controller, action);
|
|
54
|
+
}
|
|
55
|
+
options(path, controller, action) {
|
|
56
|
+
this.crud('options', path, controller, action);
|
|
57
|
+
}
|
|
58
|
+
prefixPathWithNamespaces(str) {
|
|
59
|
+
if (!this.currentNamespaces.length)
|
|
60
|
+
return str;
|
|
61
|
+
return '/' + this.currentNamespacePaths.join('/') + '/' + str;
|
|
62
|
+
}
|
|
63
|
+
crud(httpMethod, path, controller, action) {
|
|
64
|
+
controller ||= (0, helpers_js_1.lookupControllerOrFail)(this, { path, httpMethod });
|
|
65
|
+
action ||= path.replace(/^\//, '');
|
|
66
|
+
if (action.match(/\//))
|
|
67
|
+
throw new Error('action cant have a slash in it - action was inferred from path');
|
|
68
|
+
this.routeManager.addRoute({
|
|
69
|
+
httpMethod,
|
|
70
|
+
path: this.prefixPathWithNamespaces(path),
|
|
71
|
+
controller,
|
|
72
|
+
action,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
namespace(namespace, cb) {
|
|
76
|
+
const nestedRouter = new PsychicNestedRouter(this.app, this.config, this.routeManager, {
|
|
77
|
+
namespaces: this.currentNamespaces,
|
|
78
|
+
});
|
|
79
|
+
this.runNestedCallbacks(namespace, nestedRouter, cb);
|
|
80
|
+
}
|
|
81
|
+
scope(scope, cb) {
|
|
82
|
+
const nestedRouter = new PsychicNestedRouter(this.app, this.config, this.routeManager, {
|
|
83
|
+
namespaces: this.currentNamespaces,
|
|
84
|
+
});
|
|
85
|
+
this.runNestedCallbacks(scope, nestedRouter, cb, { treatNamespaceAsScope: true });
|
|
86
|
+
}
|
|
87
|
+
resources(path, optionsOrCb, cb) {
|
|
88
|
+
return this.makeResource(path, optionsOrCb, cb, true);
|
|
89
|
+
}
|
|
90
|
+
resource(path, optionsOrCb, cb) {
|
|
91
|
+
return this.makeResource(path, optionsOrCb, cb, false);
|
|
92
|
+
}
|
|
93
|
+
collection(cb) {
|
|
94
|
+
const replacedNamespaces = this.currentNamespaces.slice(0, this.currentNamespaces.length - 1);
|
|
95
|
+
const nestedRouter = new PsychicNestedRouter(this.app, this.config, this.routeManager, {
|
|
96
|
+
namespaces: replacedNamespaces,
|
|
97
|
+
});
|
|
98
|
+
const currentNamespace = replacedNamespaces[replacedNamespaces.length - 1];
|
|
99
|
+
if (!currentNamespace)
|
|
100
|
+
throw new Error('Must be within a resource to call the collection method');
|
|
101
|
+
cb(nestedRouter);
|
|
102
|
+
}
|
|
103
|
+
makeResource(path, optionsOrCb, cb, plural) {
|
|
104
|
+
if (cb) {
|
|
105
|
+
if (typeof optionsOrCb === 'function')
|
|
106
|
+
throw new Error('cannot pass a function as a second arg when passing 3 args');
|
|
107
|
+
this._makeResource(path, optionsOrCb, cb, plural);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
if (typeof optionsOrCb === 'function')
|
|
111
|
+
this._makeResource(path, undefined, optionsOrCb, plural);
|
|
112
|
+
else
|
|
113
|
+
this._makeResource(path, optionsOrCb, undefined, plural);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
_makeResource(path, options, cb, plural) {
|
|
117
|
+
const nestedRouter = new PsychicNestedRouter(this.app, this.config, this.routeManager, {
|
|
118
|
+
namespaces: this.currentNamespaces,
|
|
119
|
+
});
|
|
120
|
+
const { only, except } = options || {};
|
|
121
|
+
let resourceMethods = plural ? types_js_1.ResourcesMethods : types_js_1.ResourceMethods;
|
|
122
|
+
if (only) {
|
|
123
|
+
resourceMethods = only;
|
|
124
|
+
}
|
|
125
|
+
else if (except) {
|
|
126
|
+
resourceMethods = resourceMethods.filter(m => !except.includes(m));
|
|
127
|
+
}
|
|
128
|
+
const originalCurrentNamespaces = this.currentNamespaces;
|
|
129
|
+
this.makeRoomForNewIdParam(nestedRouter);
|
|
130
|
+
this.runNestedCallbacks(path, nestedRouter, cb, { asMember: plural, resourceful: true });
|
|
131
|
+
this.currentNamespaces = originalCurrentNamespaces;
|
|
132
|
+
resourceMethods.forEach(action => {
|
|
133
|
+
if (plural) {
|
|
134
|
+
(0, helpers_js_1.applyResourcesAction)(path, action, nestedRouter, options);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
(0, helpers_js_1.applyResourceAction)(path, action, nestedRouter, options);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
runNestedCallbacks(namespace, nestedRouter, cb, { asMember = false, resourceful = false, treatNamespaceAsScope = false, } = {}) {
|
|
142
|
+
this.addNamespace(namespace, resourceful, { nestedRouter, treatNamespaceAsScope });
|
|
143
|
+
if (asMember) {
|
|
144
|
+
this.addNamespace(':id', resourceful, { nestedRouter, treatNamespaceAsScope: true });
|
|
145
|
+
}
|
|
146
|
+
if (cb)
|
|
147
|
+
cb(nestedRouter);
|
|
148
|
+
this.removeLastNamespace(nestedRouter);
|
|
149
|
+
if (asMember)
|
|
150
|
+
this.removeLastNamespace(nestedRouter);
|
|
151
|
+
}
|
|
152
|
+
addNamespace(namespace, resourceful, { nestedRouter, treatNamespaceAsScope, } = {}) {
|
|
153
|
+
this.currentNamespaces = [
|
|
154
|
+
...this.currentNamespaces,
|
|
155
|
+
{
|
|
156
|
+
namespace,
|
|
157
|
+
resourceful,
|
|
158
|
+
isScope: treatNamespaceAsScope || false,
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
if (nestedRouter)
|
|
162
|
+
nestedRouter.currentNamespaces = this.currentNamespaces;
|
|
163
|
+
}
|
|
164
|
+
removeLastNamespace(nestedRouter) {
|
|
165
|
+
this.currentNamespaces.pop();
|
|
166
|
+
if (nestedRouter)
|
|
167
|
+
nestedRouter.currentNamespaces = this.currentNamespaces;
|
|
168
|
+
}
|
|
169
|
+
makeRoomForNewIdParam(nestedRouter) {
|
|
170
|
+
this.currentNamespaces = [
|
|
171
|
+
...this.currentNamespaces.map((namespace, index) => {
|
|
172
|
+
const previousNamespace = this.currentNamespaces[index - 1];
|
|
173
|
+
if (namespace.namespace === ':id' && previousNamespace) {
|
|
174
|
+
return {
|
|
175
|
+
...namespace,
|
|
176
|
+
namespace: `:${(0, dream_1.camelize)(pluralize_esm_1.default.singular(previousNamespace.namespace))}Id`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
else
|
|
180
|
+
return namespace;
|
|
181
|
+
}),
|
|
182
|
+
];
|
|
183
|
+
if (nestedRouter)
|
|
184
|
+
nestedRouter.currentNamespaces = this.currentNamespaces;
|
|
185
|
+
}
|
|
186
|
+
async handle(controller, action, { req, res, }) {
|
|
187
|
+
const controllerInstance = this._initializeController(controller, req, res, action);
|
|
188
|
+
try {
|
|
189
|
+
await controllerInstance.runAction(action);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
const err = error;
|
|
193
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
194
|
+
if (!EnvInternal_js_1.default.isTest)
|
|
195
|
+
psychicApp.logger.error(err.message);
|
|
196
|
+
if ((0, errorIsRescuableHttpError_js_1.default)(err)) {
|
|
197
|
+
const httpErr = err;
|
|
198
|
+
if (httpErr.data) {
|
|
199
|
+
res.status(httpErr.status).json(httpErr.data);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
res.sendStatus(httpErr.status);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else if (err instanceof dream_1.RecordNotFound) {
|
|
206
|
+
res.sendStatus(404);
|
|
207
|
+
}
|
|
208
|
+
else if (err instanceof dream_1.ValidationError) {
|
|
209
|
+
res.status(422).json({ errors: err.errors || {} });
|
|
210
|
+
}
|
|
211
|
+
else if (err instanceof params_js_1.ParamValidationError) {
|
|
212
|
+
let errorsJson = {};
|
|
213
|
+
try {
|
|
214
|
+
errorsJson = JSON.parse(err.message);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// noop
|
|
218
|
+
}
|
|
219
|
+
res.status(400).json({
|
|
220
|
+
errors: errorsJson,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// by default, ts-node will mask these errors for no good reason, causing us
|
|
225
|
+
// to have to apply an ugly and annoying try-catch pattern to our controllers
|
|
226
|
+
// and manually console log the error to determine what the actual error was.
|
|
227
|
+
// this block enables us to not have to do that anymore.
|
|
228
|
+
if (EnvInternal_js_1.default.isTest && !EnvInternal_js_1.default.boolean('PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR')) {
|
|
229
|
+
index_js_1.default.log('ATTENTION: a server error was detected:');
|
|
230
|
+
index_js_1.default.logWithLevel('error', err);
|
|
231
|
+
}
|
|
232
|
+
if (this.config.specialHooks.serverError.length) {
|
|
233
|
+
try {
|
|
234
|
+
for (const hook of this.config.specialHooks.serverError) {
|
|
235
|
+
await hook(err, req, res);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (EnvInternal_js_1.default.isDevelopmentOrTest) {
|
|
240
|
+
// In development and test, we want to throw so that, for example, double-setting of
|
|
241
|
+
// status headers throws an error in specs. We couldn't figure out how to write
|
|
242
|
+
// a spec for ensuring that such errors made it through because Supertest would
|
|
243
|
+
// respond with the first header sent, which was successful, and the exception only
|
|
244
|
+
// happened when Jest ended the spec.
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
index_js_1.default.logWithLevel('error', `
|
|
249
|
+
Something went wrong while attempting to call your custom server:error hooks.
|
|
250
|
+
Psychic will rescue errors thrown here to prevent the server from crashing.
|
|
251
|
+
The error thrown is:
|
|
252
|
+
`);
|
|
253
|
+
index_js_1.default.logWithLevel('error', error);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else
|
|
258
|
+
throw err;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
_initializeController(ControllerClass, req, res, action) {
|
|
263
|
+
return new ControllerClass(req, res, {
|
|
264
|
+
config: this.config,
|
|
265
|
+
action,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.default = PsychicRouter;
|
|
270
|
+
class PsychicNestedRouter extends PsychicRouter {
|
|
271
|
+
router;
|
|
272
|
+
constructor(app, config, routeManager, { namespaces = [], } = {}) {
|
|
273
|
+
super(app, config);
|
|
274
|
+
this.router = (0, express_1.Router)();
|
|
275
|
+
this.currentNamespaces = namespaces;
|
|
276
|
+
this.routeManager = routeManager;
|
|
277
|
+
}
|
|
278
|
+
get routingMechanism() {
|
|
279
|
+
return this.router;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
exports.PsychicNestedRouter = PsychicNestedRouter;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class RouteManager {
|
|
4
|
+
routes = [];
|
|
5
|
+
addRoute({ httpMethod, path, controller, action, }) {
|
|
6
|
+
this.routes.push({
|
|
7
|
+
httpMethod,
|
|
8
|
+
path,
|
|
9
|
+
controller,
|
|
10
|
+
action,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.default = RouteManager;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethods = exports.ResourceMethods = exports.ResourcesMethods = void 0;
|
|
4
|
+
exports.ResourcesMethods = ['index', 'create', 'update', 'show', 'destroy'];
|
|
5
|
+
exports.ResourceMethods = ['create', 'update', 'show', 'destroy'];
|
|
6
|
+
exports.HttpMethods = ['get', 'post', 'put', 'patch', 'delete', 'options'];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sspawn_js_1 = require("../helpers/sspawn.js");
|
|
4
|
+
class FrontEndClientServer {
|
|
5
|
+
child;
|
|
6
|
+
start(port = 3000) {
|
|
7
|
+
this.child = (0, sspawn_js_1.ssspawn)(`PORT=${port} yarn client`, { stdio: 'ignore' });
|
|
8
|
+
}
|
|
9
|
+
stop() {
|
|
10
|
+
if (!this.child)
|
|
11
|
+
return;
|
|
12
|
+
this.child.kill();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = FrontEndClientServer;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = startPsychicServer;
|
|
4
|
+
exports.createPsychicHttpInstance = createPsychicHttpInstance;
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const http = require("http");
|
|
7
|
+
const https = require("https");
|
|
8
|
+
const EnvInternal_js_1 = require("../../helpers/EnvInternal.js");
|
|
9
|
+
const index_js_1 = require("../../psychic-application/index.js");
|
|
10
|
+
const index_js_2 = require("../../server/index.js");
|
|
11
|
+
async function startPsychicServer({ app, port, withFrontEndClient, frontEndPort, sslCredentials, }) {
|
|
12
|
+
return await new Promise(accept => {
|
|
13
|
+
const httpOrHttps = createPsychicHttpInstance(app, sslCredentials);
|
|
14
|
+
const server = httpOrHttps.listen(port, () => {
|
|
15
|
+
welcomeMessage({ port, withFrontEndClient, frontEndPort });
|
|
16
|
+
accept(server);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function createPsychicHttpInstance(app, sslCredentials) {
|
|
21
|
+
if (sslCredentials?.key && sslCredentials?.cert) {
|
|
22
|
+
return https.createServer({
|
|
23
|
+
key: fs.readFileSync(sslCredentials.key),
|
|
24
|
+
cert: fs.readFileSync(sslCredentials.cert),
|
|
25
|
+
}, app);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return http.createServer(app);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function welcomeMessage({ port, withFrontEndClient, frontEndPort, }) {
|
|
32
|
+
if (!EnvInternal_js_1.default.isTest) {
|
|
33
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
34
|
+
psychicApp.logger.info(index_js_2.default.asciiLogo());
|
|
35
|
+
psychicApp.logger.info(`psychic dev server started at port ${port}`);
|
|
36
|
+
if (withFrontEndClient)
|
|
37
|
+
psychicApp.logger.info(`client dev server on port ${frontEndPort}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dream_1 = require("@rvoh/dream");
|
|
4
|
+
const cookieParser = require("cookie-parser");
|
|
5
|
+
const cors = require("cors");
|
|
6
|
+
const express = require("express");
|
|
7
|
+
const OpenApiValidator = require("express-openapi-validator");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
|
|
10
|
+
const isOpenapiError_js_1 = require("../helpers/isOpenapiError.js");
|
|
11
|
+
const index_js_1 = require("../psychic-application/index.js");
|
|
12
|
+
const logo_js_1 = require("../psychic-application/logo.js");
|
|
13
|
+
const index_js_2 = require("../router/index.js");
|
|
14
|
+
const front_end_client_js_1 = require("./front-end-client.js");
|
|
15
|
+
const startPsychicServer_js_1 = require("./helpers/startPsychicServer.js");
|
|
16
|
+
class PsychicServer {
|
|
17
|
+
static async startPsychicServer(opts) {
|
|
18
|
+
return await (0, startPsychicServer_js_1.default)(opts);
|
|
19
|
+
}
|
|
20
|
+
static createPsychicHttpInstance(app, sslCredentials) {
|
|
21
|
+
return (0, startPsychicServer_js_1.createPsychicHttpInstance)(app, sslCredentials);
|
|
22
|
+
}
|
|
23
|
+
static asciiLogo() {
|
|
24
|
+
return (0, logo_js_1.default)();
|
|
25
|
+
}
|
|
26
|
+
expressApp;
|
|
27
|
+
frontEndClient;
|
|
28
|
+
httpServer;
|
|
29
|
+
booted = false;
|
|
30
|
+
constructor() {
|
|
31
|
+
this.buildApp();
|
|
32
|
+
}
|
|
33
|
+
get config() {
|
|
34
|
+
return index_js_1.default.getOrFail();
|
|
35
|
+
}
|
|
36
|
+
async routes() {
|
|
37
|
+
const r = new index_js_2.default(this.expressApp, this.config);
|
|
38
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
39
|
+
await psychicApp.routesCb(r);
|
|
40
|
+
return r.routes;
|
|
41
|
+
}
|
|
42
|
+
async boot() {
|
|
43
|
+
if (this.booted)
|
|
44
|
+
return;
|
|
45
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
46
|
+
this.expressApp.use((_, res, next) => {
|
|
47
|
+
Object.keys(psychicApp.defaultResponseHeaders).forEach(key => {
|
|
48
|
+
res.setHeader(key, psychicApp.defaultResponseHeaders[key]);
|
|
49
|
+
});
|
|
50
|
+
next();
|
|
51
|
+
});
|
|
52
|
+
await this.config['runHooksFor']('boot');
|
|
53
|
+
this.initializeCors();
|
|
54
|
+
this.initializeJSON();
|
|
55
|
+
try {
|
|
56
|
+
await this.config.boot();
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
const error = err;
|
|
60
|
+
index_js_1.default.logWithLevel('error', error);
|
|
61
|
+
throw new Error(`
|
|
62
|
+
Failed to boot psychic config. the error thrown was:
|
|
63
|
+
${error.message}
|
|
64
|
+
`);
|
|
65
|
+
}
|
|
66
|
+
for (const expressInitHook of this.config.specialHooks.serverInit) {
|
|
67
|
+
await expressInitHook(this);
|
|
68
|
+
}
|
|
69
|
+
this.initializeOpenapiValidation();
|
|
70
|
+
await this.buildRoutes();
|
|
71
|
+
for (const afterRoutesHook of this.config.specialHooks.serverInitAfterRoutes) {
|
|
72
|
+
await afterRoutesHook(this);
|
|
73
|
+
}
|
|
74
|
+
this.booted = true;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
// TODO: use config helper for fetching default port
|
|
78
|
+
async start(port, { withFrontEndClient = EnvInternal_js_1.default.boolean('CLIENT'), frontEndPort = 3000, } = {}) {
|
|
79
|
+
await this.boot();
|
|
80
|
+
if (withFrontEndClient) {
|
|
81
|
+
this.frontEndClient = new front_end_client_js_1.default();
|
|
82
|
+
this.frontEndClient.start(frontEndPort);
|
|
83
|
+
}
|
|
84
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
85
|
+
const startOverride = psychicApp['overrides']['server:start'];
|
|
86
|
+
if (startOverride) {
|
|
87
|
+
this.httpServer = await startOverride(this, { port, withFrontEndClient, frontEndPort });
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const httpServer = await (0, startPsychicServer_js_1.default)({
|
|
91
|
+
app: this.expressApp,
|
|
92
|
+
port: port || psychicApp.port,
|
|
93
|
+
withFrontEndClient,
|
|
94
|
+
frontEndPort,
|
|
95
|
+
sslCredentials: this.config.sslCredentials,
|
|
96
|
+
});
|
|
97
|
+
this.httpServer = httpServer;
|
|
98
|
+
}
|
|
99
|
+
for (const hook of psychicApp.specialHooks.serverStart) {
|
|
100
|
+
await hook(this);
|
|
101
|
+
}
|
|
102
|
+
process.on('SIGINT', () => {
|
|
103
|
+
void this.shutdownAndExit();
|
|
104
|
+
});
|
|
105
|
+
process.on('SIGTERM', () => {
|
|
106
|
+
void this.shutdownAndExit();
|
|
107
|
+
});
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
+
attach(id, obj) {
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
113
|
+
this.$attached[id] = obj;
|
|
114
|
+
}
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
+
$attached = {};
|
|
117
|
+
async shutdownAndExit() {
|
|
118
|
+
await this.stop();
|
|
119
|
+
process.exit();
|
|
120
|
+
}
|
|
121
|
+
async stop({ bypassClosingDbConnections = false } = {}) {
|
|
122
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
123
|
+
for (const hook of psychicApp.specialHooks.serverShutdown) {
|
|
124
|
+
await hook(this);
|
|
125
|
+
}
|
|
126
|
+
this.frontEndClient?.stop();
|
|
127
|
+
this.httpServer?.close();
|
|
128
|
+
if (!bypassClosingDbConnections) {
|
|
129
|
+
await (0, dream_1.closeAllDbConnections)();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async serveForRequestSpecs(block) {
|
|
133
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
134
|
+
const port = psychicApp.port;
|
|
135
|
+
await this.boot();
|
|
136
|
+
let server;
|
|
137
|
+
await new Promise(accept => {
|
|
138
|
+
server = this.expressApp.listen(port, () => accept({}));
|
|
139
|
+
});
|
|
140
|
+
await block();
|
|
141
|
+
server.close();
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
buildApp() {
|
|
145
|
+
this.expressApp = express.default();
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
147
|
+
this.expressApp.use(cookieParser.default());
|
|
148
|
+
}
|
|
149
|
+
initializeCors() {
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
+
this.expressApp.use(cors.default(this.config.corsOptions));
|
|
152
|
+
}
|
|
153
|
+
initializeJSON() {
|
|
154
|
+
this.expressApp.use(express.json(this.config.jsonOptions));
|
|
155
|
+
}
|
|
156
|
+
initializeOpenapiValidation() {
|
|
157
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
158
|
+
for (const openapiName in psychicApp.openapi) {
|
|
159
|
+
const openapiOpts = psychicApp.openapi[openapiName];
|
|
160
|
+
if (openapiOpts?.validation) {
|
|
161
|
+
const opts = openapiOpts.validation;
|
|
162
|
+
opts.apiSpec ||= path.join(psychicApp.apiRoot, 'openapi.json');
|
|
163
|
+
this.expressApp.use(OpenApiValidator.middleware(opts));
|
|
164
|
+
this.expressApp.use((err, req, res, next) => {
|
|
165
|
+
if ((0, isOpenapiError_js_1.default)(err)) {
|
|
166
|
+
if (EnvInternal_js_1.default.isDebug) {
|
|
167
|
+
index_js_1.default.log(JSON.stringify(err));
|
|
168
|
+
console.trace();
|
|
169
|
+
}
|
|
170
|
+
res.status(err.status).json({
|
|
171
|
+
message: err.message,
|
|
172
|
+
errors: err.errors,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (EnvInternal_js_1.default.isDebug) {
|
|
177
|
+
index_js_1.default.logWithLevel('error', err);
|
|
178
|
+
}
|
|
179
|
+
next();
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async buildRoutes() {
|
|
186
|
+
const r = new index_js_2.default(this.expressApp, this.config);
|
|
187
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
188
|
+
await psychicApp.routesCb(r);
|
|
189
|
+
r.commit();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.default = PsychicServer;
|