@lovrabet/rabetbase-cli 2.5.13 → 2.6.0-beta.2
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/README.md +42 -17
- package/lib/api/api-doc.js +3 -1
- package/lib/api/api-group.js +3 -1
- package/lib/api/fetch-model-list.js +1 -1
- package/lib/api/generate-api-file.js +8 -1
- package/lib/api/generate-sdk-config-file.js +1 -1
- package/lib/api/legacy-api-file.js +2 -1
- package/lib/api/model-registry-file.js +11 -1
- package/lib/api/model-registry-scaffold.js +2 -1
- package/lib/api/model-source.js +3 -1
- package/lib/auth/auth-server-ui.js +2 -1
- package/lib/auth/auth-server.js +5 -1
- package/lib/auth/constant.js +1 -1
- package/lib/auth/get-cookie.js +1 -1
- package/lib/auth/get-session-user.js +1 -1
- package/lib/auth/is-session-valid.js +1 -1
- package/lib/auth/login-success-html.js +3 -1
- package/lib/auth/logout.js +1 -1
- package/lib/cli-flags.js +1 -1
- package/lib/cli.js +5 -1
- package/lib/commands/api/generate.js +4 -1
- package/lib/commands/api/index.js +1 -1
- package/lib/commands/api/list.js +2 -1
- package/lib/commands/api/pull.js +10 -1
- package/lib/commands/api/shared.js +1 -1
- package/lib/commands/app/detail.js +1 -1
- package/lib/commands/app/index.js +1 -1
- package/lib/commands/app/list.js +5 -1
- package/lib/commands/app/members-list.js +1 -1
- package/lib/commands/app/remote-directory.js +1 -1
- package/lib/commands/app/shared.js +4 -1
- package/lib/commands/app-config/delete.js +2 -1
- package/lib/commands/app-config/get.js +2 -1
- package/lib/commands/app-config/index.js +1 -1
- package/lib/commands/app-config/list.js +2 -1
- package/lib/commands/app-config/set.js +3 -1
- package/lib/commands/app-config/shared.d.ts +9 -2
- package/lib/commands/app-config/shared.js +6 -1
- package/lib/commands/auth/index.js +1 -1
- package/lib/commands/bff/create.js +11 -1
- package/lib/commands/bff/delete.js +6 -1
- package/lib/commands/bff/detail.js +1 -1
- package/lib/commands/bff/index.js +1 -1
- package/lib/commands/bff/list.js +1 -1
- package/lib/commands/bff/logs.js +4 -1
- package/lib/commands/bff/pull.js +22 -1
- package/lib/commands/bff/push.js +16 -1
- package/lib/commands/bff/status.js +3 -1
- package/lib/commands/cli-skill/index.js +2 -1
- package/lib/commands/cli-update.js +7 -1
- package/lib/commands/codegen/index.js +1 -1
- package/lib/commands/codegen/sdk.js +1 -1
- package/lib/commands/codegen/sql.js +1 -1
- package/lib/commands/common/app-registry.js +4 -1
- package/lib/commands/common/app-selector.js +4 -1
- package/lib/commands/common/async-task.js +2 -1
- package/lib/commands/common/dry-run.js +1 -1
- package/lib/commands/common/flags.js +3 -1
- package/lib/commands/common/local-file.js +1 -1
- package/lib/commands/common/validate.js +1 -1
- package/lib/commands/config/delete.js +2 -1
- package/lib/commands/config/get.js +1 -1
- package/lib/commands/config/index.js +1 -1
- package/lib/commands/config/init.js +5 -1
- package/lib/commands/config/list.js +1 -1
- package/lib/commands/config/set.js +4 -1
- package/lib/commands/config/shared.js +2 -1
- package/lib/commands/dataset/batch-design.js +9 -1
- package/lib/commands/dataset/business-group-update.js +10 -1
- package/lib/commands/dataset/business-groups.js +1 -1
- package/lib/commands/dataset/capability.js +3 -1
- package/lib/commands/dataset/cross-relation-create.js +2 -1
- package/lib/commands/dataset/cross-relation-delete.js +1 -1
- package/lib/commands/dataset/cross-relation-list.js +2 -1
- package/lib/commands/dataset/cross-relation-shared.js +10 -1
- package/lib/commands/dataset/cross-relation-update.js +2 -1
- package/lib/commands/dataset/delete.js +6 -1
- package/lib/commands/dataset/design-context.js +1 -1
- package/lib/commands/dataset/design-start.js +1 -1
- package/lib/commands/dataset/design-status.js +1 -1
- package/lib/commands/dataset/design-sync-retry.js +1 -1
- package/lib/commands/dataset/design-sync-status.js +1 -1
- package/lib/commands/dataset/design-validate.js +1 -1
- package/lib/commands/dataset/detail.js +5 -1
- package/lib/commands/dataset/extend-update.js +7 -1
- package/lib/commands/dataset/field-restore.js +7 -1
- package/lib/commands/dataset/field-update.js +7 -1
- package/lib/commands/dataset/generate.js +19 -1
- package/lib/commands/dataset/index.js +3 -1
- package/lib/commands/dataset/list.js +2 -1
- package/lib/commands/dataset/operations.js +2 -1
- package/lib/commands/dataset/relation-audit.js +7 -1
- package/lib/commands/dataset/relation-create.js +3 -1
- package/lib/commands/dataset/relation-delete.js +3 -1
- package/lib/commands/dataset/relation-shared.js +21 -1
- package/lib/commands/dataset/relation-update.js +4 -1
- package/lib/commands/dataset/relations.js +7 -1
- package/lib/commands/dataset/rename.js +4 -1
- package/lib/commands/dataset/restore.js +7 -1
- package/lib/commands/dataset/user-deleted-field-list.js +3 -1
- package/lib/commands/db/analysis-batching.js +3 -1
- package/lib/commands/db/analyze-batch-plan.js +2 -1
- package/lib/commands/db/analyze-cancel.js +1 -1
- package/lib/commands/db/analyze-start.js +3 -1
- package/lib/commands/db/analyze-status.js +6 -1
- package/lib/commands/db/create.js +4 -1
- package/lib/commands/db/cross-db-analysis-shared.js +3 -1
- package/lib/commands/db/cross-db-analyze-latest.js +1 -1
- package/lib/commands/db/cross-db-analyze-start.js +2 -1
- package/lib/commands/db/cross-db-analyze-status.js +1 -1
- package/lib/commands/db/delete.js +3 -1
- package/lib/commands/db/detail.js +1 -1
- package/lib/commands/db/diff-refresh-start.js +1 -1
- package/lib/commands/db/diff-refresh-status.js +2 -1
- package/lib/commands/db/diff.js +3 -1
- package/lib/commands/db/index.js +2 -1
- package/lib/commands/db/list.js +2 -1
- package/lib/commands/db/shared.js +3 -1
- package/lib/commands/db/table-diff-shared.js +2 -1
- package/lib/commands/db/tables.js +2 -1
- package/lib/commands/db/test.js +2 -1
- package/lib/commands/db/update.js +4 -1
- package/lib/commands/deployment/index.js +1 -1
- package/lib/commands/deployment/sync-all.js +3 -1
- package/lib/commands/deployment/sync-jobs.js +2 -1
- package/lib/commands/deployment/sync-status.js +2 -1
- package/lib/commands/doctor.js +12 -1
- package/lib/commands/file/index.js +3 -1
- package/lib/commands/flow/create.js +2 -1
- package/lib/commands/flow/detail.js +3 -1
- package/lib/commands/flow/index.js +1 -1
- package/lib/commands/flow/list.js +2 -1
- package/lib/commands/flow/page-list.js +2 -1
- package/lib/commands/flow/publish.js +2 -1
- package/lib/commands/flow/runtime-resources-shared.js +3 -1
- package/lib/commands/flow/runtime-role-list.js +2 -1
- package/lib/commands/flow/runtime-role-user-list.js +2 -1
- package/lib/commands/flow/runtime-user-search.js +2 -1
- package/lib/commands/flow/shared.js +6 -1
- package/lib/commands/flow/update.js +4 -1
- package/lib/commands/flow/validate.js +2 -1
- package/lib/commands/instant-api-policy/current.js +1 -1
- package/lib/commands/instant-api-policy/index.js +1 -1
- package/lib/commands/instant-api-policy/init.js +2 -1
- package/lib/commands/instant-api-policy/publish.js +5 -1
- package/lib/commands/instant-api-policy/pull.js +2 -1
- package/lib/commands/instant-api-policy/revision.js +1 -1
- package/lib/commands/instant-api-policy/revisions.js +1 -1
- package/lib/commands/instant-api-policy/rollback.js +5 -1
- package/lib/commands/instant-api-policy/shared.js +5 -1
- package/lib/commands/instant-api-policy/validate.js +1 -1
- package/lib/commands/issue/context.js +1 -1
- package/lib/commands/issue/index.js +1 -1
- package/lib/commands/issue/nudge.js +2 -1
- package/lib/commands/issue/report.js +5 -1
- package/lib/commands/kb/create.js +5 -1
- package/lib/commands/kb/delete.js +5 -1
- package/lib/commands/kb/detail.js +1 -1
- package/lib/commands/kb/import-api.d.ts +3 -0
- package/lib/commands/kb/import-api.js +1 -0
- package/lib/commands/kb/import-resume.d.ts +2 -0
- package/lib/commands/kb/import-resume.js +2 -0
- package/lib/commands/kb/import-shared.d.ts +69 -0
- package/lib/commands/kb/import-shared.js +9 -0
- package/lib/commands/kb/import-status.d.ts +2 -0
- package/lib/commands/kb/import-status.js +1 -0
- package/lib/commands/kb/import.d.ts +2 -0
- package/lib/commands/kb/import.js +3 -0
- package/lib/commands/kb/index.js +1 -1
- package/lib/commands/kb/list.js +1 -1
- package/lib/commands/kb/search.js +3 -1
- package/lib/commands/kb/shared.js +9 -1
- package/lib/commands/kb/update.js +7 -1
- package/lib/commands/logs/index.js +2 -1
- package/lib/commands/menu/asset-update.js +8 -1
- package/lib/commands/menu/delete.js +15 -1
- package/lib/commands/menu/external-link-create.js +16 -1
- package/lib/commands/menu/external-link-update.js +10 -1
- package/lib/commands/menu/group-create.js +8 -1
- package/lib/commands/menu/group-update.js +6 -1
- package/lib/commands/menu/index.js +2 -1
- package/lib/commands/menu/list.js +1 -1
- package/lib/commands/menu/move.js +6 -1
- package/lib/commands/menu/regroup-start.js +11 -1
- package/lib/commands/menu/rename.js +9 -1
- package/lib/commands/menu/shared/compare-table.js +2 -1
- package/lib/commands/menu/shared/delete-plan.js +13 -1
- package/lib/commands/menu/shared/facts.js +5 -1
- package/lib/commands/menu/shared/index.js +1 -1
- package/lib/commands/menu/shared/inquirer.js +4 -1
- package/lib/commands/menu/shared/local-pages.js +5 -1
- package/lib/commands/menu/shared/logic.js +3 -1
- package/lib/commands/menu/shared/mutations.js +9 -1
- package/lib/commands/menu/shared/path.js +1 -1
- package/lib/commands/menu/shared/service.js +4 -1
- package/lib/commands/menu/shared/subapp-assets.js +4 -1
- package/lib/commands/menu/shared/sync-core.js +7 -1
- package/lib/commands/menu/shared/types.js +1 -1
- package/lib/commands/menu/shared/update-core.js +8 -1
- package/lib/commands/menu/shared/valid-url.js +1 -1
- package/lib/commands/menu/subapp-assets-status.js +1 -1
- package/lib/commands/menu/subapp-assets-update.js +7 -1
- package/lib/commands/menu/sync.js +7 -1
- package/lib/commands/menu/visibility-update.js +13 -1
- package/lib/commands/metric/contract.d.ts +8 -0
- package/lib/commands/metric/contract.js +5 -0
- package/lib/commands/metric/definition.d.ts +43 -0
- package/lib/commands/metric/definition.js +4 -0
- package/lib/commands/metric/delete.d.ts +2 -0
- package/lib/commands/metric/delete.js +3 -0
- package/lib/commands/metric/detail.d.ts +2 -0
- package/lib/commands/metric/detail.js +1 -0
- package/lib/commands/metric/example.d.ts +2 -0
- package/lib/commands/metric/example.js +1 -0
- package/lib/commands/metric/index.d.ts +2 -0
- package/lib/commands/metric/index.js +1 -0
- package/lib/commands/metric/list.d.ts +2 -0
- package/lib/commands/metric/list.js +2 -0
- package/lib/commands/metric/publication-diff.d.ts +8 -0
- package/lib/commands/metric/publication-diff.js +1 -0
- package/lib/commands/metric/publish.d.ts +2 -0
- package/lib/commands/metric/publish.js +4 -0
- package/lib/commands/metric/schema.d.ts +2 -0
- package/lib/commands/metric/schema.js +1 -0
- package/lib/commands/metric/shared.d.ts +14 -0
- package/lib/commands/metric/shared.js +2 -0
- package/lib/commands/metric/validate.d.ts +2 -0
- package/lib/commands/metric/validate.js +1 -0
- package/lib/commands/notification/config-create.js +4 -1
- package/lib/commands/notification/config-delete.js +4 -1
- package/lib/commands/notification/config-list.js +2 -1
- package/lib/commands/notification/config-update.js +4 -1
- package/lib/commands/notification/index.js +1 -1
- package/lib/commands/notification/shared.js +18 -1
- package/lib/commands/ocr/index.js +4 -1
- package/lib/commands/page/create.js +6 -1
- package/lib/commands/page/custom/detail.js +2 -1
- package/lib/commands/page/custom/list.js +2 -1
- package/lib/commands/page/custom/publish.js +3 -1
- package/lib/commands/page/custom/shared.js +3 -1
- package/lib/commands/page/custom/syntax.js +2 -1
- package/lib/commands/page/custom/update.js +3 -1
- package/lib/commands/page/data-list-status.js +2 -1
- package/lib/commands/page/generate-start.js +5 -1
- package/lib/commands/page/generate-status.js +4 -1
- package/lib/commands/page/index.js +2 -1
- package/lib/commands/page/pull.js +6 -1
- package/lib/commands/page/push.js +11 -1
- package/lib/commands/page/relation-audit.js +15 -1
- package/lib/commands/page/restore.js +5 -1
- package/lib/commands/page/shared.js +16 -1
- package/lib/commands/page/sync.js +2 -1
- package/lib/commands/project/api-architecture-upgrade.js +11 -1
- package/lib/commands/project/create/enhanced-guided-create.js +2 -1
- package/lib/commands/project/create/format-elapsed.js +1 -1
- package/lib/commands/project/create/main.js +13 -1
- package/lib/commands/project/create/materialize-project-template.js +12 -1
- package/lib/commands/project/create/project-name.js +1 -1
- package/lib/commands/project/create/project-template-archive.js +5 -1
- package/lib/commands/project/create/project-template-path.js +1 -1
- package/lib/commands/project/create/use-copy-project-template.js +2 -1
- package/lib/commands/project/create/use-format-code.js +1 -1
- package/lib/commands/project/create/use-install-dependencies.js +1 -1
- package/lib/commands/project/domain-routing-sync.js +1 -1
- package/lib/commands/project/index.js +4 -1
- package/lib/commands/project/upgrade.js +7 -1
- package/lib/commands/registry.js +10 -1
- package/lib/commands/role/delete.js +2 -1
- package/lib/commands/role/detail.js +1 -1
- package/lib/commands/role/index.js +1 -1
- package/lib/commands/role/list.js +2 -1
- package/lib/commands/role/shared.js +8 -1
- package/lib/commands/role/update.js +3 -1
- package/lib/commands/role/user-add.js +2 -1
- package/lib/commands/role/user-remove.js +2 -1
- package/lib/commands/role/user-resolve.js +1 -1
- package/lib/commands/rule/get.js +1 -1
- package/lib/commands/rule/index.js +1 -1
- package/lib/commands/rule/list.js +1 -1
- package/lib/commands/rule/set.js +7 -1
- package/lib/commands/rule/shared.js +4 -1
- package/lib/commands/run/index.js +5 -1
- package/lib/commands/schema.js +1 -1
- package/lib/commands/sql/create.js +7 -1
- package/lib/commands/sql/delete.js +4 -1
- package/lib/commands/sql/detail.js +1 -1
- package/lib/commands/sql/exec.js +1 -1
- package/lib/commands/sql/index.js +1 -1
- package/lib/commands/sql/list.js +2 -1
- package/lib/commands/sql/pull.js +10 -1
- package/lib/commands/sql/push.js +9 -1
- package/lib/commands/sql/shared.js +5 -1
- package/lib/commands/sql/status.js +3 -1
- package/lib/commands/sql/validate.js +5 -1
- package/lib/commands/task/index.js +1 -1
- package/lib/commands/task/status.js +2 -1
- package/lib/commands/tenant/index.js +1 -1
- package/lib/commands/tenant/members-list.js +2 -1
- package/lib/commands/tenant/shared.js +2 -1
- package/lib/commands/user-account/dingding-sandbox-bind.js +2 -1
- package/lib/commands/user-account/feishu-bind.js +2 -1
- package/lib/commands/user-account/index.js +1 -1
- package/lib/commands/workspace/add.js +1 -1
- package/lib/commands/workspace/index.js +7 -1
- package/lib/commands/workspace/remove.js +1 -1
- package/lib/config/domain-config.js +8 -1
- package/lib/config/project-domain-routing.js +3 -1
- package/lib/config/region-config.js +2 -1
- package/lib/config/schema.js +7 -1
- package/lib/constant/cdn.js +2 -1
- package/lib/constant/cli.js +8 -1
- package/lib/constant/defaults.js +1 -1
- package/lib/constant/domain.js +4 -1
- package/lib/constant/env.js +1 -1
- package/lib/constant/output.js +1 -1
- package/lib/constant/paths.js +1 -1
- package/lib/constant/region.js +1 -1
- package/lib/constant/risk.js +1 -1
- package/lib/constant/routing-profile.js +1 -1
- package/lib/context/app-resolver.js +7 -1
- package/lib/context/auth-resolver.js +1 -1
- package/lib/context/config-loader.js +7 -1
- package/lib/context.js +9 -1
- package/lib/core/alias-resolver.js +5 -1
- package/lib/core/api-client.d.ts +14 -7
- package/lib/core/api-client.js +69 -1
- package/lib/core/bff/config.js +1 -1
- package/lib/core/bff/file-system.js +6 -1
- package/lib/core/bff/hash.js +1 -1
- package/lib/core/bff/hook-directory.js +9 -1
- package/lib/core/bff/lock.js +2 -1
- package/lib/core/bff/types.js +1 -1
- package/lib/core/bff/utils.js +3 -1
- package/lib/core/cross-db-analysis.js +1 -1
- package/lib/core/cross-db-relation.js +1 -1
- package/lib/core/db-resolver.js +2 -1
- package/lib/core/flow-config.js +49 -1
- package/lib/core/instant-api-policy/config.js +7 -1
- package/lib/core/instant-api-policy/endpoints.js +1 -1
- package/lib/core/kb-management-client.d.ts +11 -0
- package/lib/core/kb-management-client.js +4 -1
- package/lib/core/kb-search-client.js +3 -1
- package/lib/core/page/file-system.js +2 -1
- package/lib/core/page/hash.js +1 -1
- package/lib/core/page/lock.js +2 -1
- package/lib/core/page/lr-smart-jsx.js +4 -1
- package/lib/core/page/types.js +1 -1
- package/lib/core/sql-index-auditor.js +14 -1
- package/lib/core/sql-sync/config.js +1 -1
- package/lib/core/sql-sync/file-system.js +3 -1
- package/lib/core/sql-sync/hash.js +1 -1
- package/lib/core/sql-sync/lock.js +2 -1
- package/lib/core/sql-sync/types.js +1 -1
- package/lib/core/sql-sync/utils.js +2 -1
- package/lib/core/sql-validator.js +15 -1
- package/lib/errors.js +3 -1
- package/lib/framework/build-all-flags.js +1 -1
- package/lib/framework/error-output.js +1 -1
- package/lib/framework/explicit-yes.js +1 -1
- package/lib/framework/flags.js +1 -1
- package/lib/framework/help.js +2 -1
- package/lib/framework/index.js +1 -1
- package/lib/framework/output.js +2 -1
- package/lib/framework/response.js +1 -1
- package/lib/framework/runner-alias.js +2 -1
- package/lib/framework/runner.js +9 -1
- package/lib/framework/schema-export.js +1 -1
- package/lib/framework/supported-flags.js +2 -1
- package/lib/framework/types.js +1 -1
- package/lib/generated/build-info.d.ts +4 -4
- package/lib/generated/build-info.js +1 -1
- package/lib/generated/official-routing.js +3 -1
- package/lib/generated/routing-contract.js +1 -1
- package/lib/help.js +1 -1
- package/lib/runtime/confirmation.js +2 -1
- package/lib/runtime/event.js +1 -1
- package/lib/runtime/index.js +4 -1
- package/lib/runtime/queue.js +1 -1
- package/lib/runtime/resolve.js +2 -1
- package/lib/runtime/types.js +1 -1
- package/lib/services/dataset-design/checkpoint.js +2 -1
- package/lib/services/dataset-design/commands.js +14 -1
- package/lib/services/dataset-design/contract.js +8 -1
- package/lib/skills/builtin-skill.js +8 -1
- package/lib/skills/install-updated-skill.d.ts +8 -0
- package/lib/skills/install-updated-skill.js +3 -0
- package/lib/skills/local-skills-installer.d.ts +2 -0
- package/lib/skills/local-skills-installer.js +1 -0
- package/lib/skills/main.js +2 -1
- package/lib/skills/npx-skills-add.d.ts +6 -6
- package/lib/skills/npx-skills-add.js +5 -1
- package/lib/skills/skill-presence.d.ts +1 -30
- package/lib/skills/skill-presence.js +2 -1
- package/lib/telemetry/cli-command-trace.js +2 -1
- package/lib/telemetry/cli-help-trace.js +1 -1
- package/lib/telemetry/ensure-cli-otel-config.js +1 -1
- package/lib/telemetry/register-otel-exit-shutdown.js +1 -1
- package/lib/telemetry/send-cli-trace-log.js +1 -1
- package/lib/types/index.js +1 -1
- package/lib/utils/ai_config.js +3 -1
- package/lib/utils/apply-jq-filter.js +1 -1
- package/lib/utils/cdn-config.js +1 -1
- package/lib/utils/check-sdk-version.js +5 -1
- package/lib/utils/cli-version-check.js +4 -1
- package/lib/utils/cli-version-policy.js +3 -1
- package/lib/utils/config.js +1 -1
- package/lib/utils/entity-with-id.js +1 -1
- package/lib/utils/file-utils.js +1 -1
- package/lib/utils/guides-cdn.js +3 -1
- package/lib/utils/http-client.js +2 -1
- package/lib/utils/is-non-interactive.js +1 -1
- package/lib/utils/logger.js +3 -1
- package/lib/utils/params.js +1 -1
- package/lib/utils/platform.js +1 -1
- package/lib/utils/sleep.js +1 -1
- package/lib/utils/template-replacer.js +5 -1
- package/lib/utils/update-notice.js +3 -1
- package/lib/utils/version.js +1 -1
- package/lib/utils/with-active-cookie.js +1 -1
- package/lib/utils/write-cli-side-channel.js +1 -1
- package/package.json +10 -7
- package/skills/rabetbase/SKILL.md +11 -7
- package/skills/rabetbase/guides/backend-function.md +3 -1
- package/skills/rabetbase/guides/data-api-guidelines.md +1 -1
- package/skills/rabetbase/guides/frontend-development.md +1 -0
- package/skills/rabetbase/guides/metric-development.md +185 -0
- package/skills/rabetbase/references/rabetbase-app-config.md +4 -3
- package/skills/rabetbase/references/rabetbase-cli-skill-install.md +5 -5
- package/skills/rabetbase/references/rabetbase-dataset-design.md +1 -1
- package/skills/rabetbase/references/rabetbase-kb.md +16 -0
- package/skills/rabetbase/references/rabetbase-metric.md +119 -0
- package/skills/rabetbase/references/rabetbase-update.md +7 -5
- package/skills/rabetbase-dataset-generation/SKILL.md +1 -1
- package/skills/rabetbase-dataset-generation/references/workflow.md +1 -1
- package/skills/rabetbase-metrics-generation/SKILL.md +22 -0
- package/skills/rabetbase-metrics-generation/references/verification.md +19 -0
- package/skills/rabetbase-metrics-generation/references/workflow.md +41 -0
- package/skills/rabetbase-metrics-generation/templates/statistics-delivery.md +11 -0
- package/skills/rabetbase-page-generation/SKILL.md +1 -1
- package/skills/rabetbase-page-generation/references/generation.md +1 -1
- package/skills/rabetbase.manifest.json +5 -3
- package/templates/metrics/definition.json +78 -0
- package/templates/metrics/metric-definition.schema.json +136 -0
- package/lib/postinstall.d.ts +0 -3
- package/lib/postinstall.js +0 -1
- package/scripts/postinstall.mjs +0 -24
- package/templates/README.md +0 -130
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import{createKnowledgeClient,KnowledgeServiceError}from"@lovrabet/sdk";import{AsyncLocalStorage}from"node:async_hooks";import{getKbServiceDomain}from"../constant/domain.js";import{normalizeKbServiceOrigin}from"../core/kb-search-client.js";import{CliError,CliErrors}from"../errors.js";const WRITE_RECONCILIATION=" The entry may already have been saved. Use read-only detail or list reconciliation; do not resubmit automatically.";const session=new AsyncLocalStorage;export class KbManagementError extends CliError{transportFailure;remoteErrorCode;httpStatus;pageTooLarge;constructor(message,transportFailure=false,remoteErrorCode,httpStatus,pageTooLarge=false){super("api_error",1,message,remoteErrorCode?`API error code: ${remoteErrorCode}`:undefined);this.transportFailure=transportFailure;this.remoteErrorCode=remoteErrorCode;this.httpStatus=httpStatus;this.pageTooLarge=pageTooLarge;if(remoteErrorCode)Object.defineProperty(this,"data",{value:{remoteErrorCode:remoteErrorCode},enumerable:false})}}
|
|
2
|
+
export class KbCreateReadbackUnavailableError extends KbManagementError{documentId;version;constructor(documentId,version){super("The create response was received, but its exact detail could not be verified. Inspect it without resubmitting.");this.documentId=documentId;this.version=version}}export function isKbReadbackUnavailable(error){if(error instanceof KbManagementError){return error.transportFailure||error.httpStatus===408||error.httpStatus===429||error.httpStatus!==undefined&&error.httpStatus>=500}return error instanceof CliError&&error.code==="auth_required"}function resolveOrigin(){const value=getKbServiceDomain();if(!value)throw CliErrors.validation("Configure kbServiceDomain with a trusted HTTPS origin for knowledge management.");try{return normalizeKbServiceOrigin(value)}catch{throw CliErrors.validation("Invalid kbServiceDomain: expected an HTTPS origin without credentials, path, query, or fragment.")}}export function getKbManagementSession(){return session.getStore()??{
|
|
3
|
+
origin:resolveOrigin(),signal:undefined}}export function withKbManagementSession(signal,action){return session.run({origin:resolveOrigin(),signal:signal},action)}export async function withKbManagementClient(cookie,action,requestOptions={}){const origin=session.getStore()?.origin??resolveOrigin();if(!cookie.trim())throw CliErrors.authRequired();const signal=requestOptions.signal??session.getStore()?.signal;if(signal?.aborted)throw CliErrors.cancelled("Knowledge management request cancelled.");try{const client=createKnowledgeClient({kbServiceDomain:origin,authMode:"cookie",cookie:cookie,invokeSource:"cli:rabetbase"});return await action(client,{signal:signal})}catch(error){if(!(error instanceof KnowledgeServiceError))throw error;if(error.kind==="auth")throw CliErrors.authRequired();if(error.kind==="validation")throw CliErrors.validation(error.message);const transportFailure=error.kind==="network"||error.kind==="timeout"||error.kind==="cancelled"
|
|
4
|
+
;throw new KbManagementError(error.message+(error.writeUncertain?WRITE_RECONCILIATION:""),transportFailure,/^\d+$/.test(error.code??"")?error.code:undefined,error.status,error.pageTooLarge)}}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import{createKnowledgeClient,KnowledgeServiceError,normalizeKnowledgeServiceOrigin}from"@lovrabet/sdk";import{CliErrors}from"../errors.js";export function normalizeKbServiceOrigin(input){try{return normalizeKnowledgeServiceOrigin(input)}catch{throw CliErrors.validation("Invalid --kb-service-url: expected an HTTPS origin without credentials, path, query, or fragment.")}}export async function searchDirectKnowledge(input){const appCode=input.appCode.trim(),query=input.query.trim();if(!appCode)throw CliErrors.validation("Knowledge search appCode is required.");if(!query)throw CliErrors.validation("Knowledge search query is required.");if(!input.cookie.trim())throw CliErrors.authRequired();const origin=normalizeKbServiceOrigin(input.serviceUrl);try{const client=createKnowledgeClient({kbServiceDomain:origin,authMode:"cookie",cookie:input.cookie,invokeSource:"cli:rabetbase"});const result=await client.search({appCode:appCode,query:query,scopes:["public","company"],...input.topK!==undefined?{
|
|
2
|
+
topK:input.topK}:{}},{signal:input.signal});return{...result,hits:result.hits,schemaVersion:2,profile:"development",total:result.hits.length}}catch(error){if(!(error instanceof KnowledgeServiceError))throw error;if(error.kind==="auth")throw CliErrors.authRequired();if(error.kind==="validation")throw CliErrors.validation(error.message);if(error.kind==="cancelled")throw new DOMException("Knowledge search cancelled.","AbortError");if(error.kind==="network"||error.kind==="timeout")throw CliErrors.networkError(error.kind==="timeout"?"KB Service knowledge search request timed out.":"KB Service knowledge search request failed.");const message=error.kind==="contract"&&error.message.includes("out-of-scope")?"KB Service knowledge search returned an invalid response contract.":error.message;const mapped=CliErrors.apiError(error.status!==undefined&&error.status!==200&&!message.includes(`HTTP ${error.status}`)?`${message} (HTTP ${error.status})`:message)
|
|
3
|
+
;if(/^\d+$/.test(error.code??""))Object.defineProperty(mapped,"data",{value:{remoteErrorCode:error.code},enumerable:false});throw mapped}}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{constants}from"node:fs";import{access,lstat,mkdir,readFile,readdir}from"node:fs/promises";import{dirname,join,relative,resolve,sep}from"node:path";import{CliErrors}from"../../errors.js";export function loadPageProjectConfig(appCode,cwd=process.cwd()){const projectRoot=resolve(cwd);const pagesBaseDir=join(projectRoot,".rabetbase","page");return{projectRoot:projectRoot,pagesBaseDir:pagesBaseDir,appPagesDir:join(pagesBaseDir,appCode),lockFilePath:join(projectRoot,".rabetbase","page.lock.json")}}export function buildPageFileName(pageId,type){return`${pageId}-${type.toUpperCase()}.json`}export function resolvePageFilePath(config,pageId,type){return join(config.appPagesDir,buildPageFileName(pageId,type))}export async function ensureParentDirectory(filePath){await mkdir(dirname(filePath),{recursive:true})}export async function fileExists(filePath){try{await access(filePath,constants.F_OK);return true}catch{return false}}export async function readCustomPageDirectory(directory){
|
|
2
|
+
const inputDirectory=directory.trim();if(!inputDirectory)throw CliErrors.flagMissing("page-dir");const root=resolve(inputDirectory);let stats;try{stats=await lstat(root)}catch{throw CliErrors.validation(`Page directory not found: ${inputDirectory}`)}if(!stats.isDirectory()){throw CliErrors.validation(`Page directory is not a directory: ${inputDirectory}`)}const files={};await readDirectory(root,root,files);return files}async function readDirectory(root,directory,files){const entries=await readdir(directory,{withFileTypes:true});for(const entry of entries.sort((left,right)=>left.name.localeCompare(right.name))){const filePath=join(directory,entry.name);if(entry.isDirectory()){await readDirectory(root,filePath,files);continue}if(!entry.isFile()){throw CliErrors.validation(`Unsupported file in page directory: ${filePath}`)}files[relative(root,filePath).split(sep).join("/")]=await readFile(filePath,"utf8")}}
|
package/lib/core/page/hash.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import crypto from"node:crypto";import{readFile}from"node:fs/promises";export function serializePageSchemaForFile(schema){return JSON.stringify(JSON.parse(schema),null,2)+"\n"}export function computePageContentHash(content){return crypto.createHash("md5").update(content).digest("hex")}export function computeSerializedSchemaHash(schema){return computePageContentHash(serializePageSchemaForFile(schema))}export async function computePageFileHash(filePath){const content=await readFile(filePath,"utf8");return computePageContentHash(content)}
|
package/lib/core/page/lock.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{mkdir,readFile,writeFile}from"node:fs/promises";import{dirname}from"node:path";export function createEmptyPageLock(){return{apps:{}}}export function ensurePageLockScope(lockData,appCode){const normalized={apps:lockData.apps&&typeof lockData.apps==="object"?lockData.apps:{}};let appLock=normalized.apps[appCode];if(!appLock){appLock={lastSync:"",pages:{}};normalized.apps[appCode]=appLock;return{lockData:normalized,appLock:appLock}}if(!appLock.lastSync){appLock.lastSync=""}if(!appLock.pages||typeof appLock.pages!=="object"){appLock.pages={}}return{lockData:normalized,appLock:appLock}}export async function readPageLockFile(lockFilePath){try{const content=await readFile(lockFilePath,"utf8");const raw=JSON.parse(content);return{apps:raw.apps&&typeof raw.apps==="object"?raw.apps:{}}}catch(error){if(error.code==="ENOENT"){return null}throw new Error(`Failed to read page lock file: ${String(error)}`)}}export async function writePageLockFile(lockFilePath,lockData){
|
|
2
|
+
await mkdir(dirname(lockFilePath),{recursive:true});await writeFile(lockFilePath,JSON.stringify(lockData,null,2),"utf8")}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import{CliErrors}from"../../errors.js";export async function prepareLrSmartJsxForPush(localContent,remoteContent,transpile){const localSchema=parseSchema(localContent,"local");const remoteSchema=parseSchema(remoteContent,"remote");const localNodes=collectLrSmartJsx(localSchema,true);if(localNodes.length===0){return{content:localContent,compiledNodes:0,normalizedNodes:0}}const remoteNodes=new Map(collectLrSmartJsx(remoteSchema).map(item=>[item.key,item]));let compiledNodes=0;let normalizedNodes=0;for(const local of localNodes){const source=readNonEmptyString(local.render.source);const value=readNonEmptyString(local.render.value);const remote=remoteNodes.get(local.key);const remoteSource=readNonEmptyString(remote?.render.source);const remoteValue=readNonEmptyString(remote?.render.value);let normalized=false;if(local.render.type!=="JSFunction"){local.render.type="JSFunction";normalized=true}if(!isPageContextExpression(local.props._context)){local.props._context={type:"JSExpression",
|
|
2
|
+
value:"this"};normalized=true}if(!source){if(!value){throw CliErrors.validation(`LrSmartJsx node "${local.label}" is missing both render.source and render.value.`,"Add JSX source in the page editor or remove the incomplete component.")}if(normalized)normalizedNodes+=1;continue}const sourceChanged=!remote||source!==remoteSource;const valueMissing=!value;if(!sourceChanged&&value&&remoteValue&&value!==remoteValue){throw CliErrors.validation(`LrSmartJsx node "${local.label}" has a manually changed render.value.`,"Edit render.source instead; render.value is generated during page push.")}if(sourceChanged||valueMissing||!remoteValue){const compiled=readNonEmptyString(await transpile(source));if(!compiled){throw CliErrors.apiError(`LrSmartJsx compilation returned no code for node "${local.label}".`)}local.render.value=compiled;compiledNodes+=1;normalized=true}if(normalized)normalizedNodes+=1}if(normalizedNodes===0){return{content:localContent,compiledNodes:compiledNodes,
|
|
3
|
+
normalizedNodes:normalizedNodes}}return{content:JSON.stringify(localSchema),compiledNodes:compiledNodes,normalizedNodes:normalizedNodes}}function parseSchema(content,label){try{return JSON.parse(content)}catch{throw CliErrors.validation(`Invalid JSON in ${label} page schema.`)}}function collectLrSmartJsx(value,validateStructure=false){const found=[];const visit=(current,path)=>{if(Array.isArray(current)){current.forEach((item,index)=>visit(item,`${path}[${index}]`));return}if(!isObject(current))return;if(current.componentName==="LrSmartJsx"){const id=readNonEmptyString(current.id);const label=id||path;const props=isObject(current.props)?current.props:undefined;if(!props){if(validateStructure){throw CliErrors.validation(`LrSmartJsx node "${label}" has missing or invalid props.`,"Set props to an object containing a render object.")}return}const render=isObject(props.render)?props.render:undefined;if(!render){if(validateStructure){
|
|
4
|
+
throw CliErrors.validation(`LrSmartJsx node "${label}" has missing or invalid props.render.`,"Set props.render to an object containing render.source or render.value.")}return}found.push({key:id?`id:${id}`:`path:${path}`,label:label,props:props,render:render})}for(const[key,child]of Object.entries(current)){if(key==="props"&¤t.componentName==="LrSmartJsx")continue;visit(child,`${path}.${key}`)}};visit(value,"$");return found}function isObject(value){return Boolean(value)&&typeof value==="object"&&!Array.isArray(value)}function readNonEmptyString(value){return typeof value==="string"&&value.trim()?value:undefined}function isPageContextExpression(value){return isObject(value)&&value.type==="JSExpression"&&value.value==="this"}
|
package/lib/core/page/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export{};
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
(function(_0x6b4829,_0x23a490){const _0x4d9f74=a309_0x236a,_0x27a485=_0x6b4829();while(!![]){try{const _0x4602a6=parseInt(_0x4d9f74(0x1be))/0x1*(parseInt(_0x4d9f74(0x187))/0x2)+-parseInt(_0x4d9f74(0x183))/0x3*(-parseInt(_0x4d9f74(0x1a3))/0x4)+parseInt(_0x4d9f74(0x1b2))/0x5*(-parseInt(_0x4d9f74(0x18f))/0x6)+-parseInt(_0x4d9f74(0x1b6))/0x7*(parseInt(_0x4d9f74(0x17f))/0x8)+-parseInt(_0x4d9f74(0x181))/0x9+-parseInt(_0x4d9f74(0x1ac))/0xa*(parseInt(_0x4d9f74(0x17a))/0xb)+parseInt(_0x4d9f74(0x1af))/0xc*(parseInt(_0x4d9f74(0x1bd))/0xd);if(_0x4602a6===_0x23a490)break;else _0x27a485['push'](_0x27a485['shift']());}catch(_0x110757){_0x27a485['push'](_0x27a485['shift']());}}}(a309_0x3948,0x26290));import{MYBATIS_DYNAMIC_END_MARKER,MYBATIS_DYNAMIC_START_MARKER,MYBATIS_INCLUDE_MARKER,normalizeSqlForStaticAnalysis}from'./sql-validator.js';export function auditSqlJoinIndexes(_0x4e9626,_0x28221c){const _0x3ccfaa=a309_0x236a,_0x4e6991=[],_0x23c998=normalizeSqlForStaticAnalysis(_0x4e9626),_0x17c442=(_0x23c998['error']?[]:extractJoinFacts(_0x23c998[_0x3ccfaa(0x1c3)]))['map'](_0x2e04a7=>{const _0x2aa669=_0x3ccfaa;if(_0x2e04a7[_0x2aa669(0x1c1)]||_0x2e04a7[_0x2aa669(0x186)][_0x2aa669(0x1ae)]===0x0)return _0x4e6991[_0x2aa669(0x19d)]({'code':'JOIN_PREDICATE_UNSUPPORTED','table':_0x2e04a7['table'],'alias':_0x2e04a7[_0x2aa669(0x196)],'columns':_0x2e04a7['columns'],'reason':_0x2e04a7['unsupportedReason']??_0x2aa669(0x1c6)}),{'table':_0x2e04a7[_0x2aa669(0x199)],'alias':_0x2e04a7[_0x2aa669(0x196)],'columns':_0x2e04a7[_0x2aa669(0x186)],'status':'unavailable'};const _0x1107da=resolveTableMetadata(_0x28221c,_0x2e04a7[_0x2aa669(0x199)]),_0x5b362b=(_0x1107da?.[_0x2aa669(0x17d)]??[])[_0x2aa669(0x193)](_0x1e5798=>({'index':_0x1e5798,'matchedPrefix':findEqualityPrefix(_0x1e5798[_0x2aa669(0x186)],_0x2e04a7[_0x2aa669(0x186)])}))['filter'](_0x3bf898=>_0x3bf898[_0x2aa669(0x192)]['length']>0x0),_0xb7417c=_0x5b362b[_0x2aa669(0x1aa)]((_0x20741a,_0x90d6fa)=>!_0x20741a||_0x90d6fa[_0x2aa669(0x192)][_0x2aa669(0x1ae)]>_0x20741a[_0x2aa669(0x192)][_0x2aa669(0x1ae)]?_0x90d6fa:_0x20741a,_0x5b362b[0x0]);if(_0xb7417c)return{'table':_0x2e04a7[_0x2aa669(0x199)],'alias':_0x2e04a7['alias'],'columns':_0x2e04a7[_0x2aa669(0x186)],'status':_0x2aa669(0x1b0),'matchedIndex':{..._0xb7417c['index'],'matchedPrefix':_0xb7417c['matchedPrefix']}};const _0x4944cc=_0x1107da?.[_0x2aa669(0x17d)]['filter'](_0x128192=>_0x128192['columns'][_0x2aa669(0x185)](_0x590086=>_0x2e04a7['columns']['some'](_0x57692c=>columnNamesMatch(_0x590086,_0x57692c))))??[];if(_0x4944cc[_0x2aa669(0x1ae)]>0x0)return _0x4e6991[_0x2aa669(0x19d)]({'code':_0x2aa669(0x1a1),'table':_0x2e04a7['table'],'alias':_0x2e04a7[_0x2aa669(0x196)],'columns':_0x2e04a7[_0x2aa669(0x186)],'reason':_0x2aa669(0x18d)}),{'table':_0x2e04a7[_0x2aa669(0x199)],'alias':_0x2e04a7[_0x2aa669(0x196)],'columns':_0x2e04a7[_0x2aa669(0x186)],'status':_0x2aa669(0x1ba),'candidateIndexes':_0x4944cc};if(_0x1107da&&_0x1107da['metadataAvailable']!==![]&&_0x1107da[_0x2aa669(0x17d)][_0x2aa669(0x1ae)]>0x0&&_0x2e04a7[_0x2aa669(0x186)][_0x2aa669(0x1ae)]>0x0)return _0x4e6991[_0x2aa669(0x19d)]({'code':_0x2aa669(0x18c),'table':_0x2e04a7[_0x2aa669(0x199)],'alias':_0x2e04a7[_0x2aa669(0x196)],'columns':_0x2e04a7[_0x2aa669(0x186)],'reason':_0x2aa669(0x19e)}),{'table':_0x2e04a7[_0x2aa669(0x199)],'alias':_0x2e04a7[_0x2aa669(0x196)],'columns':_0x2e04a7[_0x2aa669(0x186)],'status':_0x2aa669(0x1ba)};return _0x4e6991[_0x2aa669(0x19d)]({'code':_0x2aa669(0x17b),'table':_0x2e04a7[_0x2aa669(0x199)],'alias':_0x2e04a7[_0x2aa669(0x196)],'columns':_0x2e04a7['columns'],'reason':_0x1107da?_0x2aa669(0x1bf):_0x2aa669(0x18b)}),{'table':_0x2e04a7['table'],'alias':_0x2e04a7[_0x2aa669(0x196)],'columns':_0x2e04a7[_0x2aa669(0x186)],'status':_0x2aa669(0x18e)};});return{'checked':_0x17c442[_0x3ccfaa(0x1ae)]>0x0,'joins':_0x17c442,'warnings':_0x4e6991};}function extractJoinFacts(_0xe4a534){const _0x8bcf47=a309_0x236a,_0xea4d43=maskNestedQueries(stripSqlNoise(_0xe4a534)),_0x53dd16=maskQuotedIdentifiers(_0xea4d43),_0x3752b2=[],_0x34d44=new Set(),_0x5c818b=/\b(?:(INNER|LEFT|RIGHT|FULL)(?:\s+OUTER)?\s+)?JOIN\s+([`"\w$.]+)(?:\s+(?:AS\s+)?([`"\w$]+))?\s+ON\s+([\s\S]*?)(?=\s+(?:(?:(?:INNER|LEFT|RIGHT|FULL)(?:\s+OUTER)?\s+)?JOIN\b|(?:WHERE|GROUP\s+BY|ORDER\s+BY|HAVING|LIMIT|UNION)\b)|;|$)/gi;for(const _0x29c736 of _0xea4d43[_0x8bcf47(0x197)](_0x5c818b)){const _0x582b4a=_0x29c736[_0x8bcf47(0x1a0)]??0x0,_0x43bd7e=_0x29c736[0x0]['search'](/\bJOIN\b/i),_0x550b1e=_0x582b4a+Math[_0x8bcf47(0x1b4)](0x0,_0x43bd7e);if(!/^JOIN\b/i[_0x8bcf47(0x1a5)](_0x53dd16[_0x8bcf47(0x17e)](_0x550b1e)))continue;_0x34d44[_0x8bcf47(0x1b9)](_0x550b1e);const _0x2a21f9=normalizeIdentifier(_0x29c736[0x1]||_0x8bcf47(0x1a8)),_0x40e619=normalizeIdentifier(_0x29c736[0x2]??''),_0x1c4ec4=normalizeIdentifier(_0x29c736[0x3]||_0x40e619['split']('.')['at'](-0x1)||_0x40e619),_0x4d9eaa=[],_0x2ed3b9=_0x40e619==='__sq__';let _0x2d2227=_0x2a21f9===_0x8bcf47(0x1a9)||_0x2a21f9===_0x8bcf47(0x1b3)||_0x2ed3b9,_0xc2cc8=_0x2d2227?_0x2ed3b9?'Derived-table\x20JOIN\x20targets\x20are\x20not\x20supported.':_0x2a21f9[_0x8bcf47(0x198)]()+_0x8bcf47(0x1a4):undefined;const _0x560a45=stripOuterParentheses(_0x29c736[0x4]??''),_0x44de47=_0x560a45['includes'](MYBATIS_DYNAMIC_START_MARKER)||_0x560a45[_0x8bcf47(0x188)](MYBATIS_DYNAMIC_END_MARKER),_0xe161d4=_0x560a45[_0x8bcf47(0x188)](MYBATIS_INCLUDE_MARKER);_0x44de47&&(_0x2d2227=!![],_0xc2cc8??=_0x8bcf47(0x1a2));_0xe161d4&&(_0x2d2227=!![],_0xc2cc8??=_0x8bcf47(0x19a));const _0x47b5de=_0x560a45[_0x8bcf47(0x1c5)](MYBATIS_DYNAMIC_START_MARKER,'\x20')['replaceAll'](MYBATIS_DYNAMIC_END_MARKER,'\x20')[_0x8bcf47(0x1c5)](MYBATIS_INCLUDE_MARKER,'\x20');hasTopLevelKeyword(_0x47b5de,'OR')&&(_0x2d2227=!![],_0xc2cc8??='OR-connected\x20JOIN\x20predicates\x20are\x20not\x20supported.');for(const _0x3ce247 of splitTopLevelAnd(_0x47b5de)){const _0x4e5671=stripOuterParentheses(_0x3ce247);if(hasTopLevelKeyword(_0x4e5671,'OR')){_0x2d2227=!![],_0xc2cc8??='OR-connected\x20JOIN\x20predicates\x20are\x20not\x20supported.';continue;}const _0x9c8d48=splitEquality(_0x4e5671);if(!_0x9c8d48){containsColumnReference(_0x3ce247,_0x1c4ec4)&&(_0x2d2227=!![]);continue;}const _0x4e3208=parseDirectColumnReference(_0x9c8d48[0x0],_0x1c4ec4),_0x9e0b64=parseDirectColumnReference(_0x9c8d48[0x1],_0x1c4ec4),_0x183c90=containsColumnReference(_0x9c8d48[0x0],_0x1c4ec4),_0x4d84d4=containsColumnReference(_0x9c8d48[0x1],_0x1c4ec4),_0x3e4a56=_0x4e3208&&!_0x4d84d4?_0x4e3208:_0x9e0b64&&!_0x183c90?_0x9e0b64:null;if(_0x3e4a56&&!_0x4d9eaa[_0x8bcf47(0x188)](_0x3e4a56))_0x4d9eaa[_0x8bcf47(0x19d)](_0x3e4a56);else!_0x3e4a56&&containsColumnReference(_0x3ce247,_0x1c4ec4)&&(_0x2d2227=!![]);}_0x3752b2['push']({'table':_0x40e619,'alias':_0x1c4ec4,'columns':_0x4d9eaa,'unsupportedPredicate':_0x2d2227,'unsupportedReason':_0xc2cc8,'containsUnresolvedInclude':_0xe161d4,'position':_0x550b1e});}for(const _0x39eb93 of _0x53dd16[_0x8bcf47(0x197)](/\bJOIN\b/gi)){const _0x2fbe5e=_0x39eb93[_0x8bcf47(0x1a0)]??0x0;if(_0x34d44['has'](_0x2fbe5e))continue;const _0x281ecc=/^\s+([`"\w$.]+)(?:\s+(?:AS\s+)?([`"\w$]+))?/[_0x8bcf47(0x1b7)](_0xea4d43[_0x8bcf47(0x17e)](_0x2fbe5e+_0x39eb93[0x0][_0x8bcf47(0x1ae)])),_0x4491e8=normalizeIdentifier(_0x281ecc?.[0x1]||_0x8bcf47(0x18a)),_0xd889b9=normalizeIdentifier(_0x281ecc?.[0x2]||''),_0x51f5ec=isSqlClauseKeyword(_0xd889b9)?_0x4491e8[_0x8bcf47(0x1bc)]('.')['at'](-0x1)||_0x4491e8:_0xd889b9||_0x4491e8['split']('.')['at'](-0x1)||_0x4491e8;_0x3752b2[_0x8bcf47(0x19d)]({'table':_0x4491e8,'alias':_0x51f5ec,'columns':[],'unsupportedPredicate':!![],'unsupportedReason':_0x8bcf47(0x194),'position':_0x2fbe5e});}const _0x486bee=_0x53dd16[_0x8bcf47(0x1a7)](MYBATIS_INCLUDE_MARKER);return _0x486bee>=0x0&&!_0x3752b2[_0x8bcf47(0x185)](_0x2df61e=>_0x2df61e[_0x8bcf47(0x180)])&&_0x3752b2[_0x8bcf47(0x19d)]({'table':_0x8bcf47(0x18a),'alias':'unknown','columns':[],'unsupportedPredicate':!![],'unsupportedReason':'MyBatis\x20<include>\x20fragments\x20cannot\x20be\x20expanded\x20for\x20JOIN\x20auditing.','containsUnresolvedInclude':!![],'position':_0x486bee}),_0x3752b2[_0x8bcf47(0x1c2)]((_0x2651d5,_0x182d56)=>_0x2651d5[_0x8bcf47(0x184)]-_0x182d56[_0x8bcf47(0x184)]);}function a309_0x3948(){const _0x35d0ba=['250248ceZzFX','covered','has','7120APELRB','full','max','inner','14rsYIRP','exec','cross','add','warning','\x5c$&','split','377kBNcrt','628LBioMJ','The\x20dataset\x20returned\x20no\x20distinguishable\x20index\x20metadata.','from','unsupportedPredicate','sort','sql','\x5cs*\x5c.\x5cs*[\x5cw$]+','replaceAll','Not\x20every\x20JOIN\x20target\x20predicate\x20could\x20be\x20audited\x20safely.','56111FRffkG','INDEX_METADATA_UNAVAILABLE','where','indexes','slice','1114184uLUuSW','containsUnresolvedInclude','920880cxbgmS','tableName','27WUSRws','position','some','columns','508AsgexC','includes','match','unknown','No\x20dataset\x20metadata\x20matched\x20the\x20JOIN\x20table.','JOIN_INDEX_MISSING','Relevant\x20columns\x20do\x20not\x20form\x20a\x20complete\x20leftmost\x20index\x20prefix.','unavailable','72MBMmph','join','min','matchedPrefix','map','Only\x20explicit\x20table\x20JOIN\x20clauses\x20with\x20an\x20ON\x20predicate\x20are\x20supported.','toLowerCase','alias','matchAll','toUpperCase','table','MyBatis\x20<include>\x20JOIN\x20fragments\x20cannot\x20be\x20expanded\x20statically.','filter','trim','push','No\x20reported\x20index\x20contains\x20the\x20JOIN\x20access\x20columns.','(?:^|[^\x5cw$])','index','JOIN_INDEX_NOT_USABLE','MyBatis\x20dynamic\x20JOIN\x20predicates\x20cannot\x20be\x20audited\x20deterministically.','13212ruzOMV','\x20JOIN\x20direction\x20is\x20not\x20supported\x20by\x20static\x20index\x20auditing.','test','replace','indexOf','INNER','right','reduce','natural','470gdomBn','using','length'];a309_0x3948=function(){return _0x35d0ba;};return a309_0x3948();}function stripSqlNoise(_0x437188){const _0x22181a=a309_0x236a,_0x47e114=Array[_0x22181a(0x1c0)](_0x437188),_0xcf5850=(_0x59cb59,_0x3829a7)=>{for(let _0x5ccc10=_0x59cb59;_0x5ccc10<_0x3829a7;_0x5ccc10+=0x1){_0x47e114[_0x5ccc10]!=='\x0a'&&_0x47e114[_0x5ccc10]!=='\x0d'&&(_0x47e114[_0x5ccc10]='\x20');}};for(let _0x3f61df=0x0;_0x3f61df<_0x47e114['length'];_0x3f61df+=0x1){const _0x504d00=_0x47e114[_0x3f61df],_0x2887da=_0x47e114[_0x3f61df+0x1];if(_0x504d00==='\x27'||_0x504d00==='\x22'||_0x504d00==='`'){const _0x2769a2=_0x504d00,_0x5c520b=_0x3f61df;_0x3f61df+=0x1;while(_0x3f61df<_0x47e114[_0x22181a(0x1ae)]){if(_0x47e114[_0x3f61df]==='\x5c'&&_0x3f61df+0x1<_0x47e114[_0x22181a(0x1ae)]){_0x3f61df+=0x2;continue;}if(_0x47e114[_0x3f61df]!==_0x2769a2){_0x3f61df+=0x1;continue;}if(_0x47e114[_0x3f61df+0x1]===_0x2769a2){_0x3f61df+=0x2;continue;}break;}if(_0x2769a2==='\x27')_0xcf5850(_0x5c520b,Math['min'](_0x3f61df+0x1,_0x47e114[_0x22181a(0x1ae)]));continue;}if(_0x504d00==='-'&&_0x2887da==='-'){const _0x54ce62=_0x3f61df;while(_0x3f61df<_0x47e114[_0x22181a(0x1ae)]&&_0x47e114[_0x3f61df]!=='\x0a')_0x3f61df+=0x1;_0xcf5850(_0x54ce62,_0x3f61df);continue;}if(_0x504d00==='/'&&_0x2887da==='*'){const _0x424338=_0x3f61df;_0x3f61df+=0x2;while(_0x3f61df<_0x47e114[_0x22181a(0x1ae)]&&!(_0x47e114[_0x3f61df]==='*'&&_0x47e114[_0x3f61df+0x1]==='/')){_0x3f61df+=0x1;}_0x3f61df=Math[_0x22181a(0x191)](_0x3f61df+0x1,_0x47e114[_0x22181a(0x1ae)]-0x1),_0xcf5850(_0x424338,_0x3f61df+0x1);continue;}if(_0x504d00==='#'&&_0x2887da!=='{'){const _0xc6d546=_0x3f61df;while(_0x3f61df<_0x47e114[_0x22181a(0x1ae)]&&_0x47e114[_0x3f61df]!=='\x0a')_0x3f61df+=0x1;_0xcf5850(_0xc6d546,_0x3f61df);continue;}if((_0x504d00==='#'||_0x504d00==='$')&&_0x2887da==='{'){const _0x5bf4e7=_0x3f61df;_0x3f61df+=0x2;while(_0x3f61df<_0x47e114[_0x22181a(0x1ae)]&&_0x47e114[_0x3f61df]!=='}')_0x3f61df+=0x1;_0xcf5850(_0x5bf4e7,Math[_0x22181a(0x191)](_0x3f61df+0x1,_0x47e114['length']));}}return _0x47e114['join']('');}function maskQuotedIdentifiers(_0x34724e){const _0x1ca1d1=a309_0x236a,_0xc9d6ac=Array['from'](_0x34724e);for(let _0x50e7d1=0x0;_0x50e7d1<_0xc9d6ac[_0x1ca1d1(0x1ae)];_0x50e7d1+=0x1){const _0x17e968=_0xc9d6ac[_0x50e7d1];if(_0x17e968!=='\x22'&&_0x17e968!=='`')continue;_0x50e7d1+=0x1;while(_0x50e7d1<_0xc9d6ac['length']){if(_0xc9d6ac[_0x50e7d1]===_0x17e968){if(_0xc9d6ac[_0x50e7d1+0x1]===_0x17e968){_0xc9d6ac[_0x50e7d1]='\x20',_0xc9d6ac[_0x50e7d1+0x1]='\x20',_0x50e7d1+=0x2;continue;}break;}_0xc9d6ac[_0x50e7d1]='\x20',_0x50e7d1+=0x1;}}return _0xc9d6ac[_0x1ca1d1(0x190)]('');}function maskNestedQueries(_0x54bafb){const _0x1f3964=a309_0x236a,_0x49effa=Array[_0x1f3964(0x1c0)](_0x54bafb);for(let _0x2bbaa6=0x0;_0x2bbaa6<_0x49effa[_0x1f3964(0x1ae)];_0x2bbaa6+=0x1){if(_0x49effa[_0x2bbaa6]!=='(')continue;const _0xf04c53=_0x54bafb[_0x1f3964(0x17e)](_0x2bbaa6+0x1);if(!/^\s*(?:SELECT|WITH)\b/i[_0x1f3964(0x1a5)](_0xf04c53))continue;let _0x3028e8=0x1,_0x5ec51d=_0x2bbaa6+0x1;for(;_0x5ec51d<_0x49effa[_0x1f3964(0x1ae)]&&_0x3028e8>0x0;_0x5ec51d+=0x1){if(_0x49effa[_0x5ec51d]==='(')_0x3028e8+=0x1;if(_0x49effa[_0x5ec51d]===')')_0x3028e8-=0x1;}if(_0x3028e8!==0x0)continue;for(let _0x1cc616=_0x2bbaa6;_0x1cc616<_0x5ec51d;_0x1cc616+=0x1){_0x49effa[_0x1cc616]='\x20';}const _0x79eff0='__sq__';for(let _0x2ada1b=0x0;_0x2ada1b<_0x79eff0[_0x1f3964(0x1ae)]&&_0x2bbaa6+_0x2ada1b<_0x5ec51d;_0x2ada1b+=0x1){_0x49effa[_0x2bbaa6+_0x2ada1b]=_0x79eff0[_0x2ada1b];}_0x2bbaa6=_0x5ec51d-0x1;}return _0x49effa[_0x1f3964(0x190)]('');}function splitTopLevelAnd(_0x31ae53){const _0x3dd9ed=a309_0x236a,_0x2259bb=[];let _0x2f4f03=0x0,_0x6414b9=0x0;for(let _0x2c77df=0x0;_0x2c77df<_0x31ae53['length'];_0x2c77df+=0x1){const _0x52fed3=_0x31ae53[_0x2c77df];if(_0x52fed3==='(')_0x2f4f03+=0x1;if(_0x52fed3===')')_0x2f4f03=Math[_0x3dd9ed(0x1b4)](0x0,_0x2f4f03-0x1);_0x2f4f03===0x0&&_0x31ae53[_0x3dd9ed(0x17e)](_0x2c77df)[_0x3dd9ed(0x189)](/^AND\b/i)&&(_0x2c77df===0x0||/\s/[_0x3dd9ed(0x1a5)](_0x31ae53[_0x2c77df-0x1]??''))&&(_0x2259bb['push'](_0x31ae53[_0x3dd9ed(0x17e)](_0x6414b9,_0x2c77df)[_0x3dd9ed(0x19c)]()),_0x2c77df+=0x2,_0x6414b9=_0x2c77df+0x1);}const _0x175212=_0x31ae53[_0x3dd9ed(0x17e)](_0x6414b9)[_0x3dd9ed(0x19c)]();if(_0x175212)_0x2259bb['push'](_0x175212);return _0x2259bb;}function hasTopLevelKeyword(_0x578770,_0x4b31b3){const _0x5c8867=a309_0x236a;let _0x3e6803=0x0;for(let _0x24e680=0x0;_0x24e680<_0x578770[_0x5c8867(0x1ae)];_0x24e680+=0x1){const _0x3f5756=_0x578770[_0x24e680];if(_0x3f5756==='(')_0x3e6803+=0x1;if(_0x3f5756===')')_0x3e6803=Math['max'](0x0,_0x3e6803-0x1);if(_0x3e6803!==0x0)continue;const _0x206add=_0x578770[_0x5c8867(0x17e)](_0x24e680,_0x24e680+_0x4b31b3['length']),_0x2d913b=_0x578770[_0x24e680-0x1]??'\x20',_0xeae871=_0x578770[_0x24e680+_0x4b31b3[_0x5c8867(0x1ae)]]??'\x20';if(_0x206add[_0x5c8867(0x198)]()===_0x4b31b3[_0x5c8867(0x198)]()&&!/[\w$]/['test'](_0x2d913b)&&!/[\w$]/[_0x5c8867(0x1a5)](_0xeae871))return!![];}return![];}function splitEquality(_0x41ffd4){const _0x59406c=a309_0x236a,_0x22f496=stripOuterParentheses(_0x41ffd4);let _0x4d518f=0x0,_0x59f5a2;for(let _0xb8847a=0x0;_0xb8847a<_0x22f496[_0x59406c(0x1ae)];_0xb8847a+=0x1){const _0x553e3c=_0x22f496[_0xb8847a];if(_0x553e3c==='(')_0x4d518f+=0x1;if(_0x553e3c===')')_0x4d518f=Math[_0x59406c(0x1b4)](0x0,_0x4d518f-0x1);const _0x562c96=_0x22f496[_0xb8847a-0x1]??'',_0x4d38d5=_0x22f496[_0xb8847a+0x1]??'';if(_0x553e3c==='='&&_0x4d518f===0x0&&!/[!<>=:]/['test'](_0x562c96)&&_0x4d38d5!=='='){if(_0x59f5a2!==undefined)return null;_0x59f5a2=_0xb8847a;}}return _0x59f5a2===undefined?null:[_0x22f496[_0x59406c(0x17e)](0x0,_0x59f5a2)['trim'](),_0x22f496['slice'](_0x59f5a2+0x1)[_0x59406c(0x19c)]()];}function parseDirectColumnReference(_0x4677b7,_0x24da14){const _0x28dab9=/^([`"]?[\w$]+[`"]?)\s*\.\s*([`"]?[\w$]+[`"]?)$/['exec'](stripOuterParentheses(_0x4677b7));if(!_0x28dab9)return null;if(normalizeIdentifier(_0x28dab9[0x1]??'')!==normalizeIdentifier(_0x24da14))return null;return normalizeIdentifier(_0x28dab9[0x2]??'');}function containsColumnReference(_0x113b0d,_0x1ac1a4){const _0xfe02f2=a309_0x236a,_0x2ccd77=_0x113b0d[_0xfe02f2(0x1a6)](/[`"]/g,''),_0x301878=_0x1ac1a4[_0xfe02f2(0x1a6)](/[.*+?^${}()|[\]\\]/g,_0xfe02f2(0x1bb));return new RegExp(_0xfe02f2(0x19f)+_0x301878+_0xfe02f2(0x1c4),'i')[_0xfe02f2(0x1a5)](_0x2ccd77);}function findEqualityPrefix(_0x457f70,_0x46fddd){const _0x1e86e4=a309_0x236a,_0x207206=new Set(_0x46fddd['map'](normalizeIdentifier)),_0xdbdfe9=[];for(const _0x5c94dd of _0x457f70){if(!_0x207206[_0x1e86e4(0x1b1)](normalizeIdentifier(_0x5c94dd)))break;_0xdbdfe9[_0x1e86e4(0x19d)](_0x5c94dd);}return _0xdbdfe9;}function resolveTableMetadata(_0x482d58,_0x3ce158){const _0x127a01=a309_0x236a,_0x9cfc4=normalizeIdentifier(_0x3ce158),_0x2d0a26=_0x482d58[_0x127a01(0x19b)](_0x40b180=>normalizeIdentifier(_0x40b180['tableName'])===_0x9cfc4);if(_0x2d0a26[_0x127a01(0x1ae)]===0x1)return _0x2d0a26[0x0];const _0x340aae=_0x9cfc4[_0x127a01(0x188)]('.'),_0x3add60=_0x9cfc4[_0x127a01(0x1bc)]('.')['at'](-0x1),_0xcfb3a3=_0x482d58[_0x127a01(0x19b)](_0x1242a4=>{const _0x20c6e4=_0x127a01,_0x4b12ef=normalizeIdentifier(_0x1242a4[_0x20c6e4(0x182)]);if(_0x340aae&&_0x4b12ef[_0x20c6e4(0x188)]('.'))return![];return _0x4b12ef[_0x20c6e4(0x1bc)]('.')['at'](-0x1)===_0x3add60;});return _0xcfb3a3[_0x127a01(0x1ae)]===0x1?_0xcfb3a3[0x0]:undefined;}function columnNamesMatch(_0x599171,_0xa0a93d){return normalizeIdentifier(_0x599171)===normalizeIdentifier(_0xa0a93d);}function a309_0x236a(_0x35bfe0,_0x402829){_0x35bfe0=_0x35bfe0-0x17a;const _0x39487f=a309_0x3948();let _0x236a2a=_0x39487f[_0x35bfe0];return _0x236a2a;}function normalizeIdentifier(_0x2af80b){const _0x312740=a309_0x236a;return _0x2af80b[_0x312740(0x1a6)](/[`"]/g,'')[_0x312740(0x19c)]()[_0x312740(0x195)]();}function isSqlClauseKeyword(_0x209ac5){const _0x283562=a309_0x236a;return new Set(['on',_0x283562(0x1ad),_0x283562(0x17c),'join',_0x283562(0x1b5),'left',_0x283562(0x1a9),_0x283562(0x1b3),_0x283562(0x1b8),_0x283562(0x1ab)])['has'](_0x209ac5);}function stripOuterParentheses(_0x40bcb6){const _0x3169ee=a309_0x236a;let _0x30f1a0=_0x40bcb6[_0x3169ee(0x19c)]();while(_0x30f1a0['startsWith']('(')&&_0x30f1a0['endsWith'](')')){let _0x499bc2=0x0,_0xf04ae1=!![];for(let _0x38f280=0x0;_0x38f280<_0x30f1a0['length'];_0x38f280+=0x1){if(_0x30f1a0[_0x38f280]==='(')_0x499bc2+=0x1;if(_0x30f1a0[_0x38f280]===')')_0x499bc2-=0x1;if(_0x499bc2===0x0&&_0x38f280<_0x30f1a0['length']-0x1){_0xf04ae1=![];break;}}if(!_0xf04ae1||_0x499bc2!==0x0)break;_0x30f1a0=_0x30f1a0['slice'](0x1,-0x1)['trim']();}return _0x30f1a0;}
|
|
1
|
+
import{MYBATIS_DYNAMIC_END_MARKER,MYBATIS_DYNAMIC_START_MARKER,MYBATIS_INCLUDE_MARKER,normalizeSqlForStaticAnalysis}from"./sql-validator.js";export function auditSqlJoinIndexes(sqlContent,tables){const warnings=[];const source=normalizeSqlForStaticAnalysis(sqlContent);const joins=(source.error?[]:extractJoinFacts(source.sql)).map(join=>{if(join.unsupportedPredicate||join.columns.length===0){warnings.push({code:"JOIN_PREDICATE_UNSUPPORTED",table:join.table,alias:join.alias,columns:join.columns,reason:join.unsupportedReason??"Not every JOIN target predicate could be audited safely."});return{table:join.table,alias:join.alias,columns:join.columns,status:"unavailable"}}const metadata=resolveTableMetadata(tables,join.table);const matchedIndexes=(metadata?.indexes??[]).map(index=>({index:index,matchedPrefix:findEqualityPrefix(index.columns,join.columns)})).filter(match=>match.matchedPrefix.length>0)
|
|
2
|
+
;const matchedIndex=matchedIndexes.reduce((best,match)=>!best||match.matchedPrefix.length>best.matchedPrefix.length?match:best,matchedIndexes[0]);if(matchedIndex){return{table:join.table,alias:join.alias,columns:join.columns,status:"covered",matchedIndex:{...matchedIndex.index,matchedPrefix:matchedIndex.matchedPrefix}}}const candidateIndexes=metadata?.indexes.filter(index=>index.columns.some(column=>join.columns.some(joinColumn=>columnNamesMatch(column,joinColumn))))??[];if(candidateIndexes.length>0){warnings.push({code:"JOIN_INDEX_NOT_USABLE",table:join.table,alias:join.alias,columns:join.columns,reason:"Relevant columns do not form a complete leftmost index prefix."});return{table:join.table,alias:join.alias,columns:join.columns,status:"warning",candidateIndexes:candidateIndexes}}if(metadata&&metadata.metadataAvailable!==false&&metadata.indexes.length>0&&join.columns.length>0){warnings.push({code:"JOIN_INDEX_MISSING",table:join.table,alias:join.alias,columns:join.columns,
|
|
3
|
+
reason:"No reported index contains the JOIN access columns."});return{table:join.table,alias:join.alias,columns:join.columns,status:"warning"}}warnings.push({code:"INDEX_METADATA_UNAVAILABLE",table:join.table,alias:join.alias,columns:join.columns,reason:metadata?"The dataset returned no distinguishable index metadata.":"No dataset metadata matched the JOIN table."});return{table:join.table,alias:join.alias,columns:join.columns,status:"unavailable"}});return{checked:joins.length>0,joins:joins,warnings:warnings}}function extractJoinFacts(sqlContent){const cleaned=maskNestedQueries(stripSqlNoise(sqlContent));const keywordScan=maskQuotedIdentifiers(cleaned);const joins=[];const parsedJoinPositions=new Set;const joinPattern=/\b(?:(INNER|LEFT|RIGHT|FULL)(?:\s+OUTER)?\s+)?JOIN\s+([`"\w$.]+)(?:\s+(?:AS\s+)?([`"\w$]+))?\s+ON\s+([\s\S]*?)(?=\s+(?:(?:(?:INNER|LEFT|RIGHT|FULL)(?:\s+OUTER)?\s+)?JOIN\b|(?:WHERE|GROUP\s+BY|ORDER\s+BY|HAVING|LIMIT|UNION)\b)|;|$)/gi
|
|
4
|
+
;for(const match of cleaned.matchAll(joinPattern)){const matchPosition=match.index??0;const joinOffset=match[0].search(/\bJOIN\b/i);const position=matchPosition+Math.max(0,joinOffset);if(!/^JOIN\b/i.test(keywordScan.slice(position)))continue;parsedJoinPositions.add(position);const joinType=normalizeIdentifier(match[1]||"INNER");const table=normalizeIdentifier(match[2]??"");const alias=normalizeIdentifier(match[3]||table.split(".").at(-1)||table);const columns=[];const derivedTable=table==="__sq__";let unsupportedPredicate=joinType==="right"||joinType==="full"||derivedTable;let unsupportedReason=unsupportedPredicate?derivedTable?"Derived-table JOIN targets are not supported.":`${joinType.toUpperCase()} JOIN direction is not supported by static index auditing.`:undefined;const rawOnExpression=stripOuterParentheses(match[4]??"");const hasDynamicBranch=rawOnExpression.includes(MYBATIS_DYNAMIC_START_MARKER)||rawOnExpression.includes(MYBATIS_DYNAMIC_END_MARKER)
|
|
5
|
+
;const containsUnresolvedInclude=rawOnExpression.includes(MYBATIS_INCLUDE_MARKER);if(hasDynamicBranch){unsupportedPredicate=true;unsupportedReason??="MyBatis dynamic JOIN predicates cannot be audited deterministically."}if(containsUnresolvedInclude){unsupportedPredicate=true;unsupportedReason??="MyBatis <include> JOIN fragments cannot be expanded statically."}const onExpression=rawOnExpression.replaceAll(MYBATIS_DYNAMIC_START_MARKER," ").replaceAll(MYBATIS_DYNAMIC_END_MARKER," ").replaceAll(MYBATIS_INCLUDE_MARKER," ");if(hasTopLevelKeyword(onExpression,"OR")){unsupportedPredicate=true;unsupportedReason??="OR-connected JOIN predicates are not supported."}for(const predicate of splitTopLevelAnd(onExpression)){const normalizedPredicate=stripOuterParentheses(predicate);if(hasTopLevelKeyword(normalizedPredicate,"OR")){unsupportedPredicate=true;unsupportedReason??="OR-connected JOIN predicates are not supported.";continue}const equality=splitEquality(normalizedPredicate);if(!equality){
|
|
6
|
+
if(containsColumnReference(predicate,alias)){unsupportedPredicate=true}continue}const leftColumn=parseDirectColumnReference(equality[0],alias);const rightColumn=parseDirectColumnReference(equality[1],alias);const leftReferencesTarget=containsColumnReference(equality[0],alias);const rightReferencesTarget=containsColumnReference(equality[1],alias);const column=leftColumn&&!rightReferencesTarget?leftColumn:rightColumn&&!leftReferencesTarget?rightColumn:null;if(column&&!columns.includes(column)){columns.push(column)}else if(!column&&containsColumnReference(predicate,alias)){unsupportedPredicate=true}}joins.push({table:table,alias:alias,columns:columns,unsupportedPredicate:unsupportedPredicate,unsupportedReason:unsupportedReason,containsUnresolvedInclude:containsUnresolvedInclude,position:position})}for(const match of keywordScan.matchAll(/\bJOIN\b/gi)){const position=match.index??0;if(parsedJoinPositions.has(position))continue
|
|
7
|
+
;const targetMatch=/^\s+([`"\w$.]+)(?:\s+(?:AS\s+)?([`"\w$]+))?/.exec(cleaned.slice(position+match[0].length));const table=normalizeIdentifier(targetMatch?.[1]||"unknown");const parsedAlias=normalizeIdentifier(targetMatch?.[2]||"");const alias=isSqlClauseKeyword(parsedAlias)?table.split(".").at(-1)||table:parsedAlias||table.split(".").at(-1)||table;joins.push({table:table,alias:alias,columns:[],unsupportedPredicate:true,unsupportedReason:"Only explicit table JOIN clauses with an ON predicate are supported.",position:position})}const unresolvedIncludePosition=keywordScan.indexOf(MYBATIS_INCLUDE_MARKER);if(unresolvedIncludePosition>=0&&!joins.some(join=>join.containsUnresolvedInclude)){joins.push({table:"unknown",alias:"unknown",columns:[],unsupportedPredicate:true,unsupportedReason:"MyBatis <include> fragments cannot be expanded for JOIN auditing.",containsUnresolvedInclude:true,position:unresolvedIncludePosition})}return joins.sort((left,right)=>left.position-right.position)}
|
|
8
|
+
function stripSqlNoise(sqlContent){const characters=Array.from(sqlContent);const blank=(start,end)=>{for(let index=start;index<end;index+=1){if(characters[index]!=="\n"&&characters[index]!=="\r"){characters[index]=" "}}};for(let index=0;index<characters.length;index+=1){const char=characters[index];const next=characters[index+1];if(char==="'"||char==='"'||char==="`"){const quote=char;const start=index;index+=1;while(index<characters.length){if(characters[index]==="\\"&&index+1<characters.length){index+=2;continue}if(characters[index]!==quote){index+=1;continue}if(characters[index+1]===quote){index+=2;continue}break}if(quote==="'")blank(start,Math.min(index+1,characters.length));continue}if(char==="-"&&next==="-"){const start=index;while(index<characters.length&&characters[index]!=="\n")index+=1;blank(start,index);continue}if(char==="/"&&next==="*"){const start=index;index+=2;while(index<characters.length&&!(characters[index]==="*"&&characters[index+1]==="/")){index+=1}
|
|
9
|
+
index=Math.min(index+1,characters.length-1);blank(start,index+1);continue}if(char==="#"&&next!=="{"){const start=index;while(index<characters.length&&characters[index]!=="\n")index+=1;blank(start,index);continue}if((char==="#"||char==="$")&&next==="{"){const start=index;index+=2;while(index<characters.length&&characters[index]!=="}")index+=1;blank(start,Math.min(index+1,characters.length))}}return characters.join("")}function maskQuotedIdentifiers(sqlContent){const characters=Array.from(sqlContent);for(let index=0;index<characters.length;index+=1){const quote=characters[index];if(quote!=='"'&"e!=="`")continue;index+=1;while(index<characters.length){if(characters[index]===quote){if(characters[index+1]===quote){characters[index]=" ";characters[index+1]=" ";index+=2;continue}break}characters[index]=" ";index+=1}}return characters.join("")}function maskNestedQueries(sqlContent){const characters=Array.from(sqlContent);for(let index=0;index<characters.length;index+=1){
|
|
10
|
+
if(characters[index]!=="(")continue;const remainder=sqlContent.slice(index+1);if(!/^\s*(?:SELECT|WITH)\b/i.test(remainder))continue;let depth=1;let cursor=index+1;for(;cursor<characters.length&&depth>0;cursor+=1){if(characters[cursor]==="(")depth+=1;if(characters[cursor]===")")depth-=1}if(depth!==0)continue;for(let nestedIndex=index;nestedIndex<cursor;nestedIndex+=1){characters[nestedIndex]=" "}const marker="__sq__";for(let markerIndex=0;markerIndex<marker.length&&index+markerIndex<cursor;markerIndex+=1){characters[index+markerIndex]=marker[markerIndex]}index=cursor-1}return characters.join("")}function splitTopLevelAnd(expression){const parts=[];let depth=0;let start=0;for(let index=0;index<expression.length;index+=1){const char=expression[index];if(char==="(")depth+=1;if(char===")")depth=Math.max(0,depth-1);if(depth===0&&expression.slice(index).match(/^AND\b/i)&&(index===0||/\s/.test(expression[index-1]??""))){parts.push(expression.slice(start,index).trim());index+=2;start=index+1}}
|
|
11
|
+
const tail=expression.slice(start).trim();if(tail)parts.push(tail);return parts}function hasTopLevelKeyword(expression,keyword){let depth=0;for(let index=0;index<expression.length;index+=1){const char=expression[index];if(char==="(")depth+=1;if(char===")")depth=Math.max(0,depth-1);if(depth!==0)continue;const candidate=expression.slice(index,index+keyword.length);const previous=expression[index-1]??" ";const next=expression[index+keyword.length]??" ";if(candidate.toUpperCase()===keyword.toUpperCase()&&!/[\w$]/.test(previous)&&!/[\w$]/.test(next)){return true}}return false}function splitEquality(predicate){const normalizedPredicate=stripOuterParentheses(predicate);let depth=0;let equalityPosition;for(let index=0;index<normalizedPredicate.length;index+=1){const char=normalizedPredicate[index];if(char==="(")depth+=1;if(char===")")depth=Math.max(0,depth-1);const previous=normalizedPredicate[index-1]??"";const next=normalizedPredicate[index+1]??""
|
|
12
|
+
;if(char==="="&&depth===0&&!/[!<>=:]/.test(previous)&&next!=="="){if(equalityPosition!==undefined)return null;equalityPosition=index}}return equalityPosition===undefined?null:[normalizedPredicate.slice(0,equalityPosition).trim(),normalizedPredicate.slice(equalityPosition+1).trim()]}function parseDirectColumnReference(side,expectedAlias){const match=/^([`"]?[\w$]+[`"]?)\s*\.\s*([`"]?[\w$]+[`"]?)$/.exec(stripOuterParentheses(side));if(!match)return null;if(normalizeIdentifier(match[1]??"")!==normalizeIdentifier(expectedAlias)){return null}return normalizeIdentifier(match[2]??"")}function containsColumnReference(predicate,expectedAlias){const unquoted=predicate.replace(/[`"]/g,"");const escapedAlias=expectedAlias.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(?:^|[^\\w$])${escapedAlias}\\s*\\.\\s*[\\w$]+`,"i").test(unquoted)}function findEqualityPrefix(indexColumns,predicateColumns){const expected=new Set(predicateColumns.map(normalizeIdentifier));const prefix=[]
|
|
13
|
+
;for(const column of indexColumns){if(!expected.has(normalizeIdentifier(column)))break;prefix.push(column)}return prefix}function resolveTableMetadata(tables,joinTable){const normalizedJoinTable=normalizeIdentifier(joinTable);const exactMatches=tables.filter(table=>normalizeIdentifier(table.tableName)===normalizedJoinTable);if(exactMatches.length===1)return exactMatches[0];const joinTableQualified=normalizedJoinTable.includes(".");const joinBasename=normalizedJoinTable.split(".").at(-1);const basenameMatches=tables.filter(table=>{const normalizedTable=normalizeIdentifier(table.tableName);if(joinTableQualified&&normalizedTable.includes("."))return false;return normalizedTable.split(".").at(-1)===joinBasename});return basenameMatches.length===1?basenameMatches[0]:undefined}function columnNamesMatch(left,right){return normalizeIdentifier(left)===normalizeIdentifier(right)}function normalizeIdentifier(identifier){return identifier.replace(/[`"]/g,"").trim().toLowerCase()}
|
|
14
|
+
function isSqlClauseKeyword(identifier){return new Set(["on","using","where","join","inner","left","right","full","cross","natural"]).has(identifier)}function stripOuterParentheses(value){let result=value.trim();while(result.startsWith("(")&&result.endsWith(")")){let depth=0;let enclosesEntireValue=true;for(let index=0;index<result.length;index+=1){if(result[index]==="(")depth+=1;if(result[index]===")")depth-=1;if(depth===0&&index<result.length-1){enclosesEntireValue=false;break}}if(!enclosesEntireValue||depth!==0)break;result=result.slice(1,-1).trim()}return result}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{resolve}from"node:path";import{findProjectRootDirectory}from"../../context.js";const DOT_DIR=".rabetbase";const LOCK_FILE_NAME="sql.lock.json";const TRASH_DIR_NAME="sql-trash";export function loadSqlProjectConfig(appCode,projectRoot){const root=resolve(projectRoot??findProjectRootDirectory());const sqlWorkspaceRoot=`${DOT_DIR}/sql`;const sqlRoot=`${sqlWorkspaceRoot}/${appCode}`;return{projectRoot:root,appCode:appCode,sqlWorkspaceRoot:sqlWorkspaceRoot,sqlRoot:sqlRoot,sqlRootDir:resolve(root,DOT_DIR,"sql",appCode),lockFilePath:resolve(root,DOT_DIR,LOCK_FILE_NAME),trashDir:resolve(root,DOT_DIR,TRASH_DIR_NAME)}}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import{readdir,stat}from"node:fs/promises";import{extname,join,relative}from"node:path";import{buildDefaultSqlFileName,buildSqlRelativePath}from"./utils.js";function extensionToMode(extension){if(extension===".sql")return"sql";if(extension===".xml")return"mybatisXml";return undefined}async function scanSqlFilesRecursively(dir,rootDir){const result=[];try{const entries=await readdir(dir,{withFileTypes:true});for(const entry of entries){const fullPath=join(dir,entry.name);if(entry.isDirectory()){result.push(...await scanSqlFilesRecursively(fullPath,rootDir));continue}if(!entry.isFile())continue;const extension=extname(entry.name).toLowerCase();const mode=extensionToMode(extension);if(!mode)continue;const relativePath=relative(rootDir,fullPath).replace(/\\/g,"/");const segments=relativePath.split("/").filter(Boolean);const parsed=parseSqlPath(segments,entry.name,extension);if(!parsed)continue;result.push({sqlCode:parsed.sqlCode,sqlName:parsed.sqlName,dbDirectory:segments[0],
|
|
2
|
+
filePath:fullPath,relativePath:relativePath,lockKey:parsed.sqlCode,mode:mode})}}catch(error){if(error.code!=="ENOENT")throw error}return result}export async function scanLocalSqlQueries(config){return scanSqlFilesRecursively(config.sqlRootDir,config.sqlRootDir)}export function resolveLocalSqlFilePath(config,sqlCode,lockEntry){const relativePath=lockEntry?.path||(lockEntry?.sqlName||lockEntry?.dbName?buildSqlRelativePath(sqlCode,lockEntry?.sqlName,lockEntry?.dbName,lockEntry?.mode||"sql",lockEntry?.dbId):buildDefaultSqlFileName(sqlCode,lockEntry?.mode||"sql"));return join(config.sqlRootDir,relativePath)}export async function directoryExists(dirPath){try{const s=await stat(dirPath);return s.isDirectory()}catch{return false}}function parseSqlPath(segments,fileName,extension){const fileBaseName=fileName.slice(0,-extension.length);if(segments.length<2){return null}const underscoreIndex=fileBaseName.indexOf("_");if(underscoreIndex<=0||underscoreIndex>=fileBaseName.length-1){return null}
|
|
3
|
+
const sqlCode=fileBaseName.slice(0,underscoreIndex);if(!isLikelySqlCode(sqlCode)){return null}return{sqlCode:sqlCode,sqlName:fileBaseName.slice(underscoreIndex+1)}}function isLikelySqlCode(value){return/^[A-Za-z0-9-]+-[A-Za-z0-9-]+$/.test(value)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{readFile}from"node:fs/promises";import crypto from"node:crypto";export function computeSqlContentHash(content){return crypto.createHash("md5").update(content).digest("hex")}export async function computeSqlFileHash(filePath){const content=await readFile(filePath,"utf8");return computeSqlContentHash(content)}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{mkdir,readFile,writeFile}from"node:fs/promises";import{dirname}from"node:path";export function createEmptySqlLock(){return{apps:{}}}export function ensureSqlLockScope(lockData,currentAppCode,currentSqlRoot,commandName){const nextLockData=lockData??createEmptySqlLock();let appLock=nextLockData.apps[currentAppCode];if(!appLock){appLock={sqlRoot:currentSqlRoot,lastSync:"",sqls:{}};nextLockData.apps[currentAppCode]=appLock;return{lockData:nextLockData,appLock:appLock}}if(!appLock.sqlRoot){appLock.sqlRoot=currentSqlRoot}else if(appLock.sqlRoot!==currentSqlRoot){throw new Error(`${commandName}: sqlRoot mismatch — current "${currentSqlRoot}" vs lock "${appLock.sqlRoot}". `+`Check .rabetbase/sql.lock.json or operate from the correct project directory.`)}if(!appLock.sqls){appLock.sqls={}}if(!appLock.lastSync){appLock.lastSync=""}return{lockData:nextLockData,appLock:appLock}}export async function readSqlLockFile(lockFilePath){try{const content=await readFile(lockFilePath,"utf8")
|
|
2
|
+
;return JSON.parse(content)}catch(error){if(error.code==="ENOENT"){return null}throw new Error(`Failed to read SQL lock file: ${String(error)}`)}}export async function writeSqlLockFile(lockFilePath,lockData){await mkdir(dirname(lockFilePath),{recursive:true});await writeFile(lockFilePath,JSON.stringify(lockData,null,2),"utf8")}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export{};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{detectSqlSourceMode}from"../../core/sql-validator.js";export function detectSqlMode(sqlContent){return detectSqlSourceMode(sqlContent)}export function getSqlFileExtension(mode){return mode==="mybatisXml"?".xml":".sql"}export function buildDefaultSqlFileName(sqlCode,mode){return`${sqlCode}${getSqlFileExtension(mode)}`}export function sanitizeSqlPathSegment(value,fallback){const trimmed=String(value??"").trim();const normalized=trimmed.replace(/[<>:"/\\|?*\u0000-\u001F]/g,"-").replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^\.+/,"").replace(/\.+$/,"").replace(/^-+/,"").replace(/-+$/,"");return normalized||fallback}export function buildDbDirectoryName(dbName,dbId){return sanitizeSqlPathSegment(dbName,dbId!=null?`db-${dbId}`:"unknown-db")}export function buildSqlRelativePath(sqlCode,sqlName,dbName,mode,dbId){const dbDirName=buildDbDirectoryName(dbName,dbId);const safeSqlCode=sanitizeSqlPathSegment(sqlCode,"unknown-sql");const safeSqlName=sanitizeSqlPathSegment(sqlName,safeSqlCode)
|
|
2
|
+
;return`${dbDirName}/${safeSqlCode}_${safeSqlName}${getSqlFileExtension(mode)}`}
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
const a316_0x5e390b=a316_0x33c6;(function(_0x440d3d,_0x2599ab){const _0x3f92ea=a316_0x33c6,_0x583ae9=_0x440d3d();while(!![]){try{const _0x24f1e1=-parseInt(_0x3f92ea(0x13a))/0x1*(-parseInt(_0x3f92ea(0x110))/0x2)+parseInt(_0x3f92ea(0xfe))/0x3*(-parseInt(_0x3f92ea(0x121))/0x4)+parseInt(_0x3f92ea(0x115))/0x5+parseInt(_0x3f92ea(0x136))/0x6*(-parseInt(_0x3f92ea(0x103))/0x7)+-parseInt(_0x3f92ea(0x141))/0x8+-parseInt(_0x3f92ea(0x13f))/0x9*(-parseInt(_0x3f92ea(0x12b))/0xa)+-parseInt(_0x3f92ea(0xf9))/0xb;if(_0x24f1e1===_0x2599ab)break;else _0x583ae9['push'](_0x583ae9['shift']());}catch(_0x4f9936){_0x583ae9['push'](_0x583ae9['shift']());}}}(a316_0x5984,0xa0c29));const MYBATIS_OUTER_TAGS=new Map([[a316_0x5e390b(0x139),'SELECT'],['insert','INSERT'],[a316_0x5e390b(0xff),a316_0x5e390b(0x118)],[a316_0x5e390b(0x144),a316_0x5e390b(0x12f)]]),MYBATIS_DYNAMIC_TAGS=new Set(['if','where','foreach',a316_0x5e390b(0xf4),'when','otherwise',a316_0x5e390b(0x116),'set',a316_0x5e390b(0x13d),a316_0x5e390b(0x138),a316_0x5e390b(0x149)]),MYBATIS_BRANCH_TAGS=new Set(['if',a316_0x5e390b(0x12d),a316_0x5e390b(0xf4),a316_0x5e390b(0x12c),'otherwise']);export const MYBATIS_DYNAMIC_START_MARKER=a316_0x5e390b(0x11b);export const MYBATIS_DYNAMIC_END_MARKER=a316_0x5e390b(0x152);export const MYBATIS_INCLUDE_MARKER=a316_0x5e390b(0x153);const UNRESOLVED_SQL_FRAGMENT=a316_0x5e390b(0x120),MYBATIS_OUTER_TAG_PATTERN=new RegExp(a316_0x5e390b(0x14c)+[...MYBATIS_OUTER_TAGS[a316_0x5e390b(0x12a)]()]['join']('|')+')\x5cb','i');export function normalizeSqlForStaticAnalysis(_0x19c25e){const _0x9a2fbb=a316_0x5e390b,_0x1d749e=typeof _0x19c25e===_0x9a2fbb(0x137)?_0x19c25e:'';if(detectSqlSourceMode(_0x1d749e)===_0x9a2fbb(0x13e))return{'sql':_0x1d749e,'mode':_0x9a2fbb(0x13e)};let _0x31c0ef=0x0,_0x35ce97='',_0x238a8c,_0x1a9231=![],_0x1b5bae=![];const _0x587ea5=[];while(_0x31c0ef<_0x1d749e['length']){if(_0x1d749e[_0x9a2fbb(0x107)](_0x9a2fbb(0x104),_0x31c0ef)){const _0x1d0ac0=_0x1d749e[_0x9a2fbb(0x102)](_0x9a2fbb(0x148),_0x31c0ef+0x4);if(_0x1d0ac0<0x0)return invalidMybatisSource(_0x9a2fbb(0x101));_0x35ce97+='\x20',_0x31c0ef=_0x1d0ac0+0x3;continue;}if(_0x1d749e[_0x9a2fbb(0x107)](_0x9a2fbb(0x10f),_0x31c0ef)){if(!_0x1a9231||_0x1b5bae)return invalidMybatisSource(_0x9a2fbb(0xfb));const _0x232fb7=_0x1d749e[_0x9a2fbb(0x102)](_0x9a2fbb(0xf1),_0x31c0ef+0x9);if(_0x232fb7<0x0)return invalidMybatisSource('Unterminated\x20CDATA\x20section.');_0x35ce97+=_0x1d749e[_0x9a2fbb(0xfd)](_0x31c0ef+0x9,_0x232fb7),_0x31c0ef=_0x232fb7+0x3;continue;}if(_0x1d749e['startsWith']('<?',_0x31c0ef)){if(_0x1a9231)return invalidMybatisSource('XML\x20declarations\x20must\x20precede\x20the\x20MyBatis\x20statement\x20wrapper.');const _0x487d3=_0x1d749e[_0x9a2fbb(0x102)]('?>',_0x31c0ef+0x2);if(_0x487d3<0x0)return invalidMybatisSource('Unterminated\x20XML\x20declaration.');_0x35ce97+='\x20',_0x31c0ef=_0x487d3+0x2;continue;}if(_0x1d749e[_0x31c0ef]!=='<'){const _0x2d608f=_0x1d749e[_0x9a2fbb(0x102)]('<',_0x31c0ef),_0x376e6f=_0x2d608f<0x0?_0x1d749e[_0x9a2fbb(0x147)]:_0x2d608f,_0x478937=_0x1d749e[_0x9a2fbb(0xfd)](_0x31c0ef,_0x376e6f);if((!_0x1a9231||_0x1b5bae)&&_0x478937[_0x9a2fbb(0x116)]())return invalidMybatisSource(_0x9a2fbb(0x10a));if(_0x1a9231&&!_0x1b5bae){const _0xb9e68e=decodeXmlEntities(_0x478937);if(_0xb9e68e===null)return invalidMybatisSource(_0x9a2fbb(0x10d));_0x35ce97+=_0xb9e68e;}else _0x35ce97+='\x20';_0x31c0ef=_0x376e6f;continue;}const _0x39e419=findXmlTagEnd(_0x1d749e,_0x31c0ef);if(_0x39e419<0x0)return invalidMybatisSource(_0x9a2fbb(0x10b));const _0x5c64ac=_0x1d749e[_0x9a2fbb(0xfd)](_0x31c0ef,_0x39e419+0x1),_0x3e0870=/^<\s*(\/?)\s*([A-Za-z][\w:-]*)([\s\S]*?)(\/?)\s*>$/[_0x9a2fbb(0x111)](_0x5c64ac);if(!_0x3e0870)return invalidMybatisSource('Invalid\x20MyBatis\x20XML\x20tag.');const _0x3415e5=_0x3e0870[0x1]==='/',_0x29a915=_0x3e0870[0x2]??'',_0x40d337=_0x29a915['toLowerCase'](),_0x53aa59=_0x3e0870[0x3]??'',_0xc4c5de=_0x3e0870[0x4]==='/',_0x23389e=MYBATIS_OUTER_TAGS[_0x9a2fbb(0x11c)](_0x40d337);if(!_0x23389e&&!MYBATIS_DYNAMIC_TAGS[_0x9a2fbb(0x109)](_0x40d337))return invalidMybatisSource('Unsupported\x20MyBatis\x20XML\x20tag:\x20<'+_0x40d337+'>.');if(!_0x23389e&&_0x29a915!==_0x40d337)return invalidMybatisSource(_0x9a2fbb(0x126)+_0x29a915+'>.');if(_0x3415e5){if(_0x53aa59[_0x9a2fbb(0x116)]()||_0xc4c5de)return invalidMybatisSource(_0x9a2fbb(0x134)+_0x29a915+'>.');const _0x5d5144=_0x587ea5['at'](-0x1);if(!_0x5d5144||(_0x5d5144[_0x9a2fbb(0x146)]?_0x5d5144['tagName']!==_0x40d337:_0x5d5144[_0x9a2fbb(0x124)]!==_0x29a915))return invalidMybatisSource('Mismatched\x20MyBatis\x20XML\x20closing\x20tag:\x20</'+_0x29a915+'>.');_0x587ea5['pop']();if(_0x5d5144[_0x9a2fbb(0x146)])_0x1b5bae=!![];_0x35ce97+=MYBATIS_BRANCH_TAGS[_0x9a2fbb(0x109)](_0x40d337)?'\x20'+MYBATIS_DYNAMIC_END_MARKER+'\x20':'\x20';}else{if(!hasWellFormedXmlAttributes(_0x53aa59))return invalidMybatisSource(_0x9a2fbb(0x151)+_0x29a915+'>.');if(_0x40d337===_0x9a2fbb(0x149)&&(!_0xc4c5de||_0x587ea5['at'](-0x1)?.[_0x9a2fbb(0x113)]!==_0x9a2fbb(0x138)))return invalidMybatisSource(_0x9a2fbb(0x150));if(_0x23389e){if(_0x1a9231||_0x587ea5[_0x9a2fbb(0x147)]>0x0)return invalidMybatisSource(_0x9a2fbb(0x117));_0x1a9231=!![],_0x1b5bae=_0xc4c5de,_0x238a8c=_0x23389e;}else{if(!_0x1a9231||_0x1b5bae)return invalidMybatisSource(_0x9a2fbb(0x13b)+_0x29a915+'>.');}_0x35ce97+=_0x40d337==='where'?_0x9a2fbb(0x145):_0x40d337===_0x9a2fbb(0x14b)?_0x9a2fbb(0x133):_0x40d337===_0x9a2fbb(0x138)?'\x20'+MYBATIS_INCLUDE_MARKER+'\x20':MYBATIS_BRANCH_TAGS[_0x9a2fbb(0x109)](_0x40d337)&&!_0xc4c5de?'\x20'+MYBATIS_DYNAMIC_START_MARKER+'\x20':'\x20',!_0xc4c5de&&_0x587ea5[_0x9a2fbb(0x114)]({'rawName':_0x29a915,'tagName':_0x40d337,'outer':!!_0x23389e});}_0x31c0ef=_0x39e419+0x1;}if(_0x587ea5[_0x9a2fbb(0x147)]>0x0)return invalidMybatisSource(_0x9a2fbb(0x11f)+_0x587ea5['at'](-0x1)?.[_0x9a2fbb(0x124)]+'>.');if(!_0x1a9231||!_0x1b5bae)return invalidMybatisSource('MyBatis\x20XML\x20must\x20contain\x20exactly\x20one\x20complete\x20statement\x20wrapper.');return{'sql':_0x35ce97[_0x9a2fbb(0x116)](),'mode':_0x9a2fbb(0x108),..._0x238a8c?{'statementType':_0x238a8c}:{}};}function hasWellFormedXmlAttributes(_0x7fde92){const _0x2a0a01=a316_0x5e390b;let _0x259ba2=0x0;const _0x4c23ba=new Set();while(_0x259ba2<_0x7fde92[_0x2a0a01(0x147)]){while(_0x259ba2<_0x7fde92[_0x2a0a01(0x147)]&&/\s/['test'](_0x7fde92[_0x259ba2]??''))_0x259ba2+=0x1;if(_0x259ba2>=_0x7fde92[_0x2a0a01(0x147)])return!![];const _0x101fd5=/^[A-Za-z_:][\w:.-]*/[_0x2a0a01(0x111)](_0x7fde92[_0x2a0a01(0xfd)](_0x259ba2)),_0x491532=_0x101fd5?.[0x0];if(!_0x491532||_0x4c23ba[_0x2a0a01(0x109)](_0x491532))return![];_0x4c23ba[_0x2a0a01(0x125)](_0x491532),_0x259ba2+=_0x491532[_0x2a0a01(0x147)];while(_0x259ba2<_0x7fde92['length']&&/\s/[_0x2a0a01(0x14d)](_0x7fde92[_0x259ba2]??''))_0x259ba2+=0x1;if(_0x7fde92[_0x259ba2]!=='=')return![];_0x259ba2+=0x1;while(_0x259ba2<_0x7fde92['length']&&/\s/[_0x2a0a01(0x14d)](_0x7fde92[_0x259ba2]??''))_0x259ba2+=0x1;const _0x37f7e5=_0x7fde92[_0x259ba2];if(_0x37f7e5!=='\x22'&&_0x37f7e5!=='\x27')return![];_0x259ba2+=0x1;const _0xa94393=_0x7fde92[_0x2a0a01(0x102)](_0x37f7e5,_0x259ba2);if(_0xa94393<0x0)return![];if(decodeXmlEntities(_0x7fde92[_0x2a0a01(0xfd)](_0x259ba2,_0xa94393))===null)return![];_0x259ba2=_0xa94393+0x1;}return!![];}export function detectSqlSourceMode(_0x4b8e29){const _0x50849e=a316_0x5e390b;let _0x2dd284=0x0;const _0x2596db=()=>{const _0xd6bb14=a316_0x33c6;while(_0x2dd284<_0x4b8e29['length']&&/\s/[_0xd6bb14(0x14d)](_0x4b8e29[_0x2dd284]??''))_0x2dd284+=0x1;};_0x2596db();while(_0x2dd284<_0x4b8e29[_0x50849e(0x147)]){if(_0x4b8e29[_0x50849e(0x107)](_0x50849e(0x104),_0x2dd284)){const _0x4aa668=_0x4b8e29[_0x50849e(0x102)]('-->',_0x2dd284+0x4);if(_0x4aa668<0x0)return _0x50849e(0x108);_0x2dd284=_0x4aa668+0x3,_0x2596db();continue;}if(_0x4b8e29['startsWith']('<?',_0x2dd284)){const _0x752d03=_0x4b8e29[_0x50849e(0x102)]('?>',_0x2dd284+0x2);if(_0x752d03<0x0)return'mybatisXml';_0x2dd284=_0x752d03+0x2,_0x2596db();continue;}break;}return MYBATIS_OUTER_TAG_PATTERN['test'](_0x4b8e29[_0x50849e(0xfd)](_0x2dd284))?_0x50849e(0x108):'sql';}function invalidMybatisSource(_0x2c9896){return{'sql':'','mode':'mybatisXml','error':_0x2c9896};}function findXmlTagEnd(_0x30d198,_0xe967de){const _0x578ecd=a316_0x5e390b;let _0x323743;for(let _0x4f4d32=_0xe967de+0x1;_0x4f4d32<_0x30d198[_0x578ecd(0x147)];_0x4f4d32+=0x1){const _0x1bfd6b=_0x30d198[_0x4f4d32];if(_0x323743){if(_0x1bfd6b===_0x323743)_0x323743=undefined;continue;}if(_0x1bfd6b==='\x22'||_0x1bfd6b==='\x27'){_0x323743=_0x1bfd6b;continue;}if(_0x1bfd6b==='>')return _0x4f4d32;}return-0x1;}function decodeXmlEntities(_0x566924){let _0x269abe=![];const _0x38a1ac=_0x566924['replace'](/&(?:#x[0-9a-f]+;|#[0-9]+;|[A-Za-z_:][\w:.-]*;)?/g,_0x46be3a=>{const _0x550d07=a316_0x33c6;if(_0x46be3a===_0x550d07(0x14a))return'<';if(_0x46be3a===_0x550d07(0x14e))return'>';if(_0x46be3a==='"')return'\x22';if(_0x46be3a===_0x550d07(0x128))return'\x27';if(_0x46be3a===_0x550d07(0x14f))return'&';const _0x290431=/^&#(?:x([0-9a-f]+)|([0-9]+));$/[_0x550d07(0x111)](_0x46be3a);if(_0x290431){const _0x4d82ae=_0x290431[0x1],_0x2730df=_0x290431[0x2],_0x38d15c=Number['parseInt'](_0x4d82ae??_0x2730df??'',_0x4d82ae?0x10:0xa);if(isValidXmlCharacter(_0x38d15c))return String['fromCodePoint'](_0x38d15c);}return _0x269abe=!![],'';});return _0x269abe?null:_0x38a1ac;}function isValidXmlCharacter(_0x14b81d){return _0x14b81d===0x9||_0x14b81d===0xa||_0x14b81d===0xd||_0x14b81d>=0x20&&_0x14b81d<=0xd7ff||_0x14b81d>=0xe000&&_0x14b81d<=0xfffd||_0x14b81d>=0x10000&&_0x14b81d<=0x10ffff;}export function detectSqlType(_0x408af0){return detectNormalizedSqlType(normalizeSqlForStaticAnalysis(_0x408af0));}function detectNormalizedSqlType(_0x4c9fbf){const _0x52c7c6=a316_0x5e390b;if(_0x4c9fbf[_0x52c7c6(0x129)])return{'type':'UNKNOWN','isSelectOnly':![],'isDangerous':![],'reason':_0x4c9fbf[_0x52c7c6(0x129)]};if(!_0x4c9fbf[_0x52c7c6(0x13e)][_0x52c7c6(0x116)]())return{'type':'UNKNOWN','isSelectOnly':![],'isDangerous':![],'reason':'SQL\x20content\x20is\x20empty'};const _0x1ff9a1=tokenizeSqlForTypeAnalysis(_0x4c9fbf[_0x52c7c6(0x13e)]),_0x5d4382=_0x1ff9a1[_0x52c7c6(0xf3)](_0x43d9f2=>_0x43d9f2!==MYBATIS_DYNAMIC_START_MARKER&&_0x43d9f2!==MYBATIS_DYNAMIC_END_MARKER),_0x26103a=findMainStatementIndex(_0x5d4382);if(_0x26103a<0x0)return{'type':_0x52c7c6(0xfa),'isSelectOnly':![],'isDangerous':![],'reason':_0x52c7c6(0x127)};const _0x3d2b9a=_0x5d4382[_0x26103a]??'',_0x538964=_0x4c9fbf[_0x52c7c6(0x123)]??_0x3d2b9a,_0x472e79=_0x1ff9a1[_0x52c7c6(0x143)](_0x17eeac=>/^(DELETE|DROP|ALTER|CREATE|TRUNCATE)$/[_0x52c7c6(0x14d)](_0x17eeac)),_0x32190f=new Set();let _0xc7b750=![];for(let _0x38913c=0x0;_0x38913c<_0x1ff9a1[_0x52c7c6(0x147)];_0x38913c+=0x1){const _0x59eb5e=_0x1ff9a1[_0x38913c];(_0x59eb5e==='UPDATE'||_0x59eb5e===_0x52c7c6(0x142))&&isLockingClauseKeyword(_0x1ff9a1,_0x38913c)&&(_0x32190f[_0x52c7c6(0x125)](_0x38913c),_0xc7b750=!![]);if(_0x1ff9a1[_0x52c7c6(0xfd)](_0x38913c,_0x38913c+0x4)[_0x52c7c6(0x131)]('\x20')===_0x52c7c6(0x11e))_0xc7b750=!![];}if(_0x538964==='SELECT'){const _0x158973=_0x1ff9a1[_0x52c7c6(0x143)]((_0x536620,_0xfaf349)=>/^(INSERT|UPDATE|DELETE|DROP|ALTER|CREATE|TRUNCATE)$/['test'](_0x536620)&&!_0x32190f['has'](_0xfaf349));return{'type':_0x52c7c6(0x130),'isSelectOnly':!_0x158973&&!_0xc7b750,'isLockingRead':_0xc7b750,'isDangerous':_0x158973,'reason':_0x158973?_0x52c7c6(0x11a):undefined};}if(_0x538964===_0x52c7c6(0x106))return{'type':'INSERT','isSelectOnly':![],'isDangerous':_0x472e79,'reason':_0x472e79?_0x52c7c6(0x10c):undefined};if(_0x538964===_0x52c7c6(0x118))return{'type':_0x52c7c6(0x118),'isSelectOnly':![],'isDangerous':_0x472e79,'reason':_0x472e79?_0x52c7c6(0x10c):undefined};if(_0x538964==='DELETE')return{'type':'DELETE','isSelectOnly':![],'isDangerous':!![],'reason':'DELETE\x20statements\x20require\x20explicit\x20review'};if(/^(CREATE|ALTER|DROP|TRUNCATE)/i[_0x52c7c6(0x14d)](_0x3d2b9a))return{'type':'DDL','isSelectOnly':![],'isDangerous':!![],'reason':_0x52c7c6(0x135)};return{'type':'UNKNOWN','isSelectOnly':![],'isDangerous':![]};}function isLockingClauseKeyword(_0x4b0543,_0x391873){const _0x4979da=a316_0x5e390b,_0x401e79=_0x4b0543[_0x391873]===_0x4979da(0x118)?[[_0x4979da(0x105)],[_0x4979da(0x105),'NO','KEY']]:[[_0x4979da(0x105)],['FOR',_0x4979da(0xf5)]],_0x1d988e=_0x401e79['some'](_0x5355d6=>{const _0xf8b387=_0x4979da,_0x47d150=_0x391873-_0x5355d6['length'];return _0x47d150>=0x0&&_0x4b0543[_0xf8b387(0xfd)](_0x47d150,_0x391873)['join']('\x20')===_0x5355d6['join']('\x20');});if(!_0x1d988e)return![];return!_0x4b0543[_0x4979da(0xfd)](_0x391873+0x1,_0x391873+0x5)['includes']('SET');}function findMainStatementIndex(_0x23d765){const _0x4f642d=a316_0x5e390b;if(_0x23d765[0x0]!==_0x4f642d(0x119))return 0x0;let _0x5c02c2=_0x23d765[0x1]===_0x4f642d(0x132)?0x2:0x1;while(_0x5c02c2<_0x23d765['length']){const _0x1c690e=_0x23d765[_0x5c02c2];if(!_0x1c690e||!(/^[A-Z_][\w$]*$/[_0x4f642d(0x14d)](_0x1c690e)||/^[`"]/[_0x4f642d(0x14d)](_0x1c690e)))return-0x1;_0x5c02c2+=0x1;if(_0x23d765[_0x5c02c2]==='('){_0x5c02c2=skipSqlParentheses(_0x23d765,_0x5c02c2);if(_0x5c02c2<0x0)return-0x1;}if(_0x23d765[_0x5c02c2]!=='AS')return-0x1;_0x5c02c2+=0x1;if(_0x23d765[_0x5c02c2]===_0x4f642d(0xfc)&&_0x23d765[_0x5c02c2+0x1]===_0x4f642d(0xf6))_0x5c02c2+=0x2;else{if(_0x23d765[_0x5c02c2]==='MATERIALIZED')_0x5c02c2+=0x1;}_0x5c02c2=skipSqlParentheses(_0x23d765,_0x5c02c2);if(_0x5c02c2<0x0)return-0x1;if(_0x23d765[_0x5c02c2]!==','){const _0x3422ff=_0x23d765[_0x5c02c2]==='('?_0x5c02c2+0x1:_0x5c02c2;return/^(SELECT|INSERT|UPDATE|DELETE)$/[_0x4f642d(0x14d)](_0x23d765[_0x3422ff]??'')?_0x3422ff:-0x1;}_0x5c02c2+=0x1;}return-0x1;}function a316_0x33c6(_0x1c53c8,_0x52adc1){_0x1c53c8=_0x1c53c8-0xf0;const _0x598447=a316_0x5984();let _0x33c665=_0x598447[_0x1c53c8];return _0x33c665;}function skipSqlParentheses(_0x5c4b50,_0x4b8b98){const _0x4c5b1d=a316_0x5e390b;if(_0x5c4b50[_0x4b8b98]!=='(')return-0x1;let _0x1a97be=0x0;for(let _0x4d7d0d=_0x4b8b98;_0x4d7d0d<_0x5c4b50[_0x4c5b1d(0x147)];_0x4d7d0d+=0x1){const _0x5dc6f9=_0x5c4b50[_0x4d7d0d];if(_0x5dc6f9===';')return-0x1;if(_0x5dc6f9==='(')_0x1a97be+=0x1;if(_0x5dc6f9===')'&&--_0x1a97be===0x0)return _0x4d7d0d+0x1;}return-0x1;}function stripStaticAnalysisMarkers(_0x4b7028){const _0x16ce59=a316_0x5e390b;return _0x4b7028['replaceAll'](MYBATIS_DYNAMIC_START_MARKER,'\x20')[_0x16ce59(0xf7)](MYBATIS_DYNAMIC_END_MARKER,'\x20')[_0x16ce59(0xf7)](MYBATIS_INCLUDE_MARKER,'\x20'+UNRESOLVED_SQL_FRAGMENT+'\x20');}function tokenizeSqlForTypeAnalysis(_0x2da81a){const _0x1cc20e=a316_0x5e390b,_0x22fdb5=[],_0x53787=/\/\*[\s\S]*?\*\/|--[^\r\n]*|[#$]\{[^}]*\}|#[^\r\n]*|'(?:''|\\[\s\S]|[^'\\])*'|"(?:""|\\[\s\S]|[^"\\])*"|`(?:``|\\[\s\S]|[^`\\])*`|@[A-Za-z_]\w*|[A-Za-z_]\w*|\S/g;for(const _0x58a0e7 of _0x2da81a['matchAll'](_0x53787)){const _0x301446=_0x58a0e7[0x0];if(_0x301446[_0x1cc20e(0x107)]('/*')||_0x301446[_0x1cc20e(0x107)]('--')||_0x301446['startsWith']('#')&&!_0x301446[_0x1cc20e(0x107)]('#{'))continue;_0x22fdb5[_0x1cc20e(0x114)](/^["`]/[_0x1cc20e(0x14d)](_0x301446)?_0x301446:/^[\x27@#$]/[_0x1cc20e(0x14d)](_0x301446)?'?':_0x301446[_0x1cc20e(0xf2)]());}return _0x22fdb5;}function a316_0x5984(){const _0x3bb7bd=['Invalid\x20MyBatis\x20XML\x20closing\x20tag:\x20</','DDL\x20statements\x20require\x20explicit\x20review','30516YbhGwo','string','include','select','2zmuWzY','MyBatis\x20dynamic\x20tag\x20must\x20be\x20inside\x20the\x20statement\x20wrapper:\x20<','isDangerous','bind','sql','180ahjxec','Unable\x20to\x20detect\x20SQL\x20type.\x20','68000pKzSQb','SHARE','some','delete','\x20WHERE\x20','outer','length','-->','property','<','set','^<\x5cs*(?:','test','>','&','MyBatis\x20<property>\x20must\x20be\x20a\x20self-closing\x20direct\x20child\x20of\x20<include>.','Invalid\x20attributes\x20on\x20MyBatis\x20XML\x20tag:\x20<','__RABETBASE_MYBATIS_DYNAMIC_END__','__RABETBASE_MYBATIS_INCLUDE_UNRESOLVED__','unknown\x20table(s)',']]>','toUpperCase','filter','choose','KEY','MATERIALIZED','replaceAll','reason','5384764Bpcbfa','UNKNOWN','CDATA\x20sections\x20must\x20be\x20inside\x20the\x20MyBatis\x20statement\x20wrapper.','NOT','slice','12bHxfhw','update','replace','Unterminated\x20XML\x20comment.','indexOf','1393zyCGGa','<!--','FOR','INSERT','startsWith','mybatisXml','has','SQL\x20text\x20must\x20be\x20inside\x20the\x20MyBatis\x20statement\x20wrapper.','Unterminated\x20MyBatis\x20XML\x20tag.','SQL\x20contains\x20blocked\x20DELETE\x20or\x20DDL\x20statements','Invalid\x20XML\x20entity\x20reference.','match','<![CDATA[','791512hRqHJs','exec','\x20with\x20parameters:\x20','tagName','push','2886775TfLxxH','trim','Multiple\x20MyBatis\x20statement\x20wrappers\x20are\x20not\x20supported.','UPDATE','WITH','SQL\x20contains\x20modification\x20statements\x20alongside\x20SELECT','__RABETBASE_MYBATIS_DYNAMIC_START__','get','Unable\x20to\x20detect\x20SQL\x20type.\x20Please\x20check\x20the\x20SQL\x20content.','LOCK\x20IN\x20SHARE\x20MODE','Unclosed\x20MyBatis\x20XML\x20tag:\x20<','__RABETBASE_UNRESOLVED_SQL_FRAGMENT__','460396USvYKX','type','statementType','rawName','add','MyBatis\x20dynamic\x20tag\x20names\x20must\x20be\x20lowercase:\x20<','Local\x20analysis\x20could\x20not\x20parse\x20the\x20WITH\x20prefix;\x20this\x20is\x20a\x20local\x20capability\x20limit,\x20not\x20a\x20platform\x20rejection.',''','error','keys','630070QbrCqj','when','foreach','includes','DELETE','SELECT','join','RECURSIVE','\x20SET\x20'];a316_0x5984=function(){return _0x3bb7bd;};return a316_0x5984();}function extractTables(_0x5a0bf1,_0x2e3740){const _0x2c8e93=a316_0x5e390b,_0x1fa8d4=_0x5a0bf1[_0x2c8e93(0x100)](/#\{[^}]*\}/g,'?')[_0x2c8e93(0x100)](/\$\{[^}]*\}/g,'?')[_0x2c8e93(0x100)](/'[^']*'/g,'\x27\x27')[_0x2c8e93(0x100)](/--.*$/gm,'')['replace'](/\/\*[\s\S]*?\*\//g,''),_0x12b4e8=[],_0xd84ba=_0x1fa8d4[_0x2c8e93(0x10e)](/FROM\s+([^\s,)(]+)/i);addTable(_0x12b4e8,_0xd84ba?.[0x1]);for(const _0x59f792 of _0x1fa8d4['matchAll'](/(?:INNER|LEFT|RIGHT|FULL|CROSS)?\s*JOIN\s+([^\s,)(]+)/gi)){addTable(_0x12b4e8,_0x59f792[0x1]);}const _0x2295af=_0x1fa8d4[_0x2c8e93(0x10e)](/INTO\s+([^\s(]+)/i);addTable(_0x12b4e8,_0x2295af?.[0x1]);if(_0x2e3740===_0x2c8e93(0x118)){const _0x324801=_0x1fa8d4[_0x2c8e93(0x10e)](/UPDATE\s+([^\s,)(]+)/i);addTable(_0x12b4e8,_0x324801?.[0x1]);}return _0x12b4e8;}function addTable(_0x18b612,_0x128ecb){const _0x1522bd=a316_0x5e390b,_0x4c4418=_0x128ecb?.[_0x1522bd(0x100)](/[`"]/g,'');_0x4c4418&&_0x4c4418!==UNRESOLVED_SQL_FRAGMENT&&!_0x18b612[_0x1522bd(0x12e)](_0x4c4418)&&_0x18b612[_0x1522bd(0x114)](_0x4c4418);}function extractParameters(_0x3dc919){const _0x44e9a8=a316_0x5e390b,_0x56eb6e=new Set();for(const _0x21b341 of _0x3dc919['matchAll'](/[#$]\{\s*([A-Za-z_][\w.]*)\s*(?=[,}])/g)){if(_0x21b341[0x1])_0x56eb6e[_0x44e9a8(0x125)](_0x21b341[0x1]);}return Array['from'](_0x56eb6e);}export function validateSql(_0x2cbcd4){const _0x97f65=a316_0x5e390b,_0x9ac5ab=normalizeSqlForStaticAnalysis(_0x2cbcd4),_0x20946f=detectNormalizedSqlType(_0x9ac5ab),_0x3d334c=stripStaticAnalysisMarkers(_0x9ac5ab[_0x97f65(0x13e)]),_0x35c559=_0x9ac5ab[_0x97f65(0x129)]?[]:extractTables(_0x3d334c,_0x20946f[_0x97f65(0x122)]),_0x138e8f=_0x9ac5ab['error']?[]:extractParameters(_0x3d334c);if(_0x20946f[_0x97f65(0x13c)])return{'valid':![],'sqlType':_0x20946f,'tables':_0x35c559,'parameters':_0x138e8f,'message':_0x20946f['reason']||_0x20946f[_0x97f65(0x122)]+'\x20statements\x20require\x20explicit\x20review.\x20Local\x20analysis\x20does\x20not\x20authorize\x20saving\x20or\x20execution.'};if(_0x20946f['type']===_0x97f65(0xfa))return{'valid':![],'sqlType':_0x20946f,'tables':_0x35c559,'parameters':_0x138e8f,'message':_0x9ac5ab['error']?_0x97f65(0x140)+_0x9ac5ab[_0x97f65(0x129)]:_0x20946f['reason']?_0x97f65(0x140)+_0x20946f[_0x97f65(0xf8)]:_0x97f65(0x11d)};return{'valid':!![],'sqlType':_0x20946f,'tables':_0x35c559,'parameters':_0x138e8f,'message':_0x20946f[_0x97f65(0x122)]+'\x20query\x20targeting\x20'+(_0x35c559[_0x97f65(0x147)]?_0x35c559[_0x97f65(0x131)](',\x20'):_0x97f65(0xf0))+(_0x138e8f[_0x97f65(0x147)]?_0x97f65(0x112)+_0x138e8f[_0x97f65(0x131)](',\x20'):'')};}
|
|
1
|
+
const MYBATIS_OUTER_TAGS=new Map([["select","SELECT"],["insert","INSERT"],["update","UPDATE"],["delete","DELETE"]]);const MYBATIS_DYNAMIC_TAGS=new Set(["if","where","foreach","choose","when","otherwise","trim","set","bind","include","property"]);const MYBATIS_BRANCH_TAGS=new Set(["if","foreach","choose","when","otherwise"]);export const MYBATIS_DYNAMIC_START_MARKER="__RABETBASE_MYBATIS_DYNAMIC_START__";export const MYBATIS_DYNAMIC_END_MARKER="__RABETBASE_MYBATIS_DYNAMIC_END__";export const MYBATIS_INCLUDE_MARKER="__RABETBASE_MYBATIS_INCLUDE_UNRESOLVED__";const UNRESOLVED_SQL_FRAGMENT="__RABETBASE_UNRESOLVED_SQL_FRAGMENT__";const MYBATIS_OUTER_TAG_PATTERN=new RegExp(`^<\\s*(?:${[...MYBATIS_OUTER_TAGS.keys()].join("|")})\\b`,"i");export function normalizeSqlForStaticAnalysis(sqlContent){const raw=typeof sqlContent==="string"?sqlContent:"";if(detectSqlSourceMode(raw)==="sql"){return{sql:raw,mode:"sql"}}let index=0;let normalized="";let statementType;let rootSeen=false;let rootClosed=false
|
|
2
|
+
;const openTags=[];while(index<raw.length){if(raw.startsWith("\x3c!--",index)){const commentEnd=raw.indexOf("--\x3e",index+4);if(commentEnd<0){return invalidMybatisSource("Unterminated XML comment.")}normalized+=" ";index=commentEnd+3;continue}if(raw.startsWith("<![CDATA[",index)){if(!rootSeen||rootClosed){return invalidMybatisSource("CDATA sections must be inside the MyBatis statement wrapper.")}const cdataEnd=raw.indexOf("]]>",index+9);if(cdataEnd<0){return invalidMybatisSource("Unterminated CDATA section.")}normalized+=raw.slice(index+9,cdataEnd);index=cdataEnd+3;continue}if(raw.startsWith("<?",index)){if(rootSeen){return invalidMybatisSource("XML declarations must precede the MyBatis statement wrapper.")}const declarationEnd=raw.indexOf("?>",index+2);if(declarationEnd<0){return invalidMybatisSource("Unterminated XML declaration.")}normalized+=" ";index=declarationEnd+2;continue}if(raw[index]!=="<"){const nextTag=raw.indexOf("<",index);const textEnd=nextTag<0?raw.length:nextTag
|
|
3
|
+
;const text=raw.slice(index,textEnd);if((!rootSeen||rootClosed)&&text.trim()){return invalidMybatisSource("SQL text must be inside the MyBatis statement wrapper.")}if(rootSeen&&!rootClosed){const decodedText=decodeXmlEntities(text);if(decodedText===null){return invalidMybatisSource("Invalid XML entity reference.")}normalized+=decodedText}else{normalized+=" "}index=textEnd;continue}const tagEnd=findXmlTagEnd(raw,index);if(tagEnd<0){return invalidMybatisSource("Unterminated MyBatis XML tag.")}const tagText=raw.slice(index,tagEnd+1);const tagMatch=/^<\s*(\/?)\s*([A-Za-z][\w:-]*)([\s\S]*?)(\/?)\s*>$/.exec(tagText);if(!tagMatch){return invalidMybatisSource("Invalid MyBatis XML tag.")}const closing=tagMatch[1]==="/";const rawTagName=tagMatch[2]??"";const tagName=rawTagName.toLowerCase();const rawAttributes=tagMatch[3]??"";const selfClosing=tagMatch[4]==="/";const outerStatementType=MYBATIS_OUTER_TAGS.get(tagName);if(!outerStatementType&&!MYBATIS_DYNAMIC_TAGS.has(tagName)){
|
|
4
|
+
return invalidMybatisSource(`Unsupported MyBatis XML tag: <${tagName}>.`)}if(!outerStatementType&&rawTagName!==tagName){return invalidMybatisSource(`MyBatis dynamic tag names must be lowercase: <${rawTagName}>.`)}if(closing){if(rawAttributes.trim()||selfClosing){return invalidMybatisSource(`Invalid MyBatis XML closing tag: </${rawTagName}>.`)}const currentTag=openTags.at(-1);if(!currentTag||(currentTag.outer?currentTag.tagName!==tagName:currentTag.rawName!==rawTagName)){return invalidMybatisSource(`Mismatched MyBatis XML closing tag: </${rawTagName}>.`)}openTags.pop();if(currentTag.outer)rootClosed=true;normalized+=MYBATIS_BRANCH_TAGS.has(tagName)?` ${MYBATIS_DYNAMIC_END_MARKER} `:" "}else{if(!hasWellFormedXmlAttributes(rawAttributes)){return invalidMybatisSource(`Invalid attributes on MyBatis XML tag: <${rawTagName}>.`)}if(tagName==="property"&&(!selfClosing||openTags.at(-1)?.tagName!=="include")){
|
|
5
|
+
return invalidMybatisSource("MyBatis <property> must be a self-closing direct child of <include>.")}if(outerStatementType){if(rootSeen||openTags.length>0){return invalidMybatisSource("Multiple MyBatis statement wrappers are not supported.")}rootSeen=true;rootClosed=selfClosing;statementType=outerStatementType}else if(!rootSeen||rootClosed){return invalidMybatisSource(`MyBatis dynamic tag must be inside the statement wrapper: <${rawTagName}>.`)}normalized+=tagName==="where"?" WHERE ":tagName==="set"?" SET ":tagName==="include"?` ${MYBATIS_INCLUDE_MARKER} `:MYBATIS_BRANCH_TAGS.has(tagName)&&!selfClosing?` ${MYBATIS_DYNAMIC_START_MARKER} `:" ";if(!selfClosing){openTags.push({rawName:rawTagName,tagName:tagName,outer:!!outerStatementType})}}index=tagEnd+1}if(openTags.length>0){return invalidMybatisSource(`Unclosed MyBatis XML tag: <${openTags.at(-1)?.rawName}>.`)}if(!rootSeen||!rootClosed){return invalidMybatisSource("MyBatis XML must contain exactly one complete statement wrapper.")}
|
|
6
|
+
return{sql:normalized.trim(),mode:"mybatisXml",...statementType?{statementType:statementType}:{}}}function hasWellFormedXmlAttributes(content){let index=0;const names=new Set;while(index<content.length){while(index<content.length&&/\s/.test(content[index]??""))index+=1;if(index>=content.length)return true;const nameMatch=/^[A-Za-z_:][\w:.-]*/.exec(content.slice(index));const name=nameMatch?.[0];if(!name||names.has(name))return false;names.add(name);index+=name.length;while(index<content.length&&/\s/.test(content[index]??""))index+=1;if(content[index]!=="=")return false;index+=1;while(index<content.length&&/\s/.test(content[index]??""))index+=1;const quote=content[index];if(quote!=='"'&"e!=="'")return false;index+=1;const valueEnd=content.indexOf(quote,index);if(valueEnd<0)return false;if(decodeXmlEntities(content.slice(index,valueEnd))===null)return false;index=valueEnd+1}return true}export function detectSqlSourceMode(content){let index=0;const skipWhitespace=()=>{
|
|
7
|
+
while(index<content.length&&/\s/.test(content[index]??""))index+=1};skipWhitespace();while(index<content.length){if(content.startsWith("\x3c!--",index)){const commentEnd=content.indexOf("--\x3e",index+4);if(commentEnd<0)return"mybatisXml";index=commentEnd+3;skipWhitespace();continue}if(content.startsWith("<?",index)){const declarationEnd=content.indexOf("?>",index+2);if(declarationEnd<0)return"mybatisXml";index=declarationEnd+2;skipWhitespace();continue}break}return MYBATIS_OUTER_TAG_PATTERN.test(content.slice(index))?"mybatisXml":"sql"}function invalidMybatisSource(error){return{sql:"",mode:"mybatisXml",error:error}}function findXmlTagEnd(content,start){let quote;for(let index=start+1;index<content.length;index+=1){const character=content[index];if(quote){if(character===quote)quote=undefined;continue}if(character==='"'||character==="'"){quote=character;continue}if(character===">")return index}return-1}function decodeXmlEntities(content){let invalidEntity=false
|
|
8
|
+
;const decoded=content.replace(/&(?:#x[0-9a-f]+;|#[0-9]+;|[A-Za-z_:][\w:.-]*;)?/g,reference=>{if(reference==="<")return"<";if(reference===">")return">";if(reference===""")return'"';if(reference==="'")return"'";if(reference==="&")return"&";const numericReference=/^&#(?:x([0-9a-f]+)|([0-9]+));$/.exec(reference);if(numericReference){const hex=numericReference[1];const decimal=numericReference[2];const codePoint=Number.parseInt(hex??decimal??"",hex?16:10);if(isValidXmlCharacter(codePoint))return String.fromCodePoint(codePoint)}invalidEntity=true;return""});return invalidEntity?null:decoded}function isValidXmlCharacter(codePoint){return codePoint===9||codePoint===10||codePoint===13||codePoint>=32&&codePoint<=55295||codePoint>=57344&&codePoint<=65533||codePoint>=65536&&codePoint<=1114111}export function detectSqlType(sqlContent){return detectNormalizedSqlType(normalizeSqlForStaticAnalysis(sqlContent))}function detectNormalizedSqlType(source){if(source.error){return{
|
|
9
|
+
type:"UNKNOWN",isSelectOnly:false,isDangerous:false,reason:source.error}}if(!source.sql.trim()){return{type:"UNKNOWN",isSelectOnly:false,isDangerous:false,reason:"SQL content is empty"}}const tokens=tokenizeSqlForTypeAnalysis(source.sql);const structuralTokens=tokens.filter(token=>token!==MYBATIS_DYNAMIC_START_MARKER&&token!==MYBATIS_DYNAMIC_END_MARKER);const statementIndex=findMainStatementIndex(structuralTokens);if(statementIndex<0){return{type:"UNKNOWN",isSelectOnly:false,isDangerous:false,reason:"Local analysis could not parse the WITH prefix; this is a local capability limit, not a platform rejection."}}const upper=structuralTokens[statementIndex]??"";const statementType=source.statementType??upper;const hasBlockedStatement=tokens.some(token=>/^(DELETE|DROP|ALTER|CREATE|TRUNCATE)$/.test(token));const lockKeywords=new Set;let isLockingRead=false;for(let index=0;index<tokens.length;index+=1){const token=tokens[index]
|
|
10
|
+
;if((token==="UPDATE"||token==="SHARE")&&isLockingClauseKeyword(tokens,index)){lockKeywords.add(index);isLockingRead=true}if(tokens.slice(index,index+4).join(" ")==="LOCK IN SHARE MODE")isLockingRead=true}if(statementType==="SELECT"){const hasModify=tokens.some((token,index)=>/^(INSERT|UPDATE|DELETE|DROP|ALTER|CREATE|TRUNCATE)$/.test(token)&&!lockKeywords.has(index));return{type:"SELECT",isSelectOnly:!hasModify&&!isLockingRead,isLockingRead:isLockingRead,isDangerous:hasModify,reason:hasModify?"SQL contains modification statements alongside SELECT":undefined}}if(statementType==="INSERT"){return{type:"INSERT",isSelectOnly:false,isDangerous:hasBlockedStatement,reason:hasBlockedStatement?"SQL contains blocked DELETE or DDL statements":undefined}}if(statementType==="UPDATE"){return{type:"UPDATE",isSelectOnly:false,isDangerous:hasBlockedStatement,reason:hasBlockedStatement?"SQL contains blocked DELETE or DDL statements":undefined}}if(statementType==="DELETE"){return{type:"DELETE",
|
|
11
|
+
isSelectOnly:false,isDangerous:true,reason:"DELETE statements require explicit review"}}if(/^(CREATE|ALTER|DROP|TRUNCATE)/i.test(upper)){return{type:"DDL",isSelectOnly:false,isDangerous:true,reason:"DDL statements require explicit review"}}return{type:"UNKNOWN",isSelectOnly:false,isDangerous:false}}function isLockingClauseKeyword(tokens,index){const variants=tokens[index]==="UPDATE"?[["FOR"],["FOR","NO","KEY"]]:[["FOR"],["FOR","KEY"]];const anchored=variants.some(variant=>{const start=index-variant.length;return start>=0&&tokens.slice(start,index).join(" ")===variant.join(" ")});if(!anchored)return false;return!tokens.slice(index+1,index+5).includes("SET")}function findMainStatementIndex(tokens){if(tokens[0]!=="WITH")return 0;let index=tokens[1]==="RECURSIVE"?2:1;while(index<tokens.length){const name=tokens[index];if(!name||!(/^[A-Z_][\w$]*$/.test(name)||/^[`"]/.test(name)))return-1;index+=1;if(tokens[index]==="("){index=skipSqlParentheses(tokens,index);if(index<0)return-1}
|
|
12
|
+
if(tokens[index]!=="AS")return-1;index+=1;if(tokens[index]==="NOT"&&tokens[index+1]==="MATERIALIZED")index+=2;else if(tokens[index]==="MATERIALIZED")index+=1;index=skipSqlParentheses(tokens,index);if(index<0)return-1;if(tokens[index]!==","){const mainIndex=tokens[index]==="("?index+1:index;return/^(SELECT|INSERT|UPDATE|DELETE)$/.test(tokens[mainIndex]??"")?mainIndex:-1}index+=1}return-1}function skipSqlParentheses(tokens,start){if(tokens[start]!=="(")return-1;let depth=0;for(let index=start;index<tokens.length;index+=1){const token=tokens[index];if(token===";")return-1;if(token==="(")depth+=1;if(token===")"&&--depth===0)return index+1}return-1}function stripStaticAnalysisMarkers(sql){return sql.replaceAll(MYBATIS_DYNAMIC_START_MARKER," ").replaceAll(MYBATIS_DYNAMIC_END_MARKER," ").replaceAll(MYBATIS_INCLUDE_MARKER,` ${UNRESOLVED_SQL_FRAGMENT} `)}function tokenizeSqlForTypeAnalysis(sql){const tokens=[]
|
|
13
|
+
;const lexemes=/\/\*[\s\S]*?\*\/|--[^\r\n]*|[#$]\{[^}]*\}|#[^\r\n]*|'(?:''|\\[\s\S]|[^'\\])*'|"(?:""|\\[\s\S]|[^"\\])*"|`(?:``|\\[\s\S]|[^`\\])*`|@[A-Za-z_]\w*|[A-Za-z_]\w*|\S/g;for(const match of sql.matchAll(lexemes)){const token=match[0];if(token.startsWith("/*")||token.startsWith("--")||token.startsWith("#")&&!token.startsWith("#{"))continue;tokens.push(/^["`]/.test(token)?token:/^[\x27@#$]/.test(token)?"?":token.toUpperCase())}return tokens}function extractTables(sql,type){const cleaned=sql.replace(/#\{[^}]*\}/g,"?").replace(/\$\{[^}]*\}/g,"?").replace(/'[^']*'/g,"''").replace(/--.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"");const tables=[];const fromMatch=cleaned.match(/FROM\s+([^\s,)(]+)/i);addTable(tables,fromMatch?.[1]);for(const m of cleaned.matchAll(/(?:INNER|LEFT|RIGHT|FULL|CROSS)?\s*JOIN\s+([^\s,)(]+)/gi)){addTable(tables,m[1])}const intoMatch=cleaned.match(/INTO\s+([^\s(]+)/i);addTable(tables,intoMatch?.[1]);if(type==="UPDATE"){
|
|
14
|
+
const updateMatch=cleaned.match(/UPDATE\s+([^\s,)(]+)/i);addTable(tables,updateMatch?.[1])}return tables}function addTable(tables,rawTable){const table=rawTable?.replace(/[`"]/g,"");if(table&&table!==UNRESOLVED_SQL_FRAGMENT&&!tables.includes(table)){tables.push(table)}}function extractParameters(sql){const params=new Set;for(const match of sql.matchAll(/[#$]\{\s*([A-Za-z_][\w.]*)\s*(?=[,}])/g)){if(match[1])params.add(match[1])}return Array.from(params)}export function validateSql(sqlContent){const source=normalizeSqlForStaticAnalysis(sqlContent);const sqlType=detectNormalizedSqlType(source);const analysisSql=stripStaticAnalysisMarkers(source.sql);const tables=source.error?[]:extractTables(analysisSql,sqlType.type);const parameters=source.error?[]:extractParameters(analysisSql);if(sqlType.isDangerous){return{valid:false,sqlType:sqlType,tables:tables,parameters:parameters,
|
|
15
|
+
message:sqlType.reason||`${sqlType.type} statements require explicit review. Local analysis does not authorize saving or execution.`}}if(sqlType.type==="UNKNOWN"){return{valid:false,sqlType:sqlType,tables:tables,parameters:parameters,message:source.error?`Unable to detect SQL type. ${source.error}`:sqlType.reason?`Unable to detect SQL type. ${sqlType.reason}`:"Unable to detect SQL type. Please check the SQL content."}}return{valid:true,sqlType:sqlType,tables:tables,parameters:parameters,message:`${sqlType.type} query targeting ${tables.length?tables.join(", "):"unknown table(s)"}${parameters.length?` with parameters: ${parameters.join(", ")}`:""}`}}
|
package/lib/errors.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import{CliError,createCliErrors}from"@lovrabet/cli-framework";import{CLI_BIN_NAME}from"./constant/cli.js";export{CliError};const baseCliErrors=createCliErrors({cliBinName:CLI_BIN_NAME,authRequiredHint:`Run \`${CLI_BIN_NAME} auth\` to login first.`,configMissingHint:`Set appcode via \`${CLI_BIN_NAME} workspace init --appcode <code>\` or pass --appcode.\n Tip: \`${CLI_BIN_NAME} workspace add <name> --appcode <code> --global\` registers a reusable global app profile.`,notInProjectHint:"Run this command inside a project with .rabetbase.json file."});export const CliErrors={authRequired(hint){return new CliError("auth_required",1,"Authentication required",hint??`Run \`${CLI_BIN_NAME} auth\` to login first.`)},configMissing(hint){
|
|
2
|
+
return new CliError("config_missing",1,"Configuration file not found",hint??`Set appcode via \`${CLI_BIN_NAME} workspace init --appcode <code>\` or pass --appcode.\n Tip: \`${CLI_BIN_NAME} workspace add <name> --appcode <code> --global\` registers a reusable global app profile.`)},notInProject(){return new CliError("not_in_project",1,`Not in a ${CLI_BIN_NAME} project directory`,"Run this command inside a project with .rabetbase.json file.")},apiError(message,hint){return baseCliErrors.apiError(message,hint)},networkError(message){return new CliError("network_error",2,`Network error: ${message}`,"Check your internet connection and try again.")},unknownCommand(cmd){return new CliError("unknown_command",1,`Unknown command: ${cmd}`,`Run \`${CLI_BIN_NAME} --help\` to see available commands.`)},flagMissing(flagName,hint){return new CliError("flag_missing",1,`Missing required flag: --${flagName}`,hint)},validation(message,hint){return baseCliErrors.validation(message,hint)},
|
|
3
|
+
cancelled(message){return new CliError("cancelled",0,message??"Operation cancelled.")}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{DEFAULT_COMMAND_OUTPUT_FORMAT}from"../constant/defaults.js";import{buildAllFlags as buildAllFlagsBase}from"@lovrabet/cli-framework";import{EXPLICIT_YES_FLAG_DESCRIPTION,requiresExplicitYes}from"../framework/explicit-yes.js";export function buildAllFlags(def){const flags=buildAllFlagsBase(def,{defaultOutputFormat:DEFAULT_COMMAND_OUTPUT_FORMAT});if(!requiresExplicitYes(def))return flags;return flags.map(flag=>flag.name==="yes"?{...flag,description:EXPLICIT_YES_FLAG_DESCRIPTION}:flag)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{resolveOutputConfig}from"@lovrabet/cli-framework";export function usesStructuredErrorOutput(def){return def?.structuredErrors===true}export function resolveErrorOutputFormat(currentCommand){if(!currentCommand.def)return currentCommand.defaultFormat??"compress";return resolveOutputConfig({flags:currentCommand.flags??{},def:currentCommand.def,configDefault:currentCommand.defaultFormat}).format}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const EXPLICIT_YES_COMMANDS=new Set(["menu delete","kb delete","notification config-update","notification config-delete"]);export const EXPLICIT_YES_FLAG_DESCRIPTION="Required for execution after reviewing the --dry-run plan";export function requiresExplicitYes(def){return EXPLICIT_YES_COMMANDS.has(`${def.service} ${def.command}`)}
|
package/lib/framework/flags.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createFlagHelpers}from"@lovrabet/cli-framework";import{CliErrors}from"../errors.js";const helpers=createFlagHelpers(CliErrors);export const parseFlags=helpers.parseFlags;export const validateFlags=helpers.validateFlags;
|
package/lib/framework/help.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{createHelpGenerators}from"@lovrabet/cli-framework";import{buildAllFlags}from"../framework/build-all-flags.js";import{serviceRegistry,serviceGroups,getServiceEntry}from"../commands/registry.js";import{CLI_BIN_NAME,CLI_DISPLAY_NAME,GLOBAL_FLAGS}from"../constant/cli.js";import{requiresExplicitYes}from"../framework/explicit-yes.js";function createGenerators(){return createHelpGenerators({cliBinName:CLI_BIN_NAME,cliDisplayName:CLI_DISPLAY_NAME,globalFlags:GLOBAL_FLAGS,serviceRegistry:serviceRegistry,getServiceEntry:getServiceEntry,getServiceDefinitions:service=>serviceGroups.get(service),buildAllFlags:buildAllFlags,appPrerequisiteText:`Requires appcode (set via \`${CLI_BIN_NAME} workspace init\` or --appcode).`,serviceUsageSuffix:" [args] [flags]"})}export function generateCommandHelp(def){const help=createGenerators().generateCommandHelp(def);if(!requiresExplicitYes(def))return help
|
|
2
|
+
;return help.replace("Requires --yes to confirm, or interactive prompt.","Requires explicit --yes for execution; use --dry-run to preview.")}export function generateServiceHelp(service){return createGenerators().generateServiceHelp(service)}export function generateFullHelp(){return createGenerators().generateFullHelp()}
|
package/lib/framework/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{runCommand}from"../framework/runner.js";export{parseFlags,validateFlags}from"../framework/flags.js";export{formatOutput}from"../framework/output.js";export{generateCommandHelp,generateServiceHelp,generateFullHelp}from"../framework/help.js";export{extractList,extractPaging}from"../framework/response.js";export{riskLevelOrder}from"../framework/types.js";
|
package/lib/framework/output.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{createFormatOutput,resolveBundledJqPaths}from"@lovrabet/cli-framework";import{CliError,CliErrors}from"../errors.js";import{applyJqFilter}from"../utils/apply-jq-filter.js";const baseFormatOutput=createFormatOutput({cliErrors:CliErrors,jqBinaryResolverOptions:{bundledJqPaths:resolveBundledJqPaths()}});export function formatOutput(result,options){const notice=result._notice;const{_notice:_notice,...plainResult}=result;void _notice;baseFormatOutput(plainResult,options);if(options.format==="pretty"){printPrettyNotice(notice)}}export function formatCliError(error,options){if(options.format==="pretty")return false;const errorData=error.data;const envelope={ok:false,command:options.command,risk:options.risk,data:errorData??null,error:{code:error.code,message:error.message,...error.hint?{hint:error.hint}:{}}};const json=options.format==="json"?JSON.stringify(envelope,null,2):JSON.stringify(envelope);let output=json;if(options.jqFilter?.trim()){try{
|
|
2
|
+
output=applyJqFilter(json,options.jqFilter)}catch(jqError){const filterError=jqError instanceof CliError?jqError:CliErrors.validation(`jq: ${jqError instanceof Error?jqError.message:String(jqError)}`);const fallbackEnvelope={...envelope,error:{code:filterError.code,message:filterError.message,...filterError.hint?{hint:filterError.hint}:{},cause:envelope.error}};output=options.format==="json"?JSON.stringify(fallbackEnvelope,null,2):JSON.stringify(fallbackEnvelope)}}process.stdout.write(output.endsWith("\n")?output:`${output}\n`);return true}function printPrettyNotice(notice){if(!notice?.update)return;console.error(`${notice.update.message} (${notice.update.url})`)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{extractList,extractPaging}from"@lovrabet/cli-framework";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{CliErrors}from"../errors.js";import{resolveAlias,listAliases}from"../core/alias-resolver.js";import{CLI_BIN_NAME}from"../constant/cli.js";import{resolveApiModelSource}from"../api/model-source.js";export function resolveAliasToCode(def,flags,apiDir,commandLabel,appCode,selectedAppName){const hasCodeFlag=def.flags.some(f=>f.name==="code"&&f.type==="string");const hasAliasFlag=def.flags.some(f=>f.name==="alias"&&f.type==="string");if(!hasCodeFlag||!hasAliasFlag)return;const code=flags.code?String(flags.code):"";const alias=flags.alias?String(flags.alias):"";if(!code&&!alias){throw CliErrors.validation(`\`${commandLabel}\` requires either --code or --alias.`)}if(alias&&!code){const source=resolveApiModelSource(apiDir,appCode,selectedAppName);const resolved=resolveAlias(apiDir,alias,undefined,source.filePath,source.profileName);if(!resolved){const available=listAliases(apiDir,undefined,source.filePath,source.profileName).map(e=>e.alias)
|
|
2
|
+
;const hint=available.length?`Available aliases: ${available.join(", ")}`:`No model aliases found in ${apiDir}. Run \`${CLI_BIN_NAME} api pull\` first.`;throw CliErrors.validation(`Unknown alias "${alias}". ${hint}`)}flags.code=resolved}}
|