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