@lovrabet/rabetbase-cli 2.5.13-beta.1 → 2.6.0-beta.1
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
|
@@ -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(_0x3c31e0,_0x307426){const _0x3613d2=a309_0x2c50,_0x5413ba=_0x3c31e0();while(!![]){try{const _0x2b69cd=parseInt(_0x3613d2(0xc6))/0x1+-parseInt(_0x3613d2(0xa2))/0x2+parseInt(_0x3613d2(0xba))/0x3*(parseInt(_0x3613d2(0xaa))/0x4)+parseInt(_0x3613d2(0xdd))/0x5+parseInt(_0x3613d2(0x9e))/0x6*(parseInt(_0x3613d2(0xb1))/0x7)+-parseInt(_0x3613d2(0x95))/0x8*(-parseInt(_0x3613d2(0xa8))/0x9)+-parseInt(_0x3613d2(0xbb))/0xa*(parseInt(_0x3613d2(0xc7))/0xb);if(_0x2b69cd===_0x307426)break;else _0x5413ba['push'](_0x5413ba['shift']());}catch(_0x549ba2){_0x5413ba['push'](_0x5413ba['shift']());}}}(a309_0x55bd,0x9036c));import{MYBATIS_DYNAMIC_END_MARKER,MYBATIS_DYNAMIC_START_MARKER,MYBATIS_INCLUDE_MARKER,normalizeSqlForStaticAnalysis}from'./sql-validator.js';export function auditSqlJoinIndexes(_0x3461d2,_0x2e73f0){const _0x6c64d9=a309_0x2c50,_0x38e2d6=[],_0x56f2e5=normalizeSqlForStaticAnalysis(_0x3461d2),_0x5e5938=(_0x56f2e5[_0x6c64d9(0xe2)]?[]:extractJoinFacts(_0x56f2e5[_0x6c64d9(0x9d)]))[_0x6c64d9(0xd1)](_0xc0e17c=>{const _0x5af18e=_0x6c64d9;if(_0xc0e17c[_0x5af18e(0x9c)]||_0xc0e17c[_0x5af18e(0xa1)][_0x5af18e(0xb4)]===0x0)return _0x38e2d6[_0x5af18e(0xa0)]({'code':_0x5af18e(0xb8),'table':_0xc0e17c[_0x5af18e(0x97)],'alias':_0xc0e17c[_0x5af18e(0xc3)],'columns':_0xc0e17c[_0x5af18e(0xa1)],'reason':_0xc0e17c[_0x5af18e(0x9f)]??_0x5af18e(0xc5)}),{'table':_0xc0e17c['table'],'alias':_0xc0e17c[_0x5af18e(0xc3)],'columns':_0xc0e17c['columns'],'status':_0x5af18e(0xcc)};const _0x558fea=resolveTableMetadata(_0x2e73f0,_0xc0e17c['table']),_0x2bb0a0=(_0x558fea?.[_0x5af18e(0xb0)]??[])['map'](_0x346c25=>({'index':_0x346c25,'matchedPrefix':findEqualityPrefix(_0x346c25[_0x5af18e(0xa1)],_0xc0e17c[_0x5af18e(0xa1)])}))[_0x5af18e(0xce)](_0x14b92d=>_0x14b92d[_0x5af18e(0xe0)][_0x5af18e(0xb4)]>0x0),_0x4711b2=_0x2bb0a0[_0x5af18e(0xb5)]((_0xaef987,_0x5d1cb6)=>!_0xaef987||_0x5d1cb6[_0x5af18e(0xe0)][_0x5af18e(0xb4)]>_0xaef987[_0x5af18e(0xe0)]['length']?_0x5d1cb6:_0xaef987,_0x2bb0a0[0x0]);if(_0x4711b2)return{'table':_0xc0e17c[_0x5af18e(0x97)],'alias':_0xc0e17c[_0x5af18e(0xc3)],'columns':_0xc0e17c['columns'],'status':_0x5af18e(0x9a),'matchedIndex':{..._0x4711b2[_0x5af18e(0xa9)],'matchedPrefix':_0x4711b2[_0x5af18e(0xe0)]}};const _0x172ce2=_0x558fea?.[_0x5af18e(0xb0)][_0x5af18e(0xce)](_0x552dc1=>_0x552dc1[_0x5af18e(0xa1)]['some'](_0x2dcbb9=>_0xc0e17c[_0x5af18e(0xa1)][_0x5af18e(0xca)](_0x6a2b6=>columnNamesMatch(_0x2dcbb9,_0x6a2b6))))??[];if(_0x172ce2[_0x5af18e(0xb4)]>0x0)return _0x38e2d6[_0x5af18e(0xa0)]({'code':_0x5af18e(0xc4),'table':_0xc0e17c[_0x5af18e(0x97)],'alias':_0xc0e17c['alias'],'columns':_0xc0e17c['columns'],'reason':_0x5af18e(0xd4)}),{'table':_0xc0e17c[_0x5af18e(0x97)],'alias':_0xc0e17c[_0x5af18e(0xc3)],'columns':_0xc0e17c[_0x5af18e(0xa1)],'status':_0x5af18e(0xab),'candidateIndexes':_0x172ce2};if(_0x558fea&&_0x558fea[_0x5af18e(0xbe)]!==![]&&_0x558fea['indexes'][_0x5af18e(0xb4)]>0x0&&_0xc0e17c[_0x5af18e(0xa1)][_0x5af18e(0xb4)]>0x0)return _0x38e2d6['push']({'code':_0x5af18e(0xda),'table':_0xc0e17c['table'],'alias':_0xc0e17c[_0x5af18e(0xc3)],'columns':_0xc0e17c[_0x5af18e(0xa1)],'reason':_0x5af18e(0x9b)}),{'table':_0xc0e17c[_0x5af18e(0x97)],'alias':_0xc0e17c[_0x5af18e(0xc3)],'columns':_0xc0e17c[_0x5af18e(0xa1)],'status':_0x5af18e(0xab)};return _0x38e2d6[_0x5af18e(0xa0)]({'code':_0x5af18e(0xc1),'table':_0xc0e17c[_0x5af18e(0x97)],'alias':_0xc0e17c[_0x5af18e(0xc3)],'columns':_0xc0e17c[_0x5af18e(0xa1)],'reason':_0x558fea?'The\x20dataset\x20returned\x20no\x20distinguishable\x20index\x20metadata.':_0x5af18e(0xcf)}),{'table':_0xc0e17c[_0x5af18e(0x97)],'alias':_0xc0e17c[_0x5af18e(0xc3)],'columns':_0xc0e17c['columns'],'status':'unavailable'};});return{'checked':_0x5e5938[_0x6c64d9(0xb4)]>0x0,'joins':_0x5e5938,'warnings':_0x38e2d6};}function extractJoinFacts(_0x13592a){const _0x2a1d52=a309_0x2c50,_0x45c4b5=maskNestedQueries(stripSqlNoise(_0x13592a)),_0x2f0307=maskQuotedIdentifiers(_0x45c4b5),_0x4e9f65=[],_0x5c67d1=new Set(),_0x37bcab=/\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 _0x2b52c4 of _0x45c4b5[_0x2a1d52(0xcb)](_0x37bcab)){const _0x1479f2=_0x2b52c4[_0x2a1d52(0xa9)]??0x0,_0x30708f=_0x2b52c4[0x0]['search'](/\bJOIN\b/i),_0x5c24f9=_0x1479f2+Math[_0x2a1d52(0xae)](0x0,_0x30708f);if(!/^JOIN\b/i['test'](_0x2f0307[_0x2a1d52(0xc8)](_0x5c24f9)))continue;_0x5c67d1[_0x2a1d52(0xbd)](_0x5c24f9);const _0x17f50b=normalizeIdentifier(_0x2b52c4[0x1]||'INNER'),_0x592e60=normalizeIdentifier(_0x2b52c4[0x2]??''),_0x3f8505=normalizeIdentifier(_0x2b52c4[0x3]||_0x592e60[_0x2a1d52(0xb7)]('.')['at'](-0x1)||_0x592e60),_0x40129b=[],_0xe45a57=_0x592e60==='__sq__';let _0x30f81d=_0x17f50b===_0x2a1d52(0xdf)||_0x17f50b===_0x2a1d52(0xdc)||_0xe45a57,_0x23a359=_0x30f81d?_0xe45a57?'Derived-table\x20JOIN\x20targets\x20are\x20not\x20supported.':_0x17f50b[_0x2a1d52(0x99)]()+_0x2a1d52(0xb2):undefined;const _0x24cb76=stripOuterParentheses(_0x2b52c4[0x4]??''),_0x511f56=_0x24cb76[_0x2a1d52(0xd7)](MYBATIS_DYNAMIC_START_MARKER)||_0x24cb76[_0x2a1d52(0xd7)](MYBATIS_DYNAMIC_END_MARKER),_0x4c7554=_0x24cb76['includes'](MYBATIS_INCLUDE_MARKER);_0x511f56&&(_0x30f81d=!![],_0x23a359??=_0x2a1d52(0xd8));_0x4c7554&&(_0x30f81d=!![],_0x23a359??=_0x2a1d52(0xe3));const _0x324a10=_0x24cb76[_0x2a1d52(0x94)](MYBATIS_DYNAMIC_START_MARKER,'\x20')[_0x2a1d52(0x94)](MYBATIS_DYNAMIC_END_MARKER,'\x20')[_0x2a1d52(0x94)](MYBATIS_INCLUDE_MARKER,'\x20');hasTopLevelKeyword(_0x324a10,'OR')&&(_0x30f81d=!![],_0x23a359??='OR-connected\x20JOIN\x20predicates\x20are\x20not\x20supported.');for(const _0xfbb93a of splitTopLevelAnd(_0x324a10)){const _0x5797e7=stripOuterParentheses(_0xfbb93a);if(hasTopLevelKeyword(_0x5797e7,'OR')){_0x30f81d=!![],_0x23a359??=_0x2a1d52(0xd9);continue;}const _0x5f19cf=splitEquality(_0x5797e7);if(!_0x5f19cf){containsColumnReference(_0xfbb93a,_0x3f8505)&&(_0x30f81d=!![]);continue;}const _0x307b20=parseDirectColumnReference(_0x5f19cf[0x0],_0x3f8505),_0x738786=parseDirectColumnReference(_0x5f19cf[0x1],_0x3f8505),_0x10ee25=containsColumnReference(_0x5f19cf[0x0],_0x3f8505),_0x24d7dc=containsColumnReference(_0x5f19cf[0x1],_0x3f8505),_0x5b9e94=_0x307b20&&!_0x24d7dc?_0x307b20:_0x738786&&!_0x10ee25?_0x738786:null;if(_0x5b9e94&&!_0x40129b[_0x2a1d52(0xd7)](_0x5b9e94))_0x40129b[_0x2a1d52(0xa0)](_0x5b9e94);else!_0x5b9e94&&containsColumnReference(_0xfbb93a,_0x3f8505)&&(_0x30f81d=!![]);}_0x4e9f65[_0x2a1d52(0xa0)]({'table':_0x592e60,'alias':_0x3f8505,'columns':_0x40129b,'unsupportedPredicate':_0x30f81d,'unsupportedReason':_0x23a359,'containsUnresolvedInclude':_0x4c7554,'position':_0x5c24f9});}for(const _0xe550eb of _0x2f0307[_0x2a1d52(0xcb)](/\bJOIN\b/gi)){const _0x246f80=_0xe550eb[_0x2a1d52(0xa9)]??0x0;if(_0x5c67d1['has'](_0x246f80))continue;const _0x438b48=/^\s+([`"\w$.]+)(?:\s+(?:AS\s+)?([`"\w$]+))?/['exec'](_0x45c4b5[_0x2a1d52(0xc8)](_0x246f80+_0xe550eb[0x0][_0x2a1d52(0xb4)])),_0x4850e4=normalizeIdentifier(_0x438b48?.[0x1]||_0x2a1d52(0xd5)),_0x1ea7c4=normalizeIdentifier(_0x438b48?.[0x2]||''),_0x3448bb=isSqlClauseKeyword(_0x1ea7c4)?_0x4850e4['split']('.')['at'](-0x1)||_0x4850e4:_0x1ea7c4||_0x4850e4[_0x2a1d52(0xb7)]('.')['at'](-0x1)||_0x4850e4;_0x4e9f65[_0x2a1d52(0xa0)]({'table':_0x4850e4,'alias':_0x3448bb,'columns':[],'unsupportedPredicate':!![],'unsupportedReason':_0x2a1d52(0xc9),'position':_0x246f80});}const _0x39a6f4=_0x2f0307[_0x2a1d52(0xa3)](MYBATIS_INCLUDE_MARKER);return _0x39a6f4>=0x0&&!_0x4e9f65[_0x2a1d52(0xca)](_0x3fd5bf=>_0x3fd5bf[_0x2a1d52(0xcd)])&&_0x4e9f65[_0x2a1d52(0xa0)]({'table':_0x2a1d52(0xd5),'alias':_0x2a1d52(0xd5),'columns':[],'unsupportedPredicate':!![],'unsupportedReason':_0x2a1d52(0xd2),'containsUnresolvedInclude':!![],'position':_0x39a6f4}),_0x4e9f65[_0x2a1d52(0xa6)]((_0x5a4f22,_0xd9bda8)=>_0x5a4f22[_0x2a1d52(0xd3)]-_0xd9bda8[_0x2a1d52(0xd3)]);}function stripSqlNoise(_0x1bc362){const _0x4bf297=a309_0x2c50,_0x4a094f=Array[_0x4bf297(0xb9)](_0x1bc362),_0x4cc43a=(_0x59f7b1,_0x1917ec)=>{for(let _0x1b5fda=_0x59f7b1;_0x1b5fda<_0x1917ec;_0x1b5fda+=0x1){_0x4a094f[_0x1b5fda]!=='\x0a'&&_0x4a094f[_0x1b5fda]!=='\x0d'&&(_0x4a094f[_0x1b5fda]='\x20');}};for(let _0x2573c3=0x0;_0x2573c3<_0x4a094f[_0x4bf297(0xb4)];_0x2573c3+=0x1){const _0x2affac=_0x4a094f[_0x2573c3],_0x255352=_0x4a094f[_0x2573c3+0x1];if(_0x2affac==='\x27'||_0x2affac==='\x22'||_0x2affac==='`'){const _0x3492cd=_0x2affac,_0x4c9443=_0x2573c3;_0x2573c3+=0x1;while(_0x2573c3<_0x4a094f[_0x4bf297(0xb4)]){if(_0x4a094f[_0x2573c3]==='\x5c'&&_0x2573c3+0x1<_0x4a094f[_0x4bf297(0xb4)]){_0x2573c3+=0x2;continue;}if(_0x4a094f[_0x2573c3]!==_0x3492cd){_0x2573c3+=0x1;continue;}if(_0x4a094f[_0x2573c3+0x1]===_0x3492cd){_0x2573c3+=0x2;continue;}break;}if(_0x3492cd==='\x27')_0x4cc43a(_0x4c9443,Math[_0x4bf297(0xb3)](_0x2573c3+0x1,_0x4a094f[_0x4bf297(0xb4)]));continue;}if(_0x2affac==='-'&&_0x255352==='-'){const _0x5a7728=_0x2573c3;while(_0x2573c3<_0x4a094f[_0x4bf297(0xb4)]&&_0x4a094f[_0x2573c3]!=='\x0a')_0x2573c3+=0x1;_0x4cc43a(_0x5a7728,_0x2573c3);continue;}if(_0x2affac==='/'&&_0x255352==='*'){const _0x261214=_0x2573c3;_0x2573c3+=0x2;while(_0x2573c3<_0x4a094f[_0x4bf297(0xb4)]&&!(_0x4a094f[_0x2573c3]==='*'&&_0x4a094f[_0x2573c3+0x1]==='/')){_0x2573c3+=0x1;}_0x2573c3=Math[_0x4bf297(0xb3)](_0x2573c3+0x1,_0x4a094f[_0x4bf297(0xb4)]-0x1),_0x4cc43a(_0x261214,_0x2573c3+0x1);continue;}if(_0x2affac==='#'&&_0x255352!=='{'){const _0x2f70f4=_0x2573c3;while(_0x2573c3<_0x4a094f[_0x4bf297(0xb4)]&&_0x4a094f[_0x2573c3]!=='\x0a')_0x2573c3+=0x1;_0x4cc43a(_0x2f70f4,_0x2573c3);continue;}if((_0x2affac==='#'||_0x2affac==='$')&&_0x255352==='{'){const _0x2107bb=_0x2573c3;_0x2573c3+=0x2;while(_0x2573c3<_0x4a094f[_0x4bf297(0xb4)]&&_0x4a094f[_0x2573c3]!=='}')_0x2573c3+=0x1;_0x4cc43a(_0x2107bb,Math[_0x4bf297(0xb3)](_0x2573c3+0x1,_0x4a094f['length']));}}return _0x4a094f[_0x4bf297(0xbf)]('');}function maskQuotedIdentifiers(_0x59c70b){const _0x46c6c0=a309_0x2c50,_0xaa9907=Array[_0x46c6c0(0xb9)](_0x59c70b);for(let _0x1e157c=0x0;_0x1e157c<_0xaa9907[_0x46c6c0(0xb4)];_0x1e157c+=0x1){const _0x2c5104=_0xaa9907[_0x1e157c];if(_0x2c5104!=='\x22'&&_0x2c5104!=='`')continue;_0x1e157c+=0x1;while(_0x1e157c<_0xaa9907[_0x46c6c0(0xb4)]){if(_0xaa9907[_0x1e157c]===_0x2c5104){if(_0xaa9907[_0x1e157c+0x1]===_0x2c5104){_0xaa9907[_0x1e157c]='\x20',_0xaa9907[_0x1e157c+0x1]='\x20',_0x1e157c+=0x2;continue;}break;}_0xaa9907[_0x1e157c]='\x20',_0x1e157c+=0x1;}}return _0xaa9907[_0x46c6c0(0xbf)]('');}function maskNestedQueries(_0x1e403d){const _0x305365=a309_0x2c50,_0x2a440d=Array[_0x305365(0xb9)](_0x1e403d);for(let _0x2bf532=0x0;_0x2bf532<_0x2a440d[_0x305365(0xb4)];_0x2bf532+=0x1){if(_0x2a440d[_0x2bf532]!=='(')continue;const _0x39b5d4=_0x1e403d[_0x305365(0xc8)](_0x2bf532+0x1);if(!/^\s*(?:SELECT|WITH)\b/i[_0x305365(0x96)](_0x39b5d4))continue;let _0x2d2861=0x1,_0x4a58c8=_0x2bf532+0x1;for(;_0x4a58c8<_0x2a440d[_0x305365(0xb4)]&&_0x2d2861>0x0;_0x4a58c8+=0x1){if(_0x2a440d[_0x4a58c8]==='(')_0x2d2861+=0x1;if(_0x2a440d[_0x4a58c8]===')')_0x2d2861-=0x1;}if(_0x2d2861!==0x0)continue;for(let _0x3f7dfc=_0x2bf532;_0x3f7dfc<_0x4a58c8;_0x3f7dfc+=0x1){_0x2a440d[_0x3f7dfc]='\x20';}const _0x54c684='__sq__';for(let _0x5bf4bb=0x0;_0x5bf4bb<_0x54c684[_0x305365(0xb4)]&&_0x2bf532+_0x5bf4bb<_0x4a58c8;_0x5bf4bb+=0x1){_0x2a440d[_0x2bf532+_0x5bf4bb]=_0x54c684[_0x5bf4bb];}_0x2bf532=_0x4a58c8-0x1;}return _0x2a440d[_0x305365(0xbf)]('');}function splitTopLevelAnd(_0x38da2e){const _0x30760e=a309_0x2c50,_0x4f4bf5=[];let _0x4e320e=0x0,_0x3343ad=0x0;for(let _0x599c47=0x0;_0x599c47<_0x38da2e[_0x30760e(0xb4)];_0x599c47+=0x1){const _0x664f63=_0x38da2e[_0x599c47];if(_0x664f63==='(')_0x4e320e+=0x1;if(_0x664f63===')')_0x4e320e=Math[_0x30760e(0xae)](0x0,_0x4e320e-0x1);_0x4e320e===0x0&&_0x38da2e[_0x30760e(0xc8)](_0x599c47)[_0x30760e(0xa4)](/^AND\b/i)&&(_0x599c47===0x0||/\s/['test'](_0x38da2e[_0x599c47-0x1]??''))&&(_0x4f4bf5[_0x30760e(0xa0)](_0x38da2e[_0x30760e(0xc8)](_0x3343ad,_0x599c47)['trim']()),_0x599c47+=0x2,_0x3343ad=_0x599c47+0x1);}const _0x197820=_0x38da2e[_0x30760e(0xc8)](_0x3343ad)[_0x30760e(0xa5)]();if(_0x197820)_0x4f4bf5[_0x30760e(0xa0)](_0x197820);return _0x4f4bf5;}function hasTopLevelKeyword(_0x5d69a8,_0x1a06e8){const _0x354f02=a309_0x2c50;let _0x52a97a=0x0;for(let _0x1f4d55=0x0;_0x1f4d55<_0x5d69a8[_0x354f02(0xb4)];_0x1f4d55+=0x1){const _0x53f0b4=_0x5d69a8[_0x1f4d55];if(_0x53f0b4==='(')_0x52a97a+=0x1;if(_0x53f0b4===')')_0x52a97a=Math[_0x354f02(0xae)](0x0,_0x52a97a-0x1);if(_0x52a97a!==0x0)continue;const _0x330f9f=_0x5d69a8['slice'](_0x1f4d55,_0x1f4d55+_0x1a06e8[_0x354f02(0xb4)]),_0x522e62=_0x5d69a8[_0x1f4d55-0x1]??'\x20',_0xf934eb=_0x5d69a8[_0x1f4d55+_0x1a06e8['length']]??'\x20';if(_0x330f9f['toUpperCase']()===_0x1a06e8[_0x354f02(0x99)]()&&!/[\w$]/['test'](_0x522e62)&&!/[\w$]/[_0x354f02(0x96)](_0xf934eb))return!![];}return![];}function splitEquality(_0x568b42){const _0x4c7601=a309_0x2c50,_0x19cd18=stripOuterParentheses(_0x568b42);let _0x302649=0x0,_0x272e95;for(let _0x585bfa=0x0;_0x585bfa<_0x19cd18[_0x4c7601(0xb4)];_0x585bfa+=0x1){const _0x209f5c=_0x19cd18[_0x585bfa];if(_0x209f5c==='(')_0x302649+=0x1;if(_0x209f5c===')')_0x302649=Math[_0x4c7601(0xae)](0x0,_0x302649-0x1);const _0x41dfa6=_0x19cd18[_0x585bfa-0x1]??'',_0x4ec538=_0x19cd18[_0x585bfa+0x1]??'';if(_0x209f5c==='='&&_0x302649===0x0&&!/[!<>=:]/[_0x4c7601(0x96)](_0x41dfa6)&&_0x4ec538!=='='){if(_0x272e95!==undefined)return null;_0x272e95=_0x585bfa;}}return _0x272e95===undefined?null:[_0x19cd18[_0x4c7601(0xc8)](0x0,_0x272e95)[_0x4c7601(0xa5)](),_0x19cd18[_0x4c7601(0xc8)](_0x272e95+0x1)['trim']()];}function a309_0x2c50(_0x47a615,_0xd702fd){_0x47a615=_0x47a615-0x93;const _0x55bdb3=a309_0x55bd();let _0x2c5020=_0x55bdb3[_0x47a615];return _0x2c5020;}function parseDirectColumnReference(_0x3f981c,_0x9fd773){const _0x4dad3e=a309_0x2c50,_0x317469=/^([`"]?[\w$]+[`"]?)\s*\.\s*([`"]?[\w$]+[`"]?)$/[_0x4dad3e(0xc2)](stripOuterParentheses(_0x3f981c));if(!_0x317469)return null;if(normalizeIdentifier(_0x317469[0x1]??'')!==normalizeIdentifier(_0x9fd773))return null;return normalizeIdentifier(_0x317469[0x2]??'');}function containsColumnReference(_0x3e92f2,_0x255a89){const _0x195146=a309_0x2c50,_0x5d9756=_0x3e92f2[_0x195146(0xd6)](/[`"]/g,''),_0xb913ca=_0x255a89[_0x195146(0xd6)](/[.*+?^${}()|[\]\\]/g,'\x5c$&');return new RegExp(_0x195146(0xb6)+_0xb913ca+_0x195146(0xdb),'i')['test'](_0x5d9756);}function findEqualityPrefix(_0x3e4cf7,_0x4e972f){const _0x200fcf=a309_0x2c50,_0x4b60dc=new Set(_0x4e972f[_0x200fcf(0xd1)](normalizeIdentifier)),_0x5bf9a6=[];for(const _0x593ebd of _0x3e4cf7){if(!_0x4b60dc[_0x200fcf(0x98)](normalizeIdentifier(_0x593ebd)))break;_0x5bf9a6[_0x200fcf(0xa0)](_0x593ebd);}return _0x5bf9a6;}function resolveTableMetadata(_0x219bdf,_0x59e458){const _0x34f493=a309_0x2c50,_0x22e5d6=normalizeIdentifier(_0x59e458),_0x1c4a33=_0x219bdf[_0x34f493(0xce)](_0x4b600e=>normalizeIdentifier(_0x4b600e['tableName'])===_0x22e5d6);if(_0x1c4a33[_0x34f493(0xb4)]===0x1)return _0x1c4a33[0x0];const _0x2f7663=_0x22e5d6[_0x34f493(0xd7)]('.'),_0x193b31=_0x22e5d6[_0x34f493(0xb7)]('.')['at'](-0x1),_0x5e0d79=_0x219bdf['filter'](_0x505097=>{const _0x3d9cbd=_0x34f493,_0xa3506b=normalizeIdentifier(_0x505097[_0x3d9cbd(0xad)]);if(_0x2f7663&&_0xa3506b[_0x3d9cbd(0xd7)]('.'))return![];return _0xa3506b[_0x3d9cbd(0xb7)]('.')['at'](-0x1)===_0x193b31;});return _0x5e0d79[_0x34f493(0xb4)]===0x1?_0x5e0d79[0x0]:undefined;}function columnNamesMatch(_0x5ae9c4,_0x5136a){return normalizeIdentifier(_0x5ae9c4)===normalizeIdentifier(_0x5136a);}function normalizeIdentifier(_0x5d17ba){const _0x150cbd=a309_0x2c50;return _0x5d17ba[_0x150cbd(0xd6)](/[`"]/g,'')[_0x150cbd(0xa5)]()[_0x150cbd(0xde)]();}function isSqlClauseKeyword(_0x4dcad0){const _0x200270=a309_0x2c50;return new Set(['on',_0x200270(0xaf),_0x200270(0xd0),'join',_0x200270(0xc0),_0x200270(0x93),_0x200270(0xdf),'full',_0x200270(0xbc),_0x200270(0xac)])[_0x200270(0x98)](_0x4dcad0);}function stripOuterParentheses(_0x95765f){const _0xd8ac58=a309_0x2c50;let _0x5c796b=_0x95765f[_0xd8ac58(0xa5)]();while(_0x5c796b[_0xd8ac58(0xe1)]('(')&&_0x5c796b[_0xd8ac58(0xa7)](')')){let _0x4d6f99=0x0,_0x4fc85c=!![];for(let _0x80e013=0x0;_0x80e013<_0x5c796b[_0xd8ac58(0xb4)];_0x80e013+=0x1){if(_0x5c796b[_0x80e013]==='(')_0x4d6f99+=0x1;if(_0x5c796b[_0x80e013]===')')_0x4d6f99-=0x1;if(_0x4d6f99===0x0&&_0x80e013<_0x5c796b[_0xd8ac58(0xb4)]-0x1){_0x4fc85c=![];break;}}if(!_0x4fc85c||_0x4d6f99!==0x0)break;_0x5c796b=_0x5c796b[_0xd8ac58(0xc8)](0x1,-0x1)['trim']();}return _0x5c796b;}function a309_0x55bd(){const _0x48db71=['columns','1272298cBsaYF','indexOf','match','trim','sort','endsWith','5769kdztqd','index','529148TTNoxl','warning','natural','tableName','max','using','indexes','1040438FrPAwb','\x20JOIN\x20direction\x20is\x20not\x20supported\x20by\x20static\x20index\x20auditing.','min','length','reduce','(?:^|[^\x5cw$])','split','JOIN_PREDICATE_UNSUPPORTED','from','15OjRERK','9820520RGaZsm','cross','add','metadataAvailable','join','inner','INDEX_METADATA_UNAVAILABLE','exec','alias','JOIN_INDEX_NOT_USABLE','Not\x20every\x20JOIN\x20target\x20predicate\x20could\x20be\x20audited\x20safely.','445663VJCsKp','22TKqahO','slice','Only\x20explicit\x20table\x20JOIN\x20clauses\x20with\x20an\x20ON\x20predicate\x20are\x20supported.','some','matchAll','unavailable','containsUnresolvedInclude','filter','No\x20dataset\x20metadata\x20matched\x20the\x20JOIN\x20table.','where','map','MyBatis\x20<include>\x20fragments\x20cannot\x20be\x20expanded\x20for\x20JOIN\x20auditing.','position','Relevant\x20columns\x20do\x20not\x20form\x20a\x20complete\x20leftmost\x20index\x20prefix.','unknown','replace','includes','MyBatis\x20dynamic\x20JOIN\x20predicates\x20cannot\x20be\x20audited\x20deterministically.','OR-connected\x20JOIN\x20predicates\x20are\x20not\x20supported.','JOIN_INDEX_MISSING','\x5cs*\x5c.\x5cs*[\x5cw$]+','full','5623730GRorbA','toLowerCase','right','matchedPrefix','startsWith','error','MyBatis\x20<include>\x20JOIN\x20fragments\x20cannot\x20be\x20expanded\x20statically.','left','replaceAll','840FWSlwZ','test','table','has','toUpperCase','covered','No\x20reported\x20index\x20contains\x20the\x20JOIN\x20access\x20columns.','unsupportedPredicate','sql','36wkCpCj','unsupportedReason','push'];a309_0x55bd=function(){return _0x48db71;};return a309_0x55bd();}
|
|
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_0x133145=a316_0x4607;(function(_0x57c05a,_0x3e263c){const _0x888e17=a316_0x4607,_0x2eb490=_0x57c05a();while(!![]){try{const _0x586e4f=-parseInt(_0x888e17(0xfa))/0x1*(-parseInt(_0x888e17(0xf6))/0x2)+-parseInt(_0x888e17(0xec))/0x3+-parseInt(_0x888e17(0x104))/0x4+-parseInt(_0x888e17(0x108))/0x5*(-parseInt(_0x888e17(0xde))/0x6)+-parseInt(_0x888e17(0xfc))/0x7*(-parseInt(_0x888e17(0xb2))/0x8)+-parseInt(_0x888e17(0xc5))/0x9+-parseInt(_0x888e17(0xe2))/0xa*(-parseInt(_0x888e17(0xf9))/0xb);if(_0x586e4f===_0x3e263c)break;else _0x2eb490['push'](_0x2eb490['shift']());}catch(_0x172573){_0x2eb490['push'](_0x2eb490['shift']());}}}(a316_0x5d5c,0x9e103));const MYBATIS_OUTER_TAGS=new Map([['select',a316_0x133145(0x10a)],[a316_0x133145(0x10c),a316_0x133145(0xe4)],[a316_0x133145(0xdb),a316_0x133145(0xf8)],[a316_0x133145(0xc8),a316_0x133145(0x106)]]),MYBATIS_DYNAMIC_TAGS=new Set(['if','where',a316_0x133145(0xe7),a316_0x133145(0xab),a316_0x133145(0x100),'otherwise',a316_0x133145(0xd5),'set',a316_0x133145(0xa8),a316_0x133145(0xa5),a316_0x133145(0xbd)]),MYBATIS_BRANCH_TAGS=new Set(['if',a316_0x133145(0xe7),a316_0x133145(0xab),a316_0x133145(0x100),a316_0x133145(0xa7)]);function a316_0x5d5c(){const _0x264106=['Unterminated\x20XML\x20comment.','\x20statements\x20require\x20explicit\x20review.\x20Local\x20analysis\x20does\x20not\x20authorize\x20saving\x20or\x20execution.','SQL\x20contains\x20modification\x20statements\x20alongside\x20SELECT','\x20query\x20targeting\x20','property','add','Unterminated\x20CDATA\x20section.','from','DDL','SQL\x20text\x20must\x20be\x20inside\x20the\x20MyBatis\x20statement\x20wrapper.','matchAll','rawName','4761549BfnRKM','\x20with\x20parameters:\x20','\x20WHERE\x20','delete',']]>','get','outer','unknown\x20table(s)','CDATA\x20sections\x20must\x20be\x20inside\x20the\x20MyBatis\x20statement\x20wrapper.',')\x5cb','replace','some','keys','error','isDangerous','sql','trim','<!--','XML\x20declarations\x20must\x20precede\x20the\x20MyBatis\x20statement\x20wrapper.','tagName','Unterminated\x20MyBatis\x20XML\x20tag.','fromCodePoint','update','SET','reason','24pBeeGj','exec','KEY','LOCK\x20IN\x20SHARE\x20MODE','1168810SNAQvs','DDL\x20statements\x20require\x20explicit\x20review','INSERT','slice','toLowerCase','foreach','has','WITH','join','parseInt','1236711WEJkNg','__RABETBASE_UNRESOLVED_SQL_FRAGMENT__','pop','startsWith','MyBatis\x20dynamic\x20tag\x20names\x20must\x20be\x20lowercase:\x20<','-->','Multiple\x20MyBatis\x20statement\x20wrappers\x20are\x20not\x20supported.','replaceAll','mybatisXml','Unterminated\x20XML\x20declaration.','68MpUFQR','<','UPDATE','143HiCypw','4751sszKHq','Invalid\x20MyBatis\x20XML\x20closing\x20tag:\x20</','31661TrLSVg','push','__RABETBASE_MYBATIS_DYNAMIC_START__','DELETE\x20statements\x20require\x20explicit\x20review','when','Local\x20analysis\x20could\x20not\x20parse\x20the\x20WITH\x20prefix;\x20this\x20is\x20a\x20local\x20capability\x20limit,\x20not\x20a\x20platform\x20rejection.','SQL\x20contains\x20blocked\x20DELETE\x20or\x20DDL\x20statements','filter','1158824EREipW','Unable\x20to\x20detect\x20SQL\x20type.\x20','DELETE','Unable\x20to\x20detect\x20SQL\x20type.\x20Please\x20check\x20the\x20SQL\x20content.','65885nTegFU','MyBatis\x20XML\x20must\x20contain\x20exactly\x20one\x20complete\x20statement\x20wrapper.','SELECT','test','insert','Unclosed\x20MyBatis\x20XML\x20tag:\x20<','match','__RABETBASE_MYBATIS_DYNAMIC_END__','toUpperCase','where','<![CDATA[','SHARE','&','include','string','otherwise','bind','>','UNKNOWN','choose','Unsupported\x20MyBatis\x20XML\x20tag:\x20<','SQL\x20content\x20is\x20empty','type','MATERIALIZED','Invalid\x20MyBatis\x20XML\x20tag.','__RABETBASE_MYBATIS_INCLUDE_UNRESOLVED__','256ldGifA','Invalid\x20attributes\x20on\x20MyBatis\x20XML\x20tag:\x20<','NOT','includes','FOR','length','indexOf'];a316_0x5d5c=function(){return _0x264106;};return a316_0x5d5c();}export const MYBATIS_DYNAMIC_START_MARKER=a316_0x133145(0xfe);export const MYBATIS_DYNAMIC_END_MARKER=a316_0x133145(0x9f);export const MYBATIS_INCLUDE_MARKER=a316_0x133145(0xb1);const UNRESOLVED_SQL_FRAGMENT=a316_0x133145(0xed),MYBATIS_OUTER_TAG_PATTERN=new RegExp('^<\x5cs*(?:'+[...MYBATIS_OUTER_TAGS[a316_0x133145(0xd1)]()][a316_0x133145(0xea)]('|')+a316_0x133145(0xce),'i');export function normalizeSqlForStaticAnalysis(_0x47bafa){const _0x44d5d1=a316_0x133145,_0x45b6b0=typeof _0x47bafa===_0x44d5d1(0xa6)?_0x47bafa:'';if(detectSqlSourceMode(_0x45b6b0)===_0x44d5d1(0xd4))return{'sql':_0x45b6b0,'mode':_0x44d5d1(0xd4)};let _0x407d01=0x0,_0x393cf2='',_0x5ba48b,_0x29c123=![],_0x52a763=![];const _0x396178=[];while(_0x407d01<_0x45b6b0[_0x44d5d1(0xb7)]){if(_0x45b6b0['startsWith'](_0x44d5d1(0xd6),_0x407d01)){const _0x3dd45e=_0x45b6b0[_0x44d5d1(0xb8)](_0x44d5d1(0xf1),_0x407d01+0x4);if(_0x3dd45e<0x0)return invalidMybatisSource(_0x44d5d1(0xb9));_0x393cf2+='\x20',_0x407d01=_0x3dd45e+0x3;continue;}if(_0x45b6b0[_0x44d5d1(0xef)](_0x44d5d1(0xa2),_0x407d01)){if(!_0x29c123||_0x52a763)return invalidMybatisSource(_0x44d5d1(0xcd));const _0x4a6c66=_0x45b6b0[_0x44d5d1(0xb8)](_0x44d5d1(0xc9),_0x407d01+0x9);if(_0x4a6c66<0x0)return invalidMybatisSource(_0x44d5d1(0xbf));_0x393cf2+=_0x45b6b0[_0x44d5d1(0xe5)](_0x407d01+0x9,_0x4a6c66),_0x407d01=_0x4a6c66+0x3;continue;}if(_0x45b6b0[_0x44d5d1(0xef)]('<?',_0x407d01)){if(_0x29c123)return invalidMybatisSource(_0x44d5d1(0xd7));const _0x26bf72=_0x45b6b0[_0x44d5d1(0xb8)]('?>',_0x407d01+0x2);if(_0x26bf72<0x0)return invalidMybatisSource(_0x44d5d1(0xf5));_0x393cf2+='\x20',_0x407d01=_0x26bf72+0x2;continue;}if(_0x45b6b0[_0x407d01]!=='<'){const _0x3b3a35=_0x45b6b0[_0x44d5d1(0xb8)]('<',_0x407d01),_0x1d2fa4=_0x3b3a35<0x0?_0x45b6b0[_0x44d5d1(0xb7)]:_0x3b3a35,_0xbb505d=_0x45b6b0[_0x44d5d1(0xe5)](_0x407d01,_0x1d2fa4);if((!_0x29c123||_0x52a763)&&_0xbb505d[_0x44d5d1(0xd5)]())return invalidMybatisSource(_0x44d5d1(0xc2));if(_0x29c123&&!_0x52a763){const _0x3cb22c=decodeXmlEntities(_0xbb505d);if(_0x3cb22c===null)return invalidMybatisSource('Invalid\x20XML\x20entity\x20reference.');_0x393cf2+=_0x3cb22c;}else _0x393cf2+='\x20';_0x407d01=_0x1d2fa4;continue;}const _0x2bdbec=findXmlTagEnd(_0x45b6b0,_0x407d01);if(_0x2bdbec<0x0)return invalidMybatisSource(_0x44d5d1(0xd9));const _0xe22482=_0x45b6b0[_0x44d5d1(0xe5)](_0x407d01,_0x2bdbec+0x1),_0x4f7ac6=/^<\s*(\/?)\s*([A-Za-z][\w:-]*)([\s\S]*?)(\/?)\s*>$/[_0x44d5d1(0xdf)](_0xe22482);if(!_0x4f7ac6)return invalidMybatisSource(_0x44d5d1(0xb0));const _0x1d2f54=_0x4f7ac6[0x1]==='/',_0x4b388f=_0x4f7ac6[0x2]??'',_0x40de63=_0x4b388f[_0x44d5d1(0xe6)](),_0x33c742=_0x4f7ac6[0x3]??'',_0x8d5b46=_0x4f7ac6[0x4]==='/',_0x1f15e9=MYBATIS_OUTER_TAGS[_0x44d5d1(0xca)](_0x40de63);if(!_0x1f15e9&&!MYBATIS_DYNAMIC_TAGS[_0x44d5d1(0xe8)](_0x40de63))return invalidMybatisSource(_0x44d5d1(0xac)+_0x40de63+'>.');if(!_0x1f15e9&&_0x4b388f!==_0x40de63)return invalidMybatisSource(_0x44d5d1(0xf0)+_0x4b388f+'>.');if(_0x1d2f54){if(_0x33c742[_0x44d5d1(0xd5)]()||_0x8d5b46)return invalidMybatisSource(_0x44d5d1(0xfb)+_0x4b388f+'>.');const _0x196f72=_0x396178['at'](-0x1);if(!_0x196f72||(_0x196f72['outer']?_0x196f72[_0x44d5d1(0xd8)]!==_0x40de63:_0x196f72[_0x44d5d1(0xc4)]!==_0x4b388f))return invalidMybatisSource('Mismatched\x20MyBatis\x20XML\x20closing\x20tag:\x20</'+_0x4b388f+'>.');_0x396178[_0x44d5d1(0xee)]();if(_0x196f72[_0x44d5d1(0xcb)])_0x52a763=!![];_0x393cf2+=MYBATIS_BRANCH_TAGS['has'](_0x40de63)?'\x20'+MYBATIS_DYNAMIC_END_MARKER+'\x20':'\x20';}else{if(!hasWellFormedXmlAttributes(_0x33c742))return invalidMybatisSource(_0x44d5d1(0xb3)+_0x4b388f+'>.');if(_0x40de63==='property'&&(!_0x8d5b46||_0x396178['at'](-0x1)?.[_0x44d5d1(0xd8)]!==_0x44d5d1(0xa5)))return invalidMybatisSource('MyBatis\x20<property>\x20must\x20be\x20a\x20self-closing\x20direct\x20child\x20of\x20<include>.');if(_0x1f15e9){if(_0x29c123||_0x396178[_0x44d5d1(0xb7)]>0x0)return invalidMybatisSource(_0x44d5d1(0xf2));_0x29c123=!![],_0x52a763=_0x8d5b46,_0x5ba48b=_0x1f15e9;}else{if(!_0x29c123||_0x52a763)return invalidMybatisSource('MyBatis\x20dynamic\x20tag\x20must\x20be\x20inside\x20the\x20statement\x20wrapper:\x20<'+_0x4b388f+'>.');}_0x393cf2+=_0x40de63===_0x44d5d1(0xa1)?_0x44d5d1(0xc7):_0x40de63==='set'?'\x20SET\x20':_0x40de63===_0x44d5d1(0xa5)?'\x20'+MYBATIS_INCLUDE_MARKER+'\x20':MYBATIS_BRANCH_TAGS[_0x44d5d1(0xe8)](_0x40de63)&&!_0x8d5b46?'\x20'+MYBATIS_DYNAMIC_START_MARKER+'\x20':'\x20',!_0x8d5b46&&_0x396178[_0x44d5d1(0xfd)]({'rawName':_0x4b388f,'tagName':_0x40de63,'outer':!!_0x1f15e9});}_0x407d01=_0x2bdbec+0x1;}if(_0x396178['length']>0x0)return invalidMybatisSource(_0x44d5d1(0x10d)+_0x396178['at'](-0x1)?.[_0x44d5d1(0xc4)]+'>.');if(!_0x29c123||!_0x52a763)return invalidMybatisSource(_0x44d5d1(0x109));return{'sql':_0x393cf2[_0x44d5d1(0xd5)](),'mode':_0x44d5d1(0xf4),..._0x5ba48b?{'statementType':_0x5ba48b}:{}};}function hasWellFormedXmlAttributes(_0xf0b6c0){const _0x7b7904=a316_0x133145;let _0x26a281=0x0;const _0x21a989=new Set();while(_0x26a281<_0xf0b6c0[_0x7b7904(0xb7)]){while(_0x26a281<_0xf0b6c0[_0x7b7904(0xb7)]&&/\s/[_0x7b7904(0x10b)](_0xf0b6c0[_0x26a281]??''))_0x26a281+=0x1;if(_0x26a281>=_0xf0b6c0['length'])return!![];const _0x10c35e=/^[A-Za-z_:][\w:.-]*/[_0x7b7904(0xdf)](_0xf0b6c0[_0x7b7904(0xe5)](_0x26a281)),_0x55c57d=_0x10c35e?.[0x0];if(!_0x55c57d||_0x21a989[_0x7b7904(0xe8)](_0x55c57d))return![];_0x21a989['add'](_0x55c57d),_0x26a281+=_0x55c57d[_0x7b7904(0xb7)];while(_0x26a281<_0xf0b6c0[_0x7b7904(0xb7)]&&/\s/[_0x7b7904(0x10b)](_0xf0b6c0[_0x26a281]??''))_0x26a281+=0x1;if(_0xf0b6c0[_0x26a281]!=='=')return![];_0x26a281+=0x1;while(_0x26a281<_0xf0b6c0[_0x7b7904(0xb7)]&&/\s/['test'](_0xf0b6c0[_0x26a281]??''))_0x26a281+=0x1;const _0x52ceb5=_0xf0b6c0[_0x26a281];if(_0x52ceb5!=='\x22'&&_0x52ceb5!=='\x27')return![];_0x26a281+=0x1;const _0xdcc300=_0xf0b6c0[_0x7b7904(0xb8)](_0x52ceb5,_0x26a281);if(_0xdcc300<0x0)return![];if(decodeXmlEntities(_0xf0b6c0[_0x7b7904(0xe5)](_0x26a281,_0xdcc300))===null)return![];_0x26a281=_0xdcc300+0x1;}return!![];}export function detectSqlSourceMode(_0x29a427){const _0x25c952=a316_0x133145;let _0x2709f9=0x0;const _0x48150e=()=>{const _0x16d67f=a316_0x4607;while(_0x2709f9<_0x29a427[_0x16d67f(0xb7)]&&/\s/[_0x16d67f(0x10b)](_0x29a427[_0x2709f9]??''))_0x2709f9+=0x1;};_0x48150e();while(_0x2709f9<_0x29a427[_0x25c952(0xb7)]){if(_0x29a427['startsWith'](_0x25c952(0xd6),_0x2709f9)){const _0x425954=_0x29a427['indexOf']('-->',_0x2709f9+0x4);if(_0x425954<0x0)return _0x25c952(0xf4);_0x2709f9=_0x425954+0x3,_0x48150e();continue;}if(_0x29a427['startsWith']('<?',_0x2709f9)){const _0x9ec6ab=_0x29a427['indexOf']('?>',_0x2709f9+0x2);if(_0x9ec6ab<0x0)return _0x25c952(0xf4);_0x2709f9=_0x9ec6ab+0x2,_0x48150e();continue;}break;}return MYBATIS_OUTER_TAG_PATTERN['test'](_0x29a427['slice'](_0x2709f9))?_0x25c952(0xf4):_0x25c952(0xd4);}function a316_0x4607(_0x4b0f33,_0x3c01c8){_0x4b0f33=_0x4b0f33-0x9f;const _0x5d5cdd=a316_0x5d5c();let _0x460708=_0x5d5cdd[_0x4b0f33];return _0x460708;}function invalidMybatisSource(_0x1a33dd){return{'sql':'','mode':'mybatisXml','error':_0x1a33dd};}function findXmlTagEnd(_0x36b8b2,_0x27f5f2){const _0x154770=a316_0x133145;let _0x15fce6;for(let _0xc53a64=_0x27f5f2+0x1;_0xc53a64<_0x36b8b2[_0x154770(0xb7)];_0xc53a64+=0x1){const _0x480dc4=_0x36b8b2[_0xc53a64];if(_0x15fce6){if(_0x480dc4===_0x15fce6)_0x15fce6=undefined;continue;}if(_0x480dc4==='\x22'||_0x480dc4==='\x27'){_0x15fce6=_0x480dc4;continue;}if(_0x480dc4==='>')return _0xc53a64;}return-0x1;}function decodeXmlEntities(_0x6c0b0){const _0x5e0b69=a316_0x133145;let _0x1be8ba=![];const _0xb11f41=_0x6c0b0[_0x5e0b69(0xcf)](/&(?:#x[0-9a-f]+;|#[0-9]+;|[A-Za-z_:][\w:.-]*;)?/g,_0x4c35cb=>{const _0x2ceb4c=_0x5e0b69;if(_0x4c35cb===_0x2ceb4c(0xf7))return'<';if(_0x4c35cb===_0x2ceb4c(0xa9))return'>';if(_0x4c35cb==='"')return'\x22';if(_0x4c35cb===''')return'\x27';if(_0x4c35cb===_0x2ceb4c(0xa4))return'&';const _0x5eb133=/^&#(?:x([0-9a-f]+)|([0-9]+));$/[_0x2ceb4c(0xdf)](_0x4c35cb);if(_0x5eb133){const _0x471f3e=_0x5eb133[0x1],_0x45cd50=_0x5eb133[0x2],_0x140e70=Number[_0x2ceb4c(0xeb)](_0x471f3e??_0x45cd50??'',_0x471f3e?0x10:0xa);if(isValidXmlCharacter(_0x140e70))return String[_0x2ceb4c(0xda)](_0x140e70);}return _0x1be8ba=!![],'';});return _0x1be8ba?null:_0xb11f41;}function isValidXmlCharacter(_0x395435){return _0x395435===0x9||_0x395435===0xa||_0x395435===0xd||_0x395435>=0x20&&_0x395435<=0xd7ff||_0x395435>=0xe000&&_0x395435<=0xfffd||_0x395435>=0x10000&&_0x395435<=0x10ffff;}export function detectSqlType(_0x1db538){return detectNormalizedSqlType(normalizeSqlForStaticAnalysis(_0x1db538));}function detectNormalizedSqlType(_0xed18d9){const _0x41f993=a316_0x133145;if(_0xed18d9['error'])return{'type':_0x41f993(0xaa),'isSelectOnly':![],'isDangerous':![],'reason':_0xed18d9[_0x41f993(0xd2)]};if(!_0xed18d9[_0x41f993(0xd4)][_0x41f993(0xd5)]())return{'type':'UNKNOWN','isSelectOnly':![],'isDangerous':![],'reason':_0x41f993(0xad)};const _0x1f31fe=tokenizeSqlForTypeAnalysis(_0xed18d9[_0x41f993(0xd4)]),_0x29d31b=_0x1f31fe[_0x41f993(0x103)](_0x265075=>_0x265075!==MYBATIS_DYNAMIC_START_MARKER&&_0x265075!==MYBATIS_DYNAMIC_END_MARKER),_0x5e0d68=findMainStatementIndex(_0x29d31b);if(_0x5e0d68<0x0)return{'type':'UNKNOWN','isSelectOnly':![],'isDangerous':![],'reason':_0x41f993(0x101)};const _0x73e132=_0x29d31b[_0x5e0d68]??'',_0x26973b=_0xed18d9['statementType']??_0x73e132,_0x5de4ed=_0x1f31fe[_0x41f993(0xd0)](_0x219e37=>/^(DELETE|DROP|ALTER|CREATE|TRUNCATE)$/['test'](_0x219e37)),_0x4f4fa5=new Set();let _0x5dbc46=![];for(let _0x23aad5=0x0;_0x23aad5<_0x1f31fe[_0x41f993(0xb7)];_0x23aad5+=0x1){const _0x3c7aa5=_0x1f31fe[_0x23aad5];(_0x3c7aa5==='UPDATE'||_0x3c7aa5===_0x41f993(0xa3))&&isLockingClauseKeyword(_0x1f31fe,_0x23aad5)&&(_0x4f4fa5[_0x41f993(0xbe)](_0x23aad5),_0x5dbc46=!![]);if(_0x1f31fe[_0x41f993(0xe5)](_0x23aad5,_0x23aad5+0x4)[_0x41f993(0xea)]('\x20')===_0x41f993(0xe1))_0x5dbc46=!![];}if(_0x26973b===_0x41f993(0x10a)){const _0x4e27d7=_0x1f31fe['some']((_0x3142b2,_0x492c5b)=>/^(INSERT|UPDATE|DELETE|DROP|ALTER|CREATE|TRUNCATE)$/[_0x41f993(0x10b)](_0x3142b2)&&!_0x4f4fa5['has'](_0x492c5b));return{'type':_0x41f993(0x10a),'isSelectOnly':!_0x4e27d7&&!_0x5dbc46,'isLockingRead':_0x5dbc46,'isDangerous':_0x4e27d7,'reason':_0x4e27d7?_0x41f993(0xbb):undefined};}if(_0x26973b==='INSERT')return{'type':_0x41f993(0xe4),'isSelectOnly':![],'isDangerous':_0x5de4ed,'reason':_0x5de4ed?_0x41f993(0x102):undefined};if(_0x26973b===_0x41f993(0xf8))return{'type':_0x41f993(0xf8),'isSelectOnly':![],'isDangerous':_0x5de4ed,'reason':_0x5de4ed?'SQL\x20contains\x20blocked\x20DELETE\x20or\x20DDL\x20statements':undefined};if(_0x26973b===_0x41f993(0x106))return{'type':_0x41f993(0x106),'isSelectOnly':![],'isDangerous':!![],'reason':_0x41f993(0xff)};if(/^(CREATE|ALTER|DROP|TRUNCATE)/i['test'](_0x73e132))return{'type':_0x41f993(0xc1),'isSelectOnly':![],'isDangerous':!![],'reason':_0x41f993(0xe3)};return{'type':_0x41f993(0xaa),'isSelectOnly':![],'isDangerous':![]};}function isLockingClauseKeyword(_0x339ad9,_0x5b9b6c){const _0x310682=a316_0x133145,_0xa17115=_0x339ad9[_0x5b9b6c]===_0x310682(0xf8)?[[_0x310682(0xb6)],[_0x310682(0xb6),'NO',_0x310682(0xe0)]]:[[_0x310682(0xb6)],[_0x310682(0xb6),'KEY']],_0x54ba86=_0xa17115[_0x310682(0xd0)](_0x409441=>{const _0x41a396=_0x310682,_0x49cfa1=_0x5b9b6c-_0x409441[_0x41a396(0xb7)];return _0x49cfa1>=0x0&&_0x339ad9['slice'](_0x49cfa1,_0x5b9b6c)[_0x41a396(0xea)]('\x20')===_0x409441['join']('\x20');});if(!_0x54ba86)return![];return!_0x339ad9[_0x310682(0xe5)](_0x5b9b6c+0x1,_0x5b9b6c+0x5)[_0x310682(0xb5)](_0x310682(0xdc));}function findMainStatementIndex(_0x5aafc7){const _0x3ec0e2=a316_0x133145;if(_0x5aafc7[0x0]!==_0x3ec0e2(0xe9))return 0x0;let _0x455796=_0x5aafc7[0x1]==='RECURSIVE'?0x2:0x1;while(_0x455796<_0x5aafc7[_0x3ec0e2(0xb7)]){const _0x3f23ca=_0x5aafc7[_0x455796];if(!_0x3f23ca||!(/^[A-Z_][\w$]*$/['test'](_0x3f23ca)||/^[`"]/[_0x3ec0e2(0x10b)](_0x3f23ca)))return-0x1;_0x455796+=0x1;if(_0x5aafc7[_0x455796]==='('){_0x455796=skipSqlParentheses(_0x5aafc7,_0x455796);if(_0x455796<0x0)return-0x1;}if(_0x5aafc7[_0x455796]!=='AS')return-0x1;_0x455796+=0x1;if(_0x5aafc7[_0x455796]===_0x3ec0e2(0xb4)&&_0x5aafc7[_0x455796+0x1]===_0x3ec0e2(0xaf))_0x455796+=0x2;else{if(_0x5aafc7[_0x455796]===_0x3ec0e2(0xaf))_0x455796+=0x1;}_0x455796=skipSqlParentheses(_0x5aafc7,_0x455796);if(_0x455796<0x0)return-0x1;if(_0x5aafc7[_0x455796]!==','){const _0x8e057=_0x5aafc7[_0x455796]==='('?_0x455796+0x1:_0x455796;return/^(SELECT|INSERT|UPDATE|DELETE)$/['test'](_0x5aafc7[_0x8e057]??'')?_0x8e057:-0x1;}_0x455796+=0x1;}return-0x1;}function skipSqlParentheses(_0x992c31,_0x2068e4){const _0x35b63b=a316_0x133145;if(_0x992c31[_0x2068e4]!=='(')return-0x1;let _0x812c7a=0x0;for(let _0x3a9fa6=_0x2068e4;_0x3a9fa6<_0x992c31[_0x35b63b(0xb7)];_0x3a9fa6+=0x1){const _0x1e7237=_0x992c31[_0x3a9fa6];if(_0x1e7237===';')return-0x1;if(_0x1e7237==='(')_0x812c7a+=0x1;if(_0x1e7237===')'&&--_0x812c7a===0x0)return _0x3a9fa6+0x1;}return-0x1;}function stripStaticAnalysisMarkers(_0x39307a){const _0x3805c7=a316_0x133145;return _0x39307a[_0x3805c7(0xf3)](MYBATIS_DYNAMIC_START_MARKER,'\x20')['replaceAll'](MYBATIS_DYNAMIC_END_MARKER,'\x20')['replaceAll'](MYBATIS_INCLUDE_MARKER,'\x20'+UNRESOLVED_SQL_FRAGMENT+'\x20');}function tokenizeSqlForTypeAnalysis(_0x2070ee){const _0x1f0a91=a316_0x133145,_0x2926ca=[],_0x14a2ce=/\/\*[\s\S]*?\*\/|--[^\r\n]*|[#$]\{[^}]*\}|#[^\r\n]*|'(?:''|\\[\s\S]|[^'\\])*'|"(?:""|\\[\s\S]|[^"\\])*"|`(?:``|\\[\s\S]|[^`\\])*`|@[A-Za-z_]\w*|[A-Za-z_]\w*|\S/g;for(const _0x230543 of _0x2070ee[_0x1f0a91(0xc3)](_0x14a2ce)){const _0x6f0156=_0x230543[0x0];if(_0x6f0156[_0x1f0a91(0xef)]('/*')||_0x6f0156[_0x1f0a91(0xef)]('--')||_0x6f0156[_0x1f0a91(0xef)]('#')&&!_0x6f0156[_0x1f0a91(0xef)]('#{'))continue;_0x2926ca[_0x1f0a91(0xfd)](/^["`]/[_0x1f0a91(0x10b)](_0x6f0156)?_0x6f0156:/^[\x27@#$]/['test'](_0x6f0156)?'?':_0x6f0156[_0x1f0a91(0xa0)]());}return _0x2926ca;}function extractTables(_0x5c2acf,_0x31cf70){const _0x9a8ea9=a316_0x133145,_0x16b78f=_0x5c2acf[_0x9a8ea9(0xcf)](/#\{[^}]*\}/g,'?')[_0x9a8ea9(0xcf)](/\$\{[^}]*\}/g,'?')['replace'](/'[^']*'/g,'\x27\x27')[_0x9a8ea9(0xcf)](/--.*$/gm,'')[_0x9a8ea9(0xcf)](/\/\*[\s\S]*?\*\//g,''),_0x34e40b=[],_0x50aa02=_0x16b78f[_0x9a8ea9(0x10e)](/FROM\s+([^\s,)(]+)/i);addTable(_0x34e40b,_0x50aa02?.[0x1]);for(const _0x2fbe2d of _0x16b78f['matchAll'](/(?:INNER|LEFT|RIGHT|FULL|CROSS)?\s*JOIN\s+([^\s,)(]+)/gi)){addTable(_0x34e40b,_0x2fbe2d[0x1]);}const _0x189304=_0x16b78f[_0x9a8ea9(0x10e)](/INTO\s+([^\s(]+)/i);addTable(_0x34e40b,_0x189304?.[0x1]);if(_0x31cf70===_0x9a8ea9(0xf8)){const _0x4c9d4d=_0x16b78f[_0x9a8ea9(0x10e)](/UPDATE\s+([^\s,)(]+)/i);addTable(_0x34e40b,_0x4c9d4d?.[0x1]);}return _0x34e40b;}function addTable(_0x3b5238,_0x47fd9){const _0x59536e=a316_0x133145,_0x1cf0d5=_0x47fd9?.[_0x59536e(0xcf)](/[`"]/g,'');_0x1cf0d5&&_0x1cf0d5!==UNRESOLVED_SQL_FRAGMENT&&!_0x3b5238['includes'](_0x1cf0d5)&&_0x3b5238['push'](_0x1cf0d5);}function extractParameters(_0x35a47f){const _0x20a3c8=a316_0x133145,_0x5272a7=new Set();for(const _0x3b75e1 of _0x35a47f[_0x20a3c8(0xc3)](/[#$]\{\s*([A-Za-z_][\w.]*)\s*(?=[,}])/g)){if(_0x3b75e1[0x1])_0x5272a7[_0x20a3c8(0xbe)](_0x3b75e1[0x1]);}return Array[_0x20a3c8(0xc0)](_0x5272a7);}export function validateSql(_0x300afd){const _0x3c7304=a316_0x133145,_0x2f62f1=normalizeSqlForStaticAnalysis(_0x300afd),_0x2caa21=detectNormalizedSqlType(_0x2f62f1),_0x1ade12=stripStaticAnalysisMarkers(_0x2f62f1[_0x3c7304(0xd4)]),_0x9d1cc3=_0x2f62f1[_0x3c7304(0xd2)]?[]:extractTables(_0x1ade12,_0x2caa21['type']),_0x5f66d6=_0x2f62f1[_0x3c7304(0xd2)]?[]:extractParameters(_0x1ade12);if(_0x2caa21[_0x3c7304(0xd3)])return{'valid':![],'sqlType':_0x2caa21,'tables':_0x9d1cc3,'parameters':_0x5f66d6,'message':_0x2caa21[_0x3c7304(0xdd)]||_0x2caa21['type']+_0x3c7304(0xba)};if(_0x2caa21[_0x3c7304(0xae)]===_0x3c7304(0xaa))return{'valid':![],'sqlType':_0x2caa21,'tables':_0x9d1cc3,'parameters':_0x5f66d6,'message':_0x2f62f1[_0x3c7304(0xd2)]?_0x3c7304(0x105)+_0x2f62f1[_0x3c7304(0xd2)]:_0x2caa21['reason']?_0x3c7304(0x105)+_0x2caa21['reason']:_0x3c7304(0x107)};return{'valid':!![],'sqlType':_0x2caa21,'tables':_0x9d1cc3,'parameters':_0x5f66d6,'message':_0x2caa21[_0x3c7304(0xae)]+_0x3c7304(0xbc)+(_0x9d1cc3[_0x3c7304(0xb7)]?_0x9d1cc3[_0x3c7304(0xea)](',\x20'):_0x3c7304(0xcc))+(_0x5f66d6[_0x3c7304(0xb7)]?_0x3c7304(0xc6)+_0x5f66d6[_0x3c7304(0xea)](',\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}}
|