@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,511 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from "openapi-types";
|
|
2
|
+
|
|
3
|
+
import { SqlTypeCategory, categorizeSqlType, isNumericType } from "../../../databases/sqlTypeUtils";
|
|
4
|
+
import { convertFromZod } from "../../rest/openApiErrors";
|
|
5
|
+
import { type MergedEntities } from "../mergeEntities";
|
|
6
|
+
|
|
7
|
+
// Map JSON Schema type to GraphQL type
|
|
8
|
+
export const mapJSONSchemaToGraphQLType = (schema: OpenAPIV3_1.SchemaObject): string => {
|
|
9
|
+
if (!schema) return "String";
|
|
10
|
+
|
|
11
|
+
// Handle arrays
|
|
12
|
+
if (schema.type === "array") {
|
|
13
|
+
const itemsSchema = schema.items as OpenAPIV3_1.SchemaObject | undefined;
|
|
14
|
+
const itemType = itemsSchema ? mapJSONSchemaToGraphQLType(itemsSchema) : "String";
|
|
15
|
+
return `[${itemType}]`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Handle basic types
|
|
19
|
+
switch (schema.type) {
|
|
20
|
+
case "integer":
|
|
21
|
+
return "Int";
|
|
22
|
+
case "number":
|
|
23
|
+
return "Float";
|
|
24
|
+
case "boolean":
|
|
25
|
+
return "Boolean";
|
|
26
|
+
case "string":
|
|
27
|
+
default:
|
|
28
|
+
return "String";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Map SQL data types to GraphQL types
|
|
33
|
+
export const mapSQLTypeToGraphQLType = (sqlType: string | null): string => {
|
|
34
|
+
if (!sqlType) return "String";
|
|
35
|
+
|
|
36
|
+
const category = categorizeSqlType(sqlType);
|
|
37
|
+
|
|
38
|
+
switch (category) {
|
|
39
|
+
case SqlTypeCategory.INTEGER:
|
|
40
|
+
return "Int";
|
|
41
|
+
case SqlTypeCategory.FLOAT:
|
|
42
|
+
return "Float";
|
|
43
|
+
case SqlTypeCategory.BOOLEAN:
|
|
44
|
+
return "Boolean";
|
|
45
|
+
case SqlTypeCategory.DATE_TIME:
|
|
46
|
+
case SqlTypeCategory.STRING:
|
|
47
|
+
default:
|
|
48
|
+
return "String";
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Map SQL data types to condition types
|
|
53
|
+
export const mapSQLTypeToConditionType = (sqlType: string): string => {
|
|
54
|
+
const category = categorizeSqlType(sqlType);
|
|
55
|
+
|
|
56
|
+
switch (category) {
|
|
57
|
+
case SqlTypeCategory.INTEGER:
|
|
58
|
+
return "IntCondition";
|
|
59
|
+
case SqlTypeCategory.FLOAT:
|
|
60
|
+
return "FloatCondition";
|
|
61
|
+
case SqlTypeCategory.BOOLEAN:
|
|
62
|
+
return "BooleanCondition";
|
|
63
|
+
case SqlTypeCategory.DATE_TIME:
|
|
64
|
+
case SqlTypeCategory.STRING:
|
|
65
|
+
default:
|
|
66
|
+
return "StringCondition";
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Join elements of an array with a newline character
|
|
71
|
+
export const lj = <T>(keys: T[], cb?: (value: T) => string) => {
|
|
72
|
+
if (cb) {
|
|
73
|
+
return keys
|
|
74
|
+
.map((i) => cb(i))
|
|
75
|
+
.filter((a) => a.trim())
|
|
76
|
+
.join("\n");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return keys.filter((a) => (a as string).trim()).join("\n");
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Render an SDL block-string description, escaping any embedded triple-quote.
|
|
83
|
+
const sdlDesc = (description?: string | null): string =>
|
|
84
|
+
description ? `"""${description.replaceAll('"""', '\\"""')}"""\n` : "";
|
|
85
|
+
|
|
86
|
+
export const generateTableType = (mergedEntities: MergedEntities) =>
|
|
87
|
+
lj(
|
|
88
|
+
mergedEntities.tables,
|
|
89
|
+
({ resolverName, columns, relationships, relationshipsReversed, tableDescription }) => `
|
|
90
|
+
${sdlDesc(tableDescription)}type ${`${resolverName}`} {
|
|
91
|
+
${lj([
|
|
92
|
+
lj(
|
|
93
|
+
columns,
|
|
94
|
+
({ name, dataType, isNullable, description }) =>
|
|
95
|
+
`${sdlDesc(description)}${name}: ${mapSQLTypeToGraphQLType(dataType)}${isNullable ? "" : "!"}`,
|
|
96
|
+
),
|
|
97
|
+
lj(
|
|
98
|
+
relationships,
|
|
99
|
+
({ toResolverName, toInternalName }) =>
|
|
100
|
+
`${toResolverName}(where: ${toInternalName}WhereInput): ${toInternalName}`,
|
|
101
|
+
),
|
|
102
|
+
lj(
|
|
103
|
+
relationshipsReversed,
|
|
104
|
+
({ fromResolverName, fromInternalName }) =>
|
|
105
|
+
`${fromResolverName}(where: ${fromInternalName}WhereInput, orderBy: [${fromInternalName}OrderByInput]): [${fromInternalName}]`,
|
|
106
|
+
),
|
|
107
|
+
])}
|
|
108
|
+
}
|
|
109
|
+
`,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
export const generateWhereInputType = (mergedEntities: MergedEntities) =>
|
|
113
|
+
lj(
|
|
114
|
+
mergedEntities.tables.map(
|
|
115
|
+
({ resolverName, columns, relationships, relationshipsReversed }) => `
|
|
116
|
+
input ${resolverName}WhereInput {
|
|
117
|
+
${lj([
|
|
118
|
+
lj(columns, ({ name, dataType }) => `${name}: ${mapSQLTypeToConditionType(dataType)}`),
|
|
119
|
+
lj(
|
|
120
|
+
relationships,
|
|
121
|
+
({ toResolverName, toInternalName }) =>
|
|
122
|
+
`${toResolverName}: ${toInternalName}WhereInput`,
|
|
123
|
+
),
|
|
124
|
+
lj(
|
|
125
|
+
relationshipsReversed,
|
|
126
|
+
({ fromResolverName, fromInternalName }) =>
|
|
127
|
+
`${fromResolverName}: ${fromInternalName}WhereInput`,
|
|
128
|
+
),
|
|
129
|
+
])}
|
|
130
|
+
}
|
|
131
|
+
`,
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Generate OrderByInput type for each table
|
|
136
|
+
export const generateOrderByInputType = (mergedEntities: MergedEntities) =>
|
|
137
|
+
lj(
|
|
138
|
+
mergedEntities.tables.map(
|
|
139
|
+
({ internalName, columns }) => `
|
|
140
|
+
input ${internalName}OrderByInput {
|
|
141
|
+
${lj(columns, ({ name }) => `${name}: OrderByEnum`)}
|
|
142
|
+
}`,
|
|
143
|
+
),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const aggTypes: string[] = ["Min", "Max", "Sum", "Avg"];
|
|
147
|
+
|
|
148
|
+
// Generate aggregation types for each table
|
|
149
|
+
export const generateAggregationTypes = (mergedEntities: MergedEntities) => {
|
|
150
|
+
const aggregationTypes = lj(mergedEntities.tables, ({ resolverName, columns }) => {
|
|
151
|
+
const numericColumns = columns.filter((col) => isNumericType(col.dataType));
|
|
152
|
+
|
|
153
|
+
return `
|
|
154
|
+
${
|
|
155
|
+
numericColumns.length
|
|
156
|
+
? aggTypes
|
|
157
|
+
.map(
|
|
158
|
+
(agg) =>
|
|
159
|
+
`
|
|
160
|
+
type ${resolverName}${agg} {
|
|
161
|
+
${lj(numericColumns, ({ name }) => `${name}: ${mapSQLTypeToGraphQLType(columns.find((c) => c.name === name)?.dataType || "")}`)}
|
|
162
|
+
}
|
|
163
|
+
`,
|
|
164
|
+
)
|
|
165
|
+
.join("\n")
|
|
166
|
+
: ""
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
type ${resolverName}GroupBy {
|
|
170
|
+
key: ${resolverName}
|
|
171
|
+
count: Int
|
|
172
|
+
${
|
|
173
|
+
numericColumns.length
|
|
174
|
+
? aggTypes.map((agg) => `${agg.toLowerCase()}: ${resolverName}${agg}`).join("\n")
|
|
175
|
+
: ""
|
|
176
|
+
}
|
|
177
|
+
items: [${resolverName}]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
enum ${resolverName}GroupByKeys {
|
|
181
|
+
${columns.map((c) => c.name).join("\n")}
|
|
182
|
+
}
|
|
183
|
+
`;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return aggregationTypes;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const generateAuthTypes = (hasRoles: boolean = false) =>
|
|
190
|
+
hasRoles
|
|
191
|
+
? `
|
|
192
|
+
type AuthUser {
|
|
193
|
+
id: Int
|
|
194
|
+
username: String
|
|
195
|
+
role: String
|
|
196
|
+
}
|
|
197
|
+
type AuthToken {
|
|
198
|
+
access_token: String
|
|
199
|
+
expires_in: Int
|
|
200
|
+
role: String
|
|
201
|
+
}
|
|
202
|
+
`
|
|
203
|
+
: "";
|
|
204
|
+
|
|
205
|
+
export const generateQueryType = (mergedEntities: MergedEntities, hasRoles: boolean = false) => {
|
|
206
|
+
const hasRemoteQueries = mergedEntities.remoteSchemas.some((rs) => rs.queryFields.length > 0);
|
|
207
|
+
|
|
208
|
+
if (!mergedEntities.tables.length && !hasRoles && !hasRemoteQueries && !mergedEntities.ai)
|
|
209
|
+
return `type Query {
|
|
210
|
+
_no_data: String
|
|
211
|
+
}`;
|
|
212
|
+
|
|
213
|
+
return `
|
|
214
|
+
type Query {
|
|
215
|
+
${lj(
|
|
216
|
+
mergedEntities.tables,
|
|
217
|
+
({ resolverName }) =>
|
|
218
|
+
`
|
|
219
|
+
${resolverName}(where: ${resolverName}WhereInput, orderBy: [${resolverName}OrderByInput], limit: Int, offset: Int): [${resolverName}!]!
|
|
220
|
+
${resolverName}_single(where: ${resolverName}WhereInput): ${resolverName}!
|
|
221
|
+
${resolverName}_aggregate(where: ${resolverName}WhereInput, orderBy: [${resolverName}OrderByInput], groupBy: [${resolverName}GroupByKeys]!, limit: Int, offset: Int): [${resolverName}GroupBy!]!
|
|
222
|
+
`,
|
|
223
|
+
)}
|
|
224
|
+
${
|
|
225
|
+
hasRoles
|
|
226
|
+
? `
|
|
227
|
+
auth_me: AuthUser
|
|
228
|
+
`
|
|
229
|
+
: ""
|
|
230
|
+
}
|
|
231
|
+
${mergedEntities.ai ? "ask(prompt: String!): String!" : ""}
|
|
232
|
+
${mergedEntities.remoteSchemas.map((rs) => rs.queryFields.map((f) => f.sdl).join("\n ")).join("\n ")}
|
|
233
|
+
}
|
|
234
|
+
`;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export const generateSubscriptionType = (mergedEntities: MergedEntities) => {
|
|
238
|
+
return `
|
|
239
|
+
${
|
|
240
|
+
mergedEntities.tables.length || mergedEntities.queues.map((q) => q.queues).flat().length
|
|
241
|
+
? `
|
|
242
|
+
type QueueMutationResponse {
|
|
243
|
+
id: String!
|
|
244
|
+
message: String!
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
type Subscription {
|
|
248
|
+
${lj(
|
|
249
|
+
mergedEntities.tables,
|
|
250
|
+
({ resolverName }) =>
|
|
251
|
+
`
|
|
252
|
+
${resolverName}(where: ${resolverName}WhereInput, orderBy: [${resolverName}OrderByInput], limit: Int, offset: Int): [${resolverName}!]!
|
|
253
|
+
${resolverName}_single(where: ${resolverName}WhereInput): ${resolverName}!
|
|
254
|
+
${resolverName}_aggregate(where: ${resolverName}WhereInput, orderBy: [${resolverName}OrderByInput], groupBy: [${resolverName}GroupByKeys], limit: Int, offset: Int): [${resolverName}!]!
|
|
255
|
+
`,
|
|
256
|
+
)}
|
|
257
|
+
${lj(mergedEntities.queues, (queue) => queue.queues.map((q) => `${queue.name}_${q.name}: QueueMutationResponse!`).join("\n"))}
|
|
258
|
+
}
|
|
259
|
+
`
|
|
260
|
+
: ""
|
|
261
|
+
}`;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const generateGraphQLTypeFromSchema = (
|
|
265
|
+
schema: OpenAPIV3_1.SchemaObject,
|
|
266
|
+
typeName: string,
|
|
267
|
+
collector: string[],
|
|
268
|
+
): string => {
|
|
269
|
+
if (schema.type === "array") {
|
|
270
|
+
const items = schema.items as OpenAPIV3_1.SchemaObject | undefined;
|
|
271
|
+
if (items?.type === "object" && items.properties) {
|
|
272
|
+
generateGraphQLTypeFromSchema(items, typeName, collector);
|
|
273
|
+
return `[${typeName}]`;
|
|
274
|
+
}
|
|
275
|
+
return `[${mapJSONSchemaToGraphQLType(items ?? {})}]`;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (schema.type === "object" && schema.properties) {
|
|
279
|
+
const fields = Object.entries(schema.properties).map(([key, propSchema]) => {
|
|
280
|
+
const prop = propSchema as OpenAPIV3_1.SchemaObject;
|
|
281
|
+
const isRequired = schema.required?.includes(key) ?? false;
|
|
282
|
+
const bang = isRequired ? "!" : "";
|
|
283
|
+
|
|
284
|
+
if (prop.type === "object" && prop.properties) {
|
|
285
|
+
const nestedName = `${typeName}${key}`;
|
|
286
|
+
generateGraphQLTypeFromSchema(prop, nestedName, collector);
|
|
287
|
+
return `${key}: ${nestedName}${bang}`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (prop.type === "array") {
|
|
291
|
+
const items = prop.items as OpenAPIV3_1.SchemaObject | undefined;
|
|
292
|
+
if (items?.type === "object" && items.properties) {
|
|
293
|
+
const nestedName = `${typeName}${key}`;
|
|
294
|
+
generateGraphQLTypeFromSchema(items, nestedName, collector);
|
|
295
|
+
return `${key}: [${nestedName}]${bang}`;
|
|
296
|
+
}
|
|
297
|
+
return `${key}: ${mapJSONSchemaToGraphQLType(prop)}${bang}`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return `${key}: ${mapJSONSchemaToGraphQLType(prop)}${bang}`;
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
collector.push(`type ${typeName} {\n ${fields.join("\n ")}\n }`);
|
|
304
|
+
return typeName;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return mapJSONSchemaToGraphQLType(schema);
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export const generateMutationType = (mergedEntities: MergedEntities, hasRoles: boolean = false) => {
|
|
311
|
+
const authQueries = hasRoles
|
|
312
|
+
? `
|
|
313
|
+
auth_login(username: String, password: String): AuthToken
|
|
314
|
+
auth_refresh: AuthToken
|
|
315
|
+
auth_logout: Boolean
|
|
316
|
+
`
|
|
317
|
+
: "";
|
|
318
|
+
|
|
319
|
+
const atLeastOneSP = mergedEntities.storedProcedures.length > 0;
|
|
320
|
+
|
|
321
|
+
const publishers = mergedEntities.queues
|
|
322
|
+
.map((q) => q.exchanges.map((e) => e.publishers).flat())
|
|
323
|
+
.flat();
|
|
324
|
+
|
|
325
|
+
const atLeastOneQueue = mergedEntities.queues.length > 0 && publishers.length > 0;
|
|
326
|
+
|
|
327
|
+
// Filter operations that have GraphQL enabled (default: true)
|
|
328
|
+
const operationsWithMutations = Object.entries(mergedEntities.operations)
|
|
329
|
+
.filter(
|
|
330
|
+
([, operationConfig]) =>
|
|
331
|
+
operationConfig.graphql.enabled && (operationConfig.rest?.method || "GET") !== "GET",
|
|
332
|
+
)
|
|
333
|
+
.map(([operationName, operationConfig]) => {
|
|
334
|
+
const inputShape = convertFromZod(operationConfig.input);
|
|
335
|
+
const outputShape = convertFromZod(operationConfig.output);
|
|
336
|
+
|
|
337
|
+
const hasInputProperties =
|
|
338
|
+
inputShape.type === "object" &&
|
|
339
|
+
inputShape.properties &&
|
|
340
|
+
Object.keys(inputShape.properties).length > 0;
|
|
341
|
+
|
|
342
|
+
const hasOutputProperties =
|
|
343
|
+
outputShape.type === "object" &&
|
|
344
|
+
outputShape.properties &&
|
|
345
|
+
Object.keys(outputShape.properties).length > 0;
|
|
346
|
+
|
|
347
|
+
const mutationName = operationConfig.graphql?.name ?? operationName;
|
|
348
|
+
|
|
349
|
+
const output = hasOutputProperties ? `${mutationName}Output` : "Boolean";
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
input: hasInputProperties
|
|
353
|
+
? `
|
|
354
|
+
input ${mutationName}Input {
|
|
355
|
+
${Object.entries(inputShape.properties ?? {})
|
|
356
|
+
.map(
|
|
357
|
+
([key, value]) =>
|
|
358
|
+
`${key}: ${mapJSONSchemaToGraphQLType(value as OpenAPIV3_1.SchemaObject)}${inputShape.required?.includes(key) ? "!" : ""}`,
|
|
359
|
+
)
|
|
360
|
+
.join("\n")}
|
|
361
|
+
}
|
|
362
|
+
`
|
|
363
|
+
: "",
|
|
364
|
+
output: (() => {
|
|
365
|
+
if (!hasOutputProperties) return "";
|
|
366
|
+
const collector: string[] = [];
|
|
367
|
+
generateGraphQLTypeFromSchema(outputShape, `${mutationName}Output`, collector);
|
|
368
|
+
return collector.join("\n");
|
|
369
|
+
})(),
|
|
370
|
+
resolver: hasInputProperties
|
|
371
|
+
? `
|
|
372
|
+
${mutationName}(input: ${mutationName}Input!): ${output}!
|
|
373
|
+
`
|
|
374
|
+
: `
|
|
375
|
+
${mutationName}: ${output}!
|
|
376
|
+
`,
|
|
377
|
+
};
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const hasOperations = operationsWithMutations.length > 0;
|
|
381
|
+
|
|
382
|
+
const remoteMutationSDLs = mergedEntities.remoteSchemas
|
|
383
|
+
.filter((rs) => rs.mutationFields.length > 0)
|
|
384
|
+
.map((rs) => rs.mutationFields.map((f) => f.sdl).join("\n "))
|
|
385
|
+
.join("\n ");
|
|
386
|
+
|
|
387
|
+
const hasRemoteMutations = remoteMutationSDLs.length > 0;
|
|
388
|
+
|
|
389
|
+
return atLeastOneSP || atLeastOneQueue || authQueries || hasOperations || hasRemoteMutations
|
|
390
|
+
? `
|
|
391
|
+
${operationsWithMutations.map((a) => a.input).join("\n")}
|
|
392
|
+
${operationsWithMutations.map((a) => a.output).join("\n")}
|
|
393
|
+
|
|
394
|
+
type Mutation {
|
|
395
|
+
${lj(mergedEntities.storedProcedures, ({ resolverName, parameters }) => {
|
|
396
|
+
const parametersFiltered = parameters.filter((p) => p.name);
|
|
397
|
+
|
|
398
|
+
return `${resolverName}${
|
|
399
|
+
parametersFiltered.length
|
|
400
|
+
? `(${lj(
|
|
401
|
+
parametersFiltered,
|
|
402
|
+
({ name, dataType }) =>
|
|
403
|
+
`${name.replaceAll("@", "")}: ${mapSQLTypeToGraphQLType(dataType)}`,
|
|
404
|
+
)})`
|
|
405
|
+
: ""
|
|
406
|
+
}: Boolean!`;
|
|
407
|
+
})}
|
|
408
|
+
|
|
409
|
+
${lj(publishers, ({ resolverName }) => `${resolverName}(data: String!): Boolean!`)}
|
|
410
|
+
${operationsWithMutations.map((a) => a.resolver).join("\n")}
|
|
411
|
+
${authQueries}
|
|
412
|
+
${remoteMutationSDLs}
|
|
413
|
+
}
|
|
414
|
+
`
|
|
415
|
+
: "";
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const conditionTypes = `
|
|
419
|
+
enum OrderByEnum {
|
|
420
|
+
ASC
|
|
421
|
+
DESC
|
|
422
|
+
ASC_NULLS_FIRST
|
|
423
|
+
ASC_NULLS_LAST
|
|
424
|
+
DESC_NULLS_FIRST
|
|
425
|
+
DESC_NULLS_LAST
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
input IntCondition {
|
|
429
|
+
eq: Int
|
|
430
|
+
neq: Int
|
|
431
|
+
gt: Int
|
|
432
|
+
gte: Int
|
|
433
|
+
lt: Int
|
|
434
|
+
lte: Int
|
|
435
|
+
in: [Int]
|
|
436
|
+
between: [Int]
|
|
437
|
+
is_null: Boolean
|
|
438
|
+
not_null: Boolean
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
input FloatCondition {
|
|
442
|
+
eq: Float
|
|
443
|
+
neq: Float
|
|
444
|
+
gt: Float
|
|
445
|
+
gte: Float
|
|
446
|
+
lt: Float
|
|
447
|
+
lte: Float
|
|
448
|
+
in: [Float]
|
|
449
|
+
between: [Float]
|
|
450
|
+
is_null: Boolean
|
|
451
|
+
not_null: Boolean
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
input StringCondition {
|
|
455
|
+
eq: String
|
|
456
|
+
neq: String
|
|
457
|
+
like: String
|
|
458
|
+
in: [String]
|
|
459
|
+
is_null: Boolean
|
|
460
|
+
not_null: Boolean
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
input BooleanCondition {
|
|
464
|
+
eq: Boolean
|
|
465
|
+
neq: Boolean
|
|
466
|
+
is_null: Boolean
|
|
467
|
+
not_null: Boolean
|
|
468
|
+
}
|
|
469
|
+
`;
|
|
470
|
+
|
|
471
|
+
const directiveTypes = `
|
|
472
|
+
directive @uppercase on FIELD
|
|
473
|
+
directive @lowercase on FIELD
|
|
474
|
+
directive @truncate(length: Int!) on FIELD
|
|
475
|
+
directive @default(value: String!) on FIELD
|
|
476
|
+
|
|
477
|
+
directive @trim on FIELD
|
|
478
|
+
directive @ltrim on FIELD
|
|
479
|
+
directive @rtrim on FIELD
|
|
480
|
+
directive @substring(start: Int!, length: Int!) on FIELD
|
|
481
|
+
directive @replace(find: String!, replaceWith: String!) on FIELD
|
|
482
|
+
directive @concat(with: String!, position: String = "after") on FIELD
|
|
483
|
+
directive @pad(length: Int!, char: String = " ", side: String = "left") on FIELD
|
|
484
|
+
|
|
485
|
+
directive @dateFormat(format: String!) on FIELD
|
|
486
|
+
|
|
487
|
+
directive @round(decimals: Int = 0) on FIELD
|
|
488
|
+
directive @ceil on FIELD
|
|
489
|
+
directive @floor on FIELD
|
|
490
|
+
directive @abs on FIELD
|
|
491
|
+
directive @multiply(by: Float!) on FIELD
|
|
492
|
+
directive @divide(by: Float!) on FIELD
|
|
493
|
+
|
|
494
|
+
directive @when(and: [Boolean!], or: [Boolean!]) on FIELD
|
|
495
|
+
`;
|
|
496
|
+
|
|
497
|
+
export const generateTypeDefs = (mergedEntities: MergedEntities, hasAuth: boolean = false) =>
|
|
498
|
+
[
|
|
499
|
+
mergedEntities.tables.length ? conditionTypes : "",
|
|
500
|
+
mergedEntities.tables.length ? directiveTypes : "",
|
|
501
|
+
generateTableType(mergedEntities),
|
|
502
|
+
generateWhereInputType(mergedEntities),
|
|
503
|
+
generateOrderByInputType(mergedEntities),
|
|
504
|
+
generateAggregationTypes(mergedEntities),
|
|
505
|
+
generateAuthTypes(hasAuth),
|
|
506
|
+
// Append remote schema type definitions (prefixed types, inputs, enums)
|
|
507
|
+
...mergedEntities.remoteSchemas.map((rs) => rs.typeDefsSDL),
|
|
508
|
+
generateQueryType(mergedEntities, hasAuth),
|
|
509
|
+
generateSubscriptionType(mergedEntities),
|
|
510
|
+
generateMutationType(mergedEntities, hasAuth),
|
|
511
|
+
].join("\n");
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { SessionContext } from "../../utils/sessionVariables";
|
|
2
|
+
import type { HandleGraphQLRequest } from "./handleGraphQLRequestFactory";
|
|
3
|
+
|
|
4
|
+
export type ExecuteOptions = {
|
|
5
|
+
role?: string;
|
|
6
|
+
session?: SessionContext;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type RolesWithGqlHandler = Record<string, { handlers: { gql: HandleGraphQLRequest } }>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wrap the per-role GraphQL handlers in a single `execute(query, variables, opts)`
|
|
13
|
+
* function — the same orchestration the `/graphql` POST route performs (introspection
|
|
14
|
+
* / no-data short-circuits, validation, dispatch) minus the HTTP layer. Lets callers
|
|
15
|
+
* run a query in-process without standing up a server.
|
|
16
|
+
*
|
|
17
|
+
* @param roles - The analyzed-configuration role map (`analyzedConfiguration.roles`).
|
|
18
|
+
* @param defaultRole - Role used when `opts.role` is omitted (the server passes its
|
|
19
|
+
* superadmin role, so in-process execution runs with full privileges).
|
|
20
|
+
*/
|
|
21
|
+
export const buildExecute = (roles: RolesWithGqlHandler, defaultRole: string) => {
|
|
22
|
+
return async (
|
|
23
|
+
query: string,
|
|
24
|
+
variables: Record<string, unknown> = {},
|
|
25
|
+
opts: ExecuteOptions = {},
|
|
26
|
+
) => {
|
|
27
|
+
const role = opts.role ?? defaultRole;
|
|
28
|
+
const roleSchema = roles[role];
|
|
29
|
+
|
|
30
|
+
if (!roleSchema) {
|
|
31
|
+
throw new Error(`Unknown role: ${role}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { gql } = roleSchema.handlers;
|
|
35
|
+
|
|
36
|
+
if (gql.isIntrospectionQuery(query)) return gql.introspectionResult;
|
|
37
|
+
if (gql.isNoDataQuery(query)) return gql.noDataResult;
|
|
38
|
+
|
|
39
|
+
const { hasErrors, validationErrors } = gql.hasErrors(query);
|
|
40
|
+
|
|
41
|
+
if (hasErrors) {
|
|
42
|
+
return {
|
|
43
|
+
errors: validationErrors.map((error) => ({
|
|
44
|
+
message: error.message,
|
|
45
|
+
locations: error.locations,
|
|
46
|
+
})),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// No BunRequest in-process: request-dependent features (operation `init`/
|
|
51
|
+
// `beforeRequest` hooks, header-derived session variables) won't run.
|
|
52
|
+
return gql.handler(query, variables, undefined, opts.session);
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { BunRequest } from "bun";
|
|
2
|
+
import type { SelectionAnalysis } from "../../analyzeQuery/types";
|
|
3
|
+
import type { Auth } from "../../types/configuration";
|
|
4
|
+
import type { SessionContext } from "../../utils/sessionVariables";
|
|
5
|
+
|
|
6
|
+
import { resolveVariableRef } from "../../analyzeQuery/resolveVariables";
|
|
7
|
+
import { checkUserCredentials } from "../../databases";
|
|
8
|
+
import { getTokenService } from "../../singletons/authentication";
|
|
9
|
+
|
|
10
|
+
// Handle auth mutations: auth_login / auth_refresh / auth_logout
|
|
11
|
+
export const handleAuthMutation = async (
|
|
12
|
+
field: SelectionAnalysis,
|
|
13
|
+
variables: Record<string, unknown>,
|
|
14
|
+
auth: Auth | null,
|
|
15
|
+
req?: BunRequest,
|
|
16
|
+
session?: SessionContext,
|
|
17
|
+
): Promise<{ data: object }> => {
|
|
18
|
+
if (!auth?.enabled) {
|
|
19
|
+
throw new Error("Authentication is not enabled");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (field.name === "auth_login") {
|
|
23
|
+
const { username, password } = field.arguments ?? {};
|
|
24
|
+
|
|
25
|
+
const usernameValue = resolveVariableRef(variables, username);
|
|
26
|
+
const passwordValue = resolveVariableRef(variables, password);
|
|
27
|
+
|
|
28
|
+
if (!usernameValue || !passwordValue) {
|
|
29
|
+
throw new Error("Username and password are required");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const result = await checkUserCredentials(
|
|
33
|
+
auth,
|
|
34
|
+
usernameValue.toString(),
|
|
35
|
+
passwordValue.toString(),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (!result.valid) {
|
|
39
|
+
throw new Error("Invalid username or password");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const data = await getTokenService().createTokenPair({
|
|
43
|
+
sub: usernameValue.toString(),
|
|
44
|
+
role: result.role,
|
|
45
|
+
claims: result.claims,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (req?.cookies) {
|
|
49
|
+
// Set the HTTP-only cookie
|
|
50
|
+
// Implementation to set HTTP-only cookie goes here
|
|
51
|
+
const cookies = req.cookies;
|
|
52
|
+
|
|
53
|
+
cookies.set("refresh_token", data.refresh_token, {
|
|
54
|
+
httpOnly: true, // Can't be accessed by JS
|
|
55
|
+
secure: true, // Only sent over HTTPS (disable for localhost dev)
|
|
56
|
+
sameSite: "strict", // Prevents CSRF
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
data: {
|
|
62
|
+
[field.alias || field.name]: {
|
|
63
|
+
access_token: data.access_token,
|
|
64
|
+
expires_in: data.expires_in,
|
|
65
|
+
role: result.role,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (field.name === "auth_refresh") {
|
|
72
|
+
if (req?.cookies) {
|
|
73
|
+
// Set the HTTP-only cookie
|
|
74
|
+
// Implementation to set HTTP-only cookie goes here
|
|
75
|
+
const cookies = req.cookies;
|
|
76
|
+
|
|
77
|
+
const tokenValue = cookies.get("refresh_token");
|
|
78
|
+
|
|
79
|
+
if (!tokenValue) {
|
|
80
|
+
throw new Error("Refresh token is required");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const result = await getTokenService().refreshAccessToken(tokenValue.toString());
|
|
84
|
+
|
|
85
|
+
// Set the HTTP-only cookie
|
|
86
|
+
// Implementation to set HTTP-only cookie goes here
|
|
87
|
+
cookies.set("refresh_token", result.refresh_token, {
|
|
88
|
+
httpOnly: true, // Can't be accessed by JS
|
|
89
|
+
secure: true, // Only sent over HTTPS (disable for localhost dev)
|
|
90
|
+
sameSite: "strict", // Prevents CSRF
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
data: {
|
|
95
|
+
[field.alias || field.name]: {
|
|
96
|
+
access_token: result.access_token,
|
|
97
|
+
expires_in: result.expires_in,
|
|
98
|
+
role: result.role,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (field.name === "auth_logout") {
|
|
106
|
+
const tokenService = getTokenService();
|
|
107
|
+
|
|
108
|
+
if (session?.jti) {
|
|
109
|
+
await tokenService.revoke(session.jti);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const refreshCookie = req?.cookies?.get("refresh_token");
|
|
113
|
+
if (refreshCookie) {
|
|
114
|
+
try {
|
|
115
|
+
const refreshPayload = await tokenService.verifyToken(refreshCookie.toString(), {
|
|
116
|
+
audience: "refresh",
|
|
117
|
+
});
|
|
118
|
+
await tokenService.revoke(refreshPayload.jti);
|
|
119
|
+
} catch {
|
|
120
|
+
// tampered or expired cookie — nothing to revoke
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (req?.cookies) {
|
|
125
|
+
req.cookies.delete("refresh_token");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
data: {
|
|
130
|
+
[field.alias || field.name]: true,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { data: {} };
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Handle the auth_me query — returns { [alias]: { username, role } | null }
|
|
139
|
+
export const handleAuthMeQuery = (
|
|
140
|
+
field: SelectionAnalysis,
|
|
141
|
+
session?: SessionContext,
|
|
142
|
+
): Record<string, unknown> => {
|
|
143
|
+
if (field.name === "auth_me") {
|
|
144
|
+
const alias = field.alias || field.name;
|
|
145
|
+
return {
|
|
146
|
+
[alias]: session?.sub ? { username: session.sub, role: session.role } : null,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {};
|
|
150
|
+
};
|