@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,642 @@
|
|
|
1
|
+
import { isBoolean, isString } from "es-toolkit/compat";
|
|
2
|
+
|
|
3
|
+
import type { SelectionAnalysis, VariableDefinition } from "../analyzeQuery/types";
|
|
4
|
+
import type { MergedEntities } from "../configuration/getSchemas/mergeEntities";
|
|
5
|
+
import type { DatabaseType, VirtualColumn } from "../types/configuration";
|
|
6
|
+
|
|
7
|
+
import { applyDirectives } from "./directives";
|
|
8
|
+
|
|
9
|
+
// Common aggregation types
|
|
10
|
+
export interface AggregationField {
|
|
11
|
+
name: string;
|
|
12
|
+
fieldName: string;
|
|
13
|
+
fieldAlias: string;
|
|
14
|
+
alias: string;
|
|
15
|
+
nameResolved: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GroupByInfo {
|
|
19
|
+
groupByFields: string[];
|
|
20
|
+
aggregations: AggregationField[];
|
|
21
|
+
hasItems: boolean;
|
|
22
|
+
keyResolved: string;
|
|
23
|
+
hasKey: boolean;
|
|
24
|
+
keys: SelectionAnalysis[];
|
|
25
|
+
cteAlias: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const isOperatorObject = (obj: object): boolean =>
|
|
29
|
+
Object.keys(obj).some((key) =>
|
|
30
|
+
["eq", "neq", "gt", "gte", "lt", "lte", "like", "in", "is_null", "is_not_null"].includes(key),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export const generateTableAlias = (level: number): string => `t${level}`;
|
|
34
|
+
|
|
35
|
+
const mappingDbTypeCharVar: Record<DatabaseType, string> = {
|
|
36
|
+
pg: "$",
|
|
37
|
+
mysql: "$",
|
|
38
|
+
mssql: "@",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const buildConditions = (
|
|
42
|
+
entities: MergedEntities,
|
|
43
|
+
dbType: DatabaseType,
|
|
44
|
+
variablesDefinition: VariableDefinition[],
|
|
45
|
+
variables: Record<string, unknown> = {},
|
|
46
|
+
whereArgs: object | unknown | null,
|
|
47
|
+
tableAlias: string,
|
|
48
|
+
level: number,
|
|
49
|
+
aliasMap: { [alias: string]: string },
|
|
50
|
+
quoted = false,
|
|
51
|
+
): string => {
|
|
52
|
+
if (!whereArgs) return "";
|
|
53
|
+
|
|
54
|
+
const conditions: string[] = [];
|
|
55
|
+
|
|
56
|
+
const whereArg: Record<string, object> = resolveVariable(whereArgs, variables);
|
|
57
|
+
|
|
58
|
+
for (const [fieldName, value] of Object.entries(whereArg)) {
|
|
59
|
+
if (isOperatorObject(value)) {
|
|
60
|
+
for (const [operator, operand] of Object.entries(value)) {
|
|
61
|
+
// All values are now variable references (e.g., "$varName" or ["$var1", "$var2"])
|
|
62
|
+
const resolvedValue = Array.isArray(operand)
|
|
63
|
+
? operand.map((op) => {
|
|
64
|
+
if (isString(op) && op.startsWith("$")) {
|
|
65
|
+
const index = variablesDefinition.findIndex((v) => v.name === op.substring(1));
|
|
66
|
+
return `${mappingDbTypeCharVar[dbType]}${index + 1}`;
|
|
67
|
+
}
|
|
68
|
+
return op;
|
|
69
|
+
})
|
|
70
|
+
: isString(operand) && operand.startsWith("$")
|
|
71
|
+
? `${mappingDbTypeCharVar[dbType]}${variablesDefinition.findIndex((v) => v.name === operand.substring(1)) + 1}`
|
|
72
|
+
: operand;
|
|
73
|
+
|
|
74
|
+
const condition = buildCondition(tableAlias, fieldName, operator, resolvedValue, quoted);
|
|
75
|
+
|
|
76
|
+
if (condition) {
|
|
77
|
+
conditions.push(condition);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} else if (typeof value === "object" && !Array.isArray(value)) {
|
|
81
|
+
const nestedTableAlias = `t${level}`;
|
|
82
|
+
|
|
83
|
+
const parentTableName = aliasMap[tableAlias];
|
|
84
|
+
|
|
85
|
+
const joinCondition = findJoinCondition(
|
|
86
|
+
entities,
|
|
87
|
+
parentTableName,
|
|
88
|
+
fieldName,
|
|
89
|
+
tableAlias,
|
|
90
|
+
nestedTableAlias,
|
|
91
|
+
quoted,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const nestedConditions = buildConditions(
|
|
95
|
+
entities,
|
|
96
|
+
dbType,
|
|
97
|
+
variablesDefinition,
|
|
98
|
+
variables,
|
|
99
|
+
value,
|
|
100
|
+
nestedTableAlias,
|
|
101
|
+
level + 1,
|
|
102
|
+
aliasMap,
|
|
103
|
+
quoted,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const existsClause = `EXISTS (
|
|
107
|
+
SELECT 1
|
|
108
|
+
FROM ${entities.queriesMap[fieldName]!.dottedName} ${nestedTableAlias}
|
|
109
|
+
WHERE ${joinCondition}${nestedConditions ? ` AND (${nestedConditions})` : ""}
|
|
110
|
+
)`;
|
|
111
|
+
|
|
112
|
+
conditions.push(existsClause);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return conditions.length > 0 ? conditions.join(" AND ") : "";
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const wrapIf = (value: string, quoted: boolean): string => (quoted ? `"${value}"` : value);
|
|
120
|
+
|
|
121
|
+
// Helper to resolve variable values
|
|
122
|
+
const resolveVariable = <T>(value: unknown, variables: Record<string, unknown>): T => {
|
|
123
|
+
if (isString(value) && value.startsWith("$")) {
|
|
124
|
+
return variables[value.substring(1)] as T;
|
|
125
|
+
}
|
|
126
|
+
return value as T;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const buildCondition = (
|
|
130
|
+
tableAlias: string,
|
|
131
|
+
field: string,
|
|
132
|
+
operator: string,
|
|
133
|
+
value: unknown,
|
|
134
|
+
quoted = false,
|
|
135
|
+
): string | null => {
|
|
136
|
+
const wrappedField = wrapIf(field, quoted);
|
|
137
|
+
|
|
138
|
+
switch (operator) {
|
|
139
|
+
case "eq":
|
|
140
|
+
return `${tableAlias}.${wrappedField} = ${value}`;
|
|
141
|
+
case "neq":
|
|
142
|
+
return `${tableAlias}.${wrappedField} <> ${value}`;
|
|
143
|
+
case "gt":
|
|
144
|
+
return `${tableAlias}.${wrappedField} > ${value}`;
|
|
145
|
+
case "gte":
|
|
146
|
+
return `${tableAlias}.${wrappedField} >= ${value}`;
|
|
147
|
+
case "lt":
|
|
148
|
+
return `${tableAlias}.${wrappedField} < ${value}`;
|
|
149
|
+
case "lte":
|
|
150
|
+
return `${tableAlias}.${wrappedField} <= ${value}`;
|
|
151
|
+
case "like":
|
|
152
|
+
return `${tableAlias}.${wrappedField} LIKE ${value}`;
|
|
153
|
+
case "in":
|
|
154
|
+
return `${tableAlias}.${wrappedField} IN (${
|
|
155
|
+
Array.isArray(value) ? value.join(", ") : value
|
|
156
|
+
})`;
|
|
157
|
+
case "is_null":
|
|
158
|
+
return value
|
|
159
|
+
? `${tableAlias}.${wrappedField} IS NULL`
|
|
160
|
+
: `${tableAlias}.${wrappedField} IS NOT NULL`;
|
|
161
|
+
case "is_not_null":
|
|
162
|
+
return value
|
|
163
|
+
? `${tableAlias}.${wrappedField} IS NOT NULL`
|
|
164
|
+
: `${tableAlias}.${wrappedField} IS NULL`;
|
|
165
|
+
default:
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const pairsToAnd = (
|
|
171
|
+
pairs: {
|
|
172
|
+
parentAlias: string;
|
|
173
|
+
childAlias: string;
|
|
174
|
+
parentColumn: string;
|
|
175
|
+
childColumn: string;
|
|
176
|
+
}[],
|
|
177
|
+
quoted = false,
|
|
178
|
+
) =>
|
|
179
|
+
pairs
|
|
180
|
+
.map(
|
|
181
|
+
(p) =>
|
|
182
|
+
`${p.parentAlias}.${wrapIf(p.parentColumn, quoted)} = ${p.childAlias}.${wrapIf(p.childColumn, quoted)}`,
|
|
183
|
+
)
|
|
184
|
+
.join(" AND ");
|
|
185
|
+
|
|
186
|
+
export const findJoinCondition = (
|
|
187
|
+
entities: MergedEntities,
|
|
188
|
+
parentTableName: string,
|
|
189
|
+
childTableName: string,
|
|
190
|
+
parentAlias: string,
|
|
191
|
+
childAlias: string,
|
|
192
|
+
quoted = false,
|
|
193
|
+
): string => {
|
|
194
|
+
const relations = entities.getForeignKeysBetweenTables(parentTableName, childTableName);
|
|
195
|
+
|
|
196
|
+
if (!relations.relationships?.length && !relations.relationshipsReversed?.length) return "";
|
|
197
|
+
|
|
198
|
+
return [
|
|
199
|
+
...(relations.relationships?.map((relation) =>
|
|
200
|
+
pairsToAnd(
|
|
201
|
+
relation.columns.map((c) => ({
|
|
202
|
+
parentAlias,
|
|
203
|
+
childAlias,
|
|
204
|
+
parentColumn: c.source,
|
|
205
|
+
childColumn: c.target,
|
|
206
|
+
})),
|
|
207
|
+
quoted,
|
|
208
|
+
),
|
|
209
|
+
) ?? []),
|
|
210
|
+
...(relations.relationshipsReversed?.map((relation) =>
|
|
211
|
+
pairsToAnd(
|
|
212
|
+
relation.columns.map((c) => ({
|
|
213
|
+
parentAlias,
|
|
214
|
+
childAlias,
|
|
215
|
+
parentColumn: c.target,
|
|
216
|
+
childColumn: c.source,
|
|
217
|
+
})),
|
|
218
|
+
quoted,
|
|
219
|
+
),
|
|
220
|
+
) ?? []),
|
|
221
|
+
].join(" AND ");
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export const buildWhereClauseFp =
|
|
225
|
+
(dbType: DatabaseType = "pg") =>
|
|
226
|
+
(
|
|
227
|
+
entities: MergedEntities,
|
|
228
|
+
variablesDefinition: VariableDefinition[],
|
|
229
|
+
variables: Record<string, unknown>,
|
|
230
|
+
field: SelectionAnalysis,
|
|
231
|
+
tableAlias: string,
|
|
232
|
+
parentTableName: string | null,
|
|
233
|
+
parentTableAlias: string | null,
|
|
234
|
+
level: number,
|
|
235
|
+
aliasMap: { [alias: string]: string },
|
|
236
|
+
quoted = false,
|
|
237
|
+
): string => {
|
|
238
|
+
const whereConditions: string[] = [
|
|
239
|
+
buildConditions(
|
|
240
|
+
entities,
|
|
241
|
+
dbType,
|
|
242
|
+
variablesDefinition,
|
|
243
|
+
variables,
|
|
244
|
+
field.arguments?.["where"],
|
|
245
|
+
tableAlias,
|
|
246
|
+
level + 1,
|
|
247
|
+
aliasMap,
|
|
248
|
+
quoted,
|
|
249
|
+
),
|
|
250
|
+
parentTableName && parentTableAlias
|
|
251
|
+
? findJoinCondition(
|
|
252
|
+
entities,
|
|
253
|
+
parentTableName,
|
|
254
|
+
field.name,
|
|
255
|
+
parentTableAlias,
|
|
256
|
+
tableAlias,
|
|
257
|
+
quoted,
|
|
258
|
+
)
|
|
259
|
+
: null,
|
|
260
|
+
].filter(Boolean) as string[];
|
|
261
|
+
|
|
262
|
+
return whereConditions.length > 0 ? `WHERE ${whereConditions.join(" AND ")}` : "";
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export const buildWhereClauseMSSQL = buildWhereClauseFp("mssql");
|
|
266
|
+
export const buildWhereClausePG = buildWhereClauseFp("pg");
|
|
267
|
+
export const buildWhereClauseMySQL = buildWhereClauseFp("mysql");
|
|
268
|
+
|
|
269
|
+
// Helper function to parse order direction and null handling
|
|
270
|
+
const ORDER_DIRECTION_MAP: Record<string, { sort: string; nulls?: string }> = {
|
|
271
|
+
ASC: { sort: "ASC" },
|
|
272
|
+
DESC: { sort: "DESC" },
|
|
273
|
+
ASC_NULLS_FIRST: { sort: "ASC", nulls: "FIRST" },
|
|
274
|
+
ASC_NULLS_LAST: { sort: "ASC", nulls: "LAST" },
|
|
275
|
+
DESC_NULLS_FIRST: { sort: "DESC", nulls: "FIRST" },
|
|
276
|
+
DESC_NULLS_LAST: { sort: "DESC", nulls: "LAST" },
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const parseOrderDirection = (direction: string): { sort: string; nulls?: string } =>
|
|
280
|
+
ORDER_DIRECTION_MAP[direction] ?? { sort: direction };
|
|
281
|
+
|
|
282
|
+
export const buildOrderByClauseFp =
|
|
283
|
+
(dbType: DatabaseType = "pg") =>
|
|
284
|
+
(entities: MergedEntities, field: SelectionAnalysis, tableAlias: string): string => {
|
|
285
|
+
if (field.arguments?.["orderBy"]) {
|
|
286
|
+
const orderBy = field.arguments?.["orderBy"];
|
|
287
|
+
// orderBy is an array or object of { column: direction } - no variable resolution needed
|
|
288
|
+
// since column names are schema-defined and directions are enum values
|
|
289
|
+
const orderByFields = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
290
|
+
|
|
291
|
+
if (entities.queriesMap[field.name]?.rolePermission?.orderBy) {
|
|
292
|
+
orderByFields.push(
|
|
293
|
+
...(entities.queriesMap[field.name].rolePermission?.orderBy?.map((o) => ({
|
|
294
|
+
[o.column]: o.direction,
|
|
295
|
+
})) ?? []),
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const orderByList = orderByFields
|
|
300
|
+
.map((ob) => {
|
|
301
|
+
const [colName, direction] = Object.entries(ob)[0];
|
|
302
|
+
const { sort, nulls } = parseOrderDirection(direction as string);
|
|
303
|
+
|
|
304
|
+
const virtualColumn = entities.isVirtualColumn(field.name, colName);
|
|
305
|
+
|
|
306
|
+
if (nulls) {
|
|
307
|
+
if (dbType === "pg") {
|
|
308
|
+
// PostgreSQL supports NULLS FIRST/LAST natively
|
|
309
|
+
return `${tableAlias}."${colName}" ${sort} NULLS ${nulls}`;
|
|
310
|
+
} else if (dbType === "mysql") {
|
|
311
|
+
// MySQL: Use CASE statement for NULL handling
|
|
312
|
+
const nullFirst = nulls === "FIRST";
|
|
313
|
+
return `CASE WHEN ${tableAlias}.${colName} IS NULL THEN ${nullFirst ? 0 : 1} ELSE ${nullFirst ? 1 : 0} END, ${tableAlias}.${colName} ${sort}`;
|
|
314
|
+
} else {
|
|
315
|
+
// MSSQL requires CASE statements for NULL handling
|
|
316
|
+
const nullFirst = nulls === "FIRST";
|
|
317
|
+
const isAsc = sort === "ASC";
|
|
318
|
+
|
|
319
|
+
if ((nullFirst && isAsc) || (!nullFirst && !isAsc)) {
|
|
320
|
+
// NULLs naturally come first in this combination
|
|
321
|
+
return `${tableAlias}.[${colName}] ${sort}`;
|
|
322
|
+
} else {
|
|
323
|
+
// Need to force NULL positioning with CASE
|
|
324
|
+
return `CASE WHEN ${tableAlias}.${colName} IS NULL THEN ${nullFirst ? 0 : 1} ELSE ${nullFirst ? 1 : 0} END, ${tableAlias}.${colName} ${sort}`;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
} else {
|
|
328
|
+
// No explicit NULL handling - use database defaults
|
|
329
|
+
if (virtualColumn) {
|
|
330
|
+
const vc = virtualColumn as VirtualColumn;
|
|
331
|
+
return `(
|
|
332
|
+
${vc.function ? `${vc.function}(${vc.params?.join(", ")})` : `${vc.expression}`}
|
|
333
|
+
) ${sort}`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (dbType === "pg") {
|
|
337
|
+
return `${tableAlias}."${colName}" ${sort}`;
|
|
338
|
+
} else if (dbType === "mysql") {
|
|
339
|
+
return `${tableAlias}.${colName} ${sort}`;
|
|
340
|
+
} else {
|
|
341
|
+
return `${tableAlias}.${colName} ${sort}`;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
})
|
|
345
|
+
.join(", ");
|
|
346
|
+
|
|
347
|
+
return `ORDER BY ${orderByList}`;
|
|
348
|
+
}
|
|
349
|
+
return "";
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
export const buildOrderByClauseMSSQL = buildOrderByClauseFp("mssql");
|
|
353
|
+
export const buildOrderByClausePG = buildOrderByClauseFp("pg");
|
|
354
|
+
export const buildOrderByClauseMySQL = buildOrderByClauseFp("mysql");
|
|
355
|
+
|
|
356
|
+
export const filterBasedOnDirective = (
|
|
357
|
+
field: SelectionAnalysis,
|
|
358
|
+
variablesDefinition: VariableDefinition[] = [],
|
|
359
|
+
variables: Record<string, unknown>,
|
|
360
|
+
): boolean => {
|
|
361
|
+
if (field.directives?.length) {
|
|
362
|
+
const skipDirective = field.directives.find(
|
|
363
|
+
(d) => d.name === "skip" && d.arguments?.["if"] !== undefined,
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
if (skipDirective) {
|
|
367
|
+
const valueOfSkipDirective = skipDirective.arguments?.["if"];
|
|
368
|
+
|
|
369
|
+
if (isString(valueOfSkipDirective) && valueOfSkipDirective.startsWith("$")) {
|
|
370
|
+
const variableName = valueOfSkipDirective.substring(1);
|
|
371
|
+
|
|
372
|
+
const variableDefinition = variablesDefinition.find((v) => v.name === variableName);
|
|
373
|
+
|
|
374
|
+
if (!variableDefinition) {
|
|
375
|
+
throw new Error(`Variable ${variableName} not found`);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return !(variables[variableName] ?? variableDefinition.defaultValue ?? true);
|
|
379
|
+
} else if (isBoolean(valueOfSkipDirective)) {
|
|
380
|
+
return !valueOfSkipDirective;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const includeDirective = field.directives.find(
|
|
387
|
+
(d) => d.name === "include" && d.arguments?.["if"] !== undefined,
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
if (includeDirective) {
|
|
391
|
+
const valueOfIncludeDirective = includeDirective.arguments?.["if"];
|
|
392
|
+
|
|
393
|
+
if (isString(valueOfIncludeDirective) && valueOfIncludeDirective.startsWith("$")) {
|
|
394
|
+
const variableName = valueOfIncludeDirective.substring(1);
|
|
395
|
+
|
|
396
|
+
const variableDefinition = variablesDefinition.find((v) => v.name === variableName);
|
|
397
|
+
|
|
398
|
+
if (!variableDefinition) {
|
|
399
|
+
throw new Error(`Variable ${variableName} not found`);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return !!(variables[variableName] ?? variableDefinition.defaultValue ?? false);
|
|
403
|
+
} else if (isBoolean(valueOfIncludeDirective)) {
|
|
404
|
+
return valueOfIncludeDirective;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const whenDirective = field.directives.find(
|
|
411
|
+
(d) =>
|
|
412
|
+
d.name === "when" &&
|
|
413
|
+
(d.arguments?.["and"] !== undefined || d.arguments?.["or"] !== undefined),
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
if (whenDirective) {
|
|
417
|
+
const andArgs = whenDirective.arguments?.["and"] as unknown[] | undefined;
|
|
418
|
+
const orArgs = whenDirective.arguments?.["or"] as unknown[] | undefined;
|
|
419
|
+
|
|
420
|
+
if (andArgs && orArgs) {
|
|
421
|
+
throw new Error('@when directive: "and" and "or" are mutually exclusive');
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const items = andArgs ?? orArgs;
|
|
425
|
+
if (!items || !Array.isArray(items)) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const resolvedValues = items.map((item) => {
|
|
430
|
+
if (isString(item) && item.startsWith("$")) {
|
|
431
|
+
const variableName = item.substring(1);
|
|
432
|
+
const variableDefinition = variablesDefinition.find((v) => v.name === variableName);
|
|
433
|
+
|
|
434
|
+
if (!variableDefinition) {
|
|
435
|
+
throw new Error(`Variable ${variableName} not found`);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return !!(variables[variableName] ?? variableDefinition.defaultValue ?? false);
|
|
439
|
+
} else if (isBoolean(item)) {
|
|
440
|
+
return item;
|
|
441
|
+
}
|
|
442
|
+
return false;
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
return andArgs ? resolvedValues.every(Boolean) : resolvedValues.some(Boolean);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return true;
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
export const processFieldSelectionsFp =
|
|
455
|
+
(dbType: DatabaseType = "pg") =>
|
|
456
|
+
(
|
|
457
|
+
entities: MergedEntities,
|
|
458
|
+
variablesDefinition: VariableDefinition[] = [],
|
|
459
|
+
variables: Record<string, unknown> = {},
|
|
460
|
+
field: SelectionAnalysis,
|
|
461
|
+
tableName: string,
|
|
462
|
+
tableAlias: string,
|
|
463
|
+
level: number,
|
|
464
|
+
buildSubquery: (sel: SelectionAnalysis, level: number) => string,
|
|
465
|
+
selectBuilder: (entry: [name: string, selector: string]) => string,
|
|
466
|
+
quoted = false,
|
|
467
|
+
): string => {
|
|
468
|
+
const selectClauses: [string, string][] = [];
|
|
469
|
+
const subQueries: [string, string][] = [];
|
|
470
|
+
|
|
471
|
+
field.selections
|
|
472
|
+
?.filter((f) => filterBasedOnDirective(f, variablesDefinition, variables))
|
|
473
|
+
?.forEach((sel) => {
|
|
474
|
+
const colName = sel.alias || sel.name;
|
|
475
|
+
|
|
476
|
+
if (sel.selections) {
|
|
477
|
+
subQueries.push([`${colName}`, buildSubquery(sel, level + 1)]);
|
|
478
|
+
} else {
|
|
479
|
+
const virtColumn = entities.isVirtualColumn(tableName, sel.name);
|
|
480
|
+
|
|
481
|
+
if (virtColumn) {
|
|
482
|
+
// Explicit assertion needed due to Column union type inference
|
|
483
|
+
const vc = virtColumn as VirtualColumn;
|
|
484
|
+
if (vc.function) {
|
|
485
|
+
selectClauses.push([`${colName}`, `${vc.function}(${vc.params?.join(", ")})`]);
|
|
486
|
+
} else if (vc.expression) {
|
|
487
|
+
selectClauses.push([`${colName}`, `(${vc.expression})`]);
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
let querySelector = `${tableAlias}.${wrapIf(sel.name, quoted)}`;
|
|
491
|
+
|
|
492
|
+
// Apply all directives using the handler registry
|
|
493
|
+
querySelector = applyDirectives(
|
|
494
|
+
querySelector,
|
|
495
|
+
sel.directives,
|
|
496
|
+
dbType,
|
|
497
|
+
variablesDefinition,
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
selectClauses.push([colName, querySelector]);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
const selectList = [...selectClauses, ...subQueries].map(selectBuilder).join(",\n");
|
|
506
|
+
|
|
507
|
+
return selectList;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
export const processFieldSelectionsPG = processFieldSelectionsFp("pg");
|
|
511
|
+
export const processFieldSelectionsMSSQL = processFieldSelectionsFp("mssql");
|
|
512
|
+
export const processFieldSelectionsMySQL = processFieldSelectionsFp("mysql");
|
|
513
|
+
|
|
514
|
+
// Helper function to check if a field is an aggregation
|
|
515
|
+
export const isAggregationField = (fieldName: string): boolean => {
|
|
516
|
+
return ["count", "min", "max", "sum", "avg"].includes(fieldName);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// Helper function to extract aggregation info from selections
|
|
520
|
+
export const extractAggregationInfo = (
|
|
521
|
+
field: SelectionAnalysis,
|
|
522
|
+
tableAlias: string,
|
|
523
|
+
): GroupByInfo | null => {
|
|
524
|
+
const groupBy = field.arguments?.groupBy;
|
|
525
|
+
if (!groupBy || !Array.isArray(groupBy)) {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const aggregations: AggregationField[] = [];
|
|
530
|
+
const keys: SelectionAnalysis[] = [];
|
|
531
|
+
|
|
532
|
+
let keyResolved = "";
|
|
533
|
+
let hasItems = false;
|
|
534
|
+
|
|
535
|
+
field.selections?.forEach((sel) => {
|
|
536
|
+
if (sel.name === "items") {
|
|
537
|
+
hasItems = true;
|
|
538
|
+
} else if (sel.name === "key") {
|
|
539
|
+
keyResolved = sel.alias || sel.name;
|
|
540
|
+
|
|
541
|
+
// If 'key' is selected, we need to include all groupBy fields
|
|
542
|
+
sel.selections?.forEach((keySel) => {
|
|
543
|
+
if (groupBy.includes(keySel.name)) {
|
|
544
|
+
keys.push(keySel);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
} else if (isAggregationField(sel.name)) {
|
|
548
|
+
if (sel.name === "count") {
|
|
549
|
+
aggregations.push({
|
|
550
|
+
name: "count",
|
|
551
|
+
alias: "count",
|
|
552
|
+
fieldName: "*",
|
|
553
|
+
fieldAlias: "*",
|
|
554
|
+
nameResolved: sel.alias || "count",
|
|
555
|
+
});
|
|
556
|
+
} else {
|
|
557
|
+
const fieldSelected = sel.selections?.[0];
|
|
558
|
+
|
|
559
|
+
// For min, max, sum, avg - extract the field they're aggregating
|
|
560
|
+
const fieldName = fieldSelected?.name;
|
|
561
|
+
const fieldAlias = fieldSelected?.alias;
|
|
562
|
+
if (fieldName) {
|
|
563
|
+
aggregations.push({
|
|
564
|
+
name: sel.name,
|
|
565
|
+
fieldName,
|
|
566
|
+
fieldAlias: fieldAlias || fieldName,
|
|
567
|
+
alias: `${sel.name}_${fieldName}`,
|
|
568
|
+
nameResolved: sel.alias || sel.name,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
return {
|
|
576
|
+
groupByFields: groupBy,
|
|
577
|
+
aggregations,
|
|
578
|
+
hasItems,
|
|
579
|
+
keyResolved,
|
|
580
|
+
hasKey: keys.length > 0,
|
|
581
|
+
keys,
|
|
582
|
+
cteAlias: `${tableAlias}_agg`,
|
|
583
|
+
};
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// Helper function to check if a query is for a single item
|
|
587
|
+
export const isSingleQuery = (fieldName: string): boolean => fieldName.endsWith("_single");
|
|
588
|
+
|
|
589
|
+
// Helper to convert variable reference to positional placeholder
|
|
590
|
+
const toPositionalPlaceholder = (
|
|
591
|
+
value: unknown,
|
|
592
|
+
variablesDefinition: VariableDefinition[],
|
|
593
|
+
dbType: DatabaseType,
|
|
594
|
+
): string | null => {
|
|
595
|
+
if (isString(value) && value.startsWith("$")) {
|
|
596
|
+
const varName = value.substring(1);
|
|
597
|
+
const index = variablesDefinition.findIndex((v) => v.name === varName);
|
|
598
|
+
if (index >= 0) {
|
|
599
|
+
return `${mappingDbTypeCharVar[dbType]}${index + 1}`;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return null;
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// Factory function for pagination clause builders
|
|
606
|
+
export const buildPaginationClauseFp =
|
|
607
|
+
(dbType: DatabaseType = "pg") =>
|
|
608
|
+
(field: SelectionAnalysis, variablesDefinition: VariableDefinition[] = []): string => {
|
|
609
|
+
const args = field.arguments;
|
|
610
|
+
|
|
611
|
+
// MSSQL requires ORDER BY for pagination
|
|
612
|
+
if (
|
|
613
|
+
dbType === "mssql" &&
|
|
614
|
+
(!args || args["limit"] === undefined || args["orderBy"] === undefined)
|
|
615
|
+
) {
|
|
616
|
+
return "";
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (!args || args["limit"] === undefined) {
|
|
620
|
+
return "";
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// Convert limit variable reference to positional placeholder
|
|
624
|
+
const limitPlaceholder = toPositionalPlaceholder(args["limit"], variablesDefinition, dbType);
|
|
625
|
+
if (!limitPlaceholder) {
|
|
626
|
+
return ""; // Limit must be a variable reference
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Convert offset variable reference to positional placeholder (default to 0 if not provided)
|
|
630
|
+
const offsetPlaceholder = args["offset"]
|
|
631
|
+
? toPositionalPlaceholder(args["offset"], variablesDefinition, dbType)
|
|
632
|
+
: "0";
|
|
633
|
+
|
|
634
|
+
// Return database-specific syntax
|
|
635
|
+
return dbType === "mssql"
|
|
636
|
+
? `OFFSET ${offsetPlaceholder} ROWS FETCH NEXT ${limitPlaceholder} ROWS ONLY`
|
|
637
|
+
: `LIMIT ${limitPlaceholder} OFFSET ${offsetPlaceholder}`;
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
export const buildPaginationClausePG = buildPaginationClauseFp("pg");
|
|
641
|
+
export const buildPaginationClauseMSSQL = buildPaginationClauseFp("mssql");
|
|
642
|
+
export const buildPaginationClauseMySQL = buildPaginationClauseFp("mysql");
|