@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,272 @@
|
|
|
1
|
+
import { isString } from "es-toolkit";
|
|
2
|
+
|
|
3
|
+
import type { RemoteRESTResolved } from "../remoteREST/types";
|
|
4
|
+
import type { RemoteSchemaResolved } from "../remoteSchemas/types";
|
|
5
|
+
import type {
|
|
6
|
+
Auth,
|
|
7
|
+
Database,
|
|
8
|
+
MessageQueue,
|
|
9
|
+
Operations,
|
|
10
|
+
Permissions,
|
|
11
|
+
TableFilter,
|
|
12
|
+
VirtualColumns,
|
|
13
|
+
} from "../types/configuration";
|
|
14
|
+
import type { Column, ProcedureResolver, TableResolver, Tables } from "../types/db";
|
|
15
|
+
|
|
16
|
+
import { getDatabaseStructure } from "./metadata/structure";
|
|
17
|
+
import { buildProcedureResolver, buildTableResolver } from "./transformers/data-transformers";
|
|
18
|
+
import { genResolverName } from "./transformers/genResolverName";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* High-level database operations that combine multiple lower-level operations
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export const getDatabasesStructure = async (
|
|
25
|
+
databases: Database[],
|
|
26
|
+
auth?: Auth,
|
|
27
|
+
fetchStructure = getDatabaseStructure,
|
|
28
|
+
) => {
|
|
29
|
+
const entities: TableResolver[] = [];
|
|
30
|
+
const enhancedStoredProcedures: ProcedureResolver[] = [];
|
|
31
|
+
|
|
32
|
+
// The auth user table holds the password hash and must never be served via
|
|
33
|
+
// the generated API. Its resolver key matches t.schemaName, which is always
|
|
34
|
+
// computed with the default `{schema}_{name}` naming (see enrichTable).
|
|
35
|
+
const authUserKey = auth?.enabled
|
|
36
|
+
? genResolverName(auth.schema ?? "auth", "user", "table")
|
|
37
|
+
: undefined;
|
|
38
|
+
|
|
39
|
+
for (const db of databases) {
|
|
40
|
+
const { tables, storedProcedures } = await fetchStructure(db);
|
|
41
|
+
|
|
42
|
+
const tablesToAdd = tables
|
|
43
|
+
.reduce<Tables>((acc, t) => {
|
|
44
|
+
if (authUserKey && t.schemaName === authUserKey) return acc;
|
|
45
|
+
if (db.schema?.excludedTables.includes(t.schemaName)) return acc;
|
|
46
|
+
|
|
47
|
+
const tableOverride = db.schema?.database[t.schemaName];
|
|
48
|
+
|
|
49
|
+
if (!tableOverride) {
|
|
50
|
+
acc.push(t);
|
|
51
|
+
|
|
52
|
+
return acc;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (tableOverride.description !== undefined) {
|
|
56
|
+
t.tableDescription = tableOverride.description;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const [colName, desc] of Object.entries(tableOverride.columnDescriptions)) {
|
|
60
|
+
const column = t.columns.find((col) => col.name.toLowerCase() === colName.toLowerCase());
|
|
61
|
+
if (column) column.description = desc;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (tableOverride.columns.length) {
|
|
65
|
+
// Mix database columns with virtual columns from configuration
|
|
66
|
+
t.columns = [...t.columns, ...tableOverride.columns] as Column[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (tableOverride.relationships.length) {
|
|
70
|
+
const additionalForeignKeys = tableOverride.relationships.map((fk) => {
|
|
71
|
+
const toTable = tables.find(
|
|
72
|
+
(t) =>
|
|
73
|
+
`${fk.schema}_${fk.name}`.toLowerCase() === `${t.schema}_${t.name}`.toLowerCase(),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (!toTable) {
|
|
77
|
+
throw new Error(`Referenced table ${fk.schema}_${fk.name} not found`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
dashedName: `${fk.schema}_${fk.name}`,
|
|
82
|
+
schema: toTable.schema,
|
|
83
|
+
name: toTable.name,
|
|
84
|
+
columns: fk.columns.map((c) => {
|
|
85
|
+
const target = toTable.columns.find(
|
|
86
|
+
(col) => col.name.toLowerCase() === c.target.toLowerCase(),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (!target) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Referenced column ${c.target} not found in table ${toTable.name}`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const tableColumn = t.columns.find(
|
|
96
|
+
(col) => col.name.toLowerCase() === c.source.toLowerCase(),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (!tableColumn) {
|
|
100
|
+
throw new Error(`Column ${c.source} not found in table ${t.name}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
source: tableColumn.name,
|
|
105
|
+
target: target.name,
|
|
106
|
+
};
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (additionalForeignKeys.length) {
|
|
112
|
+
t.foreignKeys = [...t.foreignKeys, ...additionalForeignKeys];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
acc.push(t);
|
|
117
|
+
|
|
118
|
+
return acc;
|
|
119
|
+
}, [])
|
|
120
|
+
.map((t) => buildTableResolver(tables, t, db));
|
|
121
|
+
|
|
122
|
+
const storedProceduresToAdd = storedProcedures.map((sp) => buildProcedureResolver(sp, db));
|
|
123
|
+
|
|
124
|
+
entities.push(...tablesToAdd);
|
|
125
|
+
enhancedStoredProcedures.push(...storedProceduresToAdd);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { tables: entities, storedProcedures: enhancedStoredProcedures };
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type EntitiesOfRole = {
|
|
132
|
+
tables: TableResolver[];
|
|
133
|
+
storedProcedures: ProcedureResolver[];
|
|
134
|
+
queues: MessageQueue[];
|
|
135
|
+
operations: Operations;
|
|
136
|
+
remoteSchemas: RemoteSchemaResolved[];
|
|
137
|
+
remoteREST: RemoteRESTResolved[];
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Filters an array-shaped collection by a role's permission entry: `"ALL"`
|
|
142
|
+
* keeps everything, a `string[]` keeps items whose name (case-insensitive) is
|
|
143
|
+
* listed, anything else (undefined / malformed) keeps nothing. RBAC fails
|
|
144
|
+
* closed — an unrecognized permission shape grants no access.
|
|
145
|
+
*/
|
|
146
|
+
const filterByPermission = <T>(
|
|
147
|
+
items: T[],
|
|
148
|
+
permission: "ALL" | string[] | undefined,
|
|
149
|
+
getName: (item: T) => string,
|
|
150
|
+
): T[] => {
|
|
151
|
+
if (permission === "ALL") return items;
|
|
152
|
+
if (!Array.isArray(permission)) return [];
|
|
153
|
+
const allowed = permission.map((name) => name.toLowerCase());
|
|
154
|
+
return items.filter((item) => allowed.includes(getName(item).toLowerCase()));
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Record-keyed counterpart of {@link filterByPermission} for name-keyed
|
|
159
|
+
* collections (operations). Same `"ALL"` / allowlist / fail-closed rule.
|
|
160
|
+
*/
|
|
161
|
+
const filterRecordByPermission = <T>(
|
|
162
|
+
items: Record<string, T>,
|
|
163
|
+
permission: "ALL" | string[] | undefined,
|
|
164
|
+
): Record<string, T> => {
|
|
165
|
+
if (permission === "ALL") return items;
|
|
166
|
+
if (!Array.isArray(permission)) return {};
|
|
167
|
+
const allowed = permission.map((name) => name.toLowerCase());
|
|
168
|
+
return Object.fromEntries(
|
|
169
|
+
Object.entries(items).filter(([name]) => allowed.includes(name.toLowerCase())),
|
|
170
|
+
);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const sourcesForEachRole = (
|
|
174
|
+
tables: TableResolver[],
|
|
175
|
+
storedProcedures: ProcedureResolver[],
|
|
176
|
+
queues: MessageQueue[],
|
|
177
|
+
operations: Operations,
|
|
178
|
+
permissionsMapping: Permissions = {},
|
|
179
|
+
remoteSchemas: RemoteSchemaResolved[] = [],
|
|
180
|
+
remoteREST: RemoteRESTResolved[] = [],
|
|
181
|
+
) =>
|
|
182
|
+
Object.entries(permissionsMapping).reduce<Record<string, EntitiesOfRole>>(
|
|
183
|
+
(acc, [role, permissions]) => {
|
|
184
|
+
// Lowercase-keyed view of permissions.tables so filter and column lookup
|
|
185
|
+
// see the same normalized shape. Without this, an uppercase permission
|
|
186
|
+
// key would pass the filter step but crash the column-allowlist lookup.
|
|
187
|
+
const permissionsTablesByLowerKey = !isString(permissions.tables)
|
|
188
|
+
? Object.fromEntries(
|
|
189
|
+
Object.entries(permissions.tables).map(([k, v]) => [k.toLowerCase(), v]),
|
|
190
|
+
)
|
|
191
|
+
: null;
|
|
192
|
+
|
|
193
|
+
// Object-form permissions list the allowed tables as keys; "ALL" (the only
|
|
194
|
+
// string form left after zod normalization) keeps every table.
|
|
195
|
+
const allowedTables = filterByPermission(
|
|
196
|
+
tables,
|
|
197
|
+
permissionsTablesByLowerKey ? Object.keys(permissionsTablesByLowerKey) : "ALL",
|
|
198
|
+
(t) => t.resolverName,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const filteredTables: TableResolver[] = allowedTables.map((t) => {
|
|
202
|
+
let allowedColumns: VirtualColumns = t.columns as VirtualColumns;
|
|
203
|
+
let rolePermission: TableFilter | undefined;
|
|
204
|
+
|
|
205
|
+
if (permissionsTablesByLowerKey) {
|
|
206
|
+
const tablePerm = permissionsTablesByLowerKey[t.resolverName.toLowerCase()]!;
|
|
207
|
+
|
|
208
|
+
if (isString(tablePerm.columns) && tablePerm.columns === "ALL") {
|
|
209
|
+
allowedColumns = t.columns as VirtualColumns;
|
|
210
|
+
} else {
|
|
211
|
+
const columnsList = tablePerm.columns.map((col: string) => col.toLowerCase());
|
|
212
|
+
|
|
213
|
+
allowedColumns = t.columns.filter((c) =>
|
|
214
|
+
columnsList.includes(c.name.toLowerCase()),
|
|
215
|
+
) as VirtualColumns;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
rolePermission = { filter: tablePerm.filter, orderBy: tablePerm.orderBy };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
...t,
|
|
223
|
+
columns: allowedColumns,
|
|
224
|
+
rolePermission,
|
|
225
|
+
relationships: t.relationships.filter(
|
|
226
|
+
(fk) =>
|
|
227
|
+
allowedTables.find((t) => t.resolverName === fk.fromInternalName) &&
|
|
228
|
+
allowedTables.find((t) => t.resolverName === fk.toInternalName),
|
|
229
|
+
),
|
|
230
|
+
relationshipsReversed: t.relationshipsReversed.filter(
|
|
231
|
+
(fk) =>
|
|
232
|
+
allowedTables.find((t) => t.resolverName === fk.fromInternalName) &&
|
|
233
|
+
allowedTables.find((t) => t.resolverName === fk.toInternalName),
|
|
234
|
+
),
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const filteredStoredProcedures = filterByPermission(
|
|
239
|
+
storedProcedures,
|
|
240
|
+
permissions.storedProcedures,
|
|
241
|
+
(sp) => sp.name,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const filteredQueues = filterByPermission(queues, permissions.queues, (q) => q.name);
|
|
245
|
+
|
|
246
|
+
const filteredOperations = filterRecordByPermission(operations, permissions.operations);
|
|
247
|
+
|
|
248
|
+
const filteredRemoteSchemas = filterByPermission(
|
|
249
|
+
remoteSchemas,
|
|
250
|
+
permissions.remoteSchemas,
|
|
251
|
+
(rs) => rs.config.name,
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
const filteredRemoteREST = filterByPermission(
|
|
255
|
+
remoteREST,
|
|
256
|
+
permissions.remoteREST,
|
|
257
|
+
(rr) => rr.config.name,
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
acc[role] = {
|
|
261
|
+
tables: filteredTables,
|
|
262
|
+
storedProcedures: filteredStoredProcedures,
|
|
263
|
+
queues: filteredQueues,
|
|
264
|
+
operations: filteredOperations,
|
|
265
|
+
remoteSchemas: filteredRemoteSchemas,
|
|
266
|
+
remoteREST: filteredRemoteREST,
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
return acc;
|
|
270
|
+
},
|
|
271
|
+
{},
|
|
272
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Core database operations
|
|
2
|
+
export { executeQuery, executeQueryJSON, callStoredProcedure } from "./core/executor";
|
|
3
|
+
|
|
4
|
+
export { generateSQL } from "./core/query-builder";
|
|
5
|
+
|
|
6
|
+
export { databaseAdapters } from "./core/function-mapping";
|
|
7
|
+
|
|
8
|
+
// Database metadata operations
|
|
9
|
+
export { getDatabaseStructure, getViewsFromDB } from "./metadata/structure";
|
|
10
|
+
|
|
11
|
+
// Authentication operations
|
|
12
|
+
export {
|
|
13
|
+
createAuthTables,
|
|
14
|
+
getLoginFn,
|
|
15
|
+
checkUserCredentials,
|
|
16
|
+
insertAuthUser,
|
|
17
|
+
verifyAuthTablesExist,
|
|
18
|
+
} from "./auth/auth-operations";
|
|
19
|
+
|
|
20
|
+
// Data transformation operations
|
|
21
|
+
export {
|
|
22
|
+
buildRelationshipResolver,
|
|
23
|
+
buildTableResolver,
|
|
24
|
+
buildProcedureResolver,
|
|
25
|
+
} from "./transformers/data-transformers";
|
|
26
|
+
|
|
27
|
+
// High-level operations
|
|
28
|
+
export { getDatabasesStructure, sourcesForEachRole } from "./high-level-operations";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Database } from "../../types/configuration";
|
|
2
|
+
|
|
3
|
+
import { databaseAdapters } from "../core/function-mapping";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Database metadata and structure retrieval functions
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const getDatabaseStructure = async (db: Database) =>
|
|
10
|
+
databaseAdapters[db.type].getDatabaseStructure(db);
|
|
11
|
+
|
|
12
|
+
export const getViewsFromDB = async (db: Database) => databaseAdapters[db.type].getViews(db);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Database, DatabaseType } from "../../types/configuration";
|
|
2
|
+
import type { DatabaseStructure, View } from "../../types/db";
|
|
3
|
+
import type { GenerateCreateTablesSQL } from "./generateCreateTable";
|
|
4
|
+
import type { GenerateCreateViewsSQL } from "./generateCreateView";
|
|
5
|
+
import type { GenerateInsertSQL } from "./generateInsert";
|
|
6
|
+
|
|
7
|
+
import { buildTableResolver, getDatabaseStructure, getViewsFromDB } from "..";
|
|
8
|
+
import { generateCreateTablesSQL } from "./generateCreateTable";
|
|
9
|
+
import {
|
|
10
|
+
generateCreateViewsMSSQL,
|
|
11
|
+
generateCreateViewsMySQL,
|
|
12
|
+
generateCreateViewsPostgreSQL,
|
|
13
|
+
} from "./generateCreateView";
|
|
14
|
+
import {
|
|
15
|
+
generateInsertSQLMSSQL,
|
|
16
|
+
generateInsertSQLMySQL,
|
|
17
|
+
generateInsertSQLPostgreSQL,
|
|
18
|
+
} from "./generateInsert";
|
|
19
|
+
|
|
20
|
+
const mapping: Record<
|
|
21
|
+
DatabaseType,
|
|
22
|
+
{
|
|
23
|
+
getTablesFromDB: (db: Database) => Promise<DatabaseStructure>;
|
|
24
|
+
getViewsFromDB: (db: Database) => Promise<View[]>;
|
|
25
|
+
generateCreateTablesSQL: GenerateCreateTablesSQL;
|
|
26
|
+
generateCreateViewsSQL: GenerateCreateViewsSQL;
|
|
27
|
+
generateInsertsSQL: GenerateInsertSQL;
|
|
28
|
+
}
|
|
29
|
+
> = {
|
|
30
|
+
mssql: {
|
|
31
|
+
getTablesFromDB: getDatabaseStructure,
|
|
32
|
+
getViewsFromDB: getViewsFromDB,
|
|
33
|
+
generateCreateTablesSQL,
|
|
34
|
+
generateCreateViewsSQL: generateCreateViewsMSSQL,
|
|
35
|
+
generateInsertsSQL: generateInsertSQLMSSQL,
|
|
36
|
+
},
|
|
37
|
+
pg: {
|
|
38
|
+
getTablesFromDB: getDatabaseStructure,
|
|
39
|
+
getViewsFromDB: getViewsFromDB,
|
|
40
|
+
generateCreateTablesSQL,
|
|
41
|
+
generateCreateViewsSQL: generateCreateViewsPostgreSQL,
|
|
42
|
+
generateInsertsSQL: generateInsertSQLPostgreSQL,
|
|
43
|
+
},
|
|
44
|
+
mysql: {
|
|
45
|
+
getTablesFromDB: getDatabaseStructure,
|
|
46
|
+
getViewsFromDB: getViewsFromDB,
|
|
47
|
+
generateCreateTablesSQL,
|
|
48
|
+
generateCreateViewsSQL: generateCreateViewsMySQL,
|
|
49
|
+
generateInsertsSQL: generateInsertSQLMySQL,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const convertDatabase = async (
|
|
54
|
+
dbFrom: Database,
|
|
55
|
+
dbToType: DatabaseType,
|
|
56
|
+
tables: "ALL" | string[] = "ALL",
|
|
57
|
+
) => {
|
|
58
|
+
const databaseFrom = mapping[dbFrom.type];
|
|
59
|
+
const databaseTo = mapping[dbToType];
|
|
60
|
+
|
|
61
|
+
const dbTo: Database = {
|
|
62
|
+
...dbFrom,
|
|
63
|
+
type: dbToType,
|
|
64
|
+
name: `${dbFrom.name}_converted_to_${dbToType}`,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const fromTable = await databaseFrom.getTablesFromDB(dbFrom);
|
|
68
|
+
// const fromViews = await databaseFrom.getViewsFromDB(ciFrom);
|
|
69
|
+
|
|
70
|
+
const tablesToConvert =
|
|
71
|
+
tables === "ALL"
|
|
72
|
+
? fromTable.tables
|
|
73
|
+
: fromTable.tables.filter((table) => tables.includes(table.name));
|
|
74
|
+
|
|
75
|
+
const convertedTables = databaseTo.generateCreateTablesSQL(dbTo, tablesToConvert);
|
|
76
|
+
// const convertedViews = databaseTo.generateCreateViewsSQL(fromViews);
|
|
77
|
+
|
|
78
|
+
const inserts = tablesToConvert.map((t) =>
|
|
79
|
+
databaseTo.generateInsertsSQL(buildTableResolver(fromTable.tables, t, dbFrom), [
|
|
80
|
+
{
|
|
81
|
+
product_id: 1,
|
|
82
|
+
sku: "ELEC-001",
|
|
83
|
+
name: "Wireless Keyboard",
|
|
84
|
+
description: "Ergonomic wireless keyboard",
|
|
85
|
+
price: 49.99,
|
|
86
|
+
is_active: 1,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
product_id: 2,
|
|
90
|
+
sku: "ELEC-002",
|
|
91
|
+
name: "USB-C Hub",
|
|
92
|
+
description: "7-port USB-C hub",
|
|
93
|
+
price: 29.99,
|
|
94
|
+
is_active: 1,
|
|
95
|
+
},
|
|
96
|
+
]),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return [convertedTables, inserts].join("\n\n");
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
await Bun.write(
|
|
103
|
+
"converted.sql",
|
|
104
|
+
await convertDatabase(
|
|
105
|
+
{
|
|
106
|
+
enabled: true,
|
|
107
|
+
name: "default",
|
|
108
|
+
type: "mssql",
|
|
109
|
+
connection: {
|
|
110
|
+
host: "localhost",
|
|
111
|
+
port: 1433,
|
|
112
|
+
user: "test",
|
|
113
|
+
password: "test",
|
|
114
|
+
database: "test",
|
|
115
|
+
},
|
|
116
|
+
fieldNaming: "{schema}_{name}",
|
|
117
|
+
},
|
|
118
|
+
"pg",
|
|
119
|
+
["products"],
|
|
120
|
+
),
|
|
121
|
+
);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { uniq } from "es-toolkit";
|
|
2
|
+
|
|
3
|
+
import type { Database, DatabaseType } from "../../../types/configuration";
|
|
4
|
+
import type { TableResolver, Tables } from "../../../types/db";
|
|
5
|
+
|
|
6
|
+
import { buildTableResolver } from "../../transformers/data-transformers";
|
|
7
|
+
import { generateSchemaCreationSQL } from "../generateSchemaCreation";
|
|
8
|
+
import { splitInternalName } from "../utils";
|
|
9
|
+
|
|
10
|
+
const typeMapping: Record<DatabaseType, Record<string, string>> = {
|
|
11
|
+
mssql: {
|
|
12
|
+
varchar: "VARCHAR(MAX)",
|
|
13
|
+
int: "INT",
|
|
14
|
+
smallint: "SMALLINT",
|
|
15
|
+
nvarchar: "NVARCHAR(MAX)",
|
|
16
|
+
datetime: "DATETIME",
|
|
17
|
+
smalldatetime: "DATETIME",
|
|
18
|
+
image: "IMAGE",
|
|
19
|
+
uniqueidentifier: "UNIQUEIDENTIFIER",
|
|
20
|
+
tinyint: "TINYINT",
|
|
21
|
+
},
|
|
22
|
+
pg: {
|
|
23
|
+
varchar: "VARCHAR",
|
|
24
|
+
int: "INTEGER",
|
|
25
|
+
smallint: "SMALLINT",
|
|
26
|
+
nvarchar: "VARCHAR",
|
|
27
|
+
datetime: "TIMESTAMP",
|
|
28
|
+
smalldatetime: "TIMESTAMP",
|
|
29
|
+
image: "BYTEA",
|
|
30
|
+
uniqueidentifier: "UUID",
|
|
31
|
+
tinyint: "SMALLINT",
|
|
32
|
+
},
|
|
33
|
+
mysql: {
|
|
34
|
+
varchar: "VARCHAR(255)",
|
|
35
|
+
int: "INT",
|
|
36
|
+
smallint: "SMALLINT",
|
|
37
|
+
nvarchar: "VARCHAR(255)",
|
|
38
|
+
datetime: "DATETIME",
|
|
39
|
+
smalldatetime: "DATETIME",
|
|
40
|
+
image: "BLOB",
|
|
41
|
+
uniqueidentifier: "CHAR(36)",
|
|
42
|
+
tinyint: "TINYINT",
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type GenerateCreateTableSQLParameters = {
|
|
47
|
+
schemaCreation?: boolean;
|
|
48
|
+
schemaCreationIfExists?: boolean;
|
|
49
|
+
tableCreationIfExists?: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const generateCreateTableSQL =
|
|
53
|
+
(toDb: DatabaseType) =>
|
|
54
|
+
(
|
|
55
|
+
table: TableResolver,
|
|
56
|
+
{
|
|
57
|
+
schemaCreation = true,
|
|
58
|
+
schemaCreationIfExists = true,
|
|
59
|
+
tableCreationIfExists = true,
|
|
60
|
+
}: GenerateCreateTableSQLParameters = {},
|
|
61
|
+
) => {
|
|
62
|
+
const columnsSQL = table.columns
|
|
63
|
+
.map((column) => {
|
|
64
|
+
const targetType = typeMapping[toDb][column.dataType] || column.dataType.toUpperCase();
|
|
65
|
+
if (toDb === "mssql") {
|
|
66
|
+
return ` ${column.name} ${targetType}`;
|
|
67
|
+
} else if (toDb === "mysql") {
|
|
68
|
+
return ` \`${column.name}\` ${targetType}${column.isNullable ? " NULL" : " NOT NULL"}`;
|
|
69
|
+
} else {
|
|
70
|
+
return ` "${column.name}" ${targetType}${column.isNullable ? " NULL" : " NOT NULL"}`;
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
.join(",\n");
|
|
74
|
+
|
|
75
|
+
let sql = "";
|
|
76
|
+
|
|
77
|
+
const parsed = splitInternalName(`${table.schema}_${table.name}`, true);
|
|
78
|
+
|
|
79
|
+
// Schema creation
|
|
80
|
+
if (schemaCreation) {
|
|
81
|
+
sql += generateSchemaCreationSQL(toDb)(table.schema, schemaCreationIfExists);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Table creation
|
|
85
|
+
if (toDb === "pg") {
|
|
86
|
+
sql += `CREATE TABLE ${tableCreationIfExists ? "IF NOT EXISTS " : ""}${parsed?.nameDottedQuoted} (\n${columnsSQL}\n);`;
|
|
87
|
+
} else if (toDb === "mssql") {
|
|
88
|
+
if (tableCreationIfExists) {
|
|
89
|
+
sql += `IF NOT EXISTS (SELECT * FROM sys.tables WHERE object_id = OBJECT_ID('${parsed?.nameDotted}'))\n`;
|
|
90
|
+
}
|
|
91
|
+
sql += `CREATE TABLE ${parsed?.nameDotted} (\n${columnsSQL}\n);`;
|
|
92
|
+
} else if (toDb === "mysql") {
|
|
93
|
+
// Generate backtick version of dotted name
|
|
94
|
+
if (parsed?.nameDotted) {
|
|
95
|
+
const parts = parsed.nameDotted.split(".");
|
|
96
|
+
const dottedBacktickName = parts.map((p) => `\`${p}\``).join(".");
|
|
97
|
+
sql += `CREATE TABLE ${tableCreationIfExists ? "IF NOT EXISTS " : ""}${dottedBacktickName} (\n${columnsSQL}\n);`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return sql;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type GenerateCreateTableSQL = ReturnType<typeof generateCreateTableSQL>;
|
|
105
|
+
|
|
106
|
+
export const generateCreateTableMSSQL = generateCreateTableSQL("mssql");
|
|
107
|
+
export const generateCreateTablePostgreSQL = generateCreateTableSQL("pg");
|
|
108
|
+
export const generateCreateTableMySQL = generateCreateTableSQL("mysql");
|
|
109
|
+
|
|
110
|
+
export const generateCreateTablesSQL = (
|
|
111
|
+
db: Database,
|
|
112
|
+
tables: Tables,
|
|
113
|
+
options?: GenerateCreateTableSQLParameters,
|
|
114
|
+
) => {
|
|
115
|
+
const schemas = uniq(tables.map((table) => table.schema)).filter(
|
|
116
|
+
(schema) => !!schema,
|
|
117
|
+
) as string[];
|
|
118
|
+
|
|
119
|
+
return [
|
|
120
|
+
...schemas.map((schema) => generateSchemaCreationSQL(db.type)(schema, true)),
|
|
121
|
+
tables
|
|
122
|
+
.filter((table) => table.entityType === "table")
|
|
123
|
+
.map((table) =>
|
|
124
|
+
generateCreateTableSQL(db.type)(buildTableResolver([table], table, db), {
|
|
125
|
+
...options,
|
|
126
|
+
schemaCreation: false,
|
|
127
|
+
}),
|
|
128
|
+
)
|
|
129
|
+
.join("\n\n"),
|
|
130
|
+
].join("\n\n");
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export type GenerateCreateTablesSQL = typeof generateCreateTablesSQL;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { DatabaseType } from "../../../types/configuration";
|
|
2
|
+
import type { View } from "../../../types/db";
|
|
3
|
+
|
|
4
|
+
import { generateSchemaCreationSQL } from "../generateSchemaCreation";
|
|
5
|
+
import { convertMSSQLViewToPostgres } from "../mssqlToPostgres/convertView";
|
|
6
|
+
import { splitInternalName } from "../utils";
|
|
7
|
+
|
|
8
|
+
export type GenerateCreateViewSQLParameters = {
|
|
9
|
+
schemaCreation?: boolean;
|
|
10
|
+
schemaCreationIfExists?: boolean;
|
|
11
|
+
viewCreationIfExists?: boolean;
|
|
12
|
+
replaceExisting?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const transformViewDefinition = (definition: string, toDb: DatabaseType): string => {
|
|
16
|
+
if (toDb === "pg") return convertMSSQLViewToPostgres(definition);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
definition
|
|
20
|
+
// Remove CREATE VIEW [...] AS part if present
|
|
21
|
+
.replace(/CREATE\s+VIEW\s+.*?AS\s+/i, "")
|
|
22
|
+
.trim()
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const generateCreateViewSQL =
|
|
27
|
+
(toDb: DatabaseType) =>
|
|
28
|
+
(
|
|
29
|
+
view: View,
|
|
30
|
+
{
|
|
31
|
+
schemaCreation = true,
|
|
32
|
+
schemaCreationIfExists = true,
|
|
33
|
+
viewCreationIfExists = true,
|
|
34
|
+
replaceExisting = false,
|
|
35
|
+
}: GenerateCreateViewSQLParameters = {},
|
|
36
|
+
) => {
|
|
37
|
+
let sql = "";
|
|
38
|
+
const parsed = splitInternalName(view.name, true);
|
|
39
|
+
|
|
40
|
+
if (!parsed) return "";
|
|
41
|
+
|
|
42
|
+
// Schema creation if needed
|
|
43
|
+
if (schemaCreation) {
|
|
44
|
+
sql += generateSchemaCreationSQL(toDb)(parsed.schema, schemaCreationIfExists);
|
|
45
|
+
sql += "\n\n";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const transformedDefinition = transformViewDefinition(view.definition, toDb);
|
|
49
|
+
|
|
50
|
+
// View creation
|
|
51
|
+
if (toDb === "pg") {
|
|
52
|
+
if (replaceExisting) {
|
|
53
|
+
sql += `DROP VIEW IF EXISTS "${parsed.schema}"."${parsed.name}";\n`;
|
|
54
|
+
sql += `CREATE VIEW "${parsed.schema}"."${parsed.name}" AS\n${transformedDefinition};`;
|
|
55
|
+
} else if (viewCreationIfExists) {
|
|
56
|
+
sql += `CREATE OR REPLACE VIEW "${parsed.schema}"."${parsed.name}" AS\n${transformedDefinition};`;
|
|
57
|
+
}
|
|
58
|
+
} else if (toDb === "mssql") {
|
|
59
|
+
if (viewCreationIfExists || replaceExisting) {
|
|
60
|
+
sql += `IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID('${parsed.nameDotted}'))\n`;
|
|
61
|
+
if (replaceExisting) {
|
|
62
|
+
sql += ` DROP VIEW ${parsed.nameDotted};\n`;
|
|
63
|
+
} else {
|
|
64
|
+
sql += ` RETURN;\n`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
sql += `CREATE VIEW ${parsed.nameDotted} AS\n${transformedDefinition};`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return sql;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type GenerateCreateViewSQL = ReturnType<typeof generateCreateViewSQL>;
|
|
74
|
+
|
|
75
|
+
export const generateCreateViewMSSQL = generateCreateViewSQL("mssql");
|
|
76
|
+
export const generateCreateViewPostgreSQL = generateCreateViewSQL("pg");
|
|
77
|
+
|
|
78
|
+
export const generateCreateViewsSQL =
|
|
79
|
+
(dbType: DatabaseType) => (views: View[], options?: GenerateCreateViewSQLParameters) => {
|
|
80
|
+
const schemas = [...new Set(views.map((view) => splitInternalName(view.name)?.schema))].filter(
|
|
81
|
+
Boolean,
|
|
82
|
+
) as string[];
|
|
83
|
+
|
|
84
|
+
return [
|
|
85
|
+
...schemas.map((schema) => generateSchemaCreationSQL(dbType)(schema)),
|
|
86
|
+
views
|
|
87
|
+
.map((view) =>
|
|
88
|
+
generateCreateViewSQL(dbType)(view, {
|
|
89
|
+
...options,
|
|
90
|
+
schemaCreation: false,
|
|
91
|
+
}),
|
|
92
|
+
)
|
|
93
|
+
.join("\n\n"),
|
|
94
|
+
].join("\n\n");
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type GenerateCreateViewsSQL = ReturnType<typeof generateCreateViewsSQL>;
|
|
98
|
+
|
|
99
|
+
export const generateCreateViewsMSSQL = generateCreateViewsSQL("mssql");
|
|
100
|
+
export const generateCreateViewsPostgreSQL = generateCreateViewsSQL("pg");
|
|
101
|
+
export const generateCreateViewsMySQL = generateCreateViewsSQL("mysql");
|