@graphoria/server 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +129 -0
- package/cli.ts +105 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/src/ai/agent/agent.d.ts +37 -0
- package/dist/src/ai/agent/agent.d.ts.map +1 -0
- package/dist/src/ai/agent/index.d.ts +3 -0
- package/dist/src/ai/agent/index.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/anthropic.d.ts +10 -0
- package/dist/src/ai/agent/providers/anthropic.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/index.d.ts +8 -0
- package/dist/src/ai/agent/providers/index.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/ollama.d.ts +11 -0
- package/dist/src/ai/agent/providers/ollama.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/openai.d.ts +14 -0
- package/dist/src/ai/agent/providers/openai.d.ts.map +1 -0
- package/dist/src/ai/agent/types.d.ts +51 -0
- package/dist/src/ai/agent/types.d.ts.map +1 -0
- package/dist/src/ai/ask-field.test.d.ts +2 -0
- package/dist/src/ai/ask-field.test.d.ts.map +1 -0
- package/dist/src/ai/index.d.ts +7 -0
- package/dist/src/ai/index.d.ts.map +1 -0
- package/dist/src/ai/mcp/create-server.d.ts +14 -0
- package/dist/src/ai/mcp/create-server.d.ts.map +1 -0
- package/dist/src/ai/mcp/create-server.test.d.ts +2 -0
- package/dist/src/ai/mcp/create-server.test.d.ts.map +1 -0
- package/dist/src/ai/mcp/index.d.ts +13 -0
- package/dist/src/ai/mcp/index.d.ts.map +1 -0
- package/dist/src/ai/mcp/index.test.d.ts +2 -0
- package/dist/src/ai/mcp/index.test.d.ts.map +1 -0
- package/dist/src/ai/mcp/instructions.d.ts +2 -0
- package/dist/src/ai/mcp/instructions.d.ts.map +1 -0
- package/dist/src/ai/tools/agent.d.ts +4 -0
- package/dist/src/ai/tools/agent.d.ts.map +1 -0
- package/dist/src/ai/tools/agent.test.d.ts +2 -0
- package/dist/src/ai/tools/agent.test.d.ts.map +1 -0
- package/dist/src/ai/tools/core.d.ts +75 -0
- package/dist/src/ai/tools/core.d.ts.map +1 -0
- package/dist/src/ai/tools/query-data.d.ts +35 -0
- package/dist/src/ai/tools/query-data.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/fragmentAnalyzer.d.ts +5 -0
- package/dist/src/analyzeQuery/analyzers/fragmentAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/operationAnalyzer.d.ts +6 -0
- package/dist/src/analyzeQuery/analyzers/operationAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/selectionAnalyzer.d.ts +6 -0
- package/dist/src/analyzeQuery/analyzers/selectionAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/variableAnalyzer.d.ts +4 -0
- package/dist/src/analyzeQuery/analyzers/variableAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/depthLimit.d.ts +16 -0
- package/dist/src/analyzeQuery/depthLimit.d.ts.map +1 -0
- package/dist/src/analyzeQuery/depthLimit.test.d.ts +2 -0
- package/dist/src/analyzeQuery/depthLimit.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/directiveUtils.d.ts +4 -0
- package/dist/src/analyzeQuery/directiveUtils.d.ts.map +1 -0
- package/dist/src/analyzeQuery/directiveUtils.test.d.ts +2 -0
- package/dist/src/analyzeQuery/directiveUtils.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/index.d.ts +5 -0
- package/dist/src/analyzeQuery/index.d.ts.map +1 -0
- package/dist/src/analyzeQuery/index.test.d.ts +2 -0
- package/dist/src/analyzeQuery/index.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/resolveVariables.d.ts +71 -0
- package/dist/src/analyzeQuery/resolveVariables.d.ts.map +1 -0
- package/dist/src/analyzeQuery/resolveVariables.test.d.ts +2 -0
- package/dist/src/analyzeQuery/resolveVariables.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/staticValues.test.d.ts +2 -0
- package/dist/src/analyzeQuery/staticValues.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/typeUtils.d.ts +9 -0
- package/dist/src/analyzeQuery/typeUtils.d.ts.map +1 -0
- package/dist/src/analyzeQuery/types.d.ts +54 -0
- package/dist/src/analyzeQuery/types.d.ts.map +1 -0
- package/dist/src/analyzeQuery/valueExtractors.d.ts +4 -0
- package/dist/src/analyzeQuery/valueExtractors.d.ts.map +1 -0
- package/dist/src/authentication/duration.d.ts +14 -0
- package/dist/src/authentication/duration.d.ts.map +1 -0
- package/dist/src/authentication/duration.test.d.ts +2 -0
- package/dist/src/authentication/duration.test.d.ts.map +1 -0
- package/dist/src/authentication/index.d.ts +4 -0
- package/dist/src/authentication/index.d.ts.map +1 -0
- package/dist/src/authentication/index.test.d.ts +2 -0
- package/dist/src/authentication/index.test.d.ts.map +1 -0
- package/dist/src/authentication/jwt.d.ts +10 -0
- package/dist/src/authentication/jwt.d.ts.map +1 -0
- package/dist/src/authentication/jwt.test.d.ts +2 -0
- package/dist/src/authentication/jwt.test.d.ts.map +1 -0
- package/dist/src/authentication/paseto.d.ts +7 -0
- package/dist/src/authentication/paseto.d.ts.map +1 -0
- package/dist/src/authentication/paseto.test.d.ts +2 -0
- package/dist/src/authentication/paseto.test.d.ts.map +1 -0
- package/dist/src/authentication/tokenRepository.d.ts +14 -0
- package/dist/src/authentication/tokenRepository.d.ts.map +1 -0
- package/dist/src/authentication/tokenRepository.test.d.ts +2 -0
- package/dist/src/authentication/tokenRepository.test.d.ts.map +1 -0
- package/dist/src/authentication/types.d.ts +42 -0
- package/dist/src/authentication/types.d.ts.map +1 -0
- package/dist/src/cli/seedAuth.d.ts +4 -0
- package/dist/src/cli/seedAuth.d.ts.map +1 -0
- package/dist/src/cli/seedAuth.test.d.ts +2 -0
- package/dist/src/cli/seedAuth.test.d.ts.map +1 -0
- package/dist/src/cli/seedAuthArgs.d.ts +9 -0
- package/dist/src/cli/seedAuthArgs.d.ts.map +1 -0
- package/dist/src/config/helpers/cronHelper.d.ts +21 -0
- package/dist/src/config/helpers/cronHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/cronHelper.test.d.ts +2 -0
- package/dist/src/config/helpers/cronHelper.test.d.ts.map +1 -0
- package/dist/src/config/helpers/index.d.ts +4 -0
- package/dist/src/config/helpers/index.d.ts.map +1 -0
- package/dist/src/config/helpers/operationHelper.d.ts +44 -0
- package/dist/src/config/helpers/operationHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/queueHelper.d.ts +20 -0
- package/dist/src/config/helpers/queueHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/queueHelper.test.d.ts +2 -0
- package/dist/src/config/helpers/queueHelper.test.d.ts.map +1 -0
- package/dist/src/config/index.d.ts +236 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/types/ai.d.ts +29 -0
- package/dist/src/config/types/ai.d.ts.map +1 -0
- package/dist/src/config/types/auth.d.ts +112 -0
- package/dist/src/config/types/auth.d.ts.map +1 -0
- package/dist/src/config/types/configuration.d.ts +61 -0
- package/dist/src/config/types/configuration.d.ts.map +1 -0
- package/dist/src/config/types/cron.d.ts +81 -0
- package/dist/src/config/types/cron.d.ts.map +1 -0
- package/dist/src/config/types/db.d.ts +210 -0
- package/dist/src/config/types/db.d.ts.map +1 -0
- package/dist/src/config/types/index.d.ts +17 -0
- package/dist/src/config/types/index.d.ts.map +1 -0
- package/dist/src/config/types/operation.d.ts +226 -0
- package/dist/src/config/types/operation.d.ts.map +1 -0
- package/dist/src/config/types/queue.d.ts +142 -0
- package/dist/src/config/types/queue.d.ts.map +1 -0
- package/dist/src/config/types/remote-rest.d.ts +18 -0
- package/dist/src/config/types/remote-rest.d.ts.map +1 -0
- package/dist/src/config/types/remote-schema.d.ts +27 -0
- package/dist/src/config/types/remote-schema.d.ts.map +1 -0
- package/dist/src/config/types/virtual-columns.d.ts +89 -0
- package/dist/src/config/types/virtual-columns.d.ts.map +1 -0
- package/dist/src/config/types/virtual-columns.test.d.ts +2 -0
- package/dist/src/config/types/virtual-columns.test.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/index.d.ts +867 -0
- package/dist/src/configuration/getSchemas/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/mergeEntities/index.d.ts +412 -0
- package/dist/src/configuration/getSchemas/mergeEntities/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.d.ts +16 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.test.d.ts +2 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/buildExecute.d.ts +31 -0
- package/dist/src/configuration/gql/buildExecute.d.ts.map +1 -0
- package/dist/src/configuration/gql/buildExecute.test.d.ts +2 -0
- package/dist/src/configuration/gql/buildExecute.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/gqlAuthOperations.d.ts +9 -0
- package/dist/src/configuration/gql/gqlAuthOperations.d.ts.map +1 -0
- package/dist/src/configuration/gql/gqlAuthOperations.test.d.ts +2 -0
- package/dist/src/configuration/gql/gqlAuthOperations.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.d.ts +28 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.test.d.ts +2 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLSubscriptionFactory.d.ts +19 -0
- package/dist/src/configuration/gql/handleGraphQLSubscriptionFactory.d.ts.map +1 -0
- package/dist/src/configuration/index.d.ts +719 -0
- package/dist/src/configuration/index.d.ts.map +1 -0
- package/dist/src/configuration/rest/generateOpenAPI.d.ts +19 -0
- package/dist/src/configuration/rest/generateOpenAPI.d.ts.map +1 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.d.ts +12 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.d.ts.map +1 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.test.d.ts +2 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.test.d.ts.map +1 -0
- package/dist/src/configuration/rest/index.d.ts +20 -0
- package/dist/src/configuration/rest/index.d.ts.map +1 -0
- package/dist/src/configuration/rest/openApiErrors.d.ts +71 -0
- package/dist/src/configuration/rest/openApiErrors.d.ts.map +1 -0
- package/dist/src/console/App.d.ts +3 -0
- package/dist/src/console/App.d.ts.map +1 -0
- package/dist/src/console/Login.d.ts +6 -0
- package/dist/src/console/Login.d.ts.map +1 -0
- package/dist/src/console/api.d.ts +17 -0
- package/dist/src/console/api.d.ts.map +1 -0
- package/dist/src/console/api.test.d.ts +2 -0
- package/dist/src/console/api.test.d.ts.map +1 -0
- package/dist/src/console/client.d.ts +67 -0
- package/dist/src/console/client.d.ts.map +1 -0
- package/dist/src/console/frontend.d.ts +8 -0
- package/dist/src/console/frontend.d.ts.map +1 -0
- package/dist/src/console/pages/ConfigPage.d.ts +2 -0
- package/dist/src/console/pages/ConfigPage.d.ts.map +1 -0
- package/dist/src/console/pages/RolesPage.d.ts +2 -0
- package/dist/src/console/pages/RolesPage.d.ts.map +1 -0
- package/dist/src/console/pages/StatusPage.d.ts +2 -0
- package/dist/src/console/pages/StatusPage.d.ts.map +1 -0
- package/dist/src/console/pages/TablesPage.d.ts +2 -0
- package/dist/src/console/pages/TablesPage.d.ts.map +1 -0
- package/dist/src/console/useApi.d.ts +8 -0
- package/dist/src/console/useApi.d.ts.map +1 -0
- package/dist/src/cron/index.d.ts +63 -0
- package/dist/src/cron/index.d.ts.map +1 -0
- package/dist/src/databases/auth/auth-operations.d.ts +11 -0
- package/dist/src/databases/auth/auth-operations.d.ts.map +1 -0
- package/dist/src/databases/auth/password.d.ts +3 -0
- package/dist/src/databases/auth/password.d.ts.map +1 -0
- package/dist/src/databases/auth/password.test.d.ts +2 -0
- package/dist/src/databases/auth/password.test.d.ts.map +1 -0
- package/dist/src/databases/common.d.ts +53 -0
- package/dist/src/databases/common.d.ts.map +1 -0
- package/dist/src/databases/common.test.d.ts +2 -0
- package/dist/src/databases/common.test.d.ts.map +1 -0
- package/dist/src/databases/core/executor.d.ts +10 -0
- package/dist/src/databases/core/executor.d.ts.map +1 -0
- package/dist/src/databases/core/executor.test.d.ts +2 -0
- package/dist/src/databases/core/executor.test.d.ts.map +1 -0
- package/dist/src/databases/core/function-mapping.d.ts +38 -0
- package/dist/src/databases/core/function-mapping.d.ts.map +1 -0
- package/dist/src/databases/core/identifier.d.ts +2 -0
- package/dist/src/databases/core/identifier.d.ts.map +1 -0
- package/dist/src/databases/core/identifier.test.d.ts +2 -0
- package/dist/src/databases/core/identifier.test.d.ts.map +1 -0
- package/dist/src/databases/core/query-builder.d.ts +64 -0
- package/dist/src/databases/core/query-builder.d.ts.map +1 -0
- package/dist/src/databases/core/query-builder.test.d.ts +2 -0
- package/dist/src/databases/core/query-builder.test.d.ts.map +1 -0
- package/dist/src/databases/directives.d.ts +16 -0
- package/dist/src/databases/directives.d.ts.map +1 -0
- package/dist/src/databases/directives.test.d.ts +2 -0
- package/dist/src/databases/directives.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/auth.d.ts +9 -0
- package/dist/src/databases/engines/mssql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/mssql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/connection.d.ts +14 -0
- package/dist/src/databases/engines/mssql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/format.d.ts +5 -0
- package/dist/src/databases/engines/mssql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/mssql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/mssql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/mssql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/mssql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/auth.d.ts +9 -0
- package/dist/src/databases/engines/mysql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/mysql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/connection.d.ts +14 -0
- package/dist/src/databases/engines/mysql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/format.d.ts +5 -0
- package/dist/src/databases/engines/mysql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/mysql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/mysql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/mysql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/mysql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/auth.d.ts +9 -0
- package/dist/src/databases/engines/postgresql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/postgresql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/connection.d.ts +14 -0
- package/dist/src/databases/engines/postgresql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/format.d.ts +5 -0
- package/dist/src/databases/engines/postgresql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/postgresql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/postgresql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/postgresql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/postgresql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/shared/claims.d.ts +2 -0
- package/dist/src/databases/engines/shared/claims.d.ts.map +1 -0
- package/dist/src/databases/engines/shared/types.d.ts +8 -0
- package/dist/src/databases/engines/shared/types.d.ts.map +1 -0
- package/dist/src/databases/high-level-operations.d.ts +146 -0
- package/dist/src/databases/high-level-operations.d.ts.map +1 -0
- package/dist/src/databases/high-level-operations.test.d.ts +2 -0
- package/dist/src/databases/high-level-operations.test.d.ts.map +1 -0
- package/dist/src/databases/index.d.ts +8 -0
- package/dist/src/databases/index.d.ts.map +1 -0
- package/dist/src/databases/metadata/structure.d.ts +56 -0
- package/dist/src/databases/metadata/structure.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/convert.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/convert.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.d.ts +15 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateView/index.d.ts +18 -0
- package/dist/src/databases/schemaBuilder/generateCreateView/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.d.ts +8 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.d.ts +7 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/mssqlToPostgres/convertView.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/mssqlToPostgres/convertView.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/utils.d.ts +8 -0
- package/dist/src/databases/schemaBuilder/utils.d.ts.map +1 -0
- package/dist/src/databases/sqlTypeUtils.d.ts +24 -0
- package/dist/src/databases/sqlTypeUtils.d.ts.map +1 -0
- package/dist/src/databases/sqlTypeUtils.test.d.ts +2 -0
- package/dist/src/databases/sqlTypeUtils.test.d.ts.map +1 -0
- package/dist/src/databases/transformers/data-transformers.d.ts +215 -0
- package/dist/src/databases/transformers/data-transformers.d.ts.map +1 -0
- package/dist/src/databases/transformers/data-transformers.test.d.ts +2 -0
- package/dist/src/databases/transformers/data-transformers.test.d.ts.map +1 -0
- package/dist/src/databases/transformers/genResolverName.d.ts +2 -0
- package/dist/src/databases/transformers/genResolverName.d.ts.map +1 -0
- package/dist/src/databases/transformers/genResolverName.test.d.ts +2 -0
- package/dist/src/databases/transformers/genResolverName.test.d.ts.map +1 -0
- package/dist/src/index.d.ts +139 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/logging/index.d.ts +21 -0
- package/dist/src/logging/index.d.ts.map +1 -0
- package/dist/src/queues/kafka.d.ts +22 -0
- package/dist/src/queues/kafka.d.ts.map +1 -0
- package/dist/src/queues/rabbitmq.d.ts +34 -0
- package/dist/src/queues/rabbitmq.d.ts.map +1 -0
- package/dist/src/queues/rabbitmq.test.d.ts +2 -0
- package/dist/src/queues/rabbitmq.test.d.ts.map +1 -0
- package/dist/src/remoteREST/index.d.ts +13 -0
- package/dist/src/remoteREST/index.d.ts.map +1 -0
- package/dist/src/remoteREST/parse.d.ts +8 -0
- package/dist/src/remoteREST/parse.d.ts.map +1 -0
- package/dist/src/remoteREST/parse.test.d.ts +2 -0
- package/dist/src/remoteREST/parse.test.d.ts.map +1 -0
- package/dist/src/remoteREST/proxy.d.ts +6 -0
- package/dist/src/remoteREST/proxy.d.ts.map +1 -0
- package/dist/src/remoteREST/proxy.test.d.ts +2 -0
- package/dist/src/remoteREST/proxy.test.d.ts.map +1 -0
- package/dist/src/remoteREST/transform.d.ts +8 -0
- package/dist/src/remoteREST/transform.d.ts.map +1 -0
- package/dist/src/remoteREST/transform.test.d.ts +2 -0
- package/dist/src/remoteREST/transform.test.d.ts.map +1 -0
- package/dist/src/remoteREST/types.d.ts +37 -0
- package/dist/src/remoteREST/types.d.ts.map +1 -0
- package/dist/src/remoteSchemas/index.d.ts +13 -0
- package/dist/src/remoteSchemas/index.d.ts.map +1 -0
- package/dist/src/remoteSchemas/introspect.d.ts +7 -0
- package/dist/src/remoteSchemas/introspect.d.ts.map +1 -0
- package/dist/src/remoteSchemas/introspect.test.d.ts +2 -0
- package/dist/src/remoteSchemas/introspect.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/proxy.d.ts +7 -0
- package/dist/src/remoteSchemas/proxy.d.ts.map +1 -0
- package/dist/src/remoteSchemas/proxy.test.d.ts +2 -0
- package/dist/src/remoteSchemas/proxy.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/transform.d.ts +9 -0
- package/dist/src/remoteSchemas/transform.d.ts.map +1 -0
- package/dist/src/remoteSchemas/transform.test.d.ts +2 -0
- package/dist/src/remoteSchemas/transform.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/types.d.ts +41 -0
- package/dist/src/remoteSchemas/types.d.ts.map +1 -0
- package/dist/src/singletons/ai.d.ts +25 -0
- package/dist/src/singletons/ai.d.ts.map +1 -0
- package/dist/src/singletons/ai.test.d.ts +2 -0
- package/dist/src/singletons/ai.test.d.ts.map +1 -0
- package/dist/src/singletons/authentication.d.ts +4 -0
- package/dist/src/singletons/authentication.d.ts.map +1 -0
- package/dist/src/singletons/cache/index.d.ts +5 -0
- package/dist/src/singletons/cache/index.d.ts.map +1 -0
- package/dist/src/singletons/cache/lruCacheStore.d.ts +12 -0
- package/dist/src/singletons/cache/lruCacheStore.d.ts.map +1 -0
- package/dist/src/singletons/cache/lruCacheStore.test.d.ts +2 -0
- package/dist/src/singletons/cache/lruCacheStore.test.d.ts.map +1 -0
- package/dist/src/singletons/cache/redisCacheStore.d.ts +16 -0
- package/dist/src/singletons/cache/redisCacheStore.d.ts.map +1 -0
- package/dist/src/singletons/cache/redisClient.d.ts +3 -0
- package/dist/src/singletons/cache/redisClient.d.ts.map +1 -0
- package/dist/src/singletons/cache/registry.d.ts +7 -0
- package/dist/src/singletons/cache/registry.d.ts.map +1 -0
- package/dist/src/singletons/cache/registry.test.d.ts +2 -0
- package/dist/src/singletons/cache/registry.test.d.ts.map +1 -0
- package/dist/src/singletons/cache/types.d.ts +8 -0
- package/dist/src/singletons/cache/types.d.ts.map +1 -0
- package/dist/src/singletons/cron.d.ts +69 -0
- package/dist/src/singletons/cron.d.ts.map +1 -0
- package/dist/src/singletons/databases.d.ts +27 -0
- package/dist/src/singletons/databases.d.ts.map +1 -0
- package/dist/src/singletons/databases.test.d.ts +2 -0
- package/dist/src/singletons/databases.test.d.ts.map +1 -0
- package/dist/src/singletons/env.d.ts +494 -0
- package/dist/src/singletons/env.d.ts.map +1 -0
- package/dist/src/singletons/queues.d.ts +17 -0
- package/dist/src/singletons/queues.d.ts.map +1 -0
- package/dist/src/subscriptions/index.d.ts +4 -0
- package/dist/src/subscriptions/index.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/database.d.ts +12 -0
- package/dist/src/subscriptions/strategies/database.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/index.d.ts +12 -0
- package/dist/src/subscriptions/strategies/index.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/queue.d.ts +11 -0
- package/dist/src/subscriptions/strategies/queue.d.ts.map +1 -0
- package/dist/src/subscriptions/types.d.ts +67 -0
- package/dist/src/subscriptions/types.d.ts.map +1 -0
- package/dist/src/subscriptions/utils/polling.d.ts +17 -0
- package/dist/src/subscriptions/utils/polling.d.ts.map +1 -0
- package/dist/src/types/common.d.ts +44 -0
- package/dist/src/types/common.d.ts.map +1 -0
- package/dist/src/types/configuration.d.ts +28 -0
- package/dist/src/types/configuration.d.ts.map +1 -0
- package/dist/src/types/db.d.ts +43 -0
- package/dist/src/types/db.d.ts.map +1 -0
- package/dist/src/types/env.d.ts +2302 -0
- package/dist/src/types/env.d.ts.map +1 -0
- package/dist/src/types/env.test.d.ts +2 -0
- package/dist/src/types/env.test.d.ts.map +1 -0
- package/dist/src/types/resolver.d.ts +121 -0
- package/dist/src/types/resolver.d.ts.map +1 -0
- package/dist/src/types/zod/ai.d.ts +6 -0
- package/dist/src/types/zod/ai.d.ts.map +1 -0
- package/dist/src/types/zod/auth.d.ts +76 -0
- package/dist/src/types/zod/auth.d.ts.map +1 -0
- package/dist/src/types/zod/configuration.d.ts +1278 -0
- package/dist/src/types/zod/configuration.d.ts.map +1 -0
- package/dist/src/types/zod/configuration.test.d.ts +2 -0
- package/dist/src/types/zod/configuration.test.d.ts.map +1 -0
- package/dist/src/types/zod/cron.d.ts +32 -0
- package/dist/src/types/zod/cron.d.ts.map +1 -0
- package/dist/src/types/zod/db.d.ts +441 -0
- package/dist/src/types/zod/db.d.ts.map +1 -0
- package/dist/src/types/zod/db.test.d.ts +2 -0
- package/dist/src/types/zod/db.test.d.ts.map +1 -0
- package/dist/src/types/zod/mcp.d.ts +6 -0
- package/dist/src/types/zod/mcp.d.ts.map +1 -0
- package/dist/src/types/zod/operation.d.ts +9 -0
- package/dist/src/types/zod/operation.d.ts.map +1 -0
- package/dist/src/types/zod/queue.d.ts +656 -0
- package/dist/src/types/zod/queue.d.ts.map +1 -0
- package/dist/src/types/zod/queue.test.d.ts +2 -0
- package/dist/src/types/zod/queue.test.d.ts.map +1 -0
- package/dist/src/types/zod/remoteREST.d.ts +6 -0
- package/dist/src/types/zod/remoteREST.d.ts.map +1 -0
- package/dist/src/types/zod/remoteSchema.d.ts +6 -0
- package/dist/src/types/zod/remoteSchema.d.ts.map +1 -0
- package/dist/src/utils/benchmark.d.ts +2 -0
- package/dist/src/utils/benchmark.d.ts.map +1 -0
- package/dist/src/utils/event-emitter.d.ts +19 -0
- package/dist/src/utils/event-emitter.d.ts.map +1 -0
- package/dist/src/utils/responses.d.ts +19 -0
- package/dist/src/utils/responses.d.ts.map +1 -0
- package/dist/src/utils/responses.test.d.ts +2 -0
- package/dist/src/utils/responses.test.d.ts.map +1 -0
- package/dist/src/utils/safeJSONParse.d.ts +2 -0
- package/dist/src/utils/safeJSONParse.d.ts.map +1 -0
- package/dist/src/utils/selection.d.ts +3 -0
- package/dist/src/utils/selection.d.ts.map +1 -0
- package/dist/src/utils/selection.test.d.ts +2 -0
- package/dist/src/utils/selection.test.d.ts.map +1 -0
- package/dist/src/utils/sessionVariables.d.ts +47 -0
- package/dist/src/utils/sessionVariables.d.ts.map +1 -0
- package/dist/src/utils/sessionVariables.test.d.ts +2 -0
- package/dist/src/utils/sessionVariables.test.d.ts.map +1 -0
- package/dist/src/utils/writeSchema.d.ts +3 -0
- package/dist/src/utils/writeSchema.d.ts.map +1 -0
- package/dist/standalone.d.ts +3 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +119 -0
- package/playgrounds/console/index.html +25 -0
- package/playgrounds/graphiql/index.html +1144 -0
- package/playgrounds/scalar/index.html +19 -0
- package/src/ai/agent/agent.ts +222 -0
- package/src/ai/agent/index.ts +2 -0
- package/src/ai/agent/providers/anthropic.ts +113 -0
- package/src/ai/agent/providers/index.ts +62 -0
- package/src/ai/agent/providers/ollama.ts +128 -0
- package/src/ai/agent/providers/openai.ts +100 -0
- package/src/ai/agent/types.ts +65 -0
- package/src/ai/index.ts +8 -0
- package/src/ai/mcp/create-server.ts +444 -0
- package/src/ai/mcp/index.ts +80 -0
- package/src/ai/mcp/instructions.ts +103 -0
- package/src/ai/tools/agent.ts +111 -0
- package/src/ai/tools/core.ts +486 -0
- package/src/ai/tools/query-data.ts +109 -0
- package/src/analyzeQuery/analyzers/fragmentAnalyzer.ts +29 -0
- package/src/analyzeQuery/analyzers/operationAnalyzer.ts +50 -0
- package/src/analyzeQuery/analyzers/selectionAnalyzer.ts +135 -0
- package/src/analyzeQuery/analyzers/variableAnalyzer.ts +17 -0
- package/src/analyzeQuery/depthLimit.ts +124 -0
- package/src/analyzeQuery/directiveUtils.ts +99 -0
- package/src/analyzeQuery/index.ts +66 -0
- package/src/analyzeQuery/resolveVariables.ts +394 -0
- package/src/analyzeQuery/typeUtils.ts +47 -0
- package/src/analyzeQuery/types.ts +57 -0
- package/src/analyzeQuery/valueExtractors.ts +96 -0
- package/src/authentication/duration.ts +50 -0
- package/src/authentication/index.ts +34 -0
- package/src/authentication/jwt.ts +220 -0
- package/src/authentication/paseto.ts +256 -0
- package/src/authentication/tokenRepository.ts +75 -0
- package/src/authentication/types.ts +78 -0
- package/src/cli/seedAuth.ts +51 -0
- package/src/cli/seedAuthArgs.ts +50 -0
- package/src/config/helpers/cronHelper.ts +29 -0
- package/src/config/helpers/index.ts +8 -0
- package/src/config/helpers/operationHelper.ts +146 -0
- package/src/config/helpers/queueHelper.ts +27 -0
- package/src/config/index.ts +315 -0
- package/src/config/types/ai.ts +35 -0
- package/src/config/types/auth.ts +147 -0
- package/src/config/types/configuration.ts +69 -0
- package/src/config/types/cron.ts +140 -0
- package/src/config/types/db.ts +256 -0
- package/src/config/types/index.ts +129 -0
- package/src/config/types/operation.ts +253 -0
- package/src/config/types/queue.ts +172 -0
- package/src/config/types/remote-rest.ts +28 -0
- package/src/config/types/remote-schema.ts +39 -0
- package/src/config/types/virtual-columns.ts +157 -0
- package/src/configuration/getSchemas/index.ts +82 -0
- package/src/configuration/getSchemas/mergeEntities/index.ts +221 -0
- package/src/configuration/getSchemas/type-definition-generator/index.ts +511 -0
- package/src/configuration/gql/buildExecute.ts +54 -0
- package/src/configuration/gql/gqlAuthOperations.ts +150 -0
- package/src/configuration/gql/handleGraphQLRequestFactory.ts +415 -0
- package/src/configuration/gql/handleGraphQLSubscriptionFactory.ts +249 -0
- package/src/configuration/index.ts +138 -0
- package/src/configuration/rest/generateOpenAPI.ts +361 -0
- package/src/configuration/rest/handleRESTRequestFactory.ts +335 -0
- package/src/configuration/rest/index.ts +167 -0
- package/src/configuration/rest/openApiErrors.ts +106 -0
- package/src/console/api.ts +270 -0
- package/src/cron/index.ts +251 -0
- package/src/databases/auth/auth-operations.ts +36 -0
- package/src/databases/auth/password.ts +4 -0
- package/src/databases/common.ts +642 -0
- package/src/databases/core/executor.ts +97 -0
- package/src/databases/core/function-mapping.ts +176 -0
- package/src/databases/core/identifier.ts +8 -0
- package/src/databases/core/query-builder.ts +47 -0
- package/src/databases/directives.ts +112 -0
- package/src/databases/engines/mssql/auth.ts +112 -0
- package/src/databases/engines/mssql/connection.ts +151 -0
- package/src/databases/engines/mssql/format.ts +23 -0
- package/src/databases/engines/mssql/getStructure.ts +112 -0
- package/src/databases/engines/mssql/getViews.ts +17 -0
- package/src/databases/engines/mssql/query/index.ts +306 -0
- package/src/databases/engines/mysql/auth.ts +100 -0
- package/src/databases/engines/mysql/connection.ts +100 -0
- package/src/databases/engines/mysql/format.ts +23 -0
- package/src/databases/engines/mysql/getStructure.ts +116 -0
- package/src/databases/engines/mysql/getViews.ts +20 -0
- package/src/databases/engines/mysql/query/index.ts +291 -0
- package/src/databases/engines/postgresql/auth.ts +98 -0
- package/src/databases/engines/postgresql/connection.ts +99 -0
- package/src/databases/engines/postgresql/format.ts +23 -0
- package/src/databases/engines/postgresql/getStructure.ts +149 -0
- package/src/databases/engines/postgresql/getViews.ts +20 -0
- package/src/databases/engines/postgresql/query/index.ts +291 -0
- package/src/databases/engines/shared/claims.ts +26 -0
- package/src/databases/engines/shared/types.ts +7 -0
- package/src/databases/high-level-operations.ts +272 -0
- package/src/databases/index.ts +28 -0
- package/src/databases/metadata/structure.ts +12 -0
- package/src/databases/schemaBuilder/convert.ts +121 -0
- package/src/databases/schemaBuilder/generateCreateTable/index.ts +133 -0
- package/src/databases/schemaBuilder/generateCreateView/index.ts +101 -0
- package/src/databases/schemaBuilder/generateInsert/index.ts +47 -0
- package/src/databases/schemaBuilder/generateSchemaCreation/index.ts +29 -0
- package/src/databases/schemaBuilder/mssqlToPostgres/convertView.ts +47 -0
- package/src/databases/schemaBuilder/utils.ts +17 -0
- package/src/databases/sqlTypeUtils.ts +91 -0
- package/src/databases/transformers/data-transformers.ts +128 -0
- package/src/databases/transformers/genResolverName.ts +18 -0
- package/src/index.ts +461 -0
- package/src/logging/index.ts +69 -0
- package/src/queues/kafka.ts +409 -0
- package/src/queues/rabbitmq.ts +331 -0
- package/src/remoteREST/index.ts +46 -0
- package/src/remoteREST/parse.ts +68 -0
- package/src/remoteREST/proxy.ts +92 -0
- package/src/remoteREST/transform.ts +121 -0
- package/src/remoteREST/types.ts +38 -0
- package/src/remoteSchemas/index.ts +48 -0
- package/src/remoteSchemas/introspect.ts +44 -0
- package/src/remoteSchemas/proxy.ts +146 -0
- package/src/remoteSchemas/transform.ts +210 -0
- package/src/remoteSchemas/types.ts +43 -0
- package/src/singletons/ai.ts +91 -0
- package/src/singletons/authentication.ts +13 -0
- package/src/singletons/cache/index.ts +4 -0
- package/src/singletons/cache/lruCacheStore.ts +34 -0
- package/src/singletons/cache/redisCacheStore.ts +81 -0
- package/src/singletons/cache/redisClient.ts +12 -0
- package/src/singletons/cache/registry.ts +51 -0
- package/src/singletons/cache/types.ts +7 -0
- package/src/singletons/cron.ts +21 -0
- package/src/singletons/databases.ts +68 -0
- package/src/singletons/env.ts +3 -0
- package/src/singletons/queues.ts +101 -0
- package/src/subscriptions/index.ts +20 -0
- package/src/subscriptions/strategies/database.ts +68 -0
- package/src/subscriptions/strategies/index.ts +38 -0
- package/src/subscriptions/strategies/queue.ts +61 -0
- package/src/subscriptions/types.ts +74 -0
- package/src/subscriptions/utils/polling.ts +119 -0
- package/src/types/common.ts +57 -0
- package/src/types/configuration.ts +52 -0
- package/src/types/db.ts +87 -0
- package/src/types/env.ts +137 -0
- package/src/types/resolver.ts +181 -0
- package/src/types/zod/ai.ts +8 -0
- package/src/types/zod/auth.ts +96 -0
- package/src/types/zod/configuration.ts +46 -0
- package/src/types/zod/cron.ts +35 -0
- package/src/types/zod/db.ts +146 -0
- package/src/types/zod/mcp.ts +8 -0
- package/src/types/zod/operation.ts +37 -0
- package/src/types/zod/queue.ts +182 -0
- package/src/types/zod/remoteREST.ts +8 -0
- package/src/types/zod/remoteSchema.ts +11 -0
- package/src/utils/benchmark.ts +13 -0
- package/src/utils/event-emitter.ts +217 -0
- package/src/utils/responses.ts +42 -0
- package/src/utils/safeJSONParse.ts +10 -0
- package/src/utils/selection.ts +35 -0
- package/src/utils/sessionVariables.ts +131 -0
- package/src/utils/writeSchema.ts +13 -0
- package/standalone.ts +32 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { connect } from "amqplib";
|
|
2
|
+
import { nanoid } from "nanoid";
|
|
3
|
+
|
|
4
|
+
import type { Channel, ChannelModel, ConsumeMessage } from "amqplib";
|
|
5
|
+
import type { RabbitMQConfig } from "../types/zod/queue";
|
|
6
|
+
|
|
7
|
+
import { queryEventEmitter } from "../configuration/gql/handleGraphQLSubscriptionFactory";
|
|
8
|
+
import { InvalidationHelper } from "../singletons/cache/registry";
|
|
9
|
+
import { logger } from "../logging";
|
|
10
|
+
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Reconnection Configuration
|
|
13
|
+
// ============================================================================
|
|
14
|
+
|
|
15
|
+
const RECONNECT_INITIAL_DELAY = 1000; // 1 second
|
|
16
|
+
const RECONNECT_MAX_DELAY = 30000; // 30 seconds
|
|
17
|
+
const RECONNECT_MULTIPLIER = 2;
|
|
18
|
+
|
|
19
|
+
const sendMessage = (connectionName: string, name: string, msg: ConsumeMessage) => {
|
|
20
|
+
queryEventEmitter.sendDataUpdate(`${connectionName}_${name}`, {
|
|
21
|
+
data: {
|
|
22
|
+
message: msg.content.toString(),
|
|
23
|
+
id: msg.fields.deliveryTag,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const startConsumer = async (
|
|
29
|
+
connectionName: string,
|
|
30
|
+
name: string,
|
|
31
|
+
queueName: string,
|
|
32
|
+
channel: Channel,
|
|
33
|
+
handler?: (
|
|
34
|
+
message: unknown,
|
|
35
|
+
context: {
|
|
36
|
+
cache: {
|
|
37
|
+
invalidate: (operationName: string, pattern?: Record<string, unknown>) => Promise<boolean>;
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
) => Promise<void> | void,
|
|
41
|
+
) => {
|
|
42
|
+
const log = logger("rabbitmq").child({ queue: connectionName, consumer: name });
|
|
43
|
+
|
|
44
|
+
channel.consume(queueName, async (msg) => {
|
|
45
|
+
if (msg !== null) {
|
|
46
|
+
try {
|
|
47
|
+
sendMessage(connectionName, name, msg);
|
|
48
|
+
|
|
49
|
+
if (handler) {
|
|
50
|
+
let parsedMessage = msg.content.toString();
|
|
51
|
+
try {
|
|
52
|
+
parsedMessage = JSON.parse(parsedMessage);
|
|
53
|
+
} catch {
|
|
54
|
+
// message is not JSON, proceed with raw string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
await handler(parsedMessage, { cache: InvalidationHelper });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
channel.ack(msg);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
log.error({ err: error }, "message processing failed");
|
|
63
|
+
|
|
64
|
+
channel.nack(msg);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type RabbitMQPublisher = {
|
|
71
|
+
name: string;
|
|
72
|
+
routingKey: string;
|
|
73
|
+
exchangeName: string;
|
|
74
|
+
send: (message: string | object) => boolean;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type RabbitMQQueue = RabbitMQConfig;
|
|
78
|
+
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// RabbitMQ Connection Manager with Reconnection
|
|
81
|
+
// ============================================================================
|
|
82
|
+
|
|
83
|
+
type RabbitMQConnectionState = {
|
|
84
|
+
connection: ChannelModel | null;
|
|
85
|
+
channel: Channel | null;
|
|
86
|
+
isConnecting: boolean;
|
|
87
|
+
publishers: Record<string, RabbitMQPublisher>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type RabbitMQConnectionManager = {
|
|
91
|
+
connect: () => Promise<void>;
|
|
92
|
+
getPublishers: () => Record<string, RabbitMQPublisher>;
|
|
93
|
+
isConnected: () => boolean;
|
|
94
|
+
cleanup: () => Promise<void>;
|
|
95
|
+
onPublishersChanged: (callback: () => void) => void;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type RabbitMQConnectionManagerOptions = {
|
|
99
|
+
connect?: typeof connect;
|
|
100
|
+
setTimeout?: typeof setTimeout;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const createRabbitMQConnectionManager = (
|
|
104
|
+
queueConfig: RabbitMQQueue,
|
|
105
|
+
options: RabbitMQConnectionManagerOptions = {},
|
|
106
|
+
): RabbitMQConnectionManager => {
|
|
107
|
+
const log = logger("rabbitmq").child({ queue: queueConfig.name });
|
|
108
|
+
const connectFn = options.connect ?? connect;
|
|
109
|
+
const setTimeoutFn = options.setTimeout ?? setTimeout;
|
|
110
|
+
const state: RabbitMQConnectionState = {
|
|
111
|
+
connection: null,
|
|
112
|
+
channel: null,
|
|
113
|
+
isConnecting: false,
|
|
114
|
+
publishers: {},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Callback to notify when publishers change (connect/reconnect)
|
|
118
|
+
let publishersChangedCallback: (() => void) | null = null;
|
|
119
|
+
|
|
120
|
+
let reconnectAttempts = 0;
|
|
121
|
+
|
|
122
|
+
const setupConnection = async (): Promise<void> => {
|
|
123
|
+
if (state.isConnecting) return;
|
|
124
|
+
state.isConnecting = true;
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
log.info("connecting");
|
|
128
|
+
|
|
129
|
+
const rmqConnection = await connectFn(queueConfig.connection);
|
|
130
|
+
const channel = await rmqConnection.createChannel();
|
|
131
|
+
|
|
132
|
+
// Set up error handlers for reconnection
|
|
133
|
+
rmqConnection.on("error", (err) => {
|
|
134
|
+
log.error({ err }, "connection error");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
rmqConnection.on("close", () => {
|
|
138
|
+
log.warn("connection closed, reconnecting");
|
|
139
|
+
state.connection = null;
|
|
140
|
+
state.channel = null;
|
|
141
|
+
scheduleReconnect();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
channel.on("error", (err) => {
|
|
145
|
+
log.error({ err }, "channel error");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
channel.on("close", () => {
|
|
149
|
+
log.warn("channel closed");
|
|
150
|
+
state.channel = null;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Set up exchanges and publishers
|
|
154
|
+
for (const exchange of queueConfig.exchanges) {
|
|
155
|
+
if (queueConfig.autoSetup) {
|
|
156
|
+
await channel.assertExchange(exchange.name, exchange.type, exchange.options);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
for (const p of exchange.publishers) {
|
|
160
|
+
state.publishers[`${queueConfig.name}_${p.name}`] = {
|
|
161
|
+
name: p.name,
|
|
162
|
+
routingKey: p.routingKey,
|
|
163
|
+
exchangeName: exchange.name,
|
|
164
|
+
send: (message: string | object) => {
|
|
165
|
+
if (!state.channel) {
|
|
166
|
+
log.error("cannot send: channel not available");
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return state.channel.publish(
|
|
170
|
+
exchange.name,
|
|
171
|
+
p.routingKey,
|
|
172
|
+
Buffer.from(typeof message === "string" ? message : JSON.stringify(message)),
|
|
173
|
+
p.options,
|
|
174
|
+
);
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Set up queues and consumers
|
|
181
|
+
for (const route of queueConfig.queues) {
|
|
182
|
+
const queueName = route.queue ?? `${route.name}-${nanoid(10)}`;
|
|
183
|
+
|
|
184
|
+
const durable = route.queueOptions?.durable ?? !!route.queue;
|
|
185
|
+
const autoDelete = route.queueOptions?.autoDelete ?? !route.queue;
|
|
186
|
+
|
|
187
|
+
if (!route.queue || (route.queue && queueConfig.autoSetup)) {
|
|
188
|
+
await channel.assertQueue(queueName, {
|
|
189
|
+
...route.queueOptions,
|
|
190
|
+
durable,
|
|
191
|
+
autoDelete,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
for (const binding of route.bindings) {
|
|
195
|
+
await channel.bindQueue(queueName, binding.exchange, binding.pattern);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
await startConsumer(queueConfig.name, route.name, queueName, channel, route.handler);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
state.connection = rmqConnection;
|
|
203
|
+
state.channel = channel;
|
|
204
|
+
reconnectAttempts = 0;
|
|
205
|
+
|
|
206
|
+
// Notify that publishers have changed
|
|
207
|
+
if (publishersChangedCallback) {
|
|
208
|
+
publishersChangedCallback();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
log.info("connected");
|
|
212
|
+
} catch (error) {
|
|
213
|
+
log.error({ err: error }, "connection failed");
|
|
214
|
+
scheduleReconnect();
|
|
215
|
+
} finally {
|
|
216
|
+
state.isConnecting = false;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const scheduleReconnect = () => {
|
|
221
|
+
const delay = Math.min(
|
|
222
|
+
RECONNECT_INITIAL_DELAY * Math.pow(RECONNECT_MULTIPLIER, reconnectAttempts),
|
|
223
|
+
RECONNECT_MAX_DELAY,
|
|
224
|
+
);
|
|
225
|
+
reconnectAttempts++;
|
|
226
|
+
|
|
227
|
+
log.info({ delay, attempt: reconnectAttempts }, "scheduling reconnect");
|
|
228
|
+
|
|
229
|
+
setTimeoutFn(() => {
|
|
230
|
+
void setupConnection().catch((error) => {
|
|
231
|
+
log.error({ err: error }, "reconnect attempt failed");
|
|
232
|
+
});
|
|
233
|
+
}, delay);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const cleanup = async () => {
|
|
237
|
+
try {
|
|
238
|
+
if (state.channel) {
|
|
239
|
+
await state.channel.close();
|
|
240
|
+
}
|
|
241
|
+
if (state.connection) {
|
|
242
|
+
await state.connection.close();
|
|
243
|
+
}
|
|
244
|
+
} catch (error) {
|
|
245
|
+
log.error({ err: error }, "error during cleanup");
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
connect: setupConnection,
|
|
251
|
+
getPublishers: () => state.publishers,
|
|
252
|
+
isConnected: () => state.connection !== null && state.channel !== null,
|
|
253
|
+
cleanup,
|
|
254
|
+
onPublishersChanged: (callback: () => void) => {
|
|
255
|
+
publishersChangedCallback = callback;
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// ============================================================================
|
|
261
|
+
// Main Entry Point
|
|
262
|
+
// ============================================================================
|
|
263
|
+
|
|
264
|
+
export const startRabbitMQConnections = async (queues: RabbitMQQueue[]) => {
|
|
265
|
+
const log = logger("rabbitmq");
|
|
266
|
+
const managers = queues.map((queue) => createRabbitMQConnectionManager(queue));
|
|
267
|
+
|
|
268
|
+
// Cached publisher map with dirty flag for optimization
|
|
269
|
+
let cachedPublisherMap: Record<string, RabbitMQPublisher> = {};
|
|
270
|
+
let isPublisherMapDirty = true;
|
|
271
|
+
|
|
272
|
+
const markDirty = () => {
|
|
273
|
+
isPublisherMapDirty = true;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// Register change callbacks for each manager
|
|
277
|
+
for (const manager of managers) {
|
|
278
|
+
manager.onPublishersChanged(markDirty);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Start connection attempts for all queues (non-blocking)
|
|
282
|
+
// This allows the app to start even if RabbitMQ isn't immediately available
|
|
283
|
+
// Failed connections will automatically retry in the background
|
|
284
|
+
for (const manager of managers) {
|
|
285
|
+
manager.connect().catch((error) => {
|
|
286
|
+
log.warn({ err: error }, "initial connection failed, will retry");
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Get publisher map - rebuilds only when dirty
|
|
291
|
+
const getPublisherMap = () => {
|
|
292
|
+
if (isPublisherMapDirty) {
|
|
293
|
+
cachedPublisherMap = managers.reduce<Record<string, RabbitMQPublisher>>(
|
|
294
|
+
(acc, manager) => ({ ...acc, ...manager.getPublishers() }),
|
|
295
|
+
{},
|
|
296
|
+
);
|
|
297
|
+
isPublisherMapDirty = false;
|
|
298
|
+
}
|
|
299
|
+
return cachedPublisherMap;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const sendMessage = (publisherName: string, message: string | object, _key?: string) => {
|
|
303
|
+
const publisherMap = getPublisherMap();
|
|
304
|
+
const publisher = publisherMap[publisherName];
|
|
305
|
+
|
|
306
|
+
if (!publisher) {
|
|
307
|
+
log.error({ publisher: publisherName }, "publisher not found");
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const result = publisher.send(message);
|
|
312
|
+
|
|
313
|
+
if (!result) {
|
|
314
|
+
log.error({ publisher: publisherName }, "failed to publish message");
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return true;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const cleanup = async () => {
|
|
322
|
+
await Promise.all(managers.map((manager) => manager.cleanup()));
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
return {
|
|
326
|
+
managers,
|
|
327
|
+
publisherMap: getPublisherMap,
|
|
328
|
+
sendMessage,
|
|
329
|
+
cleanup,
|
|
330
|
+
};
|
|
331
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { RemoteRESTConfig } from "../config";
|
|
2
|
+
import type { RemoteRESTResolved } from "./types";
|
|
3
|
+
|
|
4
|
+
import { parseRemoteOpenAPI } from "./parse";
|
|
5
|
+
import { transformRemoteREST } from "./transform";
|
|
6
|
+
import { logger } from "../logging";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolve a single remote REST API: parse spec → transform → produce RemoteRESTResolved
|
|
10
|
+
*/
|
|
11
|
+
export const resolveRemoteREST = async (config: RemoteRESTConfig): Promise<RemoteRESTResolved> => {
|
|
12
|
+
const spec = await parseRemoteOpenAPI(config);
|
|
13
|
+
return transformRemoteREST(spec, config);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resolve all enabled remote REST APIs in parallel.
|
|
18
|
+
* Returns an array of successfully resolved APIs; logs warnings for failures.
|
|
19
|
+
*/
|
|
20
|
+
export const resolveRemoteRESTApis = async (
|
|
21
|
+
configs: RemoteRESTConfig[],
|
|
22
|
+
): Promise<RemoteRESTResolved[]> => {
|
|
23
|
+
const enabled = configs.filter((c) => c.enabled !== false);
|
|
24
|
+
|
|
25
|
+
if (enabled.length === 0) return [];
|
|
26
|
+
|
|
27
|
+
const results = await Promise.allSettled(enabled.map((config) => resolveRemoteREST(config)));
|
|
28
|
+
|
|
29
|
+
const resolved: RemoteRESTResolved[] = [];
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < results.length; i++) {
|
|
32
|
+
const result = results[i];
|
|
33
|
+
if (result.status === "fulfilled") {
|
|
34
|
+
resolved.push(result.value);
|
|
35
|
+
} else {
|
|
36
|
+
logger("remote-rest").warn(
|
|
37
|
+
{ api: enabled[i].name, err: result.reason },
|
|
38
|
+
"failed to resolve remote REST API",
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return resolved;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type { RemoteRESTResolved } from "./types";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { RemoteRESTConfig } from "../config";
|
|
2
|
+
import type { OpenAPIV3_1 } from "openapi-types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse an OpenAPI spec from a remote URL or local file path.
|
|
6
|
+
* Supports both JSON and YAML formats.
|
|
7
|
+
*/
|
|
8
|
+
export const parseRemoteOpenAPI = async (
|
|
9
|
+
config: RemoteRESTConfig,
|
|
10
|
+
): Promise<OpenAPIV3_1.Document> => {
|
|
11
|
+
let rawText: string;
|
|
12
|
+
|
|
13
|
+
if (config.specUrl) {
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
const timeoutId = setTimeout(() => controller.abort(), config.timeout ?? 10000);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const response = await fetch(config.specUrl, {
|
|
19
|
+
headers: config.headers,
|
|
20
|
+
signal: controller.signal,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw new Error(`Remote REST "${config.name}" spec fetch failed: HTTP ${response.status}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
rawText = await response.text();
|
|
28
|
+
} finally {
|
|
29
|
+
clearTimeout(timeoutId);
|
|
30
|
+
}
|
|
31
|
+
} else if (config.specPath) {
|
|
32
|
+
const file = Bun.file(config.specPath);
|
|
33
|
+
const exists = await file.exists();
|
|
34
|
+
|
|
35
|
+
if (!exists) {
|
|
36
|
+
throw new Error(`Remote REST "${config.name}" spec file not found: ${config.specPath}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
rawText = await file.text();
|
|
40
|
+
} else {
|
|
41
|
+
throw new Error(`Remote REST "${config.name}" requires either specUrl or specPath`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return parseSpecText(rawText, config.name);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Parse raw text as JSON or YAML OpenAPI spec
|
|
49
|
+
*/
|
|
50
|
+
const parseSpecText = (text: string, name: string): OpenAPIV3_1.Document => {
|
|
51
|
+
const trimmed = text.trimStart();
|
|
52
|
+
|
|
53
|
+
// Try JSON first (starts with { or [)
|
|
54
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(text) as OpenAPIV3_1.Document;
|
|
57
|
+
} catch {
|
|
58
|
+
throw new Error(`Remote REST "${name}" spec is not valid JSON`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Otherwise, parse as YAML using Bun's built-in YAML parser
|
|
63
|
+
try {
|
|
64
|
+
return Bun.YAML.parse(text) as OpenAPIV3_1.Document;
|
|
65
|
+
} catch {
|
|
66
|
+
throw new Error(`Remote REST "${name}" spec is not valid YAML`);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { RemoteRESTResolved, RemoteRESTRoute } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Build headers for the remote request by merging:
|
|
5
|
+
* 1. Static headers from configuration
|
|
6
|
+
* 2. Forwarded headers from the client request
|
|
7
|
+
*/
|
|
8
|
+
const buildHeaders = (
|
|
9
|
+
resolved: RemoteRESTResolved,
|
|
10
|
+
clientRequest: Request,
|
|
11
|
+
): Record<string, string> => {
|
|
12
|
+
const headers: Record<string, string> = {
|
|
13
|
+
...(resolved.config.headers ?? {}),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
if (resolved.config.forwardHeaders?.length) {
|
|
17
|
+
for (const headerName of resolved.config.forwardHeaders) {
|
|
18
|
+
const value = clientRequest.headers.get(headerName);
|
|
19
|
+
if (value) {
|
|
20
|
+
headers[headerName] = value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return headers;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Convert an OpenAPI path template to a URL by substituting path parameters.
|
|
30
|
+
* e.g. /users/{id} with { id: "123" } → /users/123
|
|
31
|
+
*/
|
|
32
|
+
const substitutePathParams = (path: string, params: Record<string, string>): string =>
|
|
33
|
+
path.replace(/\{([^}]+)\}/g, (_, key: string) => {
|
|
34
|
+
const value = params[key];
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
throw new Error(`Missing path parameter: ${key}`);
|
|
37
|
+
}
|
|
38
|
+
return encodeURIComponent(value);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Proxy a request to a remote REST API endpoint.
|
|
43
|
+
*/
|
|
44
|
+
export const proxyRemoteRESTRequest = async (
|
|
45
|
+
route: RemoteRESTRoute,
|
|
46
|
+
resolved: RemoteRESTResolved,
|
|
47
|
+
clientRequest: Request,
|
|
48
|
+
pathParams: Record<string, string>,
|
|
49
|
+
queryString: string,
|
|
50
|
+
): Promise<Response> => {
|
|
51
|
+
const targetPath = substitutePathParams(route.originalPath, pathParams);
|
|
52
|
+
const targetUrl = `${resolved.baseUrl}${targetPath}${queryString ? `?${queryString}` : ""}`;
|
|
53
|
+
|
|
54
|
+
const headers = buildHeaders(resolved, clientRequest);
|
|
55
|
+
|
|
56
|
+
// Forward content-type from the client request if present
|
|
57
|
+
const contentType = clientRequest.headers.get("content-type");
|
|
58
|
+
if (contentType) {
|
|
59
|
+
headers["content-type"] = contentType;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
const timeoutId = setTimeout(() => controller.abort(), resolved.config.timeout ?? 10000);
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const fetchInit: RequestInit = {
|
|
67
|
+
method: route.method.toUpperCase(),
|
|
68
|
+
headers,
|
|
69
|
+
signal: controller.signal,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Forward body for methods that support it
|
|
73
|
+
if (clientRequest.body && ["post", "put", "patch"].includes(route.method)) {
|
|
74
|
+
fetchInit.body = clientRequest.body;
|
|
75
|
+
// @ts-expect-error: Bun supports duplex for streaming
|
|
76
|
+
fetchInit.duplex = "half";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const response = await fetch(targetUrl, fetchInit);
|
|
80
|
+
|
|
81
|
+
// Return the response with the same status and body
|
|
82
|
+
return new Response(response.body, {
|
|
83
|
+
status: response.status,
|
|
84
|
+
statusText: response.statusText,
|
|
85
|
+
headers: {
|
|
86
|
+
"content-type": response.headers.get("content-type") ?? "application/json",
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
} finally {
|
|
90
|
+
clearTimeout(timeoutId);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { RemoteRESTConfig } from "../config";
|
|
2
|
+
import type { OpenAPIV3_1 } from "openapi-types";
|
|
3
|
+
import type { RemoteRESTResolved, RemoteRESTRoute } from "./types";
|
|
4
|
+
|
|
5
|
+
const HTTP_METHODS = ["get", "post", "put", "delete", "patch", "head", "options"] as const;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the base URL for proxying from config or spec
|
|
9
|
+
*/
|
|
10
|
+
const resolveBaseUrl = (config: RemoteRESTConfig, spec: OpenAPIV3_1.Document): string => {
|
|
11
|
+
if (config.url) return config.url.replace(/\/$/, "");
|
|
12
|
+
|
|
13
|
+
const serverUrl = spec.servers?.[0]?.url;
|
|
14
|
+
if (serverUrl) return serverUrl.replace(/\/$/, "");
|
|
15
|
+
|
|
16
|
+
throw new Error(
|
|
17
|
+
`Remote REST "${config.name}" requires a base URL: set "url" in config or ensure the spec has a "servers" entry`,
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Prefix all $ref strings in an object tree: #/components/schemas/Foo becomes #/components/schemas/{prefix}_Foo
|
|
23
|
+
*/
|
|
24
|
+
const prefixRefs = (obj: unknown, prefix: string): unknown => {
|
|
25
|
+
if (obj === null || obj === undefined) return obj;
|
|
26
|
+
if (typeof obj === "string") return obj;
|
|
27
|
+
if (Array.isArray(obj)) return obj.map((item) => prefixRefs(item, prefix));
|
|
28
|
+
|
|
29
|
+
if (typeof obj === "object") {
|
|
30
|
+
const result: Record<string, unknown> = {};
|
|
31
|
+
for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {
|
|
32
|
+
if (
|
|
33
|
+
key === "$ref" &&
|
|
34
|
+
typeof value === "string" &&
|
|
35
|
+
value.startsWith("#/components/schemas/")
|
|
36
|
+
) {
|
|
37
|
+
const schemaName = value.slice("#/components/schemas/".length);
|
|
38
|
+
result[key] = `#/components/schemas/${prefix}_${schemaName}`;
|
|
39
|
+
} else {
|
|
40
|
+
result[key] = prefixRefs(value, prefix);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return obj;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Transform a parsed OpenAPI spec into a RemoteRESTResolved with prefixed paths and schemas
|
|
51
|
+
*/
|
|
52
|
+
export const transformRemoteREST = (
|
|
53
|
+
spec: OpenAPIV3_1.Document,
|
|
54
|
+
config: RemoteRESTConfig,
|
|
55
|
+
): RemoteRESTResolved => {
|
|
56
|
+
const prefix = config.prefix ?? config.name;
|
|
57
|
+
const baseUrl = resolveBaseUrl(config, spec);
|
|
58
|
+
|
|
59
|
+
const routes: RemoteRESTRoute[] = [];
|
|
60
|
+
const openApiPaths: Record<string, OpenAPIV3_1.PathItemObject> = {};
|
|
61
|
+
const openApiSchemas: Record<string, OpenAPIV3_1.SchemaObject> = {};
|
|
62
|
+
|
|
63
|
+
// Extract and prefix paths
|
|
64
|
+
if (spec.paths) {
|
|
65
|
+
for (const [path, pathItem] of Object.entries(spec.paths)) {
|
|
66
|
+
if (!pathItem) continue;
|
|
67
|
+
|
|
68
|
+
const prefixedPath = `/${prefix}${path}`;
|
|
69
|
+
const prefixedPathItem: OpenAPIV3_1.PathItemObject = {};
|
|
70
|
+
|
|
71
|
+
for (const method of HTTP_METHODS) {
|
|
72
|
+
const operation = (pathItem as Record<string, unknown>)[method] as
|
|
73
|
+
| OpenAPIV3_1.OperationObject
|
|
74
|
+
| undefined;
|
|
75
|
+
if (!operation) continue;
|
|
76
|
+
|
|
77
|
+
routes.push({
|
|
78
|
+
method,
|
|
79
|
+
originalPath: path,
|
|
80
|
+
prefixedPath,
|
|
81
|
+
operationId: operation.operationId,
|
|
82
|
+
description: operation.summary ?? operation.description,
|
|
83
|
+
tags: operation.tags,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Prefix $refs in the operation and add remote API tag
|
|
87
|
+
const prefixedOperation = prefixRefs(operation, prefix) as OpenAPIV3_1.OperationObject;
|
|
88
|
+
prefixedOperation.tags = [prefix];
|
|
89
|
+
|
|
90
|
+
(prefixedPathItem as Record<string, unknown>)[method] = prefixedOperation;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Copy shared parameters (path-level) if they exist
|
|
94
|
+
if (pathItem.parameters) {
|
|
95
|
+
prefixedPathItem.parameters = prefixRefs(
|
|
96
|
+
pathItem.parameters,
|
|
97
|
+
prefix,
|
|
98
|
+
) as OpenAPIV3_1.ParameterObject[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
openApiPaths[prefixedPath] = prefixedPathItem;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Extract and prefix component schemas
|
|
106
|
+
if (spec.components?.schemas) {
|
|
107
|
+
for (const [name, schema] of Object.entries(spec.components.schemas)) {
|
|
108
|
+
if (!schema) continue;
|
|
109
|
+
openApiSchemas[`${prefix}_${name}`] = prefixRefs(schema, prefix) as OpenAPIV3_1.SchemaObject;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
config,
|
|
115
|
+
prefix,
|
|
116
|
+
baseUrl,
|
|
117
|
+
routes,
|
|
118
|
+
openApiPaths,
|
|
119
|
+
openApiSchemas,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RemoteRESTConfig } from "../config";
|
|
2
|
+
import type { OpenAPIV3_1 } from "openapi-types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A single route extracted from a remote OpenAPI spec
|
|
6
|
+
*/
|
|
7
|
+
export type RemoteRESTRoute = {
|
|
8
|
+
/** HTTP method (lowercase) */
|
|
9
|
+
method: string;
|
|
10
|
+
/** Original path from the spec (e.g. /users/{id}) */
|
|
11
|
+
originalPath: string;
|
|
12
|
+
/** Path with prefix (e.g. /payments/users/{id}) */
|
|
13
|
+
prefixedPath: string;
|
|
14
|
+
/** operationId from the spec, if present */
|
|
15
|
+
operationId?: string;
|
|
16
|
+
/** Human-readable description */
|
|
17
|
+
description?: string;
|
|
18
|
+
/** Tags from the spec */
|
|
19
|
+
tags?: string[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Fully resolved remote REST API after spec parsing and transformation
|
|
24
|
+
*/
|
|
25
|
+
export type RemoteRESTResolved = {
|
|
26
|
+
/** The original configuration */
|
|
27
|
+
config: RemoteRESTConfig;
|
|
28
|
+
/** Effective prefix (subpath under /rest) */
|
|
29
|
+
prefix: string;
|
|
30
|
+
/** Base URL for proxying requests */
|
|
31
|
+
baseUrl: string;
|
|
32
|
+
/** All routes extracted from the spec */
|
|
33
|
+
routes: RemoteRESTRoute[];
|
|
34
|
+
/** Prefixed OpenAPI paths for merging into the unified spec */
|
|
35
|
+
openApiPaths: Record<string, OpenAPIV3_1.PathItemObject>;
|
|
36
|
+
/** Prefixed component schemas for merging */
|
|
37
|
+
openApiSchemas: Record<string, OpenAPIV3_1.SchemaObject>;
|
|
38
|
+
};
|