@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,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dream_1 = require("@rvoh/dream");
|
|
4
|
+
const init_missing_api_root_js_1 = require("../error/psychic-application/init-missing-api-root.js");
|
|
5
|
+
const init_missing_call_to_load_controllers_js_1 = require("../error/psychic-application/init-missing-call-to-load-controllers.js");
|
|
6
|
+
const init_missing_routes_callback_js_1 = require("../error/psychic-application/init-missing-routes-callback.js");
|
|
7
|
+
const cookieMaxAgeFromCookieOpts_js_1 = require("../helpers/cookieMaxAgeFromCookieOpts.js");
|
|
8
|
+
const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
|
|
9
|
+
const cache_js_1 = require("./cache.js");
|
|
10
|
+
const importControllers_js_1 = require("./helpers/import/importControllers.js");
|
|
11
|
+
const lookupClassByGlobalName_js_1 = require("./helpers/lookupClassByGlobalName.js");
|
|
12
|
+
class PsychicApplication {
|
|
13
|
+
static async init(cb, dreamCb, opts = {}) {
|
|
14
|
+
let psychicApp;
|
|
15
|
+
await dream_1.DreamApplication.init(dreamCb, { bypassModelIntegrityCheck: opts.bypassModelIntegrityCheck }, async (dreamApp) => {
|
|
16
|
+
psychicApp = new PsychicApplication();
|
|
17
|
+
await cb(psychicApp);
|
|
18
|
+
if (!psychicApp.loadedControllers)
|
|
19
|
+
throw new init_missing_call_to_load_controllers_js_1.default();
|
|
20
|
+
if (!psychicApp.apiRoot)
|
|
21
|
+
throw new init_missing_api_root_js_1.default();
|
|
22
|
+
if (!psychicApp.routesCb)
|
|
23
|
+
throw new init_missing_routes_callback_js_1.default();
|
|
24
|
+
if (psychicApp.encryption?.cookies?.current)
|
|
25
|
+
this.checkKey('cookies', psychicApp.encryption.cookies.current.key, psychicApp.encryption.cookies.current.algorithm);
|
|
26
|
+
await psychicApp.inflections?.();
|
|
27
|
+
dreamApp.set('projectRoot', psychicApp.apiRoot);
|
|
28
|
+
dreamApp.set('logger', psychicApp.logger);
|
|
29
|
+
(0, cache_js_1.cachePsychicApplication)(psychicApp);
|
|
30
|
+
});
|
|
31
|
+
return psychicApp;
|
|
32
|
+
}
|
|
33
|
+
static lookupClassByGlobalName(name) {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
35
|
+
return (0, lookupClassByGlobalName_js_1.default)(name);
|
|
36
|
+
}
|
|
37
|
+
static checkKey(encryptionIdentifier, key, algorithm) {
|
|
38
|
+
if (!dream_1.Encrypt.validateKey(key, algorithm))
|
|
39
|
+
console.warn(`
|
|
40
|
+
Your current key value for ${encryptionIdentifier} encryption is invalid.
|
|
41
|
+
Try setting it to something valid, like:
|
|
42
|
+
${dream_1.Encrypt.generateKey(algorithm)}
|
|
43
|
+
|
|
44
|
+
(This was done by calling:
|
|
45
|
+
Encrypt.generateKey('${algorithm}')
|
|
46
|
+
`);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the cached psychic application if it has been set.
|
|
50
|
+
* If it has not been set, an exception is raised.
|
|
51
|
+
*
|
|
52
|
+
* The psychic application can be set by calling PsychicApplication#init
|
|
53
|
+
*/
|
|
54
|
+
static getOrFail() {
|
|
55
|
+
return (0, cache_js_1.getCachedPsychicApplicationOrFail)();
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
static log(...args) {
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
60
|
+
this.getOrFail().logger.info(...args);
|
|
61
|
+
}
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
static logWithLevel(level, ...args) {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
65
|
+
this.getOrFail().logger[level](...args);
|
|
66
|
+
}
|
|
67
|
+
_apiOnly = false;
|
|
68
|
+
get apiOnly() {
|
|
69
|
+
return this._apiOnly;
|
|
70
|
+
}
|
|
71
|
+
_apiRoot;
|
|
72
|
+
get apiRoot() {
|
|
73
|
+
return this._apiRoot;
|
|
74
|
+
}
|
|
75
|
+
_sessionCookieName = 'session';
|
|
76
|
+
get sessionCookieName() {
|
|
77
|
+
return this._sessionCookieName;
|
|
78
|
+
}
|
|
79
|
+
_clientRoot;
|
|
80
|
+
get clientRoot() {
|
|
81
|
+
return this._clientRoot;
|
|
82
|
+
}
|
|
83
|
+
_encryption;
|
|
84
|
+
get encryption() {
|
|
85
|
+
return this._encryption;
|
|
86
|
+
}
|
|
87
|
+
_appName = 'untitled app';
|
|
88
|
+
get appName() {
|
|
89
|
+
return this._appName;
|
|
90
|
+
}
|
|
91
|
+
_port = EnvInternal_js_1.default.integer('PORT', { optional: true }) || 7777;
|
|
92
|
+
get port() {
|
|
93
|
+
return this._port;
|
|
94
|
+
}
|
|
95
|
+
_corsOptions = {};
|
|
96
|
+
get corsOptions() {
|
|
97
|
+
return this._corsOptions;
|
|
98
|
+
}
|
|
99
|
+
_jsonOptions;
|
|
100
|
+
get jsonOptions() {
|
|
101
|
+
return this._jsonOptions;
|
|
102
|
+
}
|
|
103
|
+
_cookieOptions;
|
|
104
|
+
get cookieOptions() {
|
|
105
|
+
return this._cookieOptions;
|
|
106
|
+
}
|
|
107
|
+
_logger = console;
|
|
108
|
+
get logger() {
|
|
109
|
+
return this._logger;
|
|
110
|
+
}
|
|
111
|
+
_sslCredentials;
|
|
112
|
+
get sslCredentials() {
|
|
113
|
+
return this._sslCredentials;
|
|
114
|
+
}
|
|
115
|
+
_saltRounds;
|
|
116
|
+
get saltRounds() {
|
|
117
|
+
return this._saltRounds;
|
|
118
|
+
}
|
|
119
|
+
_routesCb;
|
|
120
|
+
get routesCb() {
|
|
121
|
+
return this._routesCb;
|
|
122
|
+
}
|
|
123
|
+
_openapi = {
|
|
124
|
+
default: {
|
|
125
|
+
outputFilename: 'openapi.json',
|
|
126
|
+
schemaDelimeter: '',
|
|
127
|
+
info: {
|
|
128
|
+
title: 'untitled openapi spec',
|
|
129
|
+
version: 'unknown version',
|
|
130
|
+
description: '',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
get openapi() {
|
|
135
|
+
return this._openapi;
|
|
136
|
+
}
|
|
137
|
+
_client = {
|
|
138
|
+
apiPath: 'src/api',
|
|
139
|
+
};
|
|
140
|
+
get client() {
|
|
141
|
+
return this._client;
|
|
142
|
+
}
|
|
143
|
+
_paths = {
|
|
144
|
+
apiRoutes: 'src/conf/routes.ts',
|
|
145
|
+
controllers: 'src/app/controllers',
|
|
146
|
+
controllerSpecs: 'spec/unit/controllers',
|
|
147
|
+
};
|
|
148
|
+
get paths() {
|
|
149
|
+
return this._paths;
|
|
150
|
+
}
|
|
151
|
+
_inflections;
|
|
152
|
+
get inflections() {
|
|
153
|
+
return this._inflections;
|
|
154
|
+
}
|
|
155
|
+
_bootHooks = {
|
|
156
|
+
boot: [],
|
|
157
|
+
load: [],
|
|
158
|
+
'load:dev': [],
|
|
159
|
+
'load:test': [],
|
|
160
|
+
'load:prod': [],
|
|
161
|
+
};
|
|
162
|
+
get bootHooks() {
|
|
163
|
+
return this._bootHooks;
|
|
164
|
+
}
|
|
165
|
+
_specialHooks = {
|
|
166
|
+
sync: [],
|
|
167
|
+
serverInit: [],
|
|
168
|
+
serverInitAfterRoutes: [],
|
|
169
|
+
serverStart: [],
|
|
170
|
+
serverError: [],
|
|
171
|
+
serverShutdown: [],
|
|
172
|
+
};
|
|
173
|
+
get specialHooks() {
|
|
174
|
+
return this._specialHooks;
|
|
175
|
+
}
|
|
176
|
+
_overrides = {
|
|
177
|
+
['server:start']: null,
|
|
178
|
+
};
|
|
179
|
+
get overrides() {
|
|
180
|
+
return this._overrides;
|
|
181
|
+
}
|
|
182
|
+
_loadedControllers = false;
|
|
183
|
+
get loadedControllers() {
|
|
184
|
+
return this._loadedControllers;
|
|
185
|
+
}
|
|
186
|
+
_baseDefaultResponseHeaders = {
|
|
187
|
+
['cache-control']: 'max-age=0, private, must-revalidate',
|
|
188
|
+
};
|
|
189
|
+
_defaultResponseHeaders = {};
|
|
190
|
+
get defaultResponseHeaders() {
|
|
191
|
+
return {
|
|
192
|
+
...this._baseDefaultResponseHeaders,
|
|
193
|
+
...this._defaultResponseHeaders,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
get controllers() {
|
|
197
|
+
return (0, importControllers_js_1.getControllersOrFail)();
|
|
198
|
+
}
|
|
199
|
+
async load(resourceType, resourcePath,
|
|
200
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
201
|
+
importCb) {
|
|
202
|
+
switch (resourceType) {
|
|
203
|
+
case 'controllers':
|
|
204
|
+
await (0, importControllers_js_1.default)(this, resourcePath, importCb);
|
|
205
|
+
this._loadedControllers = true;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
booted = false;
|
|
210
|
+
async boot(force = false) {
|
|
211
|
+
if (this.booted && !force)
|
|
212
|
+
return;
|
|
213
|
+
// await new IntegrityChecker().check()
|
|
214
|
+
await this.runHooksFor('load');
|
|
215
|
+
switch (EnvInternal_js_1.default.nodeEnv) {
|
|
216
|
+
case 'development':
|
|
217
|
+
await this.runHooksFor('load:dev');
|
|
218
|
+
break;
|
|
219
|
+
case 'production':
|
|
220
|
+
await this.runHooksFor('load:prod');
|
|
221
|
+
break;
|
|
222
|
+
case 'test':
|
|
223
|
+
await this.runHooksFor('load:test');
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
await this.inflections?.();
|
|
227
|
+
this.booted = true;
|
|
228
|
+
}
|
|
229
|
+
on(hookEventType, cb) {
|
|
230
|
+
switch (hookEventType) {
|
|
231
|
+
case 'server:error':
|
|
232
|
+
this._specialHooks.serverError.push(cb);
|
|
233
|
+
break;
|
|
234
|
+
case 'server:init':
|
|
235
|
+
this._specialHooks.serverInit.push(cb);
|
|
236
|
+
break;
|
|
237
|
+
case 'server:start':
|
|
238
|
+
this._specialHooks.serverStart.push(cb);
|
|
239
|
+
break;
|
|
240
|
+
case 'server:shutdown':
|
|
241
|
+
this._specialHooks.serverShutdown.push(cb);
|
|
242
|
+
break;
|
|
243
|
+
case 'server:init:after-routes':
|
|
244
|
+
this._specialHooks.serverInitAfterRoutes.push(cb);
|
|
245
|
+
break;
|
|
246
|
+
case 'sync':
|
|
247
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
248
|
+
this._specialHooks['sync'].push(cb);
|
|
249
|
+
break;
|
|
250
|
+
default:
|
|
251
|
+
this.bootHooks[hookEventType].push(cb);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
set(option, unknown1, unknown2) {
|
|
255
|
+
const value = unknown2 || unknown1;
|
|
256
|
+
switch (option) {
|
|
257
|
+
case 'appName':
|
|
258
|
+
this._appName = value;
|
|
259
|
+
break;
|
|
260
|
+
case 'apiOnly':
|
|
261
|
+
this._apiOnly = value;
|
|
262
|
+
break;
|
|
263
|
+
case 'apiRoot':
|
|
264
|
+
this._apiRoot = value;
|
|
265
|
+
break;
|
|
266
|
+
case 'clientRoot':
|
|
267
|
+
this._clientRoot = value;
|
|
268
|
+
break;
|
|
269
|
+
case 'defaultResponseHeaders':
|
|
270
|
+
this._defaultResponseHeaders = Object.keys(value).reduce((agg, key) => {
|
|
271
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
272
|
+
agg[key.toLowerCase()] = value[key];
|
|
273
|
+
return agg;
|
|
274
|
+
}, {});
|
|
275
|
+
break;
|
|
276
|
+
case 'sessionCookieName':
|
|
277
|
+
this._sessionCookieName = value;
|
|
278
|
+
break;
|
|
279
|
+
case 'encryption':
|
|
280
|
+
this._encryption = value;
|
|
281
|
+
break;
|
|
282
|
+
case 'cors':
|
|
283
|
+
this._corsOptions = { ...this.corsOptions, ...value };
|
|
284
|
+
break;
|
|
285
|
+
case 'cookie':
|
|
286
|
+
this._cookieOptions = {
|
|
287
|
+
...this.cookieOptions,
|
|
288
|
+
maxAge: (0, cookieMaxAgeFromCookieOpts_js_1.default)(value.maxAge),
|
|
289
|
+
};
|
|
290
|
+
break;
|
|
291
|
+
case 'client':
|
|
292
|
+
this._client = { ...this.client, ...value };
|
|
293
|
+
break;
|
|
294
|
+
case 'routes':
|
|
295
|
+
this._routesCb = value;
|
|
296
|
+
break;
|
|
297
|
+
case 'json':
|
|
298
|
+
this._jsonOptions = { ...this.jsonOptions, ...value };
|
|
299
|
+
break;
|
|
300
|
+
case 'logger':
|
|
301
|
+
this._logger = value;
|
|
302
|
+
break;
|
|
303
|
+
case 'ssl':
|
|
304
|
+
this._sslCredentials = { ...this.sslCredentials, ...value };
|
|
305
|
+
break;
|
|
306
|
+
case 'port':
|
|
307
|
+
this._port = value;
|
|
308
|
+
break;
|
|
309
|
+
case 'saltRounds':
|
|
310
|
+
this._saltRounds = value;
|
|
311
|
+
break;
|
|
312
|
+
case 'openapi':
|
|
313
|
+
this._openapi = {
|
|
314
|
+
...this.openapi,
|
|
315
|
+
[unknown2 ? unknown1 : 'default']: {
|
|
316
|
+
outputFilename: 'openapi.json',
|
|
317
|
+
...value,
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
break;
|
|
321
|
+
case 'paths':
|
|
322
|
+
this._paths = {
|
|
323
|
+
...this.paths,
|
|
324
|
+
...value,
|
|
325
|
+
};
|
|
326
|
+
break;
|
|
327
|
+
case 'inflections':
|
|
328
|
+
this._inflections = value;
|
|
329
|
+
break;
|
|
330
|
+
default:
|
|
331
|
+
throw new Error(`Unhandled option type passed to PsychicApplication#set: ${option}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
override(override, value) {
|
|
335
|
+
switch (override) {
|
|
336
|
+
case 'server:start':
|
|
337
|
+
this.overrides['server:start'] = value;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async runHooksFor(hookEventType) {
|
|
341
|
+
for (const hook of this.bootHooks[hookEventType]) {
|
|
342
|
+
await hook(this);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
exports.default = PsychicApplication;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = logo;
|
|
4
|
+
exports.basicLogo = basicLogo;
|
|
5
|
+
const colors = require("colorette");
|
|
6
|
+
function logo() {
|
|
7
|
+
return (colors.bgMagentaBright(colors.black(`
|
|
8
|
+
,▄█▄
|
|
9
|
+
]█▄▄ ╓█████▌
|
|
10
|
+
▐██████▄ ▄█████▓╣█
|
|
11
|
+
║████████▄, , ,,▄,▄▄▄▓██████╬╬╣╣▌
|
|
12
|
+
╚███╣██████████▓▓▓▓██████████╩╠╬▓
|
|
13
|
+
╙█╬╬╬▓███████████████████████▒▓▌ `)) +
|
|
14
|
+
colors.bgMagentaBright(colors.black(`
|
|
15
|
+
╙▓█▓██████████████████████████
|
|
16
|
+
╚██████▀███████████`) + colors.greenBright(`╩█▓▌`) + colors.black(`▐▓████▄
|
|
17
|
+
'║█████`) + colors.greenBright(`\`╣█Γ║`) + colors.black(`████████▄▄φ▓█████▌
|
|
18
|
+
║█████████████████████▓█████▌
|
|
19
|
+
█████████████▓▓████████████ `)) +
|
|
20
|
+
colors.bgMagentaBright(colors.black(`
|
|
21
|
+
║█████████████████████████
|
|
22
|
+
]█████████████████████████
|
|
23
|
+
,▓██████████████████████████
|
|
24
|
+
▓█████████████████████████████µ `)) +
|
|
25
|
+
colors.bgMagentaBright(colors.black(`
|
|
26
|
+
▐███████████████████████████████▄▄
|
|
27
|
+
║█████████████████████████████████╬╬╣▓
|
|
28
|
+
,╔╦║███████████████████████████████████▓╬╬╣
|
|
29
|
+
,≥≥⌠░░░╠▓████████████████████████████████████▓▓
|
|
30
|
+
,;=-',▄█████████████████████████████████████████▓ `)) +
|
|
31
|
+
colors.bgGreen(colors.magenta(`
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
██████╗ ███████╗██╗ ██╗ ██████╗██╗ ██╗██╗ ██████╗
|
|
36
|
+
██╔══██╗██╔════╝╚██╗ ██╔╝██╔════╝██║ ██║██║██╔════╝
|
|
37
|
+
██████╔╝███████╗ ╚████╔╝ ██║ ███████║██║██║
|
|
38
|
+
██╔═══╝ ╚════██║ ╚██╔╝ ██║ ██╔══██║██║██║
|
|
39
|
+
██║ ███████║ ██║ ╚██████╗██║ ██║██║╚██████╗
|
|
40
|
+
╚═╝ ╚══════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═════╝
|
|
41
|
+
|
|
42
|
+
`)));
|
|
43
|
+
}
|
|
44
|
+
function basicLogo() {
|
|
45
|
+
return (`
|
|
46
|
+
,▄█▄
|
|
47
|
+
]█▄▄ ╓█████▌
|
|
48
|
+
▐██████▄ ▄█████▓╣█
|
|
49
|
+
║████████▄, , ,,▄,▄▄▄▓██████╬╬╣╣▌
|
|
50
|
+
╚███╣██████████▓▓▓▓██████████╩╠╬▓
|
|
51
|
+
╙█╬╬╬▓███████████████████████▒▓▌
|
|
52
|
+
╙▓█▓██████████████████████████
|
|
53
|
+
╚██████▀███████████╩█▓▌▐▓████▄
|
|
54
|
+
'║█████\`╣█Γ║████████▄▄φ▓█████▌
|
|
55
|
+
║█████████████████████▓█████▌
|
|
56
|
+
█████████████▓▓████████████
|
|
57
|
+
║█████████████████████████
|
|
58
|
+
]█████████████████████████
|
|
59
|
+
,▓██████████████████████████
|
|
60
|
+
▓█████████████████████████████µ
|
|
61
|
+
▐███████████████████████████████▄▄
|
|
62
|
+
║█████████████████████████████████╬╬╣▓
|
|
63
|
+
,╔╦║███████████████████████████████████▓╬╬╣
|
|
64
|
+
,≥≥⌠░░░╠▓████████████████████████████████████▓▓
|
|
65
|
+
,;=-',▄█████████████████████████████████████████▓
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
██████╗ ███████╗██╗ ██╗ ██████╗██╗ ██╗██╗ ██████╗
|
|
70
|
+
██╔══██╗██╔════╝╚██╗ ██╔╝██╔════╝██║ ██║██║██╔════╝
|
|
71
|
+
██████╔╝███████╗ ╚████╔╝ ██║ ███████║██║██║
|
|
72
|
+
██╔═══╝ ╚════██║ ╚██╔╝ ██║ ██╔══██║██║██║
|
|
73
|
+
██║ ███████║ ██║ ╚██████╗██║ ██║██║╚██████╗
|
|
74
|
+
╚═╝ ╚══════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═════╝
|
|
75
|
+
|
|
76
|
+
`);
|
|
77
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.routePath = routePath;
|
|
4
|
+
exports.resourcePath = resourcePath;
|
|
5
|
+
exports.sanitizedControllerPath = sanitizedControllerPath;
|
|
6
|
+
exports.controllerGlobalNameFromControllerPath = controllerGlobalNameFromControllerPath;
|
|
7
|
+
exports.namespacedRoute = namespacedRoute;
|
|
8
|
+
exports.namespacedControllerActionString = namespacedControllerActionString;
|
|
9
|
+
exports.lookupControllerOrFail = lookupControllerOrFail;
|
|
10
|
+
exports.applyResourcesAction = applyResourcesAction;
|
|
11
|
+
exports.applyResourceAction = applyResourceAction;
|
|
12
|
+
const dream_1 = require("@rvoh/dream");
|
|
13
|
+
const cannot_find_inferred_controller_from_provided_namespace_js_1 = require("../error/router/cannot-find-inferred-controller-from-provided-namespace.js");
|
|
14
|
+
const cannot_infer_controller_from_top_level_route_js_1 = require("../error/router/cannot-infer-controller-from-top-level-route.js");
|
|
15
|
+
const pascalizeFileName_js_1 = require("../helpers/pascalizeFileName.js");
|
|
16
|
+
const index_js_1 = require("../psychic-application/index.js");
|
|
17
|
+
function routePath(routePath) {
|
|
18
|
+
return `/${routePath.replace(/^\//, '')}`;
|
|
19
|
+
}
|
|
20
|
+
function resourcePath(routePath) {
|
|
21
|
+
return `/${routePath}/:id`;
|
|
22
|
+
}
|
|
23
|
+
function sanitizedControllerPath(controllerName) {
|
|
24
|
+
return controllerName.replace(/Controller$/, '') + 'Controller';
|
|
25
|
+
}
|
|
26
|
+
function controllerGlobalNameFromControllerPath(controllerName) {
|
|
27
|
+
return `controllers/${sanitizedControllerPath(controllerName)}`;
|
|
28
|
+
}
|
|
29
|
+
function namespacedRoute(namespace, route) {
|
|
30
|
+
const compactedRoutes = (0, dream_1.compact)([namespace || null, route]);
|
|
31
|
+
return '/' + compactedRoutes.join('/').replace(/^\//, '');
|
|
32
|
+
}
|
|
33
|
+
function namespacedControllerActionString(namespace, controllerActionString) {
|
|
34
|
+
return [
|
|
35
|
+
namespace
|
|
36
|
+
.split('/')
|
|
37
|
+
.filter(part => !/^:/.test(part))
|
|
38
|
+
.map(part => (0, dream_1.pascalize)(part))
|
|
39
|
+
.join('/'),
|
|
40
|
+
controllerActionString,
|
|
41
|
+
]
|
|
42
|
+
.join('/')
|
|
43
|
+
.replace(/^\//, '');
|
|
44
|
+
}
|
|
45
|
+
function lookupControllerOrFail(routingMechanism, opts) {
|
|
46
|
+
const namespaces = opts.resourceName
|
|
47
|
+
? routingMechanism.currentNamespaces.concat({
|
|
48
|
+
namespace: opts.resourceName,
|
|
49
|
+
resourceful: false,
|
|
50
|
+
isScope: false,
|
|
51
|
+
})
|
|
52
|
+
: routingMechanism.currentNamespaces;
|
|
53
|
+
const filteredNamespaces = namespaces.filter(n => !n.isScope);
|
|
54
|
+
if (!filteredNamespaces.length)
|
|
55
|
+
throw new cannot_infer_controller_from_top_level_route_js_1.default(opts.httpMethod, opts.path, (0, pascalizeFileName_js_1.default)(opts.path) + 'Controller', (0, dream_1.camelize)((0, pascalizeFileName_js_1.default)(opts.path)));
|
|
56
|
+
return inferControllerOrFail(filteredNamespaces, opts);
|
|
57
|
+
}
|
|
58
|
+
function inferControllerOrFail(filteredNamespaces, opts) {
|
|
59
|
+
const filename = filteredNamespaces.map(str => (0, dream_1.pascalize)(str.namespace)).join('/') + 'Controller';
|
|
60
|
+
const expectedPath = `controllers/${filename}`;
|
|
61
|
+
const controller = index_js_1.default.getOrFail().controllers[expectedPath];
|
|
62
|
+
if (!controller)
|
|
63
|
+
throw new cannot_find_inferred_controller_from_provided_namespace_js_1.default({
|
|
64
|
+
expectedPath,
|
|
65
|
+
controllerName: filename.replace(/\//g, ''),
|
|
66
|
+
action: (0, dream_1.camelize)((0, pascalizeFileName_js_1.default)(opts.path)),
|
|
67
|
+
httpMethod: opts.httpMethod,
|
|
68
|
+
path: opts.path,
|
|
69
|
+
});
|
|
70
|
+
return controller;
|
|
71
|
+
}
|
|
72
|
+
function applyResourcesAction(path, action, routingMechanism, options) {
|
|
73
|
+
const controller = options?.controller ||
|
|
74
|
+
lookupControllerOrFail(routingMechanism, {
|
|
75
|
+
path: action,
|
|
76
|
+
httpMethod: httpMethodFromResourcefulAction(action),
|
|
77
|
+
resourceName: path,
|
|
78
|
+
});
|
|
79
|
+
switch (action) {
|
|
80
|
+
case 'index':
|
|
81
|
+
routingMechanism.get(path, controller, 'index');
|
|
82
|
+
break;
|
|
83
|
+
case 'create':
|
|
84
|
+
routingMechanism.post(path, controller, 'create');
|
|
85
|
+
break;
|
|
86
|
+
case 'update':
|
|
87
|
+
routingMechanism.put(`${path}/:id`, controller, 'update');
|
|
88
|
+
routingMechanism.patch(`${path}/:id`, controller, 'update');
|
|
89
|
+
break;
|
|
90
|
+
case 'show':
|
|
91
|
+
routingMechanism.get(`${path}/:id`, controller, 'show');
|
|
92
|
+
break;
|
|
93
|
+
case 'destroy':
|
|
94
|
+
routingMechanism.delete(`${path}/:id`, controller, 'destroy');
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function applyResourceAction(path, action, routingMechanism, options) {
|
|
99
|
+
const controller = options?.controller ||
|
|
100
|
+
lookupControllerOrFail(routingMechanism, {
|
|
101
|
+
path: action,
|
|
102
|
+
httpMethod: httpMethodFromResourcefulAction(action),
|
|
103
|
+
resourceName: path,
|
|
104
|
+
});
|
|
105
|
+
switch (action) {
|
|
106
|
+
case 'create':
|
|
107
|
+
routingMechanism.post(path, controller, 'create');
|
|
108
|
+
break;
|
|
109
|
+
case 'update':
|
|
110
|
+
routingMechanism.put(path, controller, 'update');
|
|
111
|
+
routingMechanism.patch(path, controller, 'update');
|
|
112
|
+
break;
|
|
113
|
+
case 'show':
|
|
114
|
+
routingMechanism.get(path, controller, 'show');
|
|
115
|
+
break;
|
|
116
|
+
case 'destroy':
|
|
117
|
+
routingMechanism.delete(path, controller, 'destroy');
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
throw new Error(`unsupported resource method type: ${action}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function httpMethodFromResourcefulAction(action) {
|
|
124
|
+
switch (action) {
|
|
125
|
+
case 'index':
|
|
126
|
+
return 'get';
|
|
127
|
+
case 'show':
|
|
128
|
+
return 'get';
|
|
129
|
+
case 'create':
|
|
130
|
+
return 'post';
|
|
131
|
+
case 'update':
|
|
132
|
+
return 'patch';
|
|
133
|
+
case 'destroy':
|
|
134
|
+
return 'delete';
|
|
135
|
+
default:
|
|
136
|
+
throw new Error(`unexpected resourceful action: ${action}`);
|
|
137
|
+
}
|
|
138
|
+
}
|