moonflower 0.11.2 → 1.0.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/dist/errors/BaseHttpError.cjs +2 -0
- package/dist/errors/BaseHttpError.cjs.map +1 -0
- package/dist/{src/errors → errors}/BaseHttpError.d.ts +1 -0
- package/dist/errors/BaseHttpError.d.ts.map +1 -0
- package/dist/errors/BaseHttpError.mjs +10 -0
- package/dist/errors/BaseHttpError.mjs.map +1 -0
- package/dist/errors/HttpErrorHandler.cjs +2 -0
- package/dist/errors/HttpErrorHandler.cjs.map +1 -0
- package/dist/{src/errors → errors}/HttpErrorHandler.d.ts +2 -1
- package/dist/errors/HttpErrorHandler.d.ts.map +1 -0
- package/dist/errors/HttpErrorHandler.mjs +19 -0
- package/dist/errors/HttpErrorHandler.mjs.map +1 -0
- package/dist/errors/UserFacingErrors.cjs +2 -0
- package/dist/errors/UserFacingErrors.cjs.map +1 -0
- package/dist/{src/errors → errors}/UserFacingErrors.d.ts +1 -0
- package/dist/errors/UserFacingErrors.d.ts.map +1 -0
- package/dist/errors/UserFacingErrors.mjs +23 -0
- package/dist/errors/UserFacingErrors.mjs.map +1 -0
- package/dist/hooks/authentication/useAuth.cjs +2 -0
- package/dist/hooks/authentication/useAuth.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/authentication/useAuth.d.ts +1 -0
- package/dist/hooks/authentication/useAuth.d.ts.map +1 -0
- package/dist/hooks/authentication/useAuth.mjs +5 -0
- package/dist/hooks/authentication/useAuth.mjs.map +1 -0
- package/dist/hooks/authentication/useOptionalAuth.cjs +2 -0
- package/dist/hooks/authentication/useOptionalAuth.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/authentication/useOptionalAuth.d.ts +1 -0
- package/dist/hooks/authentication/useOptionalAuth.d.ts.map +1 -0
- package/dist/hooks/authentication/useOptionalAuth.mjs +14 -0
- package/dist/hooks/authentication/useOptionalAuth.mjs.map +1 -0
- package/dist/hooks/useApiEndpoint.cjs +2 -0
- package/dist/hooks/useApiEndpoint.cjs.map +1 -0
- package/dist/hooks/useApiEndpoint.d.ts.map +1 -0
- package/dist/hooks/useApiEndpoint.mjs +5 -0
- package/dist/hooks/useApiEndpoint.mjs.map +1 -0
- package/dist/hooks/useApiEndpoint.spec.d.ts +2 -0
- package/dist/hooks/useApiEndpoint.spec.d.ts.map +1 -0
- package/dist/hooks/useApiHeader/index.d.ts.map +1 -0
- package/dist/hooks/useApiHeader/useApiHeader.cjs +2 -0
- package/dist/hooks/useApiHeader/useApiHeader.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/useApiHeader/useApiHeader.d.ts +1 -0
- package/dist/hooks/useApiHeader/useApiHeader.d.ts.map +1 -0
- package/dist/hooks/useApiHeader/useApiHeader.mjs +6 -0
- package/dist/hooks/useApiHeader/useApiHeader.mjs.map +1 -0
- package/dist/hooks/useApiHeader/useApiHeader.spec.d.ts +2 -0
- package/dist/hooks/useApiHeader/useApiHeader.spec.d.ts.map +1 -0
- package/dist/hooks/useApiHeader/useApiHeader.spec.data.d.ts.map +1 -0
- package/dist/hooks/useCookieParams.cjs +2 -0
- package/dist/hooks/useCookieParams.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/useCookieParams.d.ts +1 -0
- package/dist/hooks/useCookieParams.d.ts.map +1 -0
- package/dist/hooks/useCookieParams.mjs +41 -0
- package/dist/hooks/useCookieParams.mjs.map +1 -0
- package/dist/hooks/useCookieParams.spec.d.ts +2 -0
- package/dist/hooks/useCookieParams.spec.d.ts.map +1 -0
- package/dist/hooks/useExposeApiModel/index.d.ts.map +1 -0
- package/dist/hooks/useExposeApiModel/useExposeApiModel.d.ts.map +1 -0
- package/dist/hooks/useExposeApiModel/useExposeApiModel.spec.d.ts +2 -0
- package/dist/hooks/useExposeApiModel/useExposeApiModel.spec.d.ts.map +1 -0
- package/dist/hooks/useExposeApiModel/useExposeApiModel.spec.data.d.ts.map +1 -0
- package/dist/hooks/useExposeApiModel.cjs +2 -0
- package/dist/hooks/useExposeApiModel.cjs.map +1 -0
- package/dist/hooks/useExposeApiModel.d.ts +1 -0
- package/dist/hooks/useExposeApiModel.mjs +8 -0
- package/dist/hooks/useExposeApiModel.mjs.map +1 -0
- package/dist/hooks/useHeaderParams.cjs +2 -0
- package/dist/hooks/useHeaderParams.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/useHeaderParams.d.ts +1 -0
- package/dist/hooks/useHeaderParams.d.ts.map +1 -0
- package/dist/hooks/useHeaderParams.mjs +42 -0
- package/dist/hooks/useHeaderParams.mjs.map +1 -0
- package/dist/hooks/useHeaderParams.spec.d.ts +2 -0
- package/dist/hooks/useHeaderParams.spec.d.ts.map +1 -0
- package/dist/hooks/usePathParams.cjs +2 -0
- package/dist/hooks/usePathParams.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/usePathParams.d.ts +1 -0
- package/dist/hooks/usePathParams.d.ts.map +1 -0
- package/dist/hooks/usePathParams.mjs +35 -0
- package/dist/hooks/usePathParams.mjs.map +1 -0
- package/dist/hooks/usePathParams.spec.d.ts +2 -0
- package/dist/hooks/usePathParams.spec.d.ts.map +1 -0
- package/dist/hooks/useQueryParams.cjs +2 -0
- package/dist/hooks/useQueryParams.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/useQueryParams.d.ts +1 -0
- package/dist/hooks/useQueryParams.d.ts.map +1 -0
- package/dist/hooks/useQueryParams.mjs +40 -0
- package/dist/hooks/useQueryParams.mjs.map +1 -0
- package/dist/hooks/useQueryParams.spec.d.ts +2 -0
- package/dist/hooks/useQueryParams.spec.d.ts.map +1 -0
- package/dist/hooks/useRequestBody.cjs +2 -0
- package/dist/hooks/useRequestBody.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/useRequestBody.d.ts +1 -0
- package/dist/hooks/useRequestBody.d.ts.map +1 -0
- package/dist/hooks/useRequestBody.mjs +42 -0
- package/dist/hooks/useRequestBody.mjs.map +1 -0
- package/dist/hooks/useRequestBody.spec.d.ts +2 -0
- package/dist/hooks/useRequestBody.spec.d.ts.map +1 -0
- package/dist/hooks/useRequestRawBody.cjs +2 -0
- package/dist/hooks/useRequestRawBody.cjs.map +1 -0
- package/dist/{src/hooks → hooks}/useRequestRawBody.d.ts +1 -0
- package/dist/hooks/useRequestRawBody.d.ts.map +1 -0
- package/dist/hooks/useRequestRawBody.mjs +27 -0
- package/dist/hooks/useRequestRawBody.mjs.map +1 -0
- package/dist/hooks/useRequestRawBody.spec.d.ts +2 -0
- package/dist/hooks/useRequestRawBody.spec.d.ts.map +1 -0
- package/dist/hooks/useReturnValue.cjs +2 -0
- package/dist/hooks/useReturnValue.cjs.map +1 -0
- package/dist/hooks/useReturnValue.d.ts.map +1 -0
- package/dist/hooks/useReturnValue.mjs +10 -0
- package/dist/hooks/useReturnValue.mjs.map +1 -0
- package/dist/hooks/useReturnValue.spec.d.ts +2 -0
- package/dist/hooks/useReturnValue.spec.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +54 -0
- package/dist/index.mjs.map +1 -0
- package/dist/openapi/analyzerModule/analyzerModule.cjs +2 -0
- package/dist/openapi/analyzerModule/analyzerModule.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/analyzerModule/analyzerModule.d.ts +1 -0
- package/dist/openapi/analyzerModule/analyzerModule.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/analyzerModule.mjs +142 -0
- package/dist/openapi/analyzerModule/analyzerModule.mjs.map +1 -0
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.cjs +2 -0
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/analyzerModule/getSourceFileTimestamp.d.ts +1 -0
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.mjs +37 -0
- package/dist/openapi/analyzerModule/getSourceFileTimestamp.mjs.map +1 -0
- package/dist/openapi/analyzerModule/nodeParsers.cjs +2 -0
- package/dist/openapi/analyzerModule/nodeParsers.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/analyzerModule/nodeParsers.d.ts +2 -1
- package/dist/openapi/analyzerModule/nodeParsers.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/nodeParsers.mjs +371 -0
- package/dist/openapi/analyzerModule/nodeParsers.mjs.map +1 -0
- package/dist/openapi/analyzerModule/parseEndpoint.cjs +2 -0
- package/dist/openapi/analyzerModule/parseEndpoint.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/analyzerModule/parseEndpoint.d.ts +1 -0
- package/dist/openapi/analyzerModule/parseEndpoint.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/parseEndpoint.mjs +185 -0
- package/dist/openapi/analyzerModule/parseEndpoint.mjs.map +1 -0
- package/dist/openapi/analyzerModule/parseExposedModels.cjs +2 -0
- package/dist/openapi/analyzerModule/parseExposedModels.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/analyzerModule/parseExposedModels.d.ts +1 -0
- package/dist/openapi/analyzerModule/parseExposedModels.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/parseExposedModels.mjs +23 -0
- package/dist/openapi/analyzerModule/parseExposedModels.mjs.map +1 -0
- package/dist/openapi/analyzerModule/sourceFileCache.cjs +2 -0
- package/dist/openapi/analyzerModule/sourceFileCache.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/analyzerModule/sourceFileCache.d.ts +1 -0
- package/dist/openapi/analyzerModule/sourceFileCache.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/sourceFileCache.mjs +49 -0
- package/dist/openapi/analyzerModule/sourceFileCache.mjs.map +1 -0
- package/dist/openapi/analyzerModule/test/openApiAnalyzer.spec.d.ts +2 -0
- package/dist/openapi/analyzerModule/test/openApiAnalyzer.spec.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/test/openApiAnalyzer.spec.data.d.ts.map +1 -0
- package/dist/openapi/analyzerModule/types.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/discoverImports/discoverImports.cjs +2 -0
- package/dist/openapi/discoveryModule/discoverImports/discoverImports.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/discoveryModule/discoverImports/discoverImports.d.ts +1 -0
- package/dist/openapi/discoveryModule/discoverImports/discoverImports.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/discoverImports/discoverImports.mjs +18 -0
- package/dist/openapi/discoveryModule/discoverImports/discoverImports.mjs.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.d.ts +4 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.d.ts +4 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs +2 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts +3 -3
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs +43 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.mjs.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.spec.d.ts +2 -0
- package/dist/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.spec.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.cjs +2 -0
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/discoveryModule/discoverRouters/discoverRouters.d.ts +2 -1
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.mjs +25 -0
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.mjs.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.spec.d.ts +2 -0
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.spec.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.d.ts +5 -0
- package/dist/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.d.ts.map +1 -0
- package/dist/openapi/discoveryModule/index.d.ts.map +1 -0
- package/dist/openapi/generatorModule/generateComponentSchemas.cjs +2 -0
- package/dist/openapi/generatorModule/generateComponentSchemas.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/generatorModule/generateComponentSchemas.d.ts +1 -0
- package/dist/openapi/generatorModule/generateComponentSchemas.d.ts.map +1 -0
- package/dist/openapi/generatorModule/generateComponentSchemas.mjs +11 -0
- package/dist/openapi/generatorModule/generateComponentSchemas.mjs.map +1 -0
- package/dist/openapi/generatorModule/generatePaths.cjs +2 -0
- package/dist/openapi/generatorModule/generatePaths.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/generatorModule/generatePaths.d.ts +1 -0
- package/dist/openapi/generatorModule/generatePaths.d.ts.map +1 -0
- package/dist/openapi/generatorModule/generatePaths.mjs +77 -0
- package/dist/openapi/generatorModule/generatePaths.mjs.map +1 -0
- package/dist/openapi/generatorModule/generatorModule.cjs +2 -0
- package/dist/openapi/generatorModule/generatorModule.cjs.map +1 -0
- package/dist/openapi/generatorModule/generatorModule.d.ts +17 -0
- package/dist/openapi/generatorModule/generatorModule.d.ts.map +1 -0
- package/dist/openapi/generatorModule/generatorModule.mjs +17 -0
- package/dist/openapi/generatorModule/generatorModule.mjs.map +1 -0
- package/dist/openapi/generatorModule/getSchema.cjs +2 -0
- package/dist/openapi/generatorModule/getSchema.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/generatorModule/getSchema.d.ts +1 -0
- package/dist/openapi/generatorModule/getSchema.d.ts.map +1 -0
- package/dist/openapi/generatorModule/getSchema.mjs +108 -0
- package/dist/openapi/generatorModule/getSchema.mjs.map +1 -0
- package/dist/openapi/generatorModule/index.d.ts.map +1 -0
- package/dist/openapi/generatorModule/test/openApiGenerator.spec.d.ts +2 -0
- package/dist/openapi/generatorModule/test/openApiGenerator.spec.d.ts.map +1 -0
- package/dist/{src/openapi → openapi}/generatorModule/test/openApiGenerator.spec.data.d.ts +1 -0
- package/dist/{src/openapi → openapi}/generatorModule/test/openApiGenerator.spec.data.d.ts.map +1 -1
- package/dist/openapi/initOpenApiEngine.cjs +2 -0
- package/dist/openapi/initOpenApiEngine.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/initOpenApiEngine.d.ts +2 -1
- package/dist/openapi/initOpenApiEngine.d.ts.map +1 -0
- package/dist/openapi/initOpenApiEngine.mjs +11 -0
- package/dist/openapi/initOpenApiEngine.mjs.map +1 -0
- package/dist/openapi/manager/OpenApiManager.cjs +2 -0
- package/dist/openapi/manager/OpenApiManager.cjs.map +1 -0
- package/dist/{src/openapi → openapi}/manager/OpenApiManager.d.ts +1 -0
- package/dist/openapi/manager/OpenApiManager.d.ts.map +1 -0
- package/dist/openapi/manager/OpenApiManager.mjs +81 -0
- package/dist/openapi/manager/OpenApiManager.mjs.map +1 -0
- package/dist/openapi/router/OpenApiRouter.cjs +2 -0
- package/dist/openapi/router/OpenApiRouter.cjs.map +1 -0
- package/dist/openapi/router/OpenApiRouter.d.ts +4 -0
- package/dist/openapi/router/OpenApiRouter.d.ts.map +1 -0
- package/dist/openapi/router/OpenApiRouter.mjs +10 -0
- package/dist/openapi/router/OpenApiRouter.mjs.map +1 -0
- package/dist/{src/openapi → openapi}/types.d.ts +1 -0
- package/dist/openapi/types.d.ts.map +1 -0
- package/dist/router/Router.cjs +2 -0
- package/dist/router/Router.cjs.map +1 -0
- package/dist/{src/router → router}/Router.d.ts +3 -2
- package/dist/router/Router.d.ts.map +1 -0
- package/dist/router/Router.mjs +63 -0
- package/dist/router/Router.mjs.map +1 -0
- package/dist/router/parseEndpointReturnValue.cjs +2 -0
- package/dist/router/parseEndpointReturnValue.cjs.map +1 -0
- package/dist/router/parseEndpointReturnValue.d.ts.map +1 -0
- package/dist/router/parseEndpointReturnValue.mjs +21 -0
- package/dist/router/parseEndpointReturnValue.mjs.map +1 -0
- package/dist/router/parseEndpointReturnValue.spec.d.ts +2 -0
- package/dist/router/parseEndpointReturnValue.spec.d.ts.map +1 -0
- package/dist/{src/setupTests.d.ts.map → setupTests.d.ts.map} +1 -1
- package/dist/test/TestAppRouter.d.ts +8 -0
- package/dist/test/TestAppRouter.d.ts.map +1 -0
- package/dist/test/app.d.ts +4 -0
- package/dist/test/app.d.ts.map +1 -0
- package/dist/test/app.spec.d.ts +2 -0
- package/dist/test/app.spec.d.ts.map +1 -0
- package/dist/utils/TypeUtils.d.ts.map +1 -0
- package/dist/utils/loadTestData.d.ts +2 -0
- package/dist/utils/loadTestData.d.ts.map +1 -0
- package/dist/utils/logger.cjs +2 -0
- package/dist/utils/logger.cjs.map +1 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.mjs +62 -0
- package/dist/utils/logger.mjs.map +1 -0
- package/dist/{src/utils → utils}/mockContext.d.ts +2 -1
- package/dist/utils/mockContext.d.ts.map +1 -0
- package/dist/utils/nameOf.d.ts.map +1 -0
- package/dist/utils/object.cjs +2 -0
- package/dist/utils/object.cjs.map +1 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.mjs +7 -0
- package/dist/utils/object.mjs.map +1 -0
- package/dist/utils/object.spec.d.ts +2 -0
- package/dist/utils/object.spec.d.ts.map +1 -0
- package/dist/{src/utils → utils}/printers.d.ts +1 -0
- package/dist/utils/printers.d.ts.map +1 -0
- package/dist/utils/printers.spec.d.ts +2 -0
- package/dist/utils/printers.spec.d.ts.map +1 -0
- package/dist/utils/validationMessages.cjs +2 -0
- package/dist/utils/validationMessages.cjs.map +1 -0
- package/dist/{src/utils → utils}/validationMessages.d.ts +1 -0
- package/dist/utils/validationMessages.d.ts.map +1 -0
- package/dist/utils/validationMessages.mjs +20 -0
- package/dist/utils/validationMessages.mjs.map +1 -0
- package/dist/validators/BuiltInValidators.cjs +2 -0
- package/dist/validators/BuiltInValidators.cjs.map +1 -0
- package/dist/{src/validators → validators}/BuiltInValidators.d.ts +10 -10
- package/dist/validators/BuiltInValidators.d.ts.map +1 -0
- package/dist/validators/BuiltInValidators.mjs +66 -0
- package/dist/validators/BuiltInValidators.mjs.map +1 -0
- package/dist/validators/InternalParamWrappers.cjs +2 -0
- package/dist/validators/InternalParamWrappers.cjs.map +1 -0
- package/dist/{src/validators → validators}/InternalParamWrappers.d.ts +1 -0
- package/dist/validators/InternalParamWrappers.d.ts.map +1 -0
- package/dist/validators/InternalParamWrappers.mjs +8 -0
- package/dist/validators/InternalParamWrappers.mjs.map +1 -0
- package/dist/validators/ParamWrappers.cjs +2 -0
- package/dist/validators/ParamWrappers.cjs.map +1 -0
- package/dist/{src/validators → validators}/ParamWrappers.d.ts +1 -0
- package/dist/validators/ParamWrappers.d.ts.map +1 -0
- package/dist/validators/ParamWrappers.mjs +16 -0
- package/dist/validators/ParamWrappers.mjs.map +1 -0
- package/dist/validators/types.d.ts.map +1 -0
- package/eslint.config.mjs +1 -2
- package/package.json +110 -10
- package/src/openapi/analyzerModule/nodeParsers.ts +17 -1
- package/src/openapi/discoveryModule/discoverImports/discoverImports.ts +0 -1
- package/src/openapi/discoveryModule/discoverRouters/discoverRouters.ts +1 -3
- package/tsconfig.json +4 -2
- package/vite.config.ts +92 -5
- package/dist/cli/cli.d.ts +0 -2
- package/dist/cli/cli.d.ts.map +0 -1
- package/dist/cli/cli.js +0 -89
- package/dist/cli/prettyprint.d.ts +0 -4
- package/dist/cli/prettyprint.d.ts.map +0 -1
- package/dist/cli/prettyprint.js +0 -19
- package/dist/src/errors/BaseHttpError.d.ts.map +0 -1
- package/dist/src/errors/BaseHttpError.js +0 -13
- package/dist/src/errors/HttpErrorHandler.d.ts.map +0 -1
- package/dist/src/errors/HttpErrorHandler.js +0 -23
- package/dist/src/errors/UserFacingErrors.d.ts.map +0 -1
- package/dist/src/errors/UserFacingErrors.js +0 -23
- package/dist/src/hooks/authentication/useAuth.d.ts.map +0 -1
- package/dist/src/hooks/authentication/useAuth.js +0 -7
- package/dist/src/hooks/authentication/useOptionalAuth.d.ts.map +0 -1
- package/dist/src/hooks/authentication/useOptionalAuth.js +0 -16
- package/dist/src/hooks/useApiEndpoint.d.ts.map +0 -1
- package/dist/src/hooks/useApiEndpoint.js +0 -7
- package/dist/src/hooks/useApiHeader/index.d.ts.map +0 -1
- package/dist/src/hooks/useApiHeader/index.js +0 -17
- package/dist/src/hooks/useApiHeader/useApiHeader.d.ts.map +0 -1
- package/dist/src/hooks/useApiHeader/useApiHeader.js +0 -6
- package/dist/src/hooks/useApiHeader/useApiHeader.spec.data.d.ts.map +0 -1
- package/dist/src/hooks/useApiHeader/useApiHeader.spec.data.js +0 -22
- package/dist/src/hooks/useCookieParams.d.ts.map +0 -1
- package/dist/src/hooks/useCookieParams.js +0 -50
- package/dist/src/hooks/useExposeApiModel/index.d.ts.map +0 -1
- package/dist/src/hooks/useExposeApiModel/index.js +0 -17
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.d.ts.map +0 -1
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.js +0 -9
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.spec.data.d.ts.map +0 -1
- package/dist/src/hooks/useExposeApiModel/useExposeApiModel.spec.data.js +0 -16
- package/dist/src/hooks/useHeaderParams.d.ts.map +0 -1
- package/dist/src/hooks/useHeaderParams.js +0 -52
- package/dist/src/hooks/usePathParams.d.ts.map +0 -1
- package/dist/src/hooks/usePathParams.js +0 -46
- package/dist/src/hooks/useQueryParams.d.ts.map +0 -1
- package/dist/src/hooks/useQueryParams.js +0 -50
- package/dist/src/hooks/useRequestBody.d.ts.map +0 -1
- package/dist/src/hooks/useRequestBody.js +0 -59
- package/dist/src/hooks/useRequestRawBody.d.ts.map +0 -1
- package/dist/src/hooks/useRequestRawBody.js +0 -34
- package/dist/src/hooks/useReturnValue.d.ts.map +0 -1
- package/dist/src/hooks/useReturnValue.js +0 -12
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -34
- package/dist/src/openapi/analyzerModule/analyzerModule.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/analyzerModule.js +0 -257
- package/dist/src/openapi/analyzerModule/analyzerWorker.d.ts +0 -2
- package/dist/src/openapi/analyzerModule/analyzerWorker.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/analyzerWorker.js +0 -10
- package/dist/src/openapi/analyzerModule/getSourceFileTimestamp.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/getSourceFileTimestamp.js +0 -52
- package/dist/src/openapi/analyzerModule/nodeParsers.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/nodeParsers.js +0 -555
- package/dist/src/openapi/analyzerModule/parseEndpoint.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/parseEndpoint.js +0 -291
- package/dist/src/openapi/analyzerModule/parseExposedModels.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/parseExposedModels.js +0 -32
- package/dist/src/openapi/analyzerModule/sourceFileCache.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/sourceFileCache.js +0 -67
- package/dist/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/test/openApiAnalyzer.spec.data.js +0 -427
- package/dist/src/openapi/analyzerModule/types.d.ts.map +0 -1
- package/dist/src/openapi/analyzerModule/types.js +0 -2
- package/dist/src/openapi/discoveryModule/discoverImports/discoverImports.d.ts.map +0 -1
- package/dist/src/openapi/discoveryModule/discoverImports/discoverImports.js +0 -33
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.d.ts +0 -3
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.d.ts.map +0 -1
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterA.spec.data.js +0 -8
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.d.ts +0 -3
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.d.ts.map +0 -1
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/data/testRouterB.spec.data.js +0 -8
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.d.ts.map +0 -1
- package/dist/src/openapi/discoveryModule/discoverRouterFiles/discoverRouterFiles.js +0 -91
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.d.ts.map +0 -1
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.js +0 -31
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.d.ts +0 -4
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.d.ts.map +0 -1
- package/dist/src/openapi/discoveryModule/discoverRouters/discoverRouters.spec.data.js +0 -38
- package/dist/src/openapi/discoveryModule/index.d.ts.map +0 -1
- package/dist/src/openapi/discoveryModule/index.js +0 -18
- package/dist/src/openapi/generatorModule/generateComponentSchemas.d.ts.map +0 -1
- package/dist/src/openapi/generatorModule/generateComponentSchemas.js +0 -12
- package/dist/src/openapi/generatorModule/generatePaths.d.ts.map +0 -1
- package/dist/src/openapi/generatorModule/generatePaths.js +0 -118
- package/dist/src/openapi/generatorModule/generatorModule.d.ts +0 -16
- package/dist/src/openapi/generatorModule/generatorModule.d.ts.map +0 -1
- package/dist/src/openapi/generatorModule/generatorModule.js +0 -18
- package/dist/src/openapi/generatorModule/getSchema.d.ts.map +0 -1
- package/dist/src/openapi/generatorModule/getSchema.js +0 -143
- package/dist/src/openapi/generatorModule/index.d.ts.map +0 -1
- package/dist/src/openapi/generatorModule/index.js +0 -20
- package/dist/src/openapi/generatorModule/test/openApiGenerator.spec.data.js +0 -1126
- package/dist/src/openapi/initOpenApiEngine.d.ts.map +0 -1
- package/dist/src/openapi/initOpenApiEngine.js +0 -14
- package/dist/src/openapi/manager/OpenApiManager.d.ts.map +0 -1
- package/dist/src/openapi/manager/OpenApiManager.js +0 -86
- package/dist/src/openapi/router/OpenApiRouter.d.ts +0 -3
- package/dist/src/openapi/router/OpenApiRouter.d.ts.map +0 -1
- package/dist/src/openapi/router/OpenApiRouter.js +0 -11
- package/dist/src/openapi/types.d.ts.map +0 -1
- package/dist/src/openapi/types.js +0 -2
- package/dist/src/router/Router.d.ts.map +0 -1
- package/dist/src/router/Router.js +0 -84
- package/dist/src/router/parseEndpointReturnValue.d.ts.map +0 -1
- package/dist/src/router/parseEndpointReturnValue.js +0 -40
- package/dist/src/router/responseValueToJson.d.ts +0 -2
- package/dist/src/router/responseValueToJson.d.ts.map +0 -1
- package/dist/src/router/responseValueToJson.js +0 -10
- package/dist/src/setupTests.js +0 -3
- package/dist/src/test/TestAppRouter.d.ts +0 -7
- package/dist/src/test/TestAppRouter.d.ts.map +0 -1
- package/dist/src/test/TestAppRouter.js +0 -64
- package/dist/src/test/app.d.ts +0 -3
- package/dist/src/test/app.d.ts.map +0 -1
- package/dist/src/test/app.js +0 -41
- package/dist/src/utils/TypeUtils.d.ts.map +0 -1
- package/dist/src/utils/TypeUtils.js +0 -2
- package/dist/src/utils/loadTestData.d.ts +0 -2
- package/dist/src/utils/loadTestData.d.ts.map +0 -1
- package/dist/src/utils/loadTestData.js +0 -50
- package/dist/src/utils/logger.d.ts.map +0 -1
- package/dist/src/utils/logger.js +0 -80
- package/dist/src/utils/mockContext.d.ts.map +0 -1
- package/dist/src/utils/mockContext.js +0 -95
- package/dist/src/utils/nameOf.d.ts.map +0 -1
- package/dist/src/utils/nameOf.js +0 -7
- package/dist/src/utils/object.d.ts.map +0 -1
- package/dist/src/utils/object.js +0 -25
- package/dist/src/utils/printers.d.ts.map +0 -1
- package/dist/src/utils/printers.js +0 -86
- package/dist/src/utils/validationMessages.d.ts.map +0 -1
- package/dist/src/utils/validationMessages.js +0 -43
- package/dist/src/validators/BuiltInValidators.d.ts.map +0 -1
- package/dist/src/validators/BuiltInValidators.js +0 -66
- package/dist/src/validators/InternalParamWrappers.d.ts.map +0 -1
- package/dist/src/validators/InternalParamWrappers.js +0 -5
- package/dist/src/validators/ParamWrappers.d.ts.map +0 -1
- package/dist/src/validators/ParamWrappers.js +0 -9
- package/dist/src/validators/types.d.ts.map +0 -1
- package/dist/src/validators/types.js +0 -2
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.build.json +0 -15
- /package/dist/{src/hooks → hooks}/useApiEndpoint.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useApiHeader/index.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useApiHeader/useApiHeader.spec.data.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useExposeApiModel/index.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useExposeApiModel/useExposeApiModel.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useExposeApiModel/useExposeApiModel.spec.data.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useReturnValue.d.ts +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/openapi → openapi}/analyzerModule/test/openApiAnalyzer.spec.data.d.ts +0 -0
- /package/dist/{src/openapi → openapi}/analyzerModule/types.d.ts +0 -0
- /package/dist/{src/openapi → openapi}/discoveryModule/index.d.ts +0 -0
- /package/dist/{src/openapi → openapi}/generatorModule/index.d.ts +0 -0
- /package/dist/{src/router → router}/parseEndpointReturnValue.d.ts +0 -0
- /package/dist/{src/setupTests.d.ts → setupTests.d.ts} +0 -0
- /package/dist/{src/utils → utils}/TypeUtils.d.ts +0 -0
- /package/dist/{src/utils → utils}/logger.d.ts +0 -0
- /package/dist/{src/utils → utils}/nameOf.d.ts +0 -0
- /package/dist/{src/utils → utils}/object.d.ts +0 -0
- /package/dist/{src/validators → validators}/types.d.ts +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ValidationError as v } from "../errors/UserFacingErrors.mjs";
|
|
2
|
+
import { keysOf as m } from "../utils/object.mjs";
|
|
3
|
+
import { getValidationResultMessage as f } from "../utils/validationMessages.mjs";
|
|
4
|
+
const x = (l, r) => {
|
|
5
|
+
const n = l.params, i = m(r).map((a) => ({
|
|
6
|
+
name: a,
|
|
7
|
+
validator: r[a]
|
|
8
|
+
})).map((a) => {
|
|
9
|
+
const e = n[a.name];
|
|
10
|
+
if (e === void 0)
|
|
11
|
+
return { param: a, validated: !0 };
|
|
12
|
+
try {
|
|
13
|
+
const t = a.validator, p = !t.prevalidate || t.prevalidate(e), d = t.parse(e), u = !t.validate || t.validate(d);
|
|
14
|
+
return {
|
|
15
|
+
param: a,
|
|
16
|
+
validated: p && u,
|
|
17
|
+
parsedValue: d
|
|
18
|
+
};
|
|
19
|
+
} catch {
|
|
20
|
+
return { param: a, validated: !1 };
|
|
21
|
+
}
|
|
22
|
+
}), o = i.filter((a) => !a.validated);
|
|
23
|
+
if (o.length > 0)
|
|
24
|
+
throw new v(
|
|
25
|
+
`Failed route param validation: ${o.map((a) => f(a.param)).join(", ")}`
|
|
26
|
+
);
|
|
27
|
+
const c = i.filter((a) => a.validated), s = {};
|
|
28
|
+
return c.forEach((a) => {
|
|
29
|
+
s[a.param.name] = a.parsedValue;
|
|
30
|
+
}), s;
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
x as usePathParams
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=usePathParams.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePathParams.mjs","sources":["../../src/hooks/usePathParams.ts"],"sourcesContent":["import { ParameterizedContext } from 'koa'\n\nimport { ValidationError } from '../errors/UserFacingErrors'\nimport { keysOf } from '../utils/object'\nimport { CleanUpPathParam } from '../utils/TypeUtils'\nimport { getValidationResultMessage } from '../utils/validationMessages'\nimport { Validator } from '../validators/types'\n\ntype CheckIfOptional<T, B> = B extends string ? (B extends `${string}?` ? T | undefined : T) : never\n\ntype ValidatedData<\n\tParamsT extends string[],\n\tTestTemplate extends {\n\t\t[K in keyof ParamsT]: {\n\t\t\toriginal: ParamsT[K]\n\t\t\tcleaned: CleanUpPathParam<ParamsT[K]>\n\t\t\tcallback: ValidatorsT[CleanUpPathParam<ParamsT[K]>]\n\t\t}\n\t},\n\tValidatorsT extends Record<TestTemplate[number]['cleaned'], Omit<Validator<any>, 'optional'>>,\n> = {\n\t[K in keyof TestTemplate as K extends `${number}` ? TestTemplate[K]['cleaned'] : never]: CheckIfOptional<\n\t\tReturnType<TestTemplate[K]['callback']['parse']>,\n\t\tTestTemplate[K]['original']\n\t>\n}\n\nexport const usePathParams = <\n\tParamsT extends string[],\n\tTestTemplate extends {\n\t\t[K in keyof ParamsT]: {\n\t\t\toriginal: ParamsT[K]\n\t\t\tcleaned: CleanUpPathParam<ParamsT[K]>\n\t\t\tcallback: ValidatorsT[CleanUpPathParam<ParamsT[K]>]\n\t\t}\n\t},\n\tValidatorsT extends Record<CleanUpPathParam<ParamsT[number]>, Omit<Validator<any>, 'optional'>>,\n>(\n\tctx: ParameterizedContext & { parsedPathParams: ParamsT },\n\tvalidators: ValidatorsT,\n): ValidatedData<ParamsT, TestTemplate, ValidatorsT> => {\n\tconst params = ctx.params\n\tconst expectedParams = keysOf(validators).map((name) => ({\n\t\tname,\n\t\tvalidator: validators[name],\n\t}))\n\n\tconst validationResults = expectedParams.map((param) => {\n\t\tconst paramValue = params[param.name] as string\n\n\t\t// Param is optional and is not provided - skip validation\n\t\tif (paramValue === undefined) {\n\t\t\treturn { param, validated: true }\n\t\t}\n\n\t\ttry {\n\t\t\tconst validatorObject = param.validator\n\t\t\tconst prevalidatorSuccess = !validatorObject.prevalidate || validatorObject.prevalidate(paramValue)\n\t\t\tconst parsedValue = validatorObject.parse(paramValue)\n\t\t\tconst validatorSuccess = !validatorObject.validate || validatorObject.validate(parsedValue)\n\t\t\treturn {\n\t\t\t\tparam,\n\t\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\t\tparsedValue,\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { param, validated: false }\n\t\t}\n\t})\n\n\tconst failedValidations = validationResults.filter((result) => !result.validated)\n\n\tif (failedValidations.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Failed route param validation: ${failedValidations\n\t\t\t\t.map((result) => getValidationResultMessage(result.param))\n\t\t\t\t.join(', ')}`,\n\t\t)\n\t}\n\n\tconst successfulValidations = validationResults.filter((result) => result.validated)\n\n\tconst returnValue: Record<string, unknown> = {}\n\tsuccessfulValidations.forEach((result) => {\n\t\treturnValue[result.param.name] = result.parsedValue\n\t})\n\n\treturn returnValue as ValidatedData<ParamsT, TestTemplate, ValidatorsT>\n}\n"],"names":["usePathParams","ctx","validators","params","validationResults","keysOf","name","param","paramValue","validatorObject","prevalidatorSuccess","parsedValue","validatorSuccess","failedValidations","result","ValidationError","getValidationResultMessage","successfulValidations","returnValue"],"mappings":";;;AA2Ba,MAAAA,IAAgB,CAW5BC,GACAC,MACuD;AACvD,QAAMC,IAASF,EAAI,QAMbG,IALiBC,EAAOH,CAAU,EAAE,IAAI,CAACI,OAAU;AAAA,IACxD,MAAAA;AAAA,IACA,WAAWJ,EAAWI,CAAI;AAAA,EAAA,EACzB,EAEuC,IAAI,CAACC,MAAU;AACjD,UAAAC,IAAaL,EAAOI,EAAM,IAAI;AAGpC,QAAIC,MAAe;AACX,aAAA,EAAE,OAAAD,GAAO,WAAW,GAAK;AAG7B,QAAA;AACH,YAAME,IAAkBF,EAAM,WACxBG,IAAsB,CAACD,EAAgB,eAAeA,EAAgB,YAAYD,CAAU,GAC5FG,IAAcF,EAAgB,MAAMD,CAAU,GAC9CI,IAAmB,CAACH,EAAgB,YAAYA,EAAgB,SAASE,CAAW;AACnF,aAAA;AAAA,QACN,OAAAJ;AAAA,QACA,WAAWG,KAAuBE;AAAA,QAClC,aAAAD;AAAA,MACD;AAAA,IAAA,QACO;AACA,aAAA,EAAE,OAAAJ,GAAO,WAAW,GAAM;AAAA,IAAA;AAAA,EAClC,CACA,GAEKM,IAAoBT,EAAkB,OAAO,CAACU,MAAW,CAACA,EAAO,SAAS;AAE5E,MAAAD,EAAkB,SAAS;AAC9B,UAAM,IAAIE;AAAA,MACT,kCAAkCF,EAChC,IAAI,CAACC,MAAWE,EAA2BF,EAAO,KAAK,CAAC,EACxD,KAAK,IAAI,CAAC;AAAA,IACb;AAGD,QAAMG,IAAwBb,EAAkB,OAAO,CAACU,MAAWA,EAAO,SAAS,GAE7EI,IAAuC,CAAC;AACxB,SAAAD,EAAA,QAAQ,CAACH,MAAW;AACzC,IAAAI,EAAYJ,EAAO,MAAM,IAAI,IAAIA,EAAO;AAAA,EAAA,CACxC,GAEMI;AACR;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePathParams.spec.d.ts","sourceRoot":"","sources":["../../src/hooks/usePathParams.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../errors/UserFacingErrors.cjs"),y=require("../utils/object.cjs"),v=require("../utils/validationMessages.cjs"),V=(g,r)=>{const s=g.query,i=y.keysOf(r).map(a=>({name:a,validator:r[a]})),o=i.filter(a=>!s[a.name]&&!a.validator.optional);if(o.length>0)throw new u.ValidationError(`Missing query params: ${o.map(a=>v.getMissingParamMessage(a)).join(", ")}`);const n=i.map(a=>{const t=s[a.name];if(t===void 0)return{param:a,validated:!0};try{const e=a.validator,p=!e.prevalidate||e.prevalidate(t),c=e.parse(t),f=!e.validate||e.validate(c);return{param:a,validated:p&&f,parsedValue:c}}catch{return{param:a,validated:!1}}}),l=n.filter(a=>!a.validated);if(l.length>0)throw new u.ValidationError(`Failed query param validation: ${l.map(a=>v.getValidationResultMessage(a.param)).join(", ")}`);const m=n.filter(a=>a.validated),d={};return m.forEach(a=>{d[a.param.name]=a.parsedValue}),d};exports.useQueryParams=V;
|
|
2
|
+
//# sourceMappingURL=useQueryParams.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueryParams.cjs","sources":["../../src/hooks/useQueryParams.ts"],"sourcesContent":["import { ParameterizedContext } from 'koa'\n\nimport { ValidationError } from '../errors/UserFacingErrors'\nimport { keysOf } from '../utils/object'\nimport { getMissingParamMessage, getValidationResultMessage } from '../utils/validationMessages'\nimport { Validator } from '../validators/types'\n\ntype CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined\n\ntype ValidatedData<T extends Record<string, Validator<any>>> = {\n\t[K in keyof T]: CheckIfOptional<ReturnType<T[K]['parse']>, T[K]['optional']>\n}\n\nexport const useQueryParams = <ValidatorsT extends Record<string, Validator<any>>>(\n\tctx: ParameterizedContext,\n\tvalidators: ValidatorsT,\n): ValidatedData<ValidatorsT> => {\n\tconst query = ctx.query\n\tconst params = keysOf(validators).map((name) => ({\n\t\tname,\n\t\tvalidator: validators[name],\n\t}))\n\n\tconst missingParams = params.filter((param) => !query[param.name] && !param.validator.optional)\n\n\tif (missingParams.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Missing query params: ${missingParams.map((param) => getMissingParamMessage(param)).join(', ')}`,\n\t\t)\n\t}\n\n\tconst validationResults = params.map((param) => {\n\t\tconst paramValue = query[param.name] as string\n\n\t\t// Param is optional and is not provided - skip validation\n\t\tif (paramValue === undefined) {\n\t\t\treturn { param, validated: true }\n\t\t}\n\n\t\ttry {\n\t\t\tconst validatorObject = param.validator\n\t\t\tconst prevalidatorSuccess = !validatorObject.prevalidate || validatorObject.prevalidate(paramValue)\n\t\t\tconst parsedValue = validatorObject.parse(paramValue)\n\t\t\tconst validatorSuccess = !validatorObject.validate || validatorObject.validate(parsedValue)\n\t\t\treturn {\n\t\t\t\tparam,\n\t\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\t\tparsedValue,\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { param, validated: false }\n\t\t}\n\t})\n\n\tconst failedValidations = validationResults.filter((result) => !result.validated)\n\n\tif (failedValidations.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Failed query param validation: ${failedValidations\n\t\t\t\t.map((result) => getValidationResultMessage(result.param))\n\t\t\t\t.join(', ')}`,\n\t\t)\n\t}\n\n\tconst successfulValidations = validationResults.filter((result) => result.validated)\n\n\tconst returnValue: Record<string, unknown> = {}\n\tsuccessfulValidations.forEach((result) => {\n\t\treturnValue[result.param.name] = result.parsedValue\n\t})\n\n\treturn returnValue as ValidatedData<ValidatorsT>\n}\n"],"names":["useQueryParams","ctx","validators","query","params","keysOf","name","missingParams","param","ValidationError","getMissingParamMessage","validationResults","paramValue","validatorObject","prevalidatorSuccess","parsedValue","validatorSuccess","failedValidations","result","getValidationResultMessage","successfulValidations","returnValue"],"mappings":"gNAaaA,EAAiB,CAC7BC,EACAC,IACgC,CAChC,MAAMC,EAAQF,EAAI,MACZG,EAASC,EAAAA,OAAOH,CAAU,EAAE,IAAKI,IAAU,CAChD,KAAAA,EACA,UAAWJ,EAAWI,CAAI,CAAA,EACzB,EAEIC,EAAgBH,EAAO,OAAQI,GAAU,CAACL,EAAMK,EAAM,IAAI,GAAK,CAACA,EAAM,UAAU,QAAQ,EAE1F,GAAAD,EAAc,OAAS,EAC1B,MAAM,IAAIE,EAAA,gBACT,yBAAyBF,EAAc,IAAKC,GAAUE,yBAAuBF,CAAK,CAAC,EAAE,KAAK,IAAI,CAAC,EAChG,EAGD,MAAMG,EAAoBP,EAAO,IAAKI,GAAU,CACzC,MAAAI,EAAaT,EAAMK,EAAM,IAAI,EAGnC,GAAII,IAAe,OACX,MAAA,CAAE,MAAAJ,EAAO,UAAW,EAAK,EAG7B,GAAA,CACH,MAAMK,EAAkBL,EAAM,UACxBM,EAAsB,CAACD,EAAgB,aAAeA,EAAgB,YAAYD,CAAU,EAC5FG,EAAcF,EAAgB,MAAMD,CAAU,EAC9CI,EAAmB,CAACH,EAAgB,UAAYA,EAAgB,SAASE,CAAW,EACnF,MAAA,CACN,MAAAP,EACA,UAAWM,GAAuBE,EAClC,YAAAD,CACD,CAAA,MACO,CACA,MAAA,CAAE,MAAAP,EAAO,UAAW,EAAM,CAAA,CAClC,CACA,EAEKS,EAAoBN,EAAkB,OAAQO,GAAW,CAACA,EAAO,SAAS,EAE5E,GAAAD,EAAkB,OAAS,EAC9B,MAAM,IAAIR,EAAA,gBACT,kCAAkCQ,EAChC,IAAKC,GAAWC,EAAAA,2BAA2BD,EAAO,KAAK,CAAC,EACxD,KAAK,IAAI,CAAC,EACb,EAGD,MAAME,EAAwBT,EAAkB,OAAQO,GAAWA,EAAO,SAAS,EAE7EG,EAAuC,CAAC,EACxB,OAAAD,EAAA,QAASF,GAAW,CACzCG,EAAYH,EAAO,MAAM,IAAI,EAAIA,EAAO,WAAA,CACxC,EAEMG,CACR"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ParameterizedContext } from 'koa';
|
|
2
2
|
import { Validator } from '../validators/types';
|
|
3
|
+
|
|
3
4
|
type CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined;
|
|
4
5
|
type ValidatedData<T extends Record<string, Validator<any>>> = {
|
|
5
6
|
[K in keyof T]: CheckIfOptional<ReturnType<T[K]['parse']>, T[K]['optional']>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueryParams.d.ts","sourceRoot":"","sources":["../../src/hooks/useQueryParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,KAAK,CAAA;AAK1C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,GAAG,SAAS,IAAI,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;AAE5F,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI;KAC7D,CAAC,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;CAC5E,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,OAC3E,oBAAoB,cACb,WAAW,KACrB,aAAa,CAAC,WAAW,CAwD3B,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ValidationError as u } from "../errors/UserFacingErrors.mjs";
|
|
2
|
+
import { keysOf as g } from "../utils/object.mjs";
|
|
3
|
+
import { getMissingParamMessage as V, getValidationResultMessage as y } from "../utils/validationMessages.mjs";
|
|
4
|
+
const M = (m, i) => {
|
|
5
|
+
const r = m.query, s = g(i).map((a) => ({
|
|
6
|
+
name: a,
|
|
7
|
+
validator: i[a]
|
|
8
|
+
})), o = s.filter((a) => !r[a.name] && !a.validator.optional);
|
|
9
|
+
if (o.length > 0)
|
|
10
|
+
throw new u(
|
|
11
|
+
`Missing query params: ${o.map((a) => V(a)).join(", ")}`
|
|
12
|
+
);
|
|
13
|
+
const n = s.map((a) => {
|
|
14
|
+
const e = r[a.name];
|
|
15
|
+
if (e === void 0)
|
|
16
|
+
return { param: a, validated: !0 };
|
|
17
|
+
try {
|
|
18
|
+
const t = a.validator, p = !t.prevalidate || t.prevalidate(e), c = t.parse(e), f = !t.validate || t.validate(c);
|
|
19
|
+
return {
|
|
20
|
+
param: a,
|
|
21
|
+
validated: p && f,
|
|
22
|
+
parsedValue: c
|
|
23
|
+
};
|
|
24
|
+
} catch {
|
|
25
|
+
return { param: a, validated: !1 };
|
|
26
|
+
}
|
|
27
|
+
}), l = n.filter((a) => !a.validated);
|
|
28
|
+
if (l.length > 0)
|
|
29
|
+
throw new u(
|
|
30
|
+
`Failed query param validation: ${l.map((a) => y(a.param)).join(", ")}`
|
|
31
|
+
);
|
|
32
|
+
const v = n.filter((a) => a.validated), d = {};
|
|
33
|
+
return v.forEach((a) => {
|
|
34
|
+
d[a.param.name] = a.parsedValue;
|
|
35
|
+
}), d;
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
M as useQueryParams
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=useQueryParams.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueryParams.mjs","sources":["../../src/hooks/useQueryParams.ts"],"sourcesContent":["import { ParameterizedContext } from 'koa'\n\nimport { ValidationError } from '../errors/UserFacingErrors'\nimport { keysOf } from '../utils/object'\nimport { getMissingParamMessage, getValidationResultMessage } from '../utils/validationMessages'\nimport { Validator } from '../validators/types'\n\ntype CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined\n\ntype ValidatedData<T extends Record<string, Validator<any>>> = {\n\t[K in keyof T]: CheckIfOptional<ReturnType<T[K]['parse']>, T[K]['optional']>\n}\n\nexport const useQueryParams = <ValidatorsT extends Record<string, Validator<any>>>(\n\tctx: ParameterizedContext,\n\tvalidators: ValidatorsT,\n): ValidatedData<ValidatorsT> => {\n\tconst query = ctx.query\n\tconst params = keysOf(validators).map((name) => ({\n\t\tname,\n\t\tvalidator: validators[name],\n\t}))\n\n\tconst missingParams = params.filter((param) => !query[param.name] && !param.validator.optional)\n\n\tif (missingParams.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Missing query params: ${missingParams.map((param) => getMissingParamMessage(param)).join(', ')}`,\n\t\t)\n\t}\n\n\tconst validationResults = params.map((param) => {\n\t\tconst paramValue = query[param.name] as string\n\n\t\t// Param is optional and is not provided - skip validation\n\t\tif (paramValue === undefined) {\n\t\t\treturn { param, validated: true }\n\t\t}\n\n\t\ttry {\n\t\t\tconst validatorObject = param.validator\n\t\t\tconst prevalidatorSuccess = !validatorObject.prevalidate || validatorObject.prevalidate(paramValue)\n\t\t\tconst parsedValue = validatorObject.parse(paramValue)\n\t\t\tconst validatorSuccess = !validatorObject.validate || validatorObject.validate(parsedValue)\n\t\t\treturn {\n\t\t\t\tparam,\n\t\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\t\tparsedValue,\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { param, validated: false }\n\t\t}\n\t})\n\n\tconst failedValidations = validationResults.filter((result) => !result.validated)\n\n\tif (failedValidations.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Failed query param validation: ${failedValidations\n\t\t\t\t.map((result) => getValidationResultMessage(result.param))\n\t\t\t\t.join(', ')}`,\n\t\t)\n\t}\n\n\tconst successfulValidations = validationResults.filter((result) => result.validated)\n\n\tconst returnValue: Record<string, unknown> = {}\n\tsuccessfulValidations.forEach((result) => {\n\t\treturnValue[result.param.name] = result.parsedValue\n\t})\n\n\treturn returnValue as ValidatedData<ValidatorsT>\n}\n"],"names":["useQueryParams","ctx","validators","query","params","keysOf","name","missingParams","param","ValidationError","getMissingParamMessage","validationResults","paramValue","validatorObject","prevalidatorSuccess","parsedValue","validatorSuccess","failedValidations","result","getValidationResultMessage","successfulValidations","returnValue"],"mappings":";;;AAaa,MAAAA,IAAiB,CAC7BC,GACAC,MACgC;AAChC,QAAMC,IAAQF,EAAI,OACZG,IAASC,EAAOH,CAAU,EAAE,IAAI,CAACI,OAAU;AAAA,IAChD,MAAAA;AAAA,IACA,WAAWJ,EAAWI,CAAI;AAAA,EAAA,EACzB,GAEIC,IAAgBH,EAAO,OAAO,CAACI,MAAU,CAACL,EAAMK,EAAM,IAAI,KAAK,CAACA,EAAM,UAAU,QAAQ;AAE1F,MAAAD,EAAc,SAAS;AAC1B,UAAM,IAAIE;AAAA,MACT,yBAAyBF,EAAc,IAAI,CAACC,MAAUE,EAAuBF,CAAK,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA,IAChG;AAGD,QAAMG,IAAoBP,EAAO,IAAI,CAACI,MAAU;AACzC,UAAAI,IAAaT,EAAMK,EAAM,IAAI;AAGnC,QAAII,MAAe;AACX,aAAA,EAAE,OAAAJ,GAAO,WAAW,GAAK;AAG7B,QAAA;AACH,YAAMK,IAAkBL,EAAM,WACxBM,IAAsB,CAACD,EAAgB,eAAeA,EAAgB,YAAYD,CAAU,GAC5FG,IAAcF,EAAgB,MAAMD,CAAU,GAC9CI,IAAmB,CAACH,EAAgB,YAAYA,EAAgB,SAASE,CAAW;AACnF,aAAA;AAAA,QACN,OAAAP;AAAA,QACA,WAAWM,KAAuBE;AAAA,QAClC,aAAAD;AAAA,MACD;AAAA,IAAA,QACO;AACA,aAAA,EAAE,OAAAP,GAAO,WAAW,GAAM;AAAA,IAAA;AAAA,EAClC,CACA,GAEKS,IAAoBN,EAAkB,OAAO,CAACO,MAAW,CAACA,EAAO,SAAS;AAE5E,MAAAD,EAAkB,SAAS;AAC9B,UAAM,IAAIR;AAAA,MACT,kCAAkCQ,EAChC,IAAI,CAACC,MAAWC,EAA2BD,EAAO,KAAK,CAAC,EACxD,KAAK,IAAI,CAAC;AAAA,IACb;AAGD,QAAME,IAAwBT,EAAkB,OAAO,CAACO,MAAWA,EAAO,SAAS,GAE7EG,IAAuC,CAAC;AACxB,SAAAD,EAAA,QAAQ,CAACF,MAAW;AACzC,IAAAG,EAAYH,EAAO,MAAM,IAAI,IAAIA,EAAO;AAAA,EAAA,CACxC,GAEMG;AACR;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueryParams.spec.d.ts","sourceRoot":"","sources":["../../src/hooks/useQueryParams.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../errors/UserFacingErrors.cjs"),V=require("../utils/object.cjs"),f=require("../utils/validationMessages.cjs"),b=(g,r)=>{const i=g.request.body||{},s=V.keysOf(r).map(e=>({name:e,validator:r[e]})),o=s.filter(e=>i[e.name]===void 0&&!r[e.name].optional);if(o.length>0)throw new v.ValidationError(`Missing body params: ${o.map(e=>f.getMissingParamMessage(e)).join(", ")}`);const n=s.map(e=>{const a=i[e.name];if(a===void 0)return{param:e,validated:!0};try{const c=a===null?null:typeof a=="object"?JSON.stringify(a):String(a),t=e.validator,m=!t.prevalidate||t.prevalidate(c),u=t.parse(c),y=!t.validate||t.validate(u);return{param:e,validated:m&&y,parsedValue:u}}catch{return{param:e,validated:!1}}}),l=n.filter(e=>!e.validated);if(l.length>0)throw new v.ValidationError(`Failed body param validation: ${l.map(e=>f.getValidationResultMessage(e.param)).join(", ")}`);const p=n.filter(e=>e.validated),d={};return p.forEach(e=>{d[e.param.name]=e.parsedValue}),d};exports.useRequestBody=b;
|
|
2
|
+
//# sourceMappingURL=useRequestBody.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestBody.cjs","sources":["../../src/hooks/useRequestBody.ts"],"sourcesContent":["import { ParameterizedContext } from 'koa'\n\nimport { ValidationError } from '../errors/UserFacingErrors'\nimport { keysOf } from '../utils/object'\nimport { getMissingParamMessage, getValidationResultMessage } from '../utils/validationMessages'\nimport { Validator } from '../validators/types'\n\ntype CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined\n\ntype ValidatedData<T extends Record<string, Validator<any>>> = {\n\t[K in keyof T]: CheckIfOptional<ReturnType<T[K]['parse']>, T[K]['optional']>\n}\n\n/**\n * Hook to access request body data in JSON or form formats.\n *\n * Supported content types:\n * - `application/json`\n * - `application/x-www-form-urlencoded`\n *\n * @param ctx Koa context\n * @param validators Validator definitions\n * @returns Validated parameters\n */\nexport const useRequestBody = <ValidatorsT extends Record<string, Validator<any>>>(\n\tctx: ParameterizedContext,\n\tvalidators: ValidatorsT,\n): ValidatedData<ValidatorsT> => {\n\tconst providedParams = (ctx.request.body || {}) as Record<string, string | number | boolean | object>\n\tconst params = keysOf(validators).map((name) => ({\n\t\tname,\n\t\tvalidator: validators[name],\n\t}))\n\n\tconst missingParams = params.filter(\n\t\t(param) => providedParams[param.name] === undefined && !validators[param.name].optional,\n\t)\n\n\tif (missingParams.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Missing body params: ${missingParams.map((param) => getMissingParamMessage(param)).join(', ')}`,\n\t\t)\n\t}\n\n\tconst validationResults = params.map((param) => {\n\t\tconst paramValue = providedParams[param.name]\n\n\t\t// Param is optional and is not provided - skip validation\n\t\tif (paramValue === undefined) {\n\t\t\treturn { param, validated: true }\n\t\t}\n\n\t\ttry {\n\t\t\tconst convertedValue = (() => {\n\t\t\t\tif (paramValue === null) {\n\t\t\t\t\treturn null\n\t\t\t\t} else if (typeof paramValue === 'object') {\n\t\t\t\t\treturn JSON.stringify(paramValue)\n\t\t\t\t}\n\t\t\t\treturn String(paramValue)\n\t\t\t})()\n\t\t\tconst validatorObject = param.validator\n\t\t\tconst prevalidatorSuccess = !validatorObject.prevalidate || validatorObject.prevalidate(convertedValue)\n\t\t\tconst parsedValue = validatorObject.parse(convertedValue)\n\t\t\tconst validatorSuccess = !validatorObject.validate || validatorObject.validate(parsedValue)\n\t\t\treturn {\n\t\t\t\tparam,\n\t\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\t\tparsedValue,\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { param, validated: false }\n\t\t}\n\t})\n\n\tconst failedValidations = validationResults.filter((result) => !result.validated)\n\n\tif (failedValidations.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Failed body param validation: ${failedValidations\n\t\t\t\t.map((result) => getValidationResultMessage(result.param))\n\t\t\t\t.join(', ')}`,\n\t\t)\n\t}\n\n\tconst successfulValidations = validationResults.filter((result) => result.validated)\n\n\tconst returnValue: Record<string, unknown> = {}\n\tsuccessfulValidations.forEach((result) => {\n\t\treturnValue[result.param.name] = result.parsedValue\n\t})\n\n\treturn returnValue as ValidatedData<ValidatorsT>\n}\n"],"names":["useRequestBody","ctx","validators","providedParams","params","keysOf","name","missingParams","param","ValidationError","getMissingParamMessage","validationResults","paramValue","convertedValue","validatorObject","prevalidatorSuccess","parsedValue","validatorSuccess","failedValidations","result","getValidationResultMessage","successfulValidations","returnValue"],"mappings":"gNAwBaA,EAAiB,CAC7BC,EACAC,IACgC,CAChC,MAAMC,EAAkBF,EAAI,QAAQ,MAAQ,CAAC,EACvCG,EAASC,EAAAA,OAAOH,CAAU,EAAE,IAAKI,IAAU,CAChD,KAAAA,EACA,UAAWJ,EAAWI,CAAI,CAAA,EACzB,EAEIC,EAAgBH,EAAO,OAC3BI,GAAUL,EAAeK,EAAM,IAAI,IAAM,QAAa,CAACN,EAAWM,EAAM,IAAI,EAAE,QAChF,EAEI,GAAAD,EAAc,OAAS,EAC1B,MAAM,IAAIE,EAAA,gBACT,wBAAwBF,EAAc,IAAKC,GAAUE,yBAAuBF,CAAK,CAAC,EAAE,KAAK,IAAI,CAAC,EAC/F,EAGD,MAAMG,EAAoBP,EAAO,IAAKI,GAAU,CACzC,MAAAI,EAAaT,EAAeK,EAAM,IAAI,EAG5C,GAAII,IAAe,OACX,MAAA,CAAE,MAAAJ,EAAO,UAAW,EAAK,EAG7B,GAAA,CACH,MAAMK,EACDD,IAAe,KACX,KACG,OAAOA,GAAe,SACzB,KAAK,UAAUA,CAAU,EAE1B,OAAOA,CAAU,EAEnBE,EAAkBN,EAAM,UACxBO,EAAsB,CAACD,EAAgB,aAAeA,EAAgB,YAAYD,CAAc,EAChGG,EAAcF,EAAgB,MAAMD,CAAc,EAClDI,EAAmB,CAACH,EAAgB,UAAYA,EAAgB,SAASE,CAAW,EACnF,MAAA,CACN,MAAAR,EACA,UAAWO,GAAuBE,EAClC,YAAAD,CACD,CAAA,MACO,CACA,MAAA,CAAE,MAAAR,EAAO,UAAW,EAAM,CAAA,CAClC,CACA,EAEKU,EAAoBP,EAAkB,OAAQQ,GAAW,CAACA,EAAO,SAAS,EAE5E,GAAAD,EAAkB,OAAS,EAC9B,MAAM,IAAIT,EAAA,gBACT,iCAAiCS,EAC/B,IAAKC,GAAWC,EAAAA,2BAA2BD,EAAO,KAAK,CAAC,EACxD,KAAK,IAAI,CAAC,EACb,EAGD,MAAME,EAAwBV,EAAkB,OAAQQ,GAAWA,EAAO,SAAS,EAE7EG,EAAuC,CAAC,EACxB,OAAAD,EAAA,QAASF,GAAW,CACzCG,EAAYH,EAAO,MAAM,IAAI,EAAIA,EAAO,WAAA,CACxC,EAEMG,CACR"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ParameterizedContext } from 'koa';
|
|
2
2
|
import { Validator } from '../validators/types';
|
|
3
|
+
|
|
3
4
|
type CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined;
|
|
4
5
|
type ValidatedData<T extends Record<string, Validator<any>>> = {
|
|
5
6
|
[K in keyof T]: CheckIfOptional<ReturnType<T[K]['parse']>, T[K]['optional']>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestBody.d.ts","sourceRoot":"","sources":["../../src/hooks/useRequestBody.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,KAAK,CAAA;AAK1C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,GAAG,SAAS,IAAI,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;AAE5F,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI;KAC7D,CAAC,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;CAC5E,CAAA;AAaD,eAAO,MAAM,cAAc,GAAI,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,OAC3E,oBAAoB,cACb,WAAW,KACrB,aAAa,CAAC,WAAW,CAkE3B,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ValidationError as f } from "../errors/UserFacingErrors.mjs";
|
|
2
|
+
import { keysOf as V } from "../utils/object.mjs";
|
|
3
|
+
import { getMissingParamMessage as y, getValidationResultMessage as h } from "../utils/validationMessages.mjs";
|
|
4
|
+
const M = (m, i) => {
|
|
5
|
+
const r = m.request.body || {}, o = V(i).map((a) => ({
|
|
6
|
+
name: a,
|
|
7
|
+
validator: i[a]
|
|
8
|
+
})), s = o.filter(
|
|
9
|
+
(a) => r[a.name] === void 0 && !i[a.name].optional
|
|
10
|
+
);
|
|
11
|
+
if (s.length > 0)
|
|
12
|
+
throw new f(
|
|
13
|
+
`Missing body params: ${s.map((a) => y(a)).join(", ")}`
|
|
14
|
+
);
|
|
15
|
+
const n = o.map((a) => {
|
|
16
|
+
const e = r[a.name];
|
|
17
|
+
if (e === void 0)
|
|
18
|
+
return { param: a, validated: !0 };
|
|
19
|
+
try {
|
|
20
|
+
const c = e === null ? null : typeof e == "object" ? JSON.stringify(e) : String(e), t = a.validator, v = !t.prevalidate || t.prevalidate(c), u = t.parse(c), g = !t.validate || t.validate(u);
|
|
21
|
+
return {
|
|
22
|
+
param: a,
|
|
23
|
+
validated: v && g,
|
|
24
|
+
parsedValue: u
|
|
25
|
+
};
|
|
26
|
+
} catch {
|
|
27
|
+
return { param: a, validated: !1 };
|
|
28
|
+
}
|
|
29
|
+
}), l = n.filter((a) => !a.validated);
|
|
30
|
+
if (l.length > 0)
|
|
31
|
+
throw new f(
|
|
32
|
+
`Failed body param validation: ${l.map((a) => h(a.param)).join(", ")}`
|
|
33
|
+
);
|
|
34
|
+
const p = n.filter((a) => a.validated), d = {};
|
|
35
|
+
return p.forEach((a) => {
|
|
36
|
+
d[a.param.name] = a.parsedValue;
|
|
37
|
+
}), d;
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
M as useRequestBody
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=useRequestBody.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestBody.mjs","sources":["../../src/hooks/useRequestBody.ts"],"sourcesContent":["import { ParameterizedContext } from 'koa'\n\nimport { ValidationError } from '../errors/UserFacingErrors'\nimport { keysOf } from '../utils/object'\nimport { getMissingParamMessage, getValidationResultMessage } from '../utils/validationMessages'\nimport { Validator } from '../validators/types'\n\ntype CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined\n\ntype ValidatedData<T extends Record<string, Validator<any>>> = {\n\t[K in keyof T]: CheckIfOptional<ReturnType<T[K]['parse']>, T[K]['optional']>\n}\n\n/**\n * Hook to access request body data in JSON or form formats.\n *\n * Supported content types:\n * - `application/json`\n * - `application/x-www-form-urlencoded`\n *\n * @param ctx Koa context\n * @param validators Validator definitions\n * @returns Validated parameters\n */\nexport const useRequestBody = <ValidatorsT extends Record<string, Validator<any>>>(\n\tctx: ParameterizedContext,\n\tvalidators: ValidatorsT,\n): ValidatedData<ValidatorsT> => {\n\tconst providedParams = (ctx.request.body || {}) as Record<string, string | number | boolean | object>\n\tconst params = keysOf(validators).map((name) => ({\n\t\tname,\n\t\tvalidator: validators[name],\n\t}))\n\n\tconst missingParams = params.filter(\n\t\t(param) => providedParams[param.name] === undefined && !validators[param.name].optional,\n\t)\n\n\tif (missingParams.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Missing body params: ${missingParams.map((param) => getMissingParamMessage(param)).join(', ')}`,\n\t\t)\n\t}\n\n\tconst validationResults = params.map((param) => {\n\t\tconst paramValue = providedParams[param.name]\n\n\t\t// Param is optional and is not provided - skip validation\n\t\tif (paramValue === undefined) {\n\t\t\treturn { param, validated: true }\n\t\t}\n\n\t\ttry {\n\t\t\tconst convertedValue = (() => {\n\t\t\t\tif (paramValue === null) {\n\t\t\t\t\treturn null\n\t\t\t\t} else if (typeof paramValue === 'object') {\n\t\t\t\t\treturn JSON.stringify(paramValue)\n\t\t\t\t}\n\t\t\t\treturn String(paramValue)\n\t\t\t})()\n\t\t\tconst validatorObject = param.validator\n\t\t\tconst prevalidatorSuccess = !validatorObject.prevalidate || validatorObject.prevalidate(convertedValue)\n\t\t\tconst parsedValue = validatorObject.parse(convertedValue)\n\t\t\tconst validatorSuccess = !validatorObject.validate || validatorObject.validate(parsedValue)\n\t\t\treturn {\n\t\t\t\tparam,\n\t\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\t\tparsedValue,\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { param, validated: false }\n\t\t}\n\t})\n\n\tconst failedValidations = validationResults.filter((result) => !result.validated)\n\n\tif (failedValidations.length > 0) {\n\t\tthrow new ValidationError(\n\t\t\t`Failed body param validation: ${failedValidations\n\t\t\t\t.map((result) => getValidationResultMessage(result.param))\n\t\t\t\t.join(', ')}`,\n\t\t)\n\t}\n\n\tconst successfulValidations = validationResults.filter((result) => result.validated)\n\n\tconst returnValue: Record<string, unknown> = {}\n\tsuccessfulValidations.forEach((result) => {\n\t\treturnValue[result.param.name] = result.parsedValue\n\t})\n\n\treturn returnValue as ValidatedData<ValidatorsT>\n}\n"],"names":["useRequestBody","ctx","validators","providedParams","params","keysOf","name","missingParams","param","ValidationError","getMissingParamMessage","validationResults","paramValue","convertedValue","validatorObject","prevalidatorSuccess","parsedValue","validatorSuccess","failedValidations","result","getValidationResultMessage","successfulValidations","returnValue"],"mappings":";;;AAwBa,MAAAA,IAAiB,CAC7BC,GACAC,MACgC;AAChC,QAAMC,IAAkBF,EAAI,QAAQ,QAAQ,CAAC,GACvCG,IAASC,EAAOH,CAAU,EAAE,IAAI,CAACI,OAAU;AAAA,IAChD,MAAAA;AAAA,IACA,WAAWJ,EAAWI,CAAI;AAAA,EAAA,EACzB,GAEIC,IAAgBH,EAAO;AAAA,IAC5B,CAACI,MAAUL,EAAeK,EAAM,IAAI,MAAM,UAAa,CAACN,EAAWM,EAAM,IAAI,EAAE;AAAA,EAChF;AAEI,MAAAD,EAAc,SAAS;AAC1B,UAAM,IAAIE;AAAA,MACT,wBAAwBF,EAAc,IAAI,CAACC,MAAUE,EAAuBF,CAAK,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA,IAC/F;AAGD,QAAMG,IAAoBP,EAAO,IAAI,CAACI,MAAU;AACzC,UAAAI,IAAaT,EAAeK,EAAM,IAAI;AAG5C,QAAII,MAAe;AACX,aAAA,EAAE,OAAAJ,GAAO,WAAW,GAAK;AAG7B,QAAA;AACH,YAAMK,IACDD,MAAe,OACX,OACG,OAAOA,KAAe,WACzB,KAAK,UAAUA,CAAU,IAE1B,OAAOA,CAAU,GAEnBE,IAAkBN,EAAM,WACxBO,IAAsB,CAACD,EAAgB,eAAeA,EAAgB,YAAYD,CAAc,GAChGG,IAAcF,EAAgB,MAAMD,CAAc,GAClDI,IAAmB,CAACH,EAAgB,YAAYA,EAAgB,SAASE,CAAW;AACnF,aAAA;AAAA,QACN,OAAAR;AAAA,QACA,WAAWO,KAAuBE;AAAA,QAClC,aAAAD;AAAA,MACD;AAAA,IAAA,QACO;AACA,aAAA,EAAE,OAAAR,GAAO,WAAW,GAAM;AAAA,IAAA;AAAA,EAClC,CACA,GAEKU,IAAoBP,EAAkB,OAAO,CAACQ,MAAW,CAACA,EAAO,SAAS;AAE5E,MAAAD,EAAkB,SAAS;AAC9B,UAAM,IAAIT;AAAA,MACT,iCAAiCS,EAC/B,IAAI,CAACC,MAAWC,EAA2BD,EAAO,KAAK,CAAC,EACxD,KAAK,IAAI,CAAC;AAAA,IACb;AAGD,QAAME,IAAwBV,EAAkB,OAAO,CAACQ,MAAWA,EAAO,SAAS,GAE7EG,IAAuC,CAAC;AACxB,SAAAD,EAAA,QAAQ,CAACF,MAAW;AACzC,IAAAG,EAAYH,EAAO,MAAM,IAAI,IAAIA,EAAO;AAAA,EAAA,CACxC,GAEMG;AACR;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestBody.spec.d.ts","sourceRoot":"","sources":["../../src/hooks/useRequestBody.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../errors/UserFacingErrors.cjs"),i=require("../utils/validationMessages.cjs"),c=(n,e)=>{const s=n.request.rawBody,t=e.optional;if(!t&&!s)throw new o.ValidationError(i.getMissingRawBodyMessage(e));if(t&&!s)return;const r=(()=>{try{const d=!e.prevalidate||e.prevalidate(s),a=e.parse(s),u=!e.validate||e.validate(a);return{validated:d&&u,parsedValue:a}}catch{return{validated:!1}}})();if(!r.validated)throw new o.ValidationError(i.getFailedRawBodyValidationMessage(e));return r.parsedValue};exports.useRequestRawBody=c;
|
|
2
|
+
//# sourceMappingURL=useRequestRawBody.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestRawBody.cjs","sources":["../../src/hooks/useRequestRawBody.ts"],"sourcesContent":["import { ParameterizedContext } from 'koa'\n\nimport { ValidationError } from '../errors/UserFacingErrors'\nimport { getFailedRawBodyValidationMessage, getMissingRawBodyMessage } from '../utils/validationMessages'\nimport { Validator } from '../validators/types'\n\ntype CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined\n\ntype ValidatedData<T extends Validator<any>> = CheckIfOptional<ReturnType<T['parse']>, T['optional']>\n\n/**\n * Hook to access request body data without parsing into an object.\n *\n * Supported content types:\n * - `text/plain`\n * - `application/json`\n * - `application/x-www-form-urlencoded`\n *\n * @param ctx Koa context\n * @param validators Validator definitions\n * @returns Validated parameters\n */\nexport const useRequestRawBody = <ValidatorT extends Validator<any>>(\n\tctx: ParameterizedContext,\n\tvalidator: ValidatorT,\n): ValidatedData<ValidatorT> => {\n\tconst providedBody = ctx.request.rawBody\n\tconst isOptional = validator.optional\n\n\tif (!isOptional && !providedBody) {\n\t\tthrow new ValidationError(getMissingRawBodyMessage(validator))\n\t}\n\n\tif (isOptional && !providedBody) {\n\t\treturn undefined as ValidatedData<ValidatorT>\n\t}\n\n\tconst validationResult = (() => {\n\t\ttry {\n\t\t\tconst prevalidatorSuccess = !validator.prevalidate || validator.prevalidate(providedBody)\n\t\t\tconst parsedValue = validator.parse(providedBody)\n\t\t\tconst validatorSuccess = !validator.validate || validator.validate(parsedValue)\n\t\t\treturn {\n\t\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\t\tparsedValue,\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { validated: false }\n\t\t}\n\t})()\n\n\tif (!validationResult.validated) {\n\t\tthrow new ValidationError(getFailedRawBodyValidationMessage(validator))\n\t}\n\treturn validationResult.parsedValue as ValidatedData<ValidatorT>\n}\n"],"names":["useRequestRawBody","ctx","validator","providedBody","isOptional","ValidationError","getMissingRawBodyMessage","validationResult","prevalidatorSuccess","parsedValue","validatorSuccess","getFailedRawBodyValidationMessage"],"mappings":"+KAsBaA,EAAoB,CAChCC,EACAC,IAC+B,CACzB,MAAAC,EAAeF,EAAI,QAAQ,QAC3BG,EAAaF,EAAU,SAEzB,GAAA,CAACE,GAAc,CAACD,EACnB,MAAM,IAAIE,EAAA,gBAAgBC,2BAAyBJ,CAAS,CAAC,EAG1D,GAAAE,GAAc,CAACD,EACX,OAGR,MAAMI,GAAoB,IAAM,CAC3B,GAAA,CACH,MAAMC,EAAsB,CAACN,EAAU,aAAeA,EAAU,YAAYC,CAAY,EAClFM,EAAcP,EAAU,MAAMC,CAAY,EAC1CO,EAAmB,CAACR,EAAU,UAAYA,EAAU,SAASO,CAAW,EACvE,MAAA,CACN,UAAWD,GAAuBE,EAClC,YAAAD,CACD,CAAA,MACO,CACA,MAAA,CAAE,UAAW,EAAM,CAAA,CAC3B,GACE,EAEC,GAAA,CAACF,EAAiB,UACrB,MAAM,IAAIF,EAAA,gBAAgBM,oCAAkCT,CAAS,CAAC,EAEvE,OAAOK,EAAiB,WACzB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ParameterizedContext } from 'koa';
|
|
2
2
|
import { Validator } from '../validators/types';
|
|
3
|
+
|
|
3
4
|
type CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined;
|
|
4
5
|
type ValidatedData<T extends Validator<any>> = CheckIfOptional<ReturnType<T['parse']>, T['optional']>;
|
|
5
6
|
export declare const useRequestRawBody: <ValidatorT extends Validator<any>>(ctx: ParameterizedContext, validator: ValidatorT) => ValidatedData<ValidatorT>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestRawBody.d.ts","sourceRoot":"","sources":["../../src/hooks/useRequestRawBody.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,KAAK,CAAA;AAI1C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,GAAG,SAAS,IAAI,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;AAE5F,KAAK,aAAa,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;AAcrG,eAAO,MAAM,iBAAiB,GAAI,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,OAC7D,oBAAoB,aACd,UAAU,KACnB,aAAa,CAAC,UAAU,CA8B1B,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ValidationError as r } from "../errors/UserFacingErrors.mjs";
|
|
2
|
+
import { getMissingRawBodyMessage as c, getFailedRawBodyValidationMessage as l } from "../utils/validationMessages.mjs";
|
|
3
|
+
const w = (i, e) => {
|
|
4
|
+
const t = i.request.rawBody, a = e.optional;
|
|
5
|
+
if (!a && !t)
|
|
6
|
+
throw new r(c(e));
|
|
7
|
+
if (a && !t)
|
|
8
|
+
return;
|
|
9
|
+
const s = (() => {
|
|
10
|
+
try {
|
|
11
|
+
const d = !e.prevalidate || e.prevalidate(t), o = e.parse(t), n = !e.validate || e.validate(o);
|
|
12
|
+
return {
|
|
13
|
+
validated: d && n,
|
|
14
|
+
parsedValue: o
|
|
15
|
+
};
|
|
16
|
+
} catch {
|
|
17
|
+
return { validated: !1 };
|
|
18
|
+
}
|
|
19
|
+
})();
|
|
20
|
+
if (!s.validated)
|
|
21
|
+
throw new r(l(e));
|
|
22
|
+
return s.parsedValue;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
w as useRequestRawBody
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=useRequestRawBody.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestRawBody.mjs","sources":["../../src/hooks/useRequestRawBody.ts"],"sourcesContent":["import { ParameterizedContext } from 'koa'\n\nimport { ValidationError } from '../errors/UserFacingErrors'\nimport { getFailedRawBodyValidationMessage, getMissingRawBodyMessage } from '../utils/validationMessages'\nimport { Validator } from '../validators/types'\n\ntype CheckIfOptional<T, B extends boolean | undefined> = B extends false ? T : T | undefined\n\ntype ValidatedData<T extends Validator<any>> = CheckIfOptional<ReturnType<T['parse']>, T['optional']>\n\n/**\n * Hook to access request body data without parsing into an object.\n *\n * Supported content types:\n * - `text/plain`\n * - `application/json`\n * - `application/x-www-form-urlencoded`\n *\n * @param ctx Koa context\n * @param validators Validator definitions\n * @returns Validated parameters\n */\nexport const useRequestRawBody = <ValidatorT extends Validator<any>>(\n\tctx: ParameterizedContext,\n\tvalidator: ValidatorT,\n): ValidatedData<ValidatorT> => {\n\tconst providedBody = ctx.request.rawBody\n\tconst isOptional = validator.optional\n\n\tif (!isOptional && !providedBody) {\n\t\tthrow new ValidationError(getMissingRawBodyMessage(validator))\n\t}\n\n\tif (isOptional && !providedBody) {\n\t\treturn undefined as ValidatedData<ValidatorT>\n\t}\n\n\tconst validationResult = (() => {\n\t\ttry {\n\t\t\tconst prevalidatorSuccess = !validator.prevalidate || validator.prevalidate(providedBody)\n\t\t\tconst parsedValue = validator.parse(providedBody)\n\t\t\tconst validatorSuccess = !validator.validate || validator.validate(parsedValue)\n\t\t\treturn {\n\t\t\t\tvalidated: prevalidatorSuccess && validatorSuccess,\n\t\t\t\tparsedValue,\n\t\t\t}\n\t\t} catch {\n\t\t\treturn { validated: false }\n\t\t}\n\t})()\n\n\tif (!validationResult.validated) {\n\t\tthrow new ValidationError(getFailedRawBodyValidationMessage(validator))\n\t}\n\treturn validationResult.parsedValue as ValidatedData<ValidatorT>\n}\n"],"names":["useRequestRawBody","ctx","validator","providedBody","isOptional","ValidationError","getMissingRawBodyMessage","validationResult","prevalidatorSuccess","parsedValue","validatorSuccess","getFailedRawBodyValidationMessage"],"mappings":";;AAsBa,MAAAA,IAAoB,CAChCC,GACAC,MAC+B;AACzB,QAAAC,IAAeF,EAAI,QAAQ,SAC3BG,IAAaF,EAAU;AAEzB,MAAA,CAACE,KAAc,CAACD;AACnB,UAAM,IAAIE,EAAgBC,EAAyBJ,CAAS,CAAC;AAG1D,MAAAE,KAAc,CAACD;AACX;AAGR,QAAMI,KAAoB,MAAM;AAC3B,QAAA;AACH,YAAMC,IAAsB,CAACN,EAAU,eAAeA,EAAU,YAAYC,CAAY,GAClFM,IAAcP,EAAU,MAAMC,CAAY,GAC1CO,IAAmB,CAACR,EAAU,YAAYA,EAAU,SAASO,CAAW;AACvE,aAAA;AAAA,QACN,WAAWD,KAAuBE;AAAA,QAClC,aAAAD;AAAA,MACD;AAAA,IAAA,QACO;AACA,aAAA,EAAE,WAAW,GAAM;AAAA,IAAA;AAAA,EAC3B,GACE;AAEC,MAAA,CAACF,EAAiB;AACrB,UAAM,IAAIF,EAAgBM,EAAkCT,CAAS,CAAC;AAEvE,SAAOK,EAAiB;AACzB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestRawBody.spec.d.ts","sourceRoot":"","sources":["../../src/hooks/useRequestRawBody.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReturnValue.cjs","sources":["../../src/hooks/useReturnValue.ts"],"sourcesContent":["export const useReturnValue = <T, S extends number, Y extends string>(\n\tvalue: T,\n\tstatus: S,\n\tcontentType: Y,\n) => {\n\treturn {\n\t\t_isUseReturnValue: true as const,\n\t\tstatus,\n\t\tvalue,\n\t\tcontentType,\n\t}\n}\n"],"names":["useReturnValue","value","status","contentType"],"mappings":"gFAAO,MAAMA,EAAiB,CAC7BC,EACAC,EACAC,KAEO,CACN,kBAAmB,GACnB,OAAAD,EACA,MAAAD,EACA,YAAAE,CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReturnValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useReturnValue.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,SAC5D,CAAC,UACA,CAAC,eACI,CAAC;;;;;CAQd,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReturnValue.mjs","sources":["../../src/hooks/useReturnValue.ts"],"sourcesContent":["export const useReturnValue = <T, S extends number, Y extends string>(\n\tvalue: T,\n\tstatus: S,\n\tcontentType: Y,\n) => {\n\treturn {\n\t\t_isUseReturnValue: true as const,\n\t\tstatus,\n\t\tvalue,\n\t\tcontentType,\n\t}\n}\n"],"names":["useReturnValue","value","status","contentType"],"mappings":"AAAO,MAAMA,IAAiB,CAC7BC,GACAC,GACAC,OAEO;AAAA,EACN,mBAAmB;AAAA,EACnB,QAAAD;AAAA,EACA,OAAAD;AAAA,EACA,aAAAE;AACD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReturnValue.spec.d.ts","sourceRoot":"","sources":["../../src/hooks/useReturnValue.spec.ts"],"names":[],"mappings":""}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./errors/HttpErrorHandler.cjs"),r=require("./errors/UserFacingErrors.cjs"),u=require("./hooks/authentication/useAuth.cjs"),i=require("./hooks/authentication/useOptionalAuth.cjs"),n=require("./hooks/useApiEndpoint.cjs"),l=require("./hooks/useApiHeader/useApiHeader.cjs"),d=require("./hooks/useCookieParams.cjs"),o=require("./hooks/useExposeApiModel.cjs"),t=require("./hooks/useHeaderParams.cjs"),p=require("./hooks/usePathParams.cjs"),m=require("./hooks/useQueryParams.cjs"),q=require("./hooks/useRequestBody.cjs"),h=require("./hooks/useRequestRawBody.cjs"),V=require("./hooks/useReturnValue.cjs"),E=require("./openapi/initOpenApiEngine.cjs"),P=require("./router/Router.cjs"),e=require("./validators/BuiltInValidators.cjs"),a=require("./validators/ParamWrappers.cjs");exports.HttpErrorHandler=s.HttpErrorHandler;exports.BadRequestError=r.BadRequestError;exports.UnauthorizedError=r.UnauthorizedError;exports.ValidationError=r.ValidationError;exports.useAuth=u.useAuth;exports.useOptionalAuth=i.useOptionalAuth;exports.useApiEndpoint=n.useApiEndpoint;exports.useApiHeader=l.useApiHeader;exports.useCookieParams=d.useCookieParams;exports.useExposeApiModel=o.useExposeApiModel;exports.useExposeNamedApiModels=o.useExposeNamedApiModels;exports.useHeaderParams=t.useHeaderParams;exports.useRequestHeaders=t.useRequestHeaders;exports.usePathParams=p.usePathParams;exports.useQueryParams=m.useQueryParams;exports.useRequestBody=q.useRequestBody;exports.useRequestRawBody=h.useRequestRawBody;exports.useReturnValue=V.useReturnValue;exports.initOpenApiEngine=E.initOpenApiEngine;exports.Router=P.Router;exports.BigIntValidator=e.BigIntValidator;exports.BooleanValidator=e.BooleanValidator;exports.EmailValidator=e.EmailValidator;exports.NonEmptyStringValidator=e.NonEmptyStringValidator;exports.NullableBigIntValidator=e.NullableBigIntValidator;exports.NullableBooleanValidator=e.NullableBooleanValidator;exports.NullableNumberValidator=e.NullableNumberValidator;exports.NullableStringValidator=e.NullableStringValidator;exports.NumberValidator=e.NumberValidator;exports.StringValidator=e.StringValidator;exports.OptionalParam=a.OptionalParam;exports.PathParam=a.PathParam;exports.RequiredParam=a.RequiredParam;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wCAAwC,CAAA;AACtD,cAAc,wBAAwB,CAAA;AACtC,cAAc,mCAAmC,CAAA;AACjD,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gCAAgC,CAAA;AAC9C,cAAc,4BAA4B,CAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { HttpErrorHandler as o } from "./errors/HttpErrorHandler.mjs";
|
|
2
|
+
import { BadRequestError as t, UnauthorizedError as i, ValidationError as l } from "./errors/UserFacingErrors.mjs";
|
|
3
|
+
import { useAuth as p } from "./hooks/authentication/useAuth.mjs";
|
|
4
|
+
import { useOptionalAuth as s } from "./hooks/authentication/useOptionalAuth.mjs";
|
|
5
|
+
import { useApiEndpoint as n } from "./hooks/useApiEndpoint.mjs";
|
|
6
|
+
import { useApiHeader as f } from "./hooks/useApiHeader/useApiHeader.mjs";
|
|
7
|
+
import { useCookieParams as E } from "./hooks/useCookieParams.mjs";
|
|
8
|
+
import { useExposeApiModel as N, useExposeNamedApiModels as R } from "./hooks/useExposeApiModel.mjs";
|
|
9
|
+
import { useHeaderParams as B, useRequestHeaders as b } from "./hooks/useHeaderParams.mjs";
|
|
10
|
+
import { usePathParams as h } from "./hooks/usePathParams.mjs";
|
|
11
|
+
import { useQueryParams as H } from "./hooks/useQueryParams.mjs";
|
|
12
|
+
import { useRequestBody as O } from "./hooks/useRequestBody.mjs";
|
|
13
|
+
import { useRequestRawBody as I } from "./hooks/useRequestRawBody.mjs";
|
|
14
|
+
import { useReturnValue as k } from "./hooks/useReturnValue.mjs";
|
|
15
|
+
import { initOpenApiEngine as z } from "./openapi/initOpenApiEngine.mjs";
|
|
16
|
+
import { Router as Q } from "./router/Router.mjs";
|
|
17
|
+
import { BigIntValidator as c, BooleanValidator as j, EmailValidator as v, NonEmptyStringValidator as D, NullableBigIntValidator as F, NullableBooleanValidator as G, NullableNumberValidator as J, NullableStringValidator as K, NumberValidator as L, StringValidator as T } from "./validators/BuiltInValidators.mjs";
|
|
18
|
+
import { OptionalParam as X, PathParam as Y, RequiredParam as Z } from "./validators/ParamWrappers.mjs";
|
|
19
|
+
export {
|
|
20
|
+
t as BadRequestError,
|
|
21
|
+
c as BigIntValidator,
|
|
22
|
+
j as BooleanValidator,
|
|
23
|
+
v as EmailValidator,
|
|
24
|
+
o as HttpErrorHandler,
|
|
25
|
+
D as NonEmptyStringValidator,
|
|
26
|
+
F as NullableBigIntValidator,
|
|
27
|
+
G as NullableBooleanValidator,
|
|
28
|
+
J as NullableNumberValidator,
|
|
29
|
+
K as NullableStringValidator,
|
|
30
|
+
L as NumberValidator,
|
|
31
|
+
X as OptionalParam,
|
|
32
|
+
Y as PathParam,
|
|
33
|
+
Z as RequiredParam,
|
|
34
|
+
Q as Router,
|
|
35
|
+
T as StringValidator,
|
|
36
|
+
i as UnauthorizedError,
|
|
37
|
+
l as ValidationError,
|
|
38
|
+
z as initOpenApiEngine,
|
|
39
|
+
n as useApiEndpoint,
|
|
40
|
+
f as useApiHeader,
|
|
41
|
+
p as useAuth,
|
|
42
|
+
E as useCookieParams,
|
|
43
|
+
N as useExposeApiModel,
|
|
44
|
+
R as useExposeNamedApiModels,
|
|
45
|
+
B as useHeaderParams,
|
|
46
|
+
s as useOptionalAuth,
|
|
47
|
+
h as usePathParams,
|
|
48
|
+
H as useQueryParams,
|
|
49
|
+
O as useRequestBody,
|
|
50
|
+
b as useRequestHeaders,
|
|
51
|
+
I as useRequestRawBody,
|
|
52
|
+
k as useReturnValue
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("path"),h=require("ts-morph"),u=require("../../utils/logger.cjs"),S=require("../discoveryModule/discoverImports/discoverImports.cjs"),q=require("../discoveryModule/discoverRouterFiles/discoverRouterFiles.cjs"),K=require("../discoveryModule/discoverRouters/discoverRouters.cjs"),k=require("../manager/OpenApiManager.cjs"),H=require("./getSourceFileTimestamp.cjs"),I=require("./nodeParsers.cjs"),U=require("./parseEndpoint.cjs"),E=require("./parseExposedModels.cjs"),N=require("./sourceFileCache.cjs");function W(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const c=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(o,a,c.get?c:{enumerable:!0,get:()=>e[a]})}}return o.default=e,Object.freeze(o)}const x=W(w),_=({logLevel:e,tsconfigPath:o,sourceFilePaths:a,sourceFileDiscovery:c,incremental:s})=>{const t=k.OpenApiManager.getInstance();if(t.isReady())return;e&&u.Logger.setLevel(e),u.Logger.info("Preparing OpenAPI spec");const r=new h.Project({tsConfigFilePath:x.resolve(o),skipFileDependencyResolution:!0}),{explicitRouters:n,discoveredRouterFiles:p,allSourceFiles:f}=(()=>{const l=(a??[]).map(d=>x.resolve(d)).map(d=>r.getSourceFileOrThrow(d)),L=l.flatMap(d=>({fileName:d.getFilePath(),sourceFile:d,routers:K.discoverRouters(d)})),{discoveredRouterFiles:b,discoveredSourceFiles:z}=(()=>{if(c===!1)return{discoveredRouterFiles:[],discoveredSourceFiles:[]};const d=performance.now(),g=q.discoverRouterFiles({targetPath:typeof c=="object"?c.rootPath:".",tsConfigPath:o});return u.Logger.info(`File discovery took ${Math.round(performance.now()-d)}ms`),g})(),j=l.reduce((d,g)=>d.some($=>$.getFilePath()===g.getFilePath())?d:d.concat(g),z);return{explicitRouters:L,discoveredRouterFiles:b,allSourceFiles:j}})(),O=n.reduce((i,m)=>i.some(l=>l.fileName===m.fileName)?i:i.concat(m),p),F=f.flatMap(i=>A(i)).filter(i=>!!i);F.length>0&&F[0]&&t.setHeader(F[0]);const R=f.flatMap(i=>T(i));t.setExposedModels(R);const v=typeof s=="object"&&s.cachePath?s.cachePath:x.resolve(process.cwd(),"node_modules",".cache","moonflower"),y=M(O,{cachePath:v,timestampCache:{}});t.setStats({discoveredRouterFiles:p.map(i=>({path:i.fileName,routers:i.routers.named.map(m=>({name:m,endpoints:y.filter(l=>l.sourceFilePath===i.fileName).map(l=>`${l.method.toUpperCase()} ${l.path}`)}))})),explicitRouterFiles:n.map(i=>({path:i.fileName,routers:i.routers.named.map(m=>({name:m,endpoints:y.filter(l=>l.sourceFilePath===i.fileName).map(l=>`${l.method.toUpperCase()} ${l.path}`)}))}))}),t.setEndpoints(y),t.markAsReady()},M=(e,o,a)=>{const c=performance.now(),s=e.map(t=>C(t,o));return u.Logger.info(`Router analysis took ${Math.round(performance.now()-c)}ms`),s.map((t,r)=>({fileName:e[r].fileName,timeTaken:t.timing})).sort((t,r)=>r.timeTaken-t.timeTaken).filter(t=>t.timeTaken>500).forEach(t=>{u.Logger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)}),s.flatMap(t=>t.endpoints)},C=(e,o,a)=>{const c=H.getSourceFileTimestamp(e.sourceFile,o.timestampCache),s=N.SourceFileCache.getCachedResults(e.sourceFile,c,o.cachePath);if(s)return u.Logger.debug(`[${e.fileName}] Found cached results`),{endpoints:s.endpoints,timing:0};u.Logger.debug(`[${e.fileName}] Analyzing...`);const t=performance.now(),r=P(e),n=performance.now();return u.Logger.debug(`[${e.fileName}] Analyzed in ${n-t}ms`),N.SourceFileCache.cacheResults(e.sourceFile,c,o.cachePath,r),{endpoints:r,timing:n-t}},P=(e,o)=>{const a=[],s=["get","post","put","delete","del","patch"].join("|");return e.routers.named.forEach(t=>{e.sourceFile.forEachChild(r=>{const n=r.getText();new RegExp(`${t}\\.(?:${s})`).test(n)&&((r.getFirstDescendantByKind(h.SyntaxKind.StringLiteral)?.getText()??"").slice(1,-1),a.push(U.parseEndpoint(r,e.fileName)))})}),a},A=e=>{const o=S.discoverImportedName({sourceFile:e,originalName:"useApiHeader"});if(!o)return null;const a=e.forEachChildAsArray().filter(r=>r.isKind(h.SyntaxKind.ExpressionStatement)).find(r=>o&&r.getText().startsWith(o));if(!a)return null;const c=a.getFirstDescendantByKindOrThrow(h.SyntaxKind.ObjectLiteralExpression),s=I.getValuesOfObjectLiteral(c),t=r=>typeof r=="string"||Array.isArray(r)&&r.every(n=>typeof n=="string")?r:r.reduce((n,p)=>typeof p=="string"?n:{...n,[p.identifier]:t(p.value)},{});return t(s)},T=e=>{const o=[],a=S.discoverImportedName({sourceFile:e,originalName:"useExposeApiModel"}),c=S.discoverImportedName({sourceFile:e,originalName:"useExposeNamedApiModels"});return e.forEachChildAsArray().filter(s=>s.isKind(h.SyntaxKind.ExpressionStatement)).map(s=>{if(a&&s.getText().startsWith(a)){const n=(s.getFirstChild()?.getChildrenOfKind(h.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!n)return;o.push(E.parseExposedModel(n));return}if(c&&s.getText().startsWith(c)){const n=(s.getFirstChild()?.getChildrenOfKind(h.SyntaxKind.SyntaxList)||[])[0].getFirstChild();if(!n)return;E.parseNamedExposedModels(n).forEach(f=>o.push(f))}}),o};exports.analyzeMultipleSourceFiles=M;exports.analyzeSourceFileApiHeader=A;exports.analyzeSourceFileEndpoints=P;exports.analyzeSourceFileExposedModels=T;exports.analyzeSourceFileWithCache=C;exports.prepareOpenApiSpec=_;
|
|
2
|
+
//# sourceMappingURL=analyzerModule.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzerModule.cjs","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"sourcesContent":["import * as path from 'path'\nimport { SourceFile, SyntaxKind } from 'ts-morph'\nimport { Project } from 'ts-morph'\n\nimport { Logger } from '../../utils/logger'\nimport { discoverImportedName } from '../discoveryModule/discoverImports/discoverImports'\nimport {\n\tDiscoveredSourceFile,\n\tdiscoverRouterFiles,\n} from '../discoveryModule/discoverRouterFiles/discoverRouterFiles'\nimport { discoverRouters } from '../discoveryModule/discoverRouters/discoverRouters'\nimport { ApiDocsHeader, OpenApiManager } from '../manager/OpenApiManager'\nimport { EndpointData, ExposedModelData } from '../types'\nimport { getSourceFileTimestamp, TimestampCache } from './getSourceFileTimestamp'\nimport { getValuesOfObjectLiteral } from './nodeParsers'\nimport { parseEndpoint } from './parseEndpoint'\nimport { parseExposedModel, parseNamedExposedModels } from './parseExposedModels'\nimport { SourceFileCache } from './sourceFileCache'\n\ntype Props = {\n\tlogLevel?: Parameters<(typeof Logger)['setLevel']>[0]\n\ttsconfigPath: string\n\tsourceFilePaths?: string[]\n\tsourceFileDiscovery?: boolean | FileDiscoveryConfig\n\tincremental?:\n\t\t| boolean\n\t\t| {\n\t\t\t\tcachePath: string\n\t\t }\n}\n\ntype FileDiscoveryConfig = {\n\trootPath: string\n}\n\n/**\n * @param tsconfigPath Path to tsconfig file relative to project root\n * @param sourceFilePaths Array of router source files relative to project root\n */\nexport const prepareOpenApiSpec = ({\n\tlogLevel,\n\ttsconfigPath,\n\tsourceFilePaths,\n\tsourceFileDiscovery,\n\tincremental,\n}: Props) => {\n\tconst openApiManager = OpenApiManager.getInstance()\n\n\tif (openApiManager.isReady()) {\n\t\treturn\n\t}\n\n\tif (logLevel) {\n\t\tLogger.setLevel(logLevel)\n\t}\n\n\tLogger.info('Preparing OpenAPI spec')\n\n\tconst project = new Project({\n\t\ttsConfigFilePath: path.resolve(tsconfigPath),\n\t\tskipFileDependencyResolution: true,\n\t})\n\n\tconst { explicitRouters, discoveredRouterFiles, allSourceFiles } = (() => {\n\t\tconst sourceFilesToAdd = sourceFilePaths ?? []\n\t\tconst resolvedSourceFilePaths = sourceFilesToAdd.map((filepath) => path.resolve(filepath))\n\t\tconst sourceFiles = resolvedSourceFilePaths.map((filePath) => project.getSourceFileOrThrow(filePath))\n\t\tconst explicitRouters = sourceFiles.flatMap((file) => ({\n\t\t\tfileName: file.getFilePath(),\n\t\t\tsourceFile: file,\n\t\t\trouters: discoverRouters(file),\n\t\t}))\n\n\t\tconst { discoveredRouterFiles, discoveredSourceFiles } = (() => {\n\t\t\tif (sourceFileDiscovery === false) {\n\t\t\t\treturn { discoveredRouterFiles: [], discoveredSourceFiles: [] }\n\t\t\t}\n\n\t\t\tconst startTime = performance.now()\n\t\t\tconst files = discoverRouterFiles({\n\t\t\t\ttargetPath: typeof sourceFileDiscovery === 'object' ? sourceFileDiscovery.rootPath : '.',\n\t\t\t\ttsConfigPath: tsconfigPath,\n\t\t\t})\n\t\t\tLogger.info(`File discovery took ${Math.round(performance.now() - startTime)}ms`)\n\t\t\treturn files\n\t\t})()\n\n\t\tconst allSourceFiles = sourceFiles.reduce(\n\t\t\t(acc, current) =>\n\t\t\t\tacc.some((r) => r.getFilePath() === current.getFilePath()) ? acc : acc.concat(current),\n\t\t\tdiscoveredSourceFiles,\n\t\t)\n\n\t\treturn { explicitRouters, discoveredRouterFiles, allSourceFiles }\n\t})()\n\n\tconst filesToAnalyze = explicitRouters.reduce(\n\t\t(acc, current) => (acc.some((r) => r.fileName === current.fileName) ? acc : acc.concat(current)),\n\t\tdiscoveredRouterFiles,\n\t)\n\n\tconst apiHeaders = allSourceFiles\n\t\t.flatMap((file) => analyzeSourceFileApiHeader(file))\n\t\t.filter((headers) => !!headers)\n\tif (apiHeaders.length > 0 && apiHeaders[0]) {\n\t\topenApiManager.setHeader(apiHeaders[0])\n\t}\n\n\tconst exposedModels = allSourceFiles.flatMap((file) => analyzeSourceFileExposedModels(file))\n\n\topenApiManager.setExposedModels(exposedModels)\n\n\tconst cachePath = (() => {\n\t\tif (typeof incremental === 'object' && incremental.cachePath) {\n\t\t\treturn incremental.cachePath\n\t\t}\n\t\treturn path.resolve(process.cwd(), 'node_modules', '.cache', 'moonflower')\n\t})()\n\tconst endpoints = analyzeMultipleSourceFiles(filesToAnalyze, {\n\t\tincremental: incremental !== false,\n\t\tcachePath,\n\t\ttimestampCache: {},\n\t})\n\n\topenApiManager.setStats({\n\t\tdiscoveredRouterFiles: discoveredRouterFiles.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t\texplicitRouterFiles: explicitRouters.map((file) => ({\n\t\t\tpath: file.fileName,\n\t\t\trouters: file.routers.named.map((r) => ({\n\t\t\t\tname: r,\n\t\t\t\tendpoints: endpoints\n\t\t\t\t\t.filter((e) => e.sourceFilePath === file.fileName)\n\t\t\t\t\t.map((e) => `${e.method.toUpperCase()} ${e.path}`),\n\t\t\t})),\n\t\t})),\n\t})\n\n\topenApiManager.setEndpoints(endpoints)\n\topenApiManager.markAsReady()\n}\n\nexport const analyzeMultipleSourceFiles = (\n\tfiles: DiscoveredSourceFile[],\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t},\n\tfilterEndpointPaths?: string[],\n): EndpointData[] => {\n\tconst startTime = performance.now()\n\tconst analyzedFiles = files.map((file) => analyzeSourceFileWithCache(file, config, filterEndpointPaths))\n\tLogger.info(`Router analysis took ${Math.round(performance.now() - startTime)}ms`)\n\n\tanalyzedFiles\n\t\t.map((f, index) => ({\n\t\t\tfileName: files[index].fileName,\n\t\t\ttimeTaken: f.timing,\n\t\t}))\n\t\t.sort((a, b) => b.timeTaken - a.timeTaken)\n\t\t.filter((t) => t.timeTaken > 500)\n\t\t.forEach((t) => {\n\t\t\tLogger.info(`- [${t.fileName}] Took ${Math.round(t.timeTaken)}ms to analyze`)\n\t\t})\n\n\treturn analyzedFiles.flatMap((f) => f.endpoints)\n}\n\nexport const analyzeSourceFileWithCache = (\n\tfile: DiscoveredSourceFile,\n\tconfig: {\n\t\tincremental: boolean\n\t\tcachePath: string\n\t\ttimestampCache: TimestampCache\n\t},\n\tfilterEndpointPaths?: string[],\n): { endpoints: EndpointData[]; timing: number } => {\n\tconst timestamp = getSourceFileTimestamp(file.sourceFile, config.timestampCache)\n\tconst cachedResults = SourceFileCache.getCachedResults(file.sourceFile, timestamp, config.cachePath)\n\n\tif (cachedResults) {\n\t\tLogger.debug(`[${file.fileName}] Found cached results`)\n\t\treturn { endpoints: cachedResults.endpoints, timing: 0 }\n\t}\n\tLogger.debug(`[${file.fileName}] Analyzing...`)\n\n\tconst t1 = performance.now()\n\tconst endpoints = analyzeSourceFileEndpoints(file, filterEndpointPaths)\n\tconst t2 = performance.now()\n\tLogger.debug(`[${file.fileName}] Analyzed in ${t2 - t1}ms`)\n\tSourceFileCache.cacheResults(file.sourceFile, timestamp, config.cachePath, endpoints)\n\treturn { endpoints, timing: t2 - t1 }\n}\n\nexport const analyzeSourceFileEndpoints = (\n\tfile: DiscoveredSourceFile,\n\tfilterEndpointPaths?: string[],\n): EndpointData[] => {\n\tconst endpoints: EndpointData[] = []\n\tconst operations = ['get', 'post', 'put', 'delete', 'del', 'patch']\n\tconst joinedOperations = operations.join('|')\n\n\tfile.routers.named.forEach((routerName) => {\n\t\tfile.sourceFile.forEachChild((node) => {\n\t\t\tconst nodeText = node.getText()\n\t\t\tconst routerPattern = new RegExp(`${routerName}\\\\.(?:${joinedOperations})`)\n\n\t\t\tif (routerPattern.test(nodeText)) {\n\t\t\t\tconst endpointText = node.getFirstDescendantByKind(SyntaxKind.StringLiteral)?.getText() ?? ''\n\t\t\t\tconst endpointPath = endpointText.slice(1, -1)\n\n\t\t\t\tif (filterEndpointPaths && !filterEndpointPaths.some((path) => endpointPath.includes(path))) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tendpoints.push(parseEndpoint(node, file.fileName))\n\t\t\t}\n\t\t})\n\t})\n\n\treturn endpoints\n}\n\nexport const analyzeSourceFileApiHeader = (sourceFile: SourceFile): ApiDocsHeader | null => {\n\tconst nameOfUseApiHeader = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useApiHeader',\n\t})\n\n\tif (!nameOfUseApiHeader) {\n\t\treturn null\n\t}\n\n\tconst node = sourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.find((node) => nameOfUseApiHeader && node.getText().startsWith(nameOfUseApiHeader))\n\n\tif (!node) {\n\t\treturn null\n\t}\n\n\tconst targetNode = node.getFirstDescendantByKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\tconst values = getValuesOfObjectLiteral(targetNode)\n\n\tconst collapseObject = (v: string | string[] | typeof values): any => {\n\t\tif (typeof v === 'string') {\n\t\t\treturn v\n\t\t}\n\t\tif (Array.isArray(v) && v.every((value) => typeof value === 'string')) {\n\t\t\treturn v\n\t\t}\n\n\t\treturn v.reduce((acc, current) => {\n\t\t\tif (typeof current === 'string') {\n\t\t\t\treturn acc\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t[current.identifier]: collapseObject(current.value as string[]),\n\t\t\t}\n\t\t}, {})\n\t}\n\treturn collapseObject(values)\n}\n\nexport const analyzeSourceFileExposedModels = (sourceFile: SourceFile): ExposedModelData[] => {\n\tconst models: ExposedModelData[] = []\n\n\tconst nameOfUseExposeApiModel = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeApiModel',\n\t})\n\n\tconst nameOfUseExposeNamedApiModels = discoverImportedName({\n\t\tsourceFile,\n\t\toriginalName: 'useExposeNamedApiModels',\n\t})\n\n\tsourceFile\n\t\t.forEachChildAsArray()\n\t\t.filter((node) => node.isKind(SyntaxKind.ExpressionStatement))\n\t\t.map((node) => {\n\t\t\tif (nameOfUseExposeApiModel && node.getText().startsWith(nameOfUseExposeApiModel)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tmodels.push(parseExposedModel(firstChild))\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (nameOfUseExposeNamedApiModels && node.getText().startsWith(nameOfUseExposeNamedApiModels)) {\n\t\t\t\tconst callExpressionNode = node.getFirstChild()\n\t\t\t\tconst syntaxListChildren = callExpressionNode?.getChildrenOfKind(SyntaxKind.SyntaxList) || []\n\n\t\t\t\tconst firstChild = syntaxListChildren[0].getFirstChild()\n\t\t\t\tif (!firstChild) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst parsedModels = parseNamedExposedModels(firstChild)\n\t\t\t\tparsedModels.forEach((model) => models.push(model))\n\t\t\t}\n\t\t})\n\treturn models\n}\n"],"names":["prepareOpenApiSpec","logLevel","tsconfigPath","sourceFilePaths","sourceFileDiscovery","incremental","openApiManager","OpenApiManager","Logger","project","Project","path","explicitRouters","discoveredRouterFiles","allSourceFiles","sourceFiles","filepath","filePath","file","discoverRouters","discoveredSourceFiles","startTime","files","discoverRouterFiles","acc","current","r","filesToAnalyze","apiHeaders","analyzeSourceFileApiHeader","headers","exposedModels","analyzeSourceFileExposedModels","cachePath","endpoints","analyzeMultipleSourceFiles","e","config","filterEndpointPaths","analyzedFiles","analyzeSourceFileWithCache","f","index","a","b","timestamp","getSourceFileTimestamp","cachedResults","SourceFileCache","t1","analyzeSourceFileEndpoints","t2","joinedOperations","routerName","node","nodeText","SyntaxKind","parseEndpoint","sourceFile","nameOfUseApiHeader","discoverImportedName","targetNode","values","getValuesOfObjectLiteral","collapseObject","v","value","models","nameOfUseExposeApiModel","nameOfUseExposeNamedApiModels","firstChild","parseExposedModel","parseNamedExposedModels","model"],"mappings":"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"}
|
|
@@ -4,6 +4,7 @@ import { DiscoveredSourceFile } from '../discoveryModule/discoverRouterFiles/dis
|
|
|
4
4
|
import { ApiDocsHeader } from '../manager/OpenApiManager';
|
|
5
5
|
import { EndpointData, ExposedModelData } from '../types';
|
|
6
6
|
import { TimestampCache } from './getSourceFileTimestamp';
|
|
7
|
+
|
|
7
8
|
type Props = {
|
|
8
9
|
logLevel?: Parameters<(typeof Logger)['setLevel']>[0];
|
|
9
10
|
tsconfigPath: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzerModule.d.ts","sourceRoot":"","sources":["../../../src/openapi/analyzerModule/analyzerModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AAGjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3C,OAAO,EACN,oBAAoB,EAEpB,MAAM,4DAA4D,CAAA;AAEnE,OAAO,EAAE,aAAa,EAAkB,MAAM,2BAA2B,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EAA0B,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAMjF,KAAK,KAAK,GAAG;IACZ,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACrD,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,mBAAmB,CAAC,EAAE,OAAO,GAAG,mBAAmB,CAAA;IACnD,WAAW,CAAC,EACT,OAAO,GACP;QACA,SAAS,EAAE,MAAM,CAAA;KAChB,CAAA;CACJ,CAAA;AAED,KAAK,mBAAmB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AAMD,eAAO,MAAM,kBAAkB,mFAM5B,KAAK,SAsGP,CAAA;AAED,eAAO,MAAM,0BAA0B,UAC/B,oBAAoB,EAAE,UACrB;IACP,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,cAAc,CAAA;CAC9B,wBACqB,MAAM,EAAE,KAC5B,YAAY,EAiBd,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,UAClB;IACP,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,cAAc,CAAA;CAC9B,wBACqB,MAAM,EAAE,KAC5B;IAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAgB7C,CAAA;AAED,eAAO,MAAM,0BAA0B,SAChC,oBAAoB,wBACJ,MAAM,EAAE,KAC5B,YAAY,EAwBd,CAAA;AAED,eAAO,MAAM,0BAA0B,eAAgB,UAAU,KAAG,aAAa,GAAG,IAyCnF,CAAA;AAED,eAAO,MAAM,8BAA8B,eAAgB,UAAU,KAAG,gBAAgB,EA4CvF,CAAA"}
|