@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,99 @@
|
|
|
1
|
+
import { SQL } from "bun";
|
|
2
|
+
|
|
3
|
+
import type { BunSQLConnectionOptions } from "../../../config";
|
|
4
|
+
import type { VariableDefinition } from "../../../analyzeQuery/types";
|
|
5
|
+
import type { Database } from "../../../types/configuration";
|
|
6
|
+
import type { ProcedureResolver } from "../../../types/db";
|
|
7
|
+
|
|
8
|
+
import { databasesConnections } from "../../../singletons/databases";
|
|
9
|
+
|
|
10
|
+
export const getPool = async (db: Database) => {
|
|
11
|
+
const opts = db.connectionOptions as BunSQLConnectionOptions | undefined;
|
|
12
|
+
const pool = new SQL({
|
|
13
|
+
host: db.connection.host,
|
|
14
|
+
port: db.connection.port,
|
|
15
|
+
user: db.connection.user,
|
|
16
|
+
password: db.connection.password,
|
|
17
|
+
database: db.connection.database,
|
|
18
|
+
max: opts?.max ?? 5,
|
|
19
|
+
idleTimeout: opts?.idleTimeout ?? 30,
|
|
20
|
+
connectionTimeout: opts?.connectionTimeout,
|
|
21
|
+
maxLifetime: opts?.maxLifetime,
|
|
22
|
+
tls: opts?.tls,
|
|
23
|
+
prepare: opts?.prepare,
|
|
24
|
+
bigint: opts?.bigint,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await pool.connect(); // Connect to the database
|
|
28
|
+
|
|
29
|
+
return pool;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const getPoolSingleton = async (db: Database) => databasesConnections[db.name] as SQL;
|
|
33
|
+
|
|
34
|
+
export const executeQueryFactory =
|
|
35
|
+
(singleQuery = false) =>
|
|
36
|
+
async <T>(
|
|
37
|
+
query: string,
|
|
38
|
+
db: Database,
|
|
39
|
+
variablesDefinition: VariableDefinition[],
|
|
40
|
+
values: Record<string, unknown> = {},
|
|
41
|
+
) => {
|
|
42
|
+
const pool = singleQuery ? await getPool(db) : await getPoolSingleton(db);
|
|
43
|
+
|
|
44
|
+
const result = await pool.unsafe<T>(
|
|
45
|
+
query,
|
|
46
|
+
variablesDefinition.map((v) => values[v.name]),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (singleQuery) {
|
|
50
|
+
await pool.close();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const executeQuery = executeQueryFactory();
|
|
57
|
+
export const executeQuerySingle = executeQueryFactory(true);
|
|
58
|
+
|
|
59
|
+
export const executeQueryJSONFactory =
|
|
60
|
+
(singleQuery = false) =>
|
|
61
|
+
async <T>(
|
|
62
|
+
query: string,
|
|
63
|
+
db: Database,
|
|
64
|
+
variablesDefinition: VariableDefinition[] = [],
|
|
65
|
+
values: Record<string, unknown> = {},
|
|
66
|
+
) => {
|
|
67
|
+
const result = await (singleQuery ? executeQuerySingle : executeQuery)<[{ json_result: T }]>(
|
|
68
|
+
query,
|
|
69
|
+
db,
|
|
70
|
+
variablesDefinition,
|
|
71
|
+
values,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return result[0].json_result as T;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const executeQueryJSON = executeQueryJSONFactory();
|
|
78
|
+
export const executeQueryJSONSingle = executeQueryJSONFactory(true);
|
|
79
|
+
|
|
80
|
+
export const callStoredProcedure = async (
|
|
81
|
+
sp: ProcedureResolver,
|
|
82
|
+
variablesDefinition: VariableDefinition[],
|
|
83
|
+
variables: Record<string, unknown>,
|
|
84
|
+
) => {
|
|
85
|
+
try {
|
|
86
|
+
const data = await executeQuery(
|
|
87
|
+
`SELECT * FROM ${sp.dottedName}(${Object.keys(variables)
|
|
88
|
+
.map((_, i) => `$${i + 1}`)
|
|
89
|
+
.join(", ")});`,
|
|
90
|
+
sp.db!,
|
|
91
|
+
variablesDefinition,
|
|
92
|
+
variables,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return data;
|
|
96
|
+
} catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { format as sqlFormatter } from "sql-formatter";
|
|
2
|
+
|
|
3
|
+
import type { AnalysisResult } from "../../../analyzeQuery/types";
|
|
4
|
+
import type { MergedEntities } from "../../../configuration/getSchemas/mergeEntities";
|
|
5
|
+
|
|
6
|
+
import { generateSQL } from "../../core/query-builder";
|
|
7
|
+
|
|
8
|
+
export const format = (sql: string) =>
|
|
9
|
+
sqlFormatter(sql, {
|
|
10
|
+
language: "postgresql",
|
|
11
|
+
paramTypes: { custom: [{ regex: String.raw`\$\d+` }] },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const genSql = (
|
|
15
|
+
entitites: MergedEntities,
|
|
16
|
+
query: AnalysisResult,
|
|
17
|
+
variables: Record<string, unknown> = {},
|
|
18
|
+
hash = false,
|
|
19
|
+
) => {
|
|
20
|
+
const [[, sql]] = generateSQL(entitites, query, variables, hash);
|
|
21
|
+
|
|
22
|
+
return format(sql);
|
|
23
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { Database } from "../../../types/configuration";
|
|
2
|
+
|
|
3
|
+
import { DatabaseStructureZod } from "../../../types/zod/db";
|
|
4
|
+
import { executeQueryJSONSingle } from "./connection";
|
|
5
|
+
|
|
6
|
+
export const getDatabaseStructure = async (db: Database) => {
|
|
7
|
+
const res = await executeQueryJSONSingle(
|
|
8
|
+
`
|
|
9
|
+
WITH tables_data AS (
|
|
10
|
+
SELECT json_agg(
|
|
11
|
+
json_build_object(
|
|
12
|
+
'schema', t.table_schema,
|
|
13
|
+
'name', t.table_name,
|
|
14
|
+
'entityType', CASE WHEN t.table_type = 'BASE TABLE' THEN 'table' ELSE 'view' END,
|
|
15
|
+
'tableDescription', t.table_description,
|
|
16
|
+
'columns', COALESCE(col.columns, '[]'::json),
|
|
17
|
+
'foreignKeys', COALESCE(fk.fk_agg, '[]'::json)
|
|
18
|
+
)
|
|
19
|
+
) AS tables
|
|
20
|
+
FROM (
|
|
21
|
+
SELECT DISTINCT
|
|
22
|
+
ist.table_schema,
|
|
23
|
+
ist.table_name,
|
|
24
|
+
ist.table_type,
|
|
25
|
+
obj_description(c.oid) AS table_description
|
|
26
|
+
FROM information_schema.tables ist
|
|
27
|
+
LEFT JOIN pg_class c ON c.relname = ist.table_name
|
|
28
|
+
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace AND n.nspname = ist.table_schema
|
|
29
|
+
WHERE ist.table_type IN ('BASE TABLE', 'VIEW')
|
|
30
|
+
AND ist.table_schema NOT IN ('pg_catalog', 'information_schema')
|
|
31
|
+
) t
|
|
32
|
+
LEFT JOIN LATERAL (
|
|
33
|
+
SELECT json_agg(
|
|
34
|
+
json_build_object(
|
|
35
|
+
'name', isc.column_name,
|
|
36
|
+
'dataType', isc.data_type,
|
|
37
|
+
'isNullable', isc.is_nullable = 'YES',
|
|
38
|
+
'description', col_desc.description
|
|
39
|
+
)
|
|
40
|
+
) AS columns
|
|
41
|
+
FROM information_schema.columns isc
|
|
42
|
+
LEFT JOIN LATERAL (
|
|
43
|
+
SELECT col_description(c.oid, a.attnum) AS description
|
|
44
|
+
FROM pg_class c
|
|
45
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
46
|
+
JOIN pg_attribute a ON a.attrelid = c.oid
|
|
47
|
+
WHERE n.nspname = isc.table_schema
|
|
48
|
+
AND c.relname = isc.table_name
|
|
49
|
+
AND a.attname = isc.column_name
|
|
50
|
+
AND a.attnum > 0
|
|
51
|
+
) col_desc ON true
|
|
52
|
+
WHERE isc.table_schema = t.table_schema
|
|
53
|
+
AND isc.table_name = t.table_name
|
|
54
|
+
) col ON true
|
|
55
|
+
LEFT JOIN LATERAL (
|
|
56
|
+
SELECT json_agg(
|
|
57
|
+
json_build_object(
|
|
58
|
+
'schema', fk_sub.referenced_table_schema,
|
|
59
|
+
'name', fk_sub.referenced_table_name,
|
|
60
|
+
'columns', fk_sub.columns_arr
|
|
61
|
+
)
|
|
62
|
+
) AS fk_agg
|
|
63
|
+
FROM (
|
|
64
|
+
SELECT
|
|
65
|
+
kcu.constraint_name AS fk_name,
|
|
66
|
+
kcu.table_schema,
|
|
67
|
+
kcu.table_name,
|
|
68
|
+
ccu.table_schema AS referenced_table_schema,
|
|
69
|
+
ccu.table_name AS referenced_table_name,
|
|
70
|
+
json_agg(
|
|
71
|
+
json_build_object(
|
|
72
|
+
'source', kcu.column_name,
|
|
73
|
+
'target', ccu.column_name
|
|
74
|
+
)
|
|
75
|
+
ORDER BY kcu.ordinal_position
|
|
76
|
+
) AS columns_arr
|
|
77
|
+
FROM information_schema.table_constraints tc
|
|
78
|
+
JOIN information_schema.key_column_usage kcu
|
|
79
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
80
|
+
AND tc.table_schema = kcu.table_schema
|
|
81
|
+
JOIN information_schema.constraint_column_usage ccu
|
|
82
|
+
ON tc.constraint_name = ccu.constraint_name
|
|
83
|
+
AND tc.table_schema = ccu.table_schema
|
|
84
|
+
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
85
|
+
AND kcu.table_schema = t.table_schema
|
|
86
|
+
AND kcu.table_name = t.table_name
|
|
87
|
+
GROUP BY kcu.constraint_name, kcu.table_schema, kcu.table_name,
|
|
88
|
+
ccu.table_schema, ccu.table_name
|
|
89
|
+
) fk_sub
|
|
90
|
+
) fk ON true
|
|
91
|
+
),
|
|
92
|
+
stored_procedures_data AS (
|
|
93
|
+
SELECT COALESCE(
|
|
94
|
+
json_agg(
|
|
95
|
+
json_build_object(
|
|
96
|
+
'schema', n.nspname,
|
|
97
|
+
'name', p.proname,
|
|
98
|
+
'signature', pg_get_function_identity_arguments(p.oid),
|
|
99
|
+
'type', CASE p.prokind
|
|
100
|
+
WHEN 'f' THEN 'function'
|
|
101
|
+
WHEN 'p' THEN 'procedure'
|
|
102
|
+
WHEN 'a' THEN 'aggregate'
|
|
103
|
+
WHEN 'w' THEN 'window'
|
|
104
|
+
ELSE 'unknown'
|
|
105
|
+
END,
|
|
106
|
+
'parameters', COALESCE(params.param_array, '[]'::json)
|
|
107
|
+
)
|
|
108
|
+
),
|
|
109
|
+
'[]'::json
|
|
110
|
+
) AS stored_procedures
|
|
111
|
+
FROM pg_proc p
|
|
112
|
+
JOIN pg_namespace n ON p.pronamespace = n.oid
|
|
113
|
+
LEFT JOIN LATERAL (
|
|
114
|
+
SELECT json_agg(
|
|
115
|
+
json_build_object(
|
|
116
|
+
'name', COALESCE(param.parameter_name, 'arg' || param.idx::text),
|
|
117
|
+
'dataType', param.data_type,
|
|
118
|
+
'maxLength', 0,
|
|
119
|
+
'precision', 0,
|
|
120
|
+
'scale', 0
|
|
121
|
+
)
|
|
122
|
+
ORDER BY param.idx
|
|
123
|
+
) AS param_array
|
|
124
|
+
FROM (
|
|
125
|
+
SELECT
|
|
126
|
+
row_number() OVER () AS idx,
|
|
127
|
+
arg_name AS parameter_name,
|
|
128
|
+
arg_type AS data_type
|
|
129
|
+
FROM (
|
|
130
|
+
SELECT
|
|
131
|
+
unnest(COALESCE(p.proargnames, ARRAY[]::text[])) AS arg_name,
|
|
132
|
+
unnest(string_to_array(pg_get_function_identity_arguments(p.oid), ', ')) AS arg_type
|
|
133
|
+
) args
|
|
134
|
+
WHERE arg_type IS NOT NULL AND arg_type != ''
|
|
135
|
+
) param
|
|
136
|
+
) params ON true
|
|
137
|
+
WHERE p.prokind IN ('f', 'p')
|
|
138
|
+
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
|
|
139
|
+
)
|
|
140
|
+
SELECT json_build_object(
|
|
141
|
+
'tables', COALESCE((SELECT tables FROM tables_data), '[]'::json),
|
|
142
|
+
'storedProcedures', COALESCE((SELECT stored_procedures FROM stored_procedures_data), '[]'::json)
|
|
143
|
+
) as json_result;
|
|
144
|
+
`,
|
|
145
|
+
db,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return DatabaseStructureZod.parse(res);
|
|
149
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Database } from "../../../types/configuration";
|
|
2
|
+
import type { View } from "../../../types/db";
|
|
3
|
+
|
|
4
|
+
import { executeQueryJSONSingle } from "./connection";
|
|
5
|
+
|
|
6
|
+
export const getViewsFromDB = async (db: Database) =>
|
|
7
|
+
executeQueryJSONSingle<View[]>(
|
|
8
|
+
`
|
|
9
|
+
SELECT json_agg(
|
|
10
|
+
json_build_object(
|
|
11
|
+
'schema', lower(schemaname),
|
|
12
|
+
'name', lower(viewname),
|
|
13
|
+
'definition', view_definition
|
|
14
|
+
)
|
|
15
|
+
)
|
|
16
|
+
FROM pg_views
|
|
17
|
+
WHERE schemaname NOT IN ('pg_catalog', 'information_schema');
|
|
18
|
+
`,
|
|
19
|
+
db,
|
|
20
|
+
);
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
OperationAnalysis,
|
|
3
|
+
SelectionAnalysis,
|
|
4
|
+
VariableDefinition,
|
|
5
|
+
} from "../../../../analyzeQuery/types";
|
|
6
|
+
import type { MergedEntities } from "../../../../configuration/getSchemas/mergeEntities";
|
|
7
|
+
import type { GroupByInfo } from "../../../common";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
buildOrderByClausePG,
|
|
11
|
+
buildPaginationClausePG,
|
|
12
|
+
buildWhereClausePG,
|
|
13
|
+
extractAggregationInfo,
|
|
14
|
+
filterBasedOnDirective,
|
|
15
|
+
generateTableAlias,
|
|
16
|
+
isAggregationField,
|
|
17
|
+
isSingleQuery,
|
|
18
|
+
processFieldSelectionsPG,
|
|
19
|
+
} from "../../../common";
|
|
20
|
+
|
|
21
|
+
// Generate CTE for aggregations
|
|
22
|
+
const buildAggregationCTE = (
|
|
23
|
+
groupByInfo: GroupByInfo,
|
|
24
|
+
dottedQuotedName: string,
|
|
25
|
+
tableAlias: string,
|
|
26
|
+
whereClause: string,
|
|
27
|
+
): string => {
|
|
28
|
+
const { groupByFields, aggregations, cteAlias } = groupByInfo;
|
|
29
|
+
|
|
30
|
+
const selectClauses: string[] = [];
|
|
31
|
+
|
|
32
|
+
// Add group by fields
|
|
33
|
+
groupByFields.forEach((field) => {
|
|
34
|
+
selectClauses.push(`${tableAlias}."${field}"`);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Add aggregations
|
|
38
|
+
aggregations.forEach((agg) => {
|
|
39
|
+
if (agg.name === "count") {
|
|
40
|
+
selectClauses.push(`COUNT(*) AS ${agg.alias}`);
|
|
41
|
+
} else {
|
|
42
|
+
const func = agg.name.toUpperCase();
|
|
43
|
+
selectClauses.push(`${func}(${tableAlias}."${agg.fieldName}") AS ${agg.alias}`);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const groupByClause = `GROUP BY ${groupByFields.map((field) => `${tableAlias}."${field}"`).join(", ")}`;
|
|
48
|
+
|
|
49
|
+
return `${cteAlias} AS (
|
|
50
|
+
SELECT
|
|
51
|
+
${selectClauses.join(",\n ")}
|
|
52
|
+
FROM ${dottedQuotedName} ${tableAlias}
|
|
53
|
+
${whereClause}
|
|
54
|
+
${groupByClause}
|
|
55
|
+
)`;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Build the main query for grouped results
|
|
59
|
+
const buildGroupedQuery = (
|
|
60
|
+
entities: MergedEntities,
|
|
61
|
+
field: SelectionAnalysis,
|
|
62
|
+
groupByInfo: GroupByInfo,
|
|
63
|
+
dottedQuotedName: string,
|
|
64
|
+
tableAlias: string,
|
|
65
|
+
whereClause: string,
|
|
66
|
+
): string => {
|
|
67
|
+
const { groupByFields, aggregations, hasItems, keyResolved, hasKey, keys, cteAlias } =
|
|
68
|
+
groupByInfo;
|
|
69
|
+
|
|
70
|
+
const selectClauses: string[] = [];
|
|
71
|
+
|
|
72
|
+
if (hasKey) {
|
|
73
|
+
// Add key object with group by fields
|
|
74
|
+
const keyFields = keys
|
|
75
|
+
.map((key) => `'${key.alias || key.name}', ${cteAlias}."${key.name}"`)
|
|
76
|
+
.join(", ");
|
|
77
|
+
|
|
78
|
+
selectClauses.push(`'${keyResolved}', json_build_object(${keyFields})`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Add aggregation results
|
|
82
|
+
aggregations.forEach((agg) => {
|
|
83
|
+
if (agg.name === "count") {
|
|
84
|
+
selectClauses.push(`'${agg.nameResolved}', ${cteAlias}.${agg.alias}`);
|
|
85
|
+
} else {
|
|
86
|
+
selectClauses.push(
|
|
87
|
+
`'${agg.nameResolved}', json_build_object('${agg.fieldAlias}', COALESCE(${cteAlias}.${agg.alias}, null))`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Add items if requested
|
|
93
|
+
if (hasItems) {
|
|
94
|
+
const itemsSelection = field.selections?.find((sel) => sel.name === "items");
|
|
95
|
+
|
|
96
|
+
if (itemsSelection?.selections) {
|
|
97
|
+
const itemFields = itemsSelection.selections
|
|
98
|
+
.filter((sel) => !isAggregationField(sel.name) && sel.name !== "items")
|
|
99
|
+
.map((sel) => `'${sel.alias || sel.name}', ${tableAlias}."${sel.name}"`)
|
|
100
|
+
.join(", ");
|
|
101
|
+
|
|
102
|
+
if (itemFields) {
|
|
103
|
+
const joinConditions = groupByFields.map(
|
|
104
|
+
(field) => `${tableAlias}."${field}" = ${cteAlias}."${field}"`,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const whereConditions = whereClause
|
|
108
|
+
? `${whereClause} AND ${joinConditions.join(" AND ")}`
|
|
109
|
+
: `WHERE ${joinConditions.join(" AND ")}`;
|
|
110
|
+
|
|
111
|
+
selectClauses.push(`'${itemsSelection.alias || itemsSelection.name}', COALESCE((
|
|
112
|
+
SELECT json_agg(json_build_object(${itemFields}))
|
|
113
|
+
FROM ${dottedQuotedName} ${tableAlias}
|
|
114
|
+
${whereConditions}
|
|
115
|
+
), '[]'::json)`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const orderByClause = buildOrderByClausePG(entities, field, cteAlias);
|
|
121
|
+
|
|
122
|
+
return `SELECT json_agg(json_build_object(${selectClauses.join(",\n ")}) ${orderByClause})
|
|
123
|
+
FROM ${cteAlias}`;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const generateSQL = (
|
|
127
|
+
entities: MergedEntities,
|
|
128
|
+
operation: OperationAnalysis,
|
|
129
|
+
variables: Record<string, unknown> = {},
|
|
130
|
+
forHashMethod: boolean = false,
|
|
131
|
+
): string => {
|
|
132
|
+
if (forHashMethod) {
|
|
133
|
+
return `SELECT MD5((${buildSQLForField(entities, operation.variables ?? [], variables, operation.fields[0], null, null, 1, {})})::text) AS "ResultHash"`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const variablesWithDefault = {
|
|
137
|
+
...operation.variables?.reduce<Record<string, unknown>>((acc, variable) => {
|
|
138
|
+
if (variable.defaultValue !== undefined) {
|
|
139
|
+
acc[variable.name] = variable.defaultValue;
|
|
140
|
+
}
|
|
141
|
+
return acc;
|
|
142
|
+
}, {}),
|
|
143
|
+
...variables,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Check if any field requires CTEs (has groupBy)
|
|
147
|
+
const filteredFields = operation.fields?.filter((f) =>
|
|
148
|
+
filterBasedOnDirective(f, operation.variables ?? [], variablesWithDefault),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const ctes: string[] = [];
|
|
152
|
+
const fieldQueries: string[] = [];
|
|
153
|
+
|
|
154
|
+
filteredFields?.forEach((field, index) => {
|
|
155
|
+
const tableAlias = generateTableAlias(index + 1);
|
|
156
|
+
const groupByInfo = extractAggregationInfo(field, tableAlias);
|
|
157
|
+
|
|
158
|
+
if (groupByInfo) {
|
|
159
|
+
// This field requires a CTE
|
|
160
|
+
const { dottedQuotedName } = entities.queriesMap[field.name]!;
|
|
161
|
+
|
|
162
|
+
const whereClause = buildWhereClausePG(
|
|
163
|
+
entities,
|
|
164
|
+
operation.variables ?? [],
|
|
165
|
+
variablesWithDefault,
|
|
166
|
+
field,
|
|
167
|
+
tableAlias,
|
|
168
|
+
null,
|
|
169
|
+
null,
|
|
170
|
+
index + 1,
|
|
171
|
+
{},
|
|
172
|
+
true,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const cte = buildAggregationCTE(groupByInfo, dottedQuotedName, tableAlias, whereClause);
|
|
176
|
+
ctes.push(cte);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const fieldSQL = buildSQLForField(
|
|
180
|
+
entities,
|
|
181
|
+
operation.variables ?? [],
|
|
182
|
+
variablesWithDefault,
|
|
183
|
+
field,
|
|
184
|
+
null,
|
|
185
|
+
null,
|
|
186
|
+
index + 1,
|
|
187
|
+
{},
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
fieldQueries.push(`'${field.alias || field.name}', ${fieldSQL}`);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const cteClause = ctes.length > 0 ? `WITH\n${ctes.join(",\n")}\n` : "";
|
|
194
|
+
|
|
195
|
+
return `
|
|
196
|
+
${cteClause}SELECT json_build_object(
|
|
197
|
+
${fieldQueries.join(",\n")}
|
|
198
|
+
) as json_result`;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export const buildSQLForField = (
|
|
202
|
+
entities: MergedEntities,
|
|
203
|
+
variablesDefinition: VariableDefinition[],
|
|
204
|
+
variables: Record<string, unknown> = {},
|
|
205
|
+
field: SelectionAnalysis,
|
|
206
|
+
parentTableName: string | null,
|
|
207
|
+
parentTableAlias: string | null,
|
|
208
|
+
level: number,
|
|
209
|
+
aliasMap: { [alias: string]: string },
|
|
210
|
+
): string => {
|
|
211
|
+
const tableAlias = generateTableAlias(level);
|
|
212
|
+
|
|
213
|
+
const withoutArrayWrapper = isSingleQuery(field.name);
|
|
214
|
+
|
|
215
|
+
const foundTable = entities.queriesMap[field.name];
|
|
216
|
+
|
|
217
|
+
if (!foundTable) {
|
|
218
|
+
throw new Error(`Table not found for field: ${field.name}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const { dottedQuotedName, resolverName } = foundTable;
|
|
222
|
+
|
|
223
|
+
aliasMap[tableAlias] = resolverName;
|
|
224
|
+
|
|
225
|
+
const whereClause = buildWhereClausePG(
|
|
226
|
+
entities,
|
|
227
|
+
variablesDefinition,
|
|
228
|
+
variables,
|
|
229
|
+
field,
|
|
230
|
+
tableAlias,
|
|
231
|
+
parentTableName,
|
|
232
|
+
parentTableAlias,
|
|
233
|
+
level,
|
|
234
|
+
aliasMap,
|
|
235
|
+
true,
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
// Check if this is a GROUP BY query
|
|
239
|
+
const groupByInfo = extractAggregationInfo(field, tableAlias);
|
|
240
|
+
|
|
241
|
+
if (groupByInfo) {
|
|
242
|
+
// Handle GROUP BY aggregation query
|
|
243
|
+
const mainQuery = buildGroupedQuery(
|
|
244
|
+
entities,
|
|
245
|
+
field,
|
|
246
|
+
groupByInfo,
|
|
247
|
+
dottedQuotedName,
|
|
248
|
+
tableAlias,
|
|
249
|
+
whereClause,
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
return `COALESCE((${mainQuery}), '[]'::json)`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Original logic for non-aggregation queries
|
|
256
|
+
const selectList = processFieldSelectionsPG(
|
|
257
|
+
entities,
|
|
258
|
+
variablesDefinition,
|
|
259
|
+
variables,
|
|
260
|
+
field,
|
|
261
|
+
resolverName,
|
|
262
|
+
tableAlias,
|
|
263
|
+
level,
|
|
264
|
+
(sel, level) =>
|
|
265
|
+
buildSQLForField(
|
|
266
|
+
entities,
|
|
267
|
+
variablesDefinition,
|
|
268
|
+
variables,
|
|
269
|
+
sel,
|
|
270
|
+
resolverName,
|
|
271
|
+
tableAlias,
|
|
272
|
+
level,
|
|
273
|
+
aliasMap,
|
|
274
|
+
),
|
|
275
|
+
([name, selector]) => `'${name}', ${selector}`,
|
|
276
|
+
true,
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const fromClause = `FROM ${dottedQuotedName} ${tableAlias}`;
|
|
280
|
+
|
|
281
|
+
const orderByClause = buildOrderByClausePG(entities, field, tableAlias);
|
|
282
|
+
const paginationClause = buildPaginationClausePG(field, variablesDefinition);
|
|
283
|
+
|
|
284
|
+
const isArraySelection = !!field.isArray && !withoutArrayWrapper;
|
|
285
|
+
|
|
286
|
+
return `
|
|
287
|
+
COALESCE((
|
|
288
|
+
SELECT ${isArraySelection ? `json_agg(json_build_object(${selectList}) ${orderByClause})` : `json_build_object(${selectList})`} ${fromClause} ${whereClause} ${withoutArrayWrapper ? " LIMIT 1" : ""} ${paginationClause ? ` ${paginationClause}` : ""}
|
|
289
|
+
), '${isArraySelection ? "[]" : "null"}'::json)
|
|
290
|
+
`;
|
|
291
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { logger } from "../../../logging";
|
|
2
|
+
|
|
3
|
+
// Returns null when the stored claims are malformed — callers must reject the login
|
|
4
|
+
// (fail closed) rather than issue a token with missing claims.
|
|
5
|
+
export const parseUserClaims = (claims: unknown): Record<string, unknown> | null => {
|
|
6
|
+
if (claims === null || claims === undefined) return {};
|
|
7
|
+
|
|
8
|
+
if (typeof claims === "object" && !Array.isArray(claims)) {
|
|
9
|
+
return claims as Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (typeof claims === "string") {
|
|
13
|
+
try {
|
|
14
|
+
const parsed: unknown = JSON.parse(claims);
|
|
15
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
16
|
+
return parsed as Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
} catch (error) {
|
|
19
|
+
logger("auth").warn({ err: error }, "failed to parse user claims");
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
logger("auth").warn("user claims are not a JSON object");
|
|
25
|
+
return null;
|
|
26
|
+
};
|