@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 RVO Health
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
> ATTENTION: we are currently in the process of releasing this code to the world, as of the afternoon of March 10th, 2025. This notice will be removed, and the version of this repo will be bumped to 1.0.0, once all of the repos have been migrated to the new spaces and we can verify that it is all working. This is anticipated to take 1 day.
|
|
2
|
+
|
|
3
|
+
# Psychic
|
|
4
|
+
|
|
5
|
+
Psychic is a typescript first Node framework built on top of [kysely](http://kysely.dev) and heavily inspired by Ruby on Rails. It provides a light-weight routing layer around [expressjs](https://expressjs.com) to create a familiar MVC pattern for those coming from a conventional MVC framework, a type-safe ORM with an incredibly powerful autocomplete API, elegant redis and socket.io bindings for distributed websocket applications, the ability to couple with a front-end framework (like react, angular, etc...) and write specs that drive through your front end, while still maintaining a back end-centric context from which to write specs.
|
|
6
|
+
|
|
7
|
+
For more comprehensive documentation, please see [The official Psychic guides](https://psychic-docs.netlify.app). We will also be publishing api docs shortly, but the Psychic guides should be comprehensive enough to provide an understanding of the technology and how to use it.
|
|
8
|
+
|
|
9
|
+
NOTE: doing so will create the new app in the psychic folder, so once done testing remember to remove it.
|
|
10
|
+
|
|
11
|
+
## Questions?
|
|
12
|
+
|
|
13
|
+
- **Ask them on [Stack Overflow](https://stackoverflow.com)**, using the `[psychic]` tag.
|
|
14
|
+
|
|
15
|
+
## Contributing
|
|
16
|
+
|
|
17
|
+
Psychic is an open source library, so we encourage you to actively contribute. Visit our [Contributing](https://github.com/rvohealth/psychic/CONTRIBUTING.md) guide to learn more about the processes we use for submitting pull requests or issues.
|
|
18
|
+
|
|
19
|
+
Are you trying to report a possible security vulnerability? Visit our [Security Policy](https://github.com/rvohealth/psychic/SECURITY.md) for guidelines about how to proceed.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = enumsAndTheirValues;
|
|
4
|
+
const dream_1 = require("@rvoh/dream");
|
|
5
|
+
const kysely_1 = require("kysely");
|
|
6
|
+
async function enumsAndTheirValues() {
|
|
7
|
+
const { rows } = await (0, kysely_1.sql) `
|
|
8
|
+
SELECT pg_type.typname AS enum_type, pg_enum.enumlabel AS enum_label FROM pg_type JOIN pg_enum ON pg_enum.enumtypid = pg_type.oid;
|
|
9
|
+
|
|
10
|
+
`.execute((0, dream_1.db)('primary'));
|
|
11
|
+
const rowData = {};
|
|
12
|
+
rows.forEach(row => {
|
|
13
|
+
rowData[row.enumType] ||= [];
|
|
14
|
+
rowData[row.enumType].push(row.enumLabel);
|
|
15
|
+
});
|
|
16
|
+
return rowData;
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = enumsFileStr;
|
|
4
|
+
const autogeneratedFileDisclaimer_js_1 = require("../../helpers/autogeneratedFileDisclaimer.js");
|
|
5
|
+
const pascalizeFileName_js_1 = require("../../helpers/pascalizeFileName.js");
|
|
6
|
+
const enumsAndTheirValues_js_1 = require("./enumsAndTheirValues.js");
|
|
7
|
+
async function enumsFileStr() {
|
|
8
|
+
const enums = await (0, enumsAndTheirValues_js_1.default)();
|
|
9
|
+
let enumsFileStr = (0, autogeneratedFileDisclaimer_js_1.default)();
|
|
10
|
+
Object.keys(enums).forEach(enumName => {
|
|
11
|
+
const exportedTypeName = (0, pascalizeFileName_js_1.default)(enumName) + 'Values';
|
|
12
|
+
const values = enums[enumName];
|
|
13
|
+
enumsFileStr += `\
|
|
14
|
+
export const ${exportedTypeName} = [
|
|
15
|
+
${values.map(val => `'${val}'`).join(',\n ')}
|
|
16
|
+
] as const
|
|
17
|
+
|
|
18
|
+
`;
|
|
19
|
+
});
|
|
20
|
+
return enumsFileStr;
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = generateRouteTypes;
|
|
4
|
+
const dream_1 = require("@rvoh/dream");
|
|
5
|
+
const fs = require("fs/promises");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const index_js_1 = require("../../psychic-application/index.js");
|
|
8
|
+
async function generateRouteTypes(routes) {
|
|
9
|
+
const fileStr = `\
|
|
10
|
+
export type RouteTypes =
|
|
11
|
+
${(0, dream_1.uniq)(routes.map(routeConf => ` | '/${routeConf.path.replace(/^\//, '')}'`)).join('\n')}
|
|
12
|
+
`;
|
|
13
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
14
|
+
const routeTypesPath = path.join(psychicApp.apiRoot, 'src/conf/routeTypes.ts');
|
|
15
|
+
await fs.writeFile(routeTypesPath, fileStr);
|
|
16
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = printRoutes;
|
|
4
|
+
const colors = require("colorette");
|
|
5
|
+
const index_js_1 = require("../../server/index.js");
|
|
6
|
+
async function printRoutes() {
|
|
7
|
+
const server = new index_js_1.default();
|
|
8
|
+
await server.boot();
|
|
9
|
+
const routes = await server.routes();
|
|
10
|
+
const expressions = buildExpressions(routes);
|
|
11
|
+
// NOTE: intentionally doing this outside of the expression loop below
|
|
12
|
+
// to avoid N+1
|
|
13
|
+
const desiredFirstGapSpaceCount = calculateNumSpacesInFirstGap(expressions);
|
|
14
|
+
const desiredLastGapSpaceCount = calculateNumSpacesInLastGap(expressions);
|
|
15
|
+
expressions.forEach(([beginning, end], i) => {
|
|
16
|
+
const partialExpression = `${beginning}${makeSpaces(beginning, desiredFirstGapSpaceCount)}${end}`;
|
|
17
|
+
const closingSpaces = makeSpaces(partialExpression, desiredLastGapSpaceCount);
|
|
18
|
+
const expression = `${partialExpression}${closingSpaces}`;
|
|
19
|
+
const colorizedExpression = i % 2 ? colors.bgWhite(colors.black(expression)) : expression;
|
|
20
|
+
console.log(colorizedExpression);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function buildExpressions(routes) {
|
|
24
|
+
return routes.map(route => {
|
|
25
|
+
const method = route.httpMethod.toUpperCase();
|
|
26
|
+
const numMethodSpaces = 8 - method.length;
|
|
27
|
+
const beginningOfExpression = `${route.httpMethod.toUpperCase()}${' '.repeat(numMethodSpaces)}${route.path}`;
|
|
28
|
+
const endOfExpression = route.controller.disaplayName + '#' + route.action;
|
|
29
|
+
return [beginningOfExpression, endOfExpression];
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function makeSpaces(expression, desiredCount) {
|
|
33
|
+
return ' '.repeat(Math.max(desiredCount - expression.length, 1));
|
|
34
|
+
}
|
|
35
|
+
function calculateNumSpacesInFirstGap(expressions) {
|
|
36
|
+
let desiredSpaceCount = 0;
|
|
37
|
+
expressions.forEach(expression => {
|
|
38
|
+
if (expression[0].length > desiredSpaceCount)
|
|
39
|
+
desiredSpaceCount = expression[0].length;
|
|
40
|
+
});
|
|
41
|
+
const gapSpaces = 3;
|
|
42
|
+
return desiredSpaceCount + gapSpaces;
|
|
43
|
+
}
|
|
44
|
+
function calculateNumSpacesInLastGap(expressions) {
|
|
45
|
+
const desiredFirstGapSpaceCount = calculateNumSpacesInFirstGap(expressions);
|
|
46
|
+
let desiredSpaceCount = 0;
|
|
47
|
+
expressions.forEach(([beginning, end]) => {
|
|
48
|
+
const spaces = desiredFirstGapSpaceCount - beginning.length;
|
|
49
|
+
const expression = `${beginning}${spaces}${end}`;
|
|
50
|
+
if (expression.length > desiredSpaceCount)
|
|
51
|
+
desiredSpaceCount = expression.length;
|
|
52
|
+
});
|
|
53
|
+
return desiredSpaceCount + 3;
|
|
54
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dream_1 = require("@rvoh/dream");
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const TypesBuilder_js_1 = require("../cli/helpers/TypesBuilder.js");
|
|
7
|
+
const controller_js_1 = require("../generate/controller.js");
|
|
8
|
+
const resource_js_1 = require("../generate/resource.js");
|
|
9
|
+
const typechecks_js_1 = require("../helpers/typechecks.js");
|
|
10
|
+
const app_js_1 = require("../openapi-renderer/app.js");
|
|
11
|
+
const index_js_1 = require("../psychic-application/index.js");
|
|
12
|
+
const index_js_2 = require("../server/index.js");
|
|
13
|
+
const enumsFileStr_js_1 = require("./helpers/enumsFileStr.js");
|
|
14
|
+
const generateRouteTypes_js_1 = require("./helpers/generateRouteTypes.js");
|
|
15
|
+
const printRoutes_js_1 = require("./helpers/printRoutes.js");
|
|
16
|
+
class PsychicBin {
|
|
17
|
+
static async generateController(controllerName, actions) {
|
|
18
|
+
await (0, controller_js_1.default)({ fullyQualifiedControllerName: controllerName, actions });
|
|
19
|
+
}
|
|
20
|
+
static async generateResource(route, fullyQualifiedModelName, columnsWithTypes) {
|
|
21
|
+
await (0, resource_js_1.default)({ route, fullyQualifiedModelName, columnsWithTypes });
|
|
22
|
+
}
|
|
23
|
+
static async routes() {
|
|
24
|
+
await (0, printRoutes_js_1.default)();
|
|
25
|
+
}
|
|
26
|
+
static async sync({ bypassDreamSync = false } = {}) {
|
|
27
|
+
if (!bypassDreamSync)
|
|
28
|
+
await dream_1.DreamBin.sync(() => { });
|
|
29
|
+
await PsychicBin.syncTypes();
|
|
30
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
31
|
+
if (!psychicApp.apiOnly) {
|
|
32
|
+
await PsychicBin.syncOpenapiJson();
|
|
33
|
+
}
|
|
34
|
+
if (psychicApp.openapi?.syncEnumsToClient) {
|
|
35
|
+
await this.syncClientEnums();
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
let output = {};
|
|
39
|
+
for (const hook of psychicApp.specialHooks.sync) {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
41
|
+
const res = await hook();
|
|
42
|
+
if ((0, typechecks_js_1.isObject)(res)) {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
44
|
+
output = { ...output, ...res };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (Object.keys(output).length) {
|
|
48
|
+
await PsychicBin.syncTypes(output);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
static async syncTypes(customTypes = undefined) {
|
|
53
|
+
console.log(`syncing types/psychic.ts...`);
|
|
54
|
+
await TypesBuilder_js_1.default.sync(customTypes);
|
|
55
|
+
console.log(`done syncing types/psychic.ts!`);
|
|
56
|
+
}
|
|
57
|
+
static async syncOpenapiJson() {
|
|
58
|
+
console.log(`syncing openapi...`);
|
|
59
|
+
await app_js_1.default.sync();
|
|
60
|
+
console.log(`done syncing openapi!`);
|
|
61
|
+
}
|
|
62
|
+
static async syncRoutes() {
|
|
63
|
+
console.log('syncing routes...');
|
|
64
|
+
const server = new index_js_2.default();
|
|
65
|
+
await server.boot();
|
|
66
|
+
const routes = await server.routes();
|
|
67
|
+
await (0, generateRouteTypes_js_1.default)(routes);
|
|
68
|
+
console.log('done syncing routes!');
|
|
69
|
+
}
|
|
70
|
+
static async syncClientEnums() {
|
|
71
|
+
console.log('syncing client enums...');
|
|
72
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
73
|
+
const apiPath = path.join(psychicApp.clientRoot, psychicApp.client.apiPath);
|
|
74
|
+
const enumsStr = await (0, enumsFileStr_js_1.default)();
|
|
75
|
+
await fs.writeFile(`${apiPath}/enums.ts`, enumsStr);
|
|
76
|
+
console.log('done syncing client enums!');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.default = PsychicBin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dream_1 = require("@rvoh/dream");
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const index_js_1 = require("../../psychic-application/index.js");
|
|
7
|
+
class TypesBuilder {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
static async sync(customTypes = undefined) {
|
|
10
|
+
const dreamApp = dream_1.DreamApplication.getOrFail();
|
|
11
|
+
const schemaPath = path.join(dreamApp.projectRoot, dreamApp.paths.types, 'psychic.ts');
|
|
12
|
+
await fs.writeFile(schemaPath, this.build(customTypes));
|
|
13
|
+
}
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
static build(customTypes = undefined) {
|
|
16
|
+
const psychicApp = index_js_1.default.getOrFail();
|
|
17
|
+
const output = {
|
|
18
|
+
openapiNames: Object.keys(psychicApp.openapi),
|
|
19
|
+
...(customTypes || {}),
|
|
20
|
+
};
|
|
21
|
+
return `const psychicTypes = ${JSON.stringify(output, null, 2)} as const
|
|
22
|
+
|
|
23
|
+
export default psychicTypes`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = TypesBuilder;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dream_1 = require("@rvoh/dream");
|
|
4
|
+
const index_js_1 = require("../bin/index.js");
|
|
5
|
+
const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
|
|
6
|
+
class PsychicCLI {
|
|
7
|
+
static provide(program, { initializePsychicApplication, seedDb, }) {
|
|
8
|
+
dream_1.DreamCLI.generateDreamCli(program, {
|
|
9
|
+
initializeDreamApplication: initializePsychicApplication,
|
|
10
|
+
seedDb,
|
|
11
|
+
onSync: async () => {
|
|
12
|
+
await index_js_1.default.sync({ bypassDreamSync: true });
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
program
|
|
16
|
+
.command('generate:resource')
|
|
17
|
+
.alias('g:resource')
|
|
18
|
+
.description('create a Dream model, migration, controller, serializer, and spec placeholders')
|
|
19
|
+
.argument('<path>', 'URL path from root domain')
|
|
20
|
+
.argument('<modelName>', 'the name of the model to create, e.g. Post or Settings/CommunicationPreferences')
|
|
21
|
+
.argument('[columnsWithTypes...]', 'properties of the model property1:text/string/enum/etc. property2:text/string/enum/etc. ... propertyN:text/string/enum/etc.')
|
|
22
|
+
.action(async (route, modelName, columnsWithTypes) => {
|
|
23
|
+
EnvInternal_js_1.default.provideDefaultNodeEnv('test');
|
|
24
|
+
await initializePsychicApplication();
|
|
25
|
+
await index_js_1.default.generateResource(route, modelName, columnsWithTypes);
|
|
26
|
+
process.exit();
|
|
27
|
+
});
|
|
28
|
+
program
|
|
29
|
+
.command('generate:controller')
|
|
30
|
+
.alias('g:controller')
|
|
31
|
+
.description('create a controller')
|
|
32
|
+
.argument('<controllerName>', 'the name of the controller to create, including namespaces, e.g. Posts or Api/V1/Posts')
|
|
33
|
+
.argument('[actions...]', 'the names of controller actions to create')
|
|
34
|
+
.action(async (controllerName, actions) => {
|
|
35
|
+
EnvInternal_js_1.default.provideDefaultNodeEnv('test');
|
|
36
|
+
await initializePsychicApplication();
|
|
37
|
+
await index_js_1.default.generateController(controllerName, actions);
|
|
38
|
+
process.exit();
|
|
39
|
+
});
|
|
40
|
+
program
|
|
41
|
+
.command('routes')
|
|
42
|
+
.description('examines your current models, building a type-map of the associations so that the ORM can understand your relational setup. This is commited to your repo, and synced to the dream repo for consumption within the underlying library.')
|
|
43
|
+
.action(async () => {
|
|
44
|
+
EnvInternal_js_1.default.provideDefaultNodeEnv('test');
|
|
45
|
+
await initializePsychicApplication();
|
|
46
|
+
await index_js_1.default.routes();
|
|
47
|
+
process.exit();
|
|
48
|
+
});
|
|
49
|
+
program
|
|
50
|
+
.command('sync')
|
|
51
|
+
.description('sync introspects your database, updating your schema to reflect, and then syncs the new schema with the installed dream node module, allowing it provide your schema to the underlying kysely integration')
|
|
52
|
+
.action(async () => {
|
|
53
|
+
EnvInternal_js_1.default.provideDefaultNodeEnv('test');
|
|
54
|
+
await initializePsychicApplication();
|
|
55
|
+
await index_js_1.default.sync();
|
|
56
|
+
process.exit();
|
|
57
|
+
});
|
|
58
|
+
program
|
|
59
|
+
.command('sync:routes')
|
|
60
|
+
.description('reads the routes generated by your app and generates a cache file, which is then used to give autocomplete support to the route helper, amoongst other things.')
|
|
61
|
+
.action(async () => {
|
|
62
|
+
EnvInternal_js_1.default.provideDefaultNodeEnv('test');
|
|
63
|
+
await index_js_1.default.syncRoutes();
|
|
64
|
+
});
|
|
65
|
+
program
|
|
66
|
+
.command('sync:openapi')
|
|
67
|
+
.description('syncs openapi.json file to current state of all psychic controllers within the app')
|
|
68
|
+
.action(async () => {
|
|
69
|
+
EnvInternal_js_1.default.provideDefaultNodeEnv('test');
|
|
70
|
+
await initializePsychicApplication();
|
|
71
|
+
await index_js_1.default.syncOpenapiJson();
|
|
72
|
+
process.exit();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.default = PsychicCLI;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeforeAction = BeforeAction;
|
|
4
|
+
exports.OpenAPI = OpenAPI;
|
|
5
|
+
const endpoint_js_1 = require("../openapi-renderer/endpoint.js");
|
|
6
|
+
const hooks_js_1 = require("./hooks.js");
|
|
7
|
+
function BeforeAction(opts = {}) {
|
|
8
|
+
return function (_, context) {
|
|
9
|
+
const methodName = context.name;
|
|
10
|
+
context.addInitializer(function () {
|
|
11
|
+
const psychicControllerClass = this.constructor;
|
|
12
|
+
if (!psychicControllerClass['globallyInitializingDecorators']) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!Object.getOwnPropertyDescriptor(psychicControllerClass, 'controllerHooks'))
|
|
16
|
+
psychicControllerClass.controllerHooks = [...psychicControllerClass.controllerHooks];
|
|
17
|
+
psychicControllerClass.controllerHooks.push(new hooks_js_1.ControllerHook(psychicControllerClass.name, methodName.toString(), opts));
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Used to annotate your controller method in a way that enables
|
|
23
|
+
* Psychic to automatically generate an openapi spec for you. Using
|
|
24
|
+
* this feature, you can easily document your api in typescript, taking
|
|
25
|
+
* advantage of powerful type completion and validation, as well as useful
|
|
26
|
+
* shorthand notation to keep annotations simple when possible.
|
|
27
|
+
*
|
|
28
|
+
* @param modelOrSerializer - a function which immediately returns either a serializer class, a dream model class, or else something that has a serializers getter on it.
|
|
29
|
+
* @param body - Optional. The shape of the request body
|
|
30
|
+
* @param headers - Optional. The list of request headers to provide for this endpoint
|
|
31
|
+
* @param many - Optional. whether or not to render a top level array for this serializer
|
|
32
|
+
* @param method - The HTTP method to use when hitting this endpoint
|
|
33
|
+
* @param path - Optional. If passed, this path will be used as the request path. If not, it will be looked up in the conf/routes.ts file.
|
|
34
|
+
* @param query - Optional. A list of query params to provide for this endpoint
|
|
35
|
+
* @param responses - Optional. A list of additional responses that your app may return
|
|
36
|
+
* @param serializerKey - Optional. Use this to override the serializer key to use when looking up a serializer by the provided model or view model.
|
|
37
|
+
* @param status - Optional. The status code this endpoint uses when responding successfully. If not passed, 200 is assummed.
|
|
38
|
+
* @param tags - Optional. string array
|
|
39
|
+
* @param uri - Optional. A list of uri segments that this endpoint uses
|
|
40
|
+
*/
|
|
41
|
+
function OpenAPI(modelOrSerializer, opts) {
|
|
42
|
+
return function (_, context) {
|
|
43
|
+
const methodName = context.name;
|
|
44
|
+
context.addInitializer(function () {
|
|
45
|
+
const psychicControllerClass = this.constructor;
|
|
46
|
+
if (!psychicControllerClass['globallyInitializingDecorators']) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const methodNameString = methodName.toString();
|
|
50
|
+
if (!Object.getOwnPropertyDescriptor(psychicControllerClass, 'openapi'))
|
|
51
|
+
psychicControllerClass.openapi = {};
|
|
52
|
+
if (!Object.getOwnPropertyDescriptor(psychicControllerClass, 'controllerActionMetadata'))
|
|
53
|
+
psychicControllerClass['controllerActionMetadata'] = {};
|
|
54
|
+
if (opts) {
|
|
55
|
+
psychicControllerClass.openapi[methodNameString] = new endpoint_js_1.default(modelOrSerializer, psychicControllerClass, methodNameString, opts);
|
|
56
|
+
psychicControllerClass['controllerActionMetadata'][methodNameString] ||= {};
|
|
57
|
+
psychicControllerClass['controllerActionMetadata'][methodNameString]['serializerKey'] =
|
|
58
|
+
opts.serializerKey;
|
|
59
|
+
//
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (isSerializable(modelOrSerializer)) {
|
|
63
|
+
psychicControllerClass.openapi[methodNameString] = new endpoint_js_1.default(modelOrSerializer, psychicControllerClass, methodNameString, undefined);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
psychicControllerClass.openapi[methodNameString] = new endpoint_js_1.default(null, psychicControllerClass, methodNameString, modelOrSerializer);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
function isSerializable(dreamOrSerializerClass) {
|
|
74
|
+
return (Array.isArray(dreamOrSerializerClass) ||
|
|
75
|
+
hasSerializersGetter(dreamOrSerializerClass) ||
|
|
76
|
+
!!dreamOrSerializerClass?.isDreamSerializer);
|
|
77
|
+
}
|
|
78
|
+
function hasSerializersGetter(dreamOrSerializerClass) {
|
|
79
|
+
try {
|
|
80
|
+
return !!dreamOrSerializerClass?.prototype?.serializers;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ControllerHook = void 0;
|
|
4
|
+
class ControllerHook {
|
|
5
|
+
controllerClassName;
|
|
6
|
+
methodName;
|
|
7
|
+
isStatic;
|
|
8
|
+
only;
|
|
9
|
+
except;
|
|
10
|
+
constructor(controllerClassName, methodName, { isStatic = false, only = [], except = [], }) {
|
|
11
|
+
this.controllerClassName = controllerClassName;
|
|
12
|
+
this.methodName = methodName;
|
|
13
|
+
this.isStatic = isStatic;
|
|
14
|
+
this.only = only;
|
|
15
|
+
this.except = except;
|
|
16
|
+
}
|
|
17
|
+
shouldFireForAction(actionName) {
|
|
18
|
+
if (!!this.only.length && this.only.includes(actionName))
|
|
19
|
+
return true;
|
|
20
|
+
if (!!this.only.length && !this.only.includes(actionName))
|
|
21
|
+
return false;
|
|
22
|
+
if (!!this.except.length && this.except.includes(actionName))
|
|
23
|
+
return false;
|
|
24
|
+
if (!!this.except.length && !this.except.includes(actionName))
|
|
25
|
+
return true;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ControllerHook = ControllerHook;
|