@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,151 @@
|
|
|
1
|
+
import { isString } from "es-toolkit";
|
|
2
|
+
import { ConnectionPool, Decimal, Int, NVarChar, Numeric, VarChar } from "mssql";
|
|
3
|
+
|
|
4
|
+
import type { MSSQLConnectionOptions } from "../../../config";
|
|
5
|
+
import type { VariableDefinition } from "../../../analyzeQuery/types";
|
|
6
|
+
import type { Database } from "../../../types/configuration";
|
|
7
|
+
import type { ProcedureResolver } from "../../../types/db";
|
|
8
|
+
|
|
9
|
+
import { databasesConnections } from "../../../singletons/databases";
|
|
10
|
+
import { logger } from "../../../logging";
|
|
11
|
+
|
|
12
|
+
export const getPool = async (db: Database) => {
|
|
13
|
+
const ci = db.connection;
|
|
14
|
+
const opts = db.connectionOptions as MSSQLConnectionOptions | undefined;
|
|
15
|
+
const pool = new ConnectionPool({
|
|
16
|
+
server: ci.host,
|
|
17
|
+
port: ci.port,
|
|
18
|
+
user: ci.user,
|
|
19
|
+
password: ci.password,
|
|
20
|
+
database: ci.database,
|
|
21
|
+
connectionTimeout: opts?.connectionTimeout ? opts.connectionTimeout * 1000 : undefined,
|
|
22
|
+
requestTimeout: opts?.requestTimeout ? opts.requestTimeout * 1000 : undefined,
|
|
23
|
+
options: {
|
|
24
|
+
encrypt: opts?.encrypt ?? false,
|
|
25
|
+
trustServerCertificate: opts?.trustServerCertificate ?? true,
|
|
26
|
+
trustedConnection: opts?.trustedConnection ?? true,
|
|
27
|
+
},
|
|
28
|
+
pool: {
|
|
29
|
+
max: opts?.pool?.max ?? 50,
|
|
30
|
+
min: opts?.pool?.min ?? 1,
|
|
31
|
+
idleTimeoutMillis: (opts?.pool?.idleTimeout ?? 30) * 1000,
|
|
32
|
+
},
|
|
33
|
+
parseJSON: opts?.parseJSON ?? true,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await pool.connect(); // Connect to the database
|
|
37
|
+
|
|
38
|
+
while (!pool.connected) {
|
|
39
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return pool;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const getPoolSingleton = async (db: Database) =>
|
|
46
|
+
databasesConnections[db.name] as ConnectionPool;
|
|
47
|
+
|
|
48
|
+
export const executeQueryFactory =
|
|
49
|
+
(singleQuery = false) =>
|
|
50
|
+
async <T>(
|
|
51
|
+
query: string,
|
|
52
|
+
db: Database,
|
|
53
|
+
variablesDefinition: VariableDefinition[] = [],
|
|
54
|
+
params: Record<string, unknown> = {},
|
|
55
|
+
) => {
|
|
56
|
+
const pool = singleQuery ? await getPool(db) : await getPoolSingleton(db);
|
|
57
|
+
|
|
58
|
+
while (!pool!.connected) {
|
|
59
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const request = pool!.request();
|
|
63
|
+
|
|
64
|
+
variablesDefinition.forEach((v, i) => {
|
|
65
|
+
const varName = (i + 1).toString();
|
|
66
|
+
const varValue = params[v.name];
|
|
67
|
+
|
|
68
|
+
if (isString(varValue)) {
|
|
69
|
+
request.input(varName, VarChar, varValue);
|
|
70
|
+
} else if (typeof varValue === "number") {
|
|
71
|
+
request.input(varName, Int, varValue);
|
|
72
|
+
} else if (typeof varValue === "boolean") {
|
|
73
|
+
request.input(varName, Int, varValue ? 1 : 0);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const result = await request.query<T>(query);
|
|
78
|
+
|
|
79
|
+
if (singleQuery) {
|
|
80
|
+
await pool.close();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return result.recordset;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const executeQuery = executeQueryFactory();
|
|
87
|
+
export const executeQuerySingle = executeQueryFactory(true);
|
|
88
|
+
|
|
89
|
+
export const executeQueryJSONFactory =
|
|
90
|
+
(singleQuery = false) =>
|
|
91
|
+
async <T>(
|
|
92
|
+
query: string,
|
|
93
|
+
db: Database,
|
|
94
|
+
variablesDefinition: VariableDefinition[] = [],
|
|
95
|
+
params: Record<string, unknown> = {},
|
|
96
|
+
): Promise<T> => {
|
|
97
|
+
const result = await (singleQuery ? executeQuerySingle : executeQuery)(
|
|
98
|
+
query,
|
|
99
|
+
db,
|
|
100
|
+
variablesDefinition,
|
|
101
|
+
params,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return result[0] as T;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const executeQueryJSON = executeQueryJSONFactory();
|
|
108
|
+
export const executeQueryJSONSingle = executeQueryJSONFactory(true);
|
|
109
|
+
|
|
110
|
+
export const callStoredProcedure = async (
|
|
111
|
+
sp: ProcedureResolver,
|
|
112
|
+
variablesDefinition: VariableDefinition[],
|
|
113
|
+
variables: Record<string, unknown> = {},
|
|
114
|
+
) => {
|
|
115
|
+
try {
|
|
116
|
+
const pool = await getPoolSingleton(sp.db!);
|
|
117
|
+
|
|
118
|
+
const request = pool!.request();
|
|
119
|
+
|
|
120
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
121
|
+
if (!value) continue;
|
|
122
|
+
|
|
123
|
+
const paramFound = sp.parameters.find((p) => p.name === `@${key}`);
|
|
124
|
+
|
|
125
|
+
if (paramFound?.dataType === "varchar") {
|
|
126
|
+
request.input(key, VarChar(paramFound.maxLength), value);
|
|
127
|
+
} else if (paramFound?.dataType === "nvarchar") {
|
|
128
|
+
request.input(
|
|
129
|
+
key,
|
|
130
|
+
paramFound.maxLength > -1 ? NVarChar(paramFound.maxLength) : NVarChar(),
|
|
131
|
+
value,
|
|
132
|
+
);
|
|
133
|
+
} else if (paramFound?.dataType === "numeric") {
|
|
134
|
+
request.input(key, Numeric(paramFound.precision, paramFound.scale), value);
|
|
135
|
+
} else if (paramFound?.dataType === "decimal") {
|
|
136
|
+
request.input(key, Decimal(paramFound.precision, paramFound.scale), value);
|
|
137
|
+
} else if (paramFound?.dataType === "int") {
|
|
138
|
+
request.input(key, Int, value);
|
|
139
|
+
} else {
|
|
140
|
+
request.input(key, value);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const data = await request.execute(sp.dottedName);
|
|
145
|
+
|
|
146
|
+
return data?.recordset ?? false;
|
|
147
|
+
} catch (e: unknown) {
|
|
148
|
+
logger("mssql").error({ err: e }, "stored procedure execution failed");
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
@@ -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: "transactsql",
|
|
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,112 @@
|
|
|
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
|
+
SELECT
|
|
10
|
+
(
|
|
11
|
+
SELECT
|
|
12
|
+
t.[schema] as 'schema',
|
|
13
|
+
t.[table] as 'name',
|
|
14
|
+
t.entityType as entityType,
|
|
15
|
+
(
|
|
16
|
+
SELECT CAST(value AS NVARCHAR(MAX))
|
|
17
|
+
FROM sys.extended_properties ep
|
|
18
|
+
INNER JOIN sys.objects o ON ep.major_id = o.object_id
|
|
19
|
+
WHERE ep.name = 'MS_Description'
|
|
20
|
+
AND o.name = t.[table]
|
|
21
|
+
AND SCHEMA_NAME(o.schema_id) = t.[schema]
|
|
22
|
+
AND ep.minor_id = 0
|
|
23
|
+
) AS tableDescription,
|
|
24
|
+
ISNULL((
|
|
25
|
+
SELECT
|
|
26
|
+
c.COLUMN_NAME AS name,
|
|
27
|
+
c.DATA_TYPE AS dataType,
|
|
28
|
+
CAST(CASE WHEN c.IS_NULLABLE = 'YES' THEN 1 ELSE 0 END AS bit) AS isNullable,
|
|
29
|
+
(
|
|
30
|
+
SELECT CAST(value AS NVARCHAR(MAX))
|
|
31
|
+
FROM sys.extended_properties ep
|
|
32
|
+
INNER JOIN sys.objects o ON ep.major_id = o.object_id
|
|
33
|
+
INNER JOIN sys.columns col ON col.object_id = o.object_id AND col.column_id = ep.minor_id
|
|
34
|
+
WHERE ep.name = 'MS_Description'
|
|
35
|
+
AND o.name = t.[table]
|
|
36
|
+
AND SCHEMA_NAME(o.schema_id) = t.[schema]
|
|
37
|
+
AND col.name = c.COLUMN_NAME
|
|
38
|
+
) AS description
|
|
39
|
+
FROM INFORMATION_SCHEMA.COLUMNS AS c
|
|
40
|
+
WHERE c.TABLE_SCHEMA = t.[schema]
|
|
41
|
+
AND c.TABLE_NAME = t.[table]
|
|
42
|
+
FOR JSON PATH
|
|
43
|
+
), '[]') AS columns,
|
|
44
|
+
ISNULL((
|
|
45
|
+
SELECT
|
|
46
|
+
SCHEMA_NAME(tr.schema_id) AS [schema],
|
|
47
|
+
tr.name AS [name],
|
|
48
|
+
ISNULL((
|
|
49
|
+
SELECT
|
|
50
|
+
cp.name AS [source],
|
|
51
|
+
cr.name AS [target]
|
|
52
|
+
FROM sys.foreign_key_columns AS fkc_inner
|
|
53
|
+
JOIN sys.columns AS cp
|
|
54
|
+
ON fkc_inner.parent_object_id = cp.object_id
|
|
55
|
+
AND fkc_inner.parent_column_id = cp.column_id
|
|
56
|
+
JOIN sys.columns AS cr
|
|
57
|
+
ON fkc_inner.referenced_object_id = cr.object_id
|
|
58
|
+
AND fkc_inner.referenced_column_id = cr.column_id
|
|
59
|
+
WHERE fkc_inner.constraint_object_id = fk.object_id
|
|
60
|
+
FOR JSON PATH
|
|
61
|
+
), '[]') AS columns
|
|
62
|
+
FROM sys.foreign_keys AS fk
|
|
63
|
+
JOIN sys.foreign_key_columns AS fkc
|
|
64
|
+
ON fk.object_id = fkc.constraint_object_id
|
|
65
|
+
JOIN sys.tables AS tp
|
|
66
|
+
ON fkc.parent_object_id = tp.object_id
|
|
67
|
+
JOIN sys.tables AS tr
|
|
68
|
+
ON fkc.referenced_object_id = tr.object_id
|
|
69
|
+
WHERE tp.name = t.[table]
|
|
70
|
+
GROUP BY fk.object_id, fk.name, tp.name, tp.schema_id, tr.name, tr.schema_id
|
|
71
|
+
FOR JSON PATH
|
|
72
|
+
), '[]') AS foreignKeys
|
|
73
|
+
FROM (
|
|
74
|
+
SELECT DISTINCT
|
|
75
|
+
TABLE_SCHEMA AS [schema],
|
|
76
|
+
TABLE_NAME AS [table],
|
|
77
|
+
CASE WHEN TABLE_TYPE = 'BASE TABLE' THEN 'table' ELSE 'view' END AS entityType
|
|
78
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
79
|
+
WHERE TABLE_TYPE IN ('BASE TABLE', 'VIEW')
|
|
80
|
+
) t
|
|
81
|
+
FOR JSON PATH, INCLUDE_NULL_VALUES
|
|
82
|
+
) AS tables,
|
|
83
|
+
(
|
|
84
|
+
SELECT
|
|
85
|
+
SCHEMA_NAME(p.schema_id) AS 'schema',
|
|
86
|
+
p.name AS name,
|
|
87
|
+
ISNULL (
|
|
88
|
+
(
|
|
89
|
+
SELECT
|
|
90
|
+
name as name,
|
|
91
|
+
TYPE_NAME(user_type_id) AS dataType,
|
|
92
|
+
max_length as maxLength,
|
|
93
|
+
precision,
|
|
94
|
+
scale
|
|
95
|
+
FROM sys.parameters
|
|
96
|
+
WHERE object_id = p.object_id
|
|
97
|
+
ORDER BY parameter_id
|
|
98
|
+
FOR JSON PATH
|
|
99
|
+
),
|
|
100
|
+
'[]'
|
|
101
|
+
) AS parameters
|
|
102
|
+
FROM sys.procedures p
|
|
103
|
+
INNER JOIN sys.objects o ON p.object_id = o.object_id
|
|
104
|
+
FOR JSON PATH, INCLUDE_NULL_VALUES
|
|
105
|
+
) AS storedProcedures
|
|
106
|
+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
|
|
107
|
+
`,
|
|
108
|
+
db,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return DatabaseStructureZod.parse(res);
|
|
112
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
10
|
+
LOWER(SCHEMA_NAME(v.schema_id)) AS schema,
|
|
11
|
+
LOWER(v.name) AS name,
|
|
12
|
+
OBJECT_DEFINITION(v.object_id) AS definition
|
|
13
|
+
FROM sys.views v
|
|
14
|
+
FOR JSON PATH, INCLUDE_NULL_VALUES
|
|
15
|
+
`,
|
|
16
|
+
db,
|
|
17
|
+
);
|
|
@@ -0,0 +1,306 @@
|
|
|
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
|
+
buildOrderByClauseMSSQL,
|
|
11
|
+
buildPaginationClauseMSSQL,
|
|
12
|
+
buildWhereClauseMSSQL,
|
|
13
|
+
extractAggregationInfo,
|
|
14
|
+
filterBasedOnDirective,
|
|
15
|
+
generateTableAlias,
|
|
16
|
+
isAggregationField,
|
|
17
|
+
isSingleQuery,
|
|
18
|
+
processFieldSelectionsMSSQL,
|
|
19
|
+
} from "../../../common";
|
|
20
|
+
|
|
21
|
+
// Generate CTE for aggregations
|
|
22
|
+
const buildAggregationCTE = (
|
|
23
|
+
groupByInfo: GroupByInfo,
|
|
24
|
+
dottedName: 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 ${dottedName} ${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
|
+
dottedName: 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((field) => `${cteAlias}.${field.name} AS ${field.alias || field.name}`)
|
|
76
|
+
.join(", ");
|
|
77
|
+
|
|
78
|
+
selectClauses.push(
|
|
79
|
+
`JSON_QUERY((SELECT ${keyFields} FOR JSON PATH, WITHOUT_ARRAY_WRAPPER, INCLUDE_NULL_VALUES)) AS [${keyResolved}]`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Add aggregation results
|
|
84
|
+
aggregations.forEach((agg) => {
|
|
85
|
+
if (agg.name === "count") {
|
|
86
|
+
selectClauses.push(`${cteAlias}.${agg.alias} AS ${agg.nameResolved}`);
|
|
87
|
+
} else {
|
|
88
|
+
selectClauses.push(
|
|
89
|
+
`JSON_QUERY((SELECT ${cteAlias}.${agg.alias} AS ${agg.fieldAlias} FOR JSON PATH, WITHOUT_ARRAY_WRAPPER, INCLUDE_NULL_VALUES)) AS ${agg.nameResolved}`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Add items if requested
|
|
95
|
+
if (hasItems) {
|
|
96
|
+
const itemsSelection = field.selections?.find((sel) => sel.name === "items");
|
|
97
|
+
|
|
98
|
+
if (itemsSelection?.selections) {
|
|
99
|
+
const itemFields = itemsSelection.selections
|
|
100
|
+
.filter((sel) => !isAggregationField(sel.name) && sel.name !== "items")
|
|
101
|
+
.map((sel) => `${tableAlias}.${sel.name} AS ${sel.alias || sel.name}`)
|
|
102
|
+
.join(", ");
|
|
103
|
+
|
|
104
|
+
if (itemFields) {
|
|
105
|
+
const joinConditions = groupByFields.map(
|
|
106
|
+
(field) => `${tableAlias}.${field} = ${cteAlias}.${field}`,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
selectClauses.push(`JSON_QUERY(ISNULL((
|
|
110
|
+
SELECT ${itemFields}
|
|
111
|
+
FROM ${dottedName} ${tableAlias}
|
|
112
|
+
${whereClause ? [whereClause, ...joinConditions].join(" AND ") : `WHERE ${joinConditions.join(" AND ")}`}
|
|
113
|
+
FOR JSON PATH, INCLUDE_NULL_VALUES
|
|
114
|
+
), '[]')) AS ${itemsSelection.alias || itemsSelection.name}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const orderByClause = buildOrderByClauseMSSQL(entities, field, cteAlias);
|
|
120
|
+
|
|
121
|
+
return `SELECT ${selectClauses.join(",\n ")}
|
|
122
|
+
FROM ${cteAlias} ${orderByClause}
|
|
123
|
+
FOR JSON PATH, INCLUDE_NULL_VALUES`;
|
|
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 HASHBYTES('MD5', (
|
|
134
|
+
${buildSQLForField(
|
|
135
|
+
entities,
|
|
136
|
+
operation.variables ?? [],
|
|
137
|
+
variables,
|
|
138
|
+
operation.fields[0],
|
|
139
|
+
null,
|
|
140
|
+
null,
|
|
141
|
+
1,
|
|
142
|
+
{},
|
|
143
|
+
)})
|
|
144
|
+
) AS ResultHash`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const variablesWithDefault = {
|
|
148
|
+
...operation.variables?.reduce<Record<string, unknown>>((acc, variable) => {
|
|
149
|
+
if (variable.defaultValue !== undefined) {
|
|
150
|
+
acc[variable.name] = variable.defaultValue;
|
|
151
|
+
}
|
|
152
|
+
return acc;
|
|
153
|
+
}, {}),
|
|
154
|
+
...variables,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Check if any field requires CTEs (has groupBy)
|
|
158
|
+
const filteredFields = operation.fields?.filter((f) =>
|
|
159
|
+
filterBasedOnDirective(f, operation.variables ?? [], variablesWithDefault),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const ctes: string[] = [];
|
|
163
|
+
const fieldQueries: string[] = [];
|
|
164
|
+
|
|
165
|
+
filteredFields?.forEach((field, index) => {
|
|
166
|
+
const tableAlias = generateTableAlias(index + 1);
|
|
167
|
+
const groupByInfo = extractAggregationInfo(field, tableAlias);
|
|
168
|
+
|
|
169
|
+
if (groupByInfo) {
|
|
170
|
+
// This field requires a CTE
|
|
171
|
+
const { dottedName } = entities.queriesMap[field.name]!;
|
|
172
|
+
|
|
173
|
+
const whereClause = buildWhereClauseMSSQL(
|
|
174
|
+
entities,
|
|
175
|
+
operation.variables ?? [],
|
|
176
|
+
variablesWithDefault,
|
|
177
|
+
field,
|
|
178
|
+
tableAlias,
|
|
179
|
+
null,
|
|
180
|
+
null,
|
|
181
|
+
index + 1,
|
|
182
|
+
{},
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const cte = buildAggregationCTE(groupByInfo, dottedName, tableAlias, whereClause);
|
|
186
|
+
ctes.push(cte);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const fieldSQL = buildSQLForField(
|
|
190
|
+
entities,
|
|
191
|
+
operation.variables ?? [],
|
|
192
|
+
variablesWithDefault,
|
|
193
|
+
field,
|
|
194
|
+
null,
|
|
195
|
+
null,
|
|
196
|
+
index + 1,
|
|
197
|
+
{},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
fieldQueries.push(`(${fieldSQL}) as ${field.alias || field.name}`);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const cteClause = ctes.length > 0 ? `WITH\n${ctes.join(",\n")}\n` : "";
|
|
204
|
+
|
|
205
|
+
return `
|
|
206
|
+
${cteClause}SELECT
|
|
207
|
+
${fieldQueries.join(",\n")}
|
|
208
|
+
FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER
|
|
209
|
+
`;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const buildSQLForField = (
|
|
213
|
+
entities: MergedEntities,
|
|
214
|
+
variablesDefinition: VariableDefinition[],
|
|
215
|
+
variables: Record<string, unknown> = {},
|
|
216
|
+
field: SelectionAnalysis,
|
|
217
|
+
parentTableName: string | null,
|
|
218
|
+
parentTableAlias: string | null,
|
|
219
|
+
level: number,
|
|
220
|
+
aliasMap: { [alias: string]: string },
|
|
221
|
+
): string => {
|
|
222
|
+
const tableAlias = generateTableAlias(level);
|
|
223
|
+
|
|
224
|
+
const withoutArrayWrapper = isSingleQuery(field.name);
|
|
225
|
+
|
|
226
|
+
const foundTable = entities.queriesMap[field.name];
|
|
227
|
+
|
|
228
|
+
if (!foundTable) {
|
|
229
|
+
throw new Error(`Table not found for field: ${field.name}`);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const { dottedName, resolverName } = foundTable;
|
|
233
|
+
|
|
234
|
+
aliasMap[tableAlias] = resolverName;
|
|
235
|
+
|
|
236
|
+
const whereClause = buildWhereClauseMSSQL(
|
|
237
|
+
entities,
|
|
238
|
+
variablesDefinition,
|
|
239
|
+
variables,
|
|
240
|
+
field,
|
|
241
|
+
tableAlias,
|
|
242
|
+
parentTableName,
|
|
243
|
+
parentTableAlias,
|
|
244
|
+
level,
|
|
245
|
+
aliasMap,
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
// Check if this is a GROUP BY query
|
|
249
|
+
const groupByInfo = extractAggregationInfo(field, tableAlias);
|
|
250
|
+
|
|
251
|
+
if (groupByInfo) {
|
|
252
|
+
// Handle GROUP BY aggregation query
|
|
253
|
+
const mainQuery = buildGroupedQuery(
|
|
254
|
+
entities,
|
|
255
|
+
field,
|
|
256
|
+
groupByInfo,
|
|
257
|
+
dottedName,
|
|
258
|
+
tableAlias,
|
|
259
|
+
whereClause,
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
return mainQuery;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Original logic for non-aggregation queries
|
|
266
|
+
const selectList = processFieldSelectionsMSSQL(
|
|
267
|
+
entities,
|
|
268
|
+
variablesDefinition,
|
|
269
|
+
variables,
|
|
270
|
+
field,
|
|
271
|
+
resolverName,
|
|
272
|
+
tableAlias,
|
|
273
|
+
level,
|
|
274
|
+
(sel, level) =>
|
|
275
|
+
buildSQLForField(
|
|
276
|
+
entities,
|
|
277
|
+
variablesDefinition,
|
|
278
|
+
variables,
|
|
279
|
+
sel,
|
|
280
|
+
resolverName,
|
|
281
|
+
tableAlias,
|
|
282
|
+
level,
|
|
283
|
+
aliasMap,
|
|
284
|
+
),
|
|
285
|
+
([name, selector]) => `${selector} AS ${name}`,
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
const fromClause = `FROM ${dottedName} ${tableAlias}`;
|
|
289
|
+
|
|
290
|
+
const orderByClause = buildOrderByClauseMSSQL(entities, field, tableAlias);
|
|
291
|
+
const paginationClause = buildPaginationClauseMSSQL(field, variablesDefinition);
|
|
292
|
+
|
|
293
|
+
const isArray = field.isArray;
|
|
294
|
+
const forJson =
|
|
295
|
+
isArray && !withoutArrayWrapper
|
|
296
|
+
? "FOR JSON PATH, INCLUDE_NULL_VALUES"
|
|
297
|
+
: "FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER";
|
|
298
|
+
|
|
299
|
+
const baseQuery = `SELECT ${selectList} ${fromClause} ${whereClause} ${orderByClause}${paginationClause ? ` ${paginationClause}` : ""} ${forJson}`;
|
|
300
|
+
|
|
301
|
+
if (isArray && !withoutArrayWrapper) {
|
|
302
|
+
return `JSON_QUERY(ISNULL((${baseQuery}), '[]'))`;
|
|
303
|
+
} else {
|
|
304
|
+
return `JSON_QUERY(NULLIF((${baseQuery}), ''))`;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import type { Auth, Database } from "../../../types/configuration";
|
|
3
|
+
import type { CheckUserCredentialsResult, InsertAuthUserInput } from "../../core/function-mapping";
|
|
4
|
+
|
|
5
|
+
import { databasesConnections } from "../../../singletons/databases";
|
|
6
|
+
import { hashPassword, verifyPassword } from "../../auth/password";
|
|
7
|
+
import { assertSafeIdentifier } from "../../core/identifier";
|
|
8
|
+
import { parseUserClaims } from "../shared/claims";
|
|
9
|
+
import type { UserRecord } from "../shared/types";
|
|
10
|
+
|
|
11
|
+
export const userTableCreation = (schema: string) => `
|
|
12
|
+
CREATE TABLE IF NOT EXISTS \`${assertSafeIdentifier(schema, "schema")}\`.\`user\` (
|
|
13
|
+
username VARCHAR(50) PRIMARY KEY,
|
|
14
|
+
password VARCHAR(255) NOT NULL,
|
|
15
|
+
role VARCHAR(20) NOT NULL,
|
|
16
|
+
is_active BOOLEAN DEFAULT TRUE,
|
|
17
|
+
claims JSON DEFAULT ('{}')
|
|
18
|
+
);
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const createAuthTables = async (auth: Auth) => {
|
|
22
|
+
const pool = databasesConnections[auth.databaseEntity.name] as SQL;
|
|
23
|
+
|
|
24
|
+
const schema = assertSafeIdentifier(auth.schema!, "schema");
|
|
25
|
+
|
|
26
|
+
// In MySQL, CREATE DATABASE is used instead of CREATE SCHEMA
|
|
27
|
+
await pool.unsafe(`CREATE DATABASE IF NOT EXISTS \`${schema}\`;`);
|
|
28
|
+
|
|
29
|
+
await pool.unsafe(userTableCreation(auth.schema!));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const checkUserCredentials = async (
|
|
33
|
+
db: Database,
|
|
34
|
+
auth: Auth,
|
|
35
|
+
username: string,
|
|
36
|
+
password: string,
|
|
37
|
+
injectedPool?: SQL,
|
|
38
|
+
): Promise<CheckUserCredentialsResult> => {
|
|
39
|
+
const pool = injectedPool ?? (databasesConnections[db.name] as SQL);
|
|
40
|
+
|
|
41
|
+
const schema = assertSafeIdentifier(auth.schema!, "schema");
|
|
42
|
+
|
|
43
|
+
const result = await pool.unsafe<UserRecord[]>(
|
|
44
|
+
`SELECT * FROM \`${schema}\`.\`user\` WHERE username = $1 AND is_active = TRUE`,
|
|
45
|
+
[username],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (result?.length === 0) {
|
|
49
|
+
return {
|
|
50
|
+
valid: false,
|
|
51
|
+
role: null,
|
|
52
|
+
claims: null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { password: hashedPassword, role, claims } = result[0];
|
|
57
|
+
|
|
58
|
+
if (!(await verifyPassword(password, hashedPassword))) {
|
|
59
|
+
return {
|
|
60
|
+
valid: false,
|
|
61
|
+
role: null,
|
|
62
|
+
claims: null,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const parsedClaims = parseUserClaims(claims);
|
|
67
|
+
|
|
68
|
+
if (parsedClaims === null) {
|
|
69
|
+
return {
|
|
70
|
+
valid: false,
|
|
71
|
+
role: null,
|
|
72
|
+
claims: null,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { valid: true, role, claims: parsedClaims };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const verifyAuthTablesExist = async (auth: Auth, injectedPool?: SQL): Promise<void> => {
|
|
80
|
+
const pool = injectedPool ?? (databasesConnections[auth.databaseEntity.name] as SQL);
|
|
81
|
+
const schema = assertSafeIdentifier(auth.schema!, "schema");
|
|
82
|
+
await pool.unsafe(`SELECT username FROM \`${schema}\`.\`user\` WHERE 1=0`);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const insertAuthUser = async (
|
|
86
|
+
auth: Auth,
|
|
87
|
+
input: InsertAuthUserInput,
|
|
88
|
+
injectedPool?: SQL,
|
|
89
|
+
): Promise<void> => {
|
|
90
|
+
const pool = injectedPool ?? (databasesConnections[auth.databaseEntity.name] as SQL);
|
|
91
|
+
|
|
92
|
+
const schema = assertSafeIdentifier(auth.schema!, "schema");
|
|
93
|
+
const hashed = await hashPassword(input.password);
|
|
94
|
+
|
|
95
|
+
await pool.unsafe(
|
|
96
|
+
`INSERT INTO \`${schema}\`.\`user\` (username, password, role, is_active, claims)
|
|
97
|
+
VALUES ($1, $2, $3, TRUE, $4)`,
|
|
98
|
+
[input.username, hashed, input.role, JSON.stringify(input.claims ?? {})],
|
|
99
|
+
);
|
|
100
|
+
};
|