@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
package/lib/commands/bff/list.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{listBffScripts}from"../../core/api-client.js";export const bffList={service:"bff",command:"list",description:"List Backend Function scripts",risk:"read",flags:[{name:"type",type:"string",description:"Script type filter",default:"ENDPOINT",enum:["ENDPOINT","COMMON"]},{name:"name",type:"string",description:"Filter by script name"},{name:"verbose",type:"boolean",description:"Return full script objects"}],async execute(ctx){const scripts=await listBffScripts(ctx.appCode,ctx.str("type"),{scriptName:ctx.str("name")||undefined});const verbose=ctx.bool("verbose");return{ok:true,data:verbose?scripts:scripts.map(s=>({id:s.id,functionName:s.functionName??"",description:s.description||"(unnamed)",scriptType:s.scriptType})),message:scripts.length===0?"No Backend Function scripts found.":undefined}}};
|
package/lib/commands/bff/logs.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{searchBffScriptLogs}from"../../core/api-client.js";import{CliErrors}from"../../errors.js";const DEFAULT_SINCE_MINUTES=30;const DEFAULT_LIMIT=200;const MAX_LIMIT=1e3;const LOG_LEVELS=["DEBUG","INFO","WARN","ERROR"];export function resolveBffLogQuery(ctx,now=Date.now()){const rawSince=ctx.flag("since");const rawStartTime=ctx.flag("start-time");const rawEndTime=ctx.flag("end-time");if(rawSince!==undefined&&rawStartTime!==undefined){throw CliErrors.validation("--since cannot be combined with --start-time.")}const endTime=rawEndTime===undefined?now:readPositiveInteger(ctx.num("end-time"),"--end-time");const startTime=rawStartTime===undefined?endTime-readSinceMinutes(ctx)*6e4:readPositiveInteger(ctx.num("start-time"),"--start-time");if(startTime<=0){throw CliErrors.validation("The resolved log start time must be greater than 0.")}if(startTime>endTime){
|
|
2
|
+
throw CliErrors.validation("--start-time must be less than or equal to --end-time.")}const limit=readPositiveInteger(ctx.num("limit",DEFAULT_LIMIT),"--limit");if(limit>MAX_LIMIT){throw CliErrors.validation(`--limit must be between 1 and ${MAX_LIMIT}.`)}const level=ctx.str("level").trim().toUpperCase()||undefined;const keyword=ctx.str("keyword").trim()||undefined;return{appCode:ctx.appCode,startTime:startTime,endTime:endTime,...rawStartTime===undefined?{sinceMinutes:readSinceMinutes(ctx)}:{},...level?{level:level}:{},...keyword?{keyword:keyword}:{},limit:limit}}function readSinceMinutes(ctx){return readPositiveInteger(ctx.num("since",DEFAULT_SINCE_MINUTES),"--since")}function readPositiveInteger(value,flag){if(!Number.isSafeInteger(value)||value<=0){throw CliErrors.validation(`${flag} must be a positive integer.`)}return value}export const bffLogs={service:"bff",command:"logs",description:"Query recent Backend Function runtime logs for development debugging",risk:"read",
|
|
3
|
+
structuredErrors:true,flags:[APPCODE_FLAG_OPTIONAL,{name:"since",type:"number",description:`Minutes before the end time to query (default: ${DEFAULT_SINCE_MINUTES})`},{name:"start-time",type:"number",description:"Query start time as a Unix timestamp in milliseconds"},{name:"end-time",type:"number",description:"Query end time as a Unix timestamp in milliseconds (default: now)"},{name:"level",type:"string",description:"Filter by log level",enum:LOG_LEVELS},{name:"keyword",type:"string",description:"Filter formatted log lines by keyword"},{name:"limit",type:"number",description:`Maximum log lines to return (1-${MAX_LIMIT})`,default:DEFAULT_LIMIT}],async validate(ctx){resolveBffLogQuery(ctx)},async execute(ctx){const query=resolveBffLogQuery(ctx);const{sinceMinutes:_sinceMinutes,...apiQuery}=query;const logs=await searchBffScriptLogs(apiQuery);return{ok:true,data:{query:query,count:logs.length,logs:logs},
|
|
4
|
+
message:logs.length===0?"No Backend Function logs found for the selected range.":`Found ${logs.length} Backend Function log line(s).`}}};
|
package/lib/commands/bff/pull.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
const a43_0x15d1eb=a43_0x25d6;(function(_0x4a6172,_0x4efe1c){const _0xbc6226=a43_0x25d6,_0x6b1862=_0x4a6172();while(!![]){try{const _0x1fb7cd=-parseInt(_0xbc6226(0x8c))/0x1+parseInt(_0xbc6226(0xa4))/0x2+parseInt(_0xbc6226(0xbf))/0x3+-parseInt(_0xbc6226(0x96))/0x4*(parseInt(_0xbc6226(0xc4))/0x5)+-parseInt(_0xbc6226(0x8a))/0x6+parseInt(_0xbc6226(0x108))/0x7*(-parseInt(_0xbc6226(0xb5))/0x8)+parseInt(_0xbc6226(0xdc))/0x9;if(_0x1fb7cd===_0x4efe1c)break;else _0x6b1862['push'](_0x6b1862['shift']());}catch(_0x2994d0){_0x6b1862['push'](_0x6b1862['shift']());}}}(a43_0x3b53,0xd6e45));import{createInterface}from'node:readline';import{readFile,rename,stat,unlink,writeFile}from'node:fs/promises';import{randomUUID}from'node:crypto';function a43_0x3b53(){const _0x56a01b=['conflict','\x22\x20from\x20the\x20lock\x20file.','/api/management/library/scripts/list?appCode=','Force\x20overwrite\x20local\x20unsynced\x20changes','Remote\x20script\x20missing\x20id.','set','mergedCli','Lock\x20scope\x20for\x20app\x20\x22','Pull\x20remote\x20Backend\x20Function\x20scripts\x20to\x20local','2639232UyLTvQ','string','801516FtwhMl','newLockKey','require','toLowerCase','rollback','¤tPage=1&pageSize=','lockFilePath','Could\x20not\x20restore\x20local\x20script\x20\x22','Failed\x20to\x20write\x20the\x20Backend\x20Function\x20lock\x20file;\x20local\x20changes\x20could\x20not\x20be\x20completely\x20rolled\x20back.','oldDirectoryPath','1316FEHNzE','Could\x20not\x20restore\x20temporary\x20HOOK\x20directory\x20\x22','\x20skipped','scriptsRoot','cancelled','oldLockKey','utf8','content','HOOK/','oldDirectory','.hook-directory-migrate-','map','Failed\x20to\x20rename\x20HOOK\x20directory\x20\x22','functionNode','2505890FYpkIT','write','lastSync','\x22:\x20','validation','unresolvable\x20target\x20path','currentApp','hash','Force\x20pull\x20will\x20overwrite\x20local\x20unsynced\x20changes.\x20Continue?\x20[y/N]\x20','\x20remote\x20Backend\x20Function\x20script(s)\x20for\x20pull','\x22\x20from\x20\x22','hookLocation','newDirectory','existed','HOOK','defaultApp','all','24aWKWPG','filter','\x20pulled','Pull\x20complete:\x20','split','stdin','Remote\x20script\x20missing\x20content.','\x20--format\x20compress','sourceFilePathByNewLockKey','entry','1400544JTccrQ','code','Could\x20not\x20restore\x20HOOK\x20directory\x20\x22','\x22:\x20it\x20is\x20now\x20another\x20Dataset\x20alias\x20and\x20contains\x20untracked\x20scripts.\x20Resolve\x20the\x20directory\x20manually\x20before\x20retrying.','\x22:\x20its\x20target\x20directory\x20is\x20unsafe.','18185vPZgKN','join','requires','NFC','mode','bool','bff','rekey','remoteId','\x22\x20may\x20remain.','pull','functions','toISOString','COMMON','appCode','\x22\x20is\x20another\x20legacy\x20key\x20being\x20migrated.\x20Resolve\x20the\x20lock\x20entries\x20manually\x20before\x20retrying.','newDirectoryPath','has','ino','push_local','keyChanges','move','close','ENDPOINT','26664372PquotQ','alias','\x22:\x20its\x20target\x20\x22','Cannot\x20migrate\x20unsafe\x20HOOK\x20directory\x20\x22','get','reverse','\x22\x20and\x20\x22','&type=','message','\x22\x20to\x20\x22','apiDir','Failed\x20to\x20write\x20local\x20script\x20\x22','\x22:\x20the\x20target\x20directory\x20already\x20exists.\x20Resolve\x20the\x20directories\x20and\x20retry.','length','\x20failed','sourceDirectoryPathByNewDirectory','question','functionName','\x20resolution','GET','\x20conflict','datasetCode','projectedFunctions','delete','If\x20the\x20reviewed\x20local\x20script\x20should\x20win,\x20run\x20this\x20command\x20to\x20update\x20the\x20remote\x20script.\x20Do\x20not\x20use\x20--force\x20to\x20resolve\x20a\x20content\x20conflict.','Would\x20inspect\x20','filePath','No\x20remote\x20Backend\x20Function\x20scripts\x20found.','operationType','stringify','scriptsRootDir','push','entries','yes','ENOENT','Cannot\x20migrate\x20HOOK\x20directory\x20\x22','--type\x20must\x20be\x20COMMON,\x20ENDPOINT,\x20or\x20HOOK.','some','read','type','nonInteractive','force','\x20bff\x20push\x20--type\x20','includes','3183467AsyJii','flatMap','scriptType','\x22\x20not\x20found\x20after\x20ensureLockScope.','lockKey','\x22.\x20Resolve\x20the\x20lock\x20entries\x20manually\x20before\x20retrying.','parse','selectedAppName','migrations','str','\x22:\x20both\x20target\x20\x22','scriptContent','case-rename','Failed\x20to\x20migrate\x20HOOK\x20directories;\x20local\x20changes\x20could\x20not\x20be\x20completely\x20rolled\x20back.','Cannot\x20migrate\x20unsafe\x20HOOK\x20lock\x20key\x20\x22','stderr','apps','Cannot\x20migrate\x20HOOK\x20directories\x20\x22','would_pull','\x22:\x20target\x20lock\x20key\x20is\x20already\x20bound\x20to\x20another\x20script.','dev'];a43_0x3b53=function(){return _0x56a01b;};return a43_0x3b53();}import{dirname,join}from'node:path';import{BFF_LIST_PAGE_SIZE,listBffScripts,getBffScriptStatistics}from'../../core/api-client.js';import{loadAliasMap}from'../../core/alias-resolver.js';import{resolveApiModelSource}from'../../api/model-source.js';import{loadBffProjectConfig}from'../../core/bff/config.js';import{createHookLocationMap,directoryExists,ensureParentDirectory,fileExists,isSafeLockKeySegment,normalizeBffType,resolveLocalFilePathFromLockKey,resolveRemoteScriptTarget,scanLocalBffFunctions}from'../../core/bff/file-system.js';import{computeContentHash,computeFileHash}from'../../core/bff/hash.js';import{assertUnambiguousHookAliases}from'../../core/bff/hook-directory.js';import{createEmptyBffLock,ensureLockScope,readBffLockFile,writeBffLockFile}from'../../core/bff/lock.js';import{CliErrors}from'../../errors.js';function a43_0x25d6(_0x4de7f8,_0x13a8d0){_0x4de7f8=_0x4de7f8-0x83;const _0x3b53f2=a43_0x3b53();let _0x25d63e=_0x3b53f2[_0x4de7f8];return _0x25d63e;}import{CLI_BIN_NAME}from'../../constant/cli.js';export const bffPull={'service':a43_0x15d1eb(0xca),'command':a43_0x15d1eb(0xce),'description':a43_0x15d1eb(0x89),'risk':a43_0x15d1eb(0x102),'structuredErrors':!![],'flags':[{'name':a43_0x15d1eb(0x103),'type':a43_0x15d1eb(0x8b),'description':'Pull\x20only\x20this\x20script\x20type','enum':[a43_0x15d1eb(0xd1),a43_0x15d1eb(0xdb),a43_0x15d1eb(0xb2)]},{'name':'force','type':'boolean','description':a43_0x15d1eb(0x84)}],async 'dryRun'(_0x4815f8){const _0x7dc967=a43_0x15d1eb,_0x4d6a85=loadBffProjectConfig(_0x4815f8['appCode']),_0x34138e=await readBffLockFile(_0x4d6a85[_0x7dc967(0x92)]),{appLock:_0x242ec1}=ensureLockScope(_0x34138e??createEmptyBffLock(),_0x4815f8[_0x7dc967(0xd2)],_0x4d6a85[_0x7dc967(0x99)],_0x7dc967(0xce)),_0x1ed462=normalizeBffType(_0x4815f8[_0x7dc967(0x111)](_0x7dc967(0x103)))??undefined,[_0x5259c2,_0x378421]=await Promise[_0x7dc967(0xb4)]([listBffScripts(_0x4815f8[_0x7dc967(0xd2)],_0x1ed462),getBffScriptStatistics(_0x4815f8[_0x7dc967(0xd2)])]),_0xd3e1ec=_0x5259c2[_0x7dc967(0x101)](_0x2bb431=>normalizeBffType(_0x2bb431[_0x7dc967(0x10a)])===_0x7dc967(0xb2)),_0x22b051=_0xd3e1ec?buildDatasetCodeToAliasMap(_0x4815f8[_0x7dc967(0xe6)],_0x4815f8['appCode'],_0x4815f8[_0x7dc967(0x10f)]||_0x4815f8['mergedCli']?.[_0x7dc967(0xaa)]||_0x4815f8['mergedCli']?.[_0x7dc967(0xb3)]):new Map(),_0x1ad380=_0xd3e1ec?await planHookDirectoryMigration(_0x4d6a85,_0x242ec1,_0x22b051,await scanLocalBffFunctions(_0x4d6a85,'HOOK')):undefined,_0x1bb6fb=createHookLocationMap(_0x378421),_0x59db8e=[];for(const _0x24fcfd of _0x5259c2){const _0x5df754=resolveRemoteScriptTarget(_0x4d6a85,_0x24fcfd,_0x1bb6fb,_0x1ad380?.[_0x7dc967(0xf2)]??_0x242ec1[_0x7dc967(0xcf)],_0x22b051);if(!_0x5df754){_0x59db8e['push']({'scriptType':_0x24fcfd[_0x7dc967(0x10a)],'functionName':_0x24fcfd['functionName']??'','status':'skipped','reason':'unresolvable\x20target\x20path'});continue;}const _0x5ee64f=(_0x1ad380?.[_0x7dc967(0xf2)]??_0x242ec1[_0x7dc967(0xcf)])[_0x5df754['lockKey']],_0x50757a=_0x24fcfd['scriptContent']!=null?computeContentHash(_0x24fcfd[_0x7dc967(0x113)]):undefined,_0xd71a17=await hasUnsyncedLocalChanges(resolveMigratedSourceFilePath(_0x1ad380,_0x5df754)??_0x5df754[_0x7dc967(0xf6)],_0x5ee64f,_0x50757a),_0x44eee5=_0xd71a17?localUnsyncedConflict(_0x5df754,_0x24fcfd['id']):undefined;_0x59db8e[_0x7dc967(0xfb)]({'lockKey':_0x5df754[_0x7dc967(0x10c)],'filePath':_0x5df754[_0x7dc967(0xf6)],'remoteId':_0x24fcfd['id']??null,'status':_0x44eee5?_0x7dc967(0x11d):_0x7dc967(0x11a),..._0x44eee5?{'conflict':_0x44eee5}:{},..._0x5df754['hookLocation']?{'alias':_0x5df754[_0x7dc967(0xaf)][_0x7dc967(0xdd)]??null,'datasetCode':_0x5df754[_0x7dc967(0xaf)]['datasetCode'],'operationType':_0x5df754[_0x7dc967(0xaf)][_0x7dc967(0xf8)],'functionNode':_0x5df754[_0x7dc967(0xaf)][_0x7dc967(0xa3)]}:{}});}return{'method':_0x7dc967(0xef),'url':_0x7dc967(0x83)+_0x4815f8[_0x7dc967(0xd2)]+(_0x1ed462?_0x7dc967(0xe3)+_0x1ed462:'')+_0x7dc967(0x91)+BFF_LIST_PAGE_SIZE,'body':{'appCode':_0x4815f8[_0x7dc967(0xd2)],'filterType':_0x1ed462??null,..._0x1ad380&&_0x1ad380[_0x7dc967(0x110)][_0x7dc967(0xe9)]>0x0?{'hookDirectoryMigrations':_0x1ad380[_0x7dc967(0x110)][_0x7dc967(0xa1)](_0x5c361f=>({'from':_0x5c361f[_0x7dc967(0x9f)],'to':_0x5c361f[_0x7dc967(0xb0)]}))}:{},'files':_0x59db8e},'description':_0x7dc967(0xf5)+_0x59db8e[_0x7dc967(0xe9)]+_0x7dc967(0xad)};},async 'execute'(_0x4b65b7){const _0x45296e=a43_0x15d1eb,_0x1145b6=loadBffProjectConfig(_0x4b65b7[_0x45296e(0xd2)]),_0x390a44=await readBffLockFile(_0x1145b6[_0x45296e(0x92)]),{lockData:_0x38f8c3,appLock:_0x2d7676}=ensureLockScope(_0x390a44??createEmptyBffLock(),_0x4b65b7[_0x45296e(0xd2)],_0x1145b6['scriptsRoot'],_0x45296e(0xce)),_0x532f5d=normalizeBffType(_0x4b65b7[_0x45296e(0x111)](_0x45296e(0x103)))??undefined;if(_0x4b65b7[_0x45296e(0x111)](_0x45296e(0x103))&&!_0x532f5d)throw CliErrors[_0x45296e(0xa8)](_0x45296e(0x100));const [_0x1b5925,_0x245ba6]=await Promise['all']([listBffScripts(_0x4b65b7['appCode'],_0x532f5d),getBffScriptStatistics(_0x4b65b7['appCode'])]);if(_0x1b5925[_0x45296e(0xe9)]===0x0)return{'ok':!![],'data':{'pulled':[],'skipped':[],'conflicts':[],'failed':[]},'message':_0x45296e(0xf7)};const _0x1bf238=_0x4b65b7[_0x45296e(0xc9)](_0x45296e(0x105));if(_0x1bf238&&!_0x4b65b7[_0x45296e(0x104)]){const _0x12241b=await confirmForce();if(!_0x12241b)throw CliErrors[_0x45296e(0x9a)]('Force\x20pull\x20cancelled.');}if(_0x1bf238&&_0x4b65b7[_0x45296e(0x104)]){}const _0x4489e1=_0x1b5925[_0x45296e(0x101)](_0xa14946=>normalizeBffType(_0xa14946[_0x45296e(0x10a)])===_0x45296e(0xb2)),_0x20cedd=_0x4489e1?buildDatasetCodeToAliasMap(_0x4b65b7[_0x45296e(0xe6)],_0x4b65b7[_0x45296e(0xd2)],_0x4b65b7['selectedAppName']||_0x4b65b7[_0x45296e(0x87)]?.['currentApp']||_0x4b65b7[_0x45296e(0x87)]?.[_0x45296e(0xb3)]):new Map(),_0x3f31cc=createHookLocationMap(_0x245ba6),_0x2ec079=JSON[_0x45296e(0x10e)](JSON[_0x45296e(0xf9)](_0x38f8c3)),_0x1d4b25=_0x4b65b7['appCode'],_0x5129fc=_0x2ec079[_0x45296e(0x118)][_0x1d4b25];if(!_0x5129fc)throw new Error(_0x45296e(0x88)+_0x1d4b25+_0x45296e(0x10b));const _0x5e8b69=_0x4489e1?await applyHookDirectoryMigration(await planHookDirectoryMigration(_0x1145b6,_0x5129fc,_0x20cedd,await scanLocalBffFunctions(_0x1145b6,_0x45296e(0xb2))),_0x5129fc):undefined,_0x4890c3=createPullFileTransaction(),_0x45d29b=[],_0x354e2b=[],_0x3491c9=[],_0x453173=[];for(const _0x1ce597 of _0x1b5925){const _0x4fc4b6=resolveRemoteScriptTarget(_0x1145b6,_0x1ce597,_0x3f31cc,_0x5129fc['functions'],_0x20cedd);if(!_0x4fc4b6){_0x354e2b['push']({'lockKey':_0x1ce597[_0x45296e(0x10a)]+'/'+_0x1ce597[_0x45296e(0xed)],'reason':_0x45296e(0xa9)});continue;}const _0x54ce6a=_0x5129fc[_0x45296e(0xcf)][_0x4fc4b6[_0x45296e(0x10c)]];try{if(!_0x1ce597['id'])throw new Error(_0x45296e(0x85));if(_0x1ce597[_0x45296e(0x113)]==null)throw new Error(_0x45296e(0xbb));const _0x25d083=_0x1ce597[_0x45296e(0x113)],_0x3689f7=computeContentHash(_0x25d083);if(!_0x1bf238){const _0x5135aa=await hasUnsyncedLocalChanges(_0x4fc4b6[_0x45296e(0xf6)],_0x54ce6a,_0x3689f7);if(_0x5135aa){_0x3491c9['push'](localUnsyncedConflict(_0x4fc4b6,_0x1ce597['id']));continue;}}await _0x4890c3[_0x45296e(0xa5)](_0x4fc4b6[_0x45296e(0xf6)],_0x25d083);const _0x586d95={'hash':_0x3689f7,'remoteId':_0x1ce597['id'],'version':_0x1ce597['version']};_0x4fc4b6[_0x45296e(0x103)]==='HOOK'&&_0x4fc4b6[_0x45296e(0xaf)]&&(_0x586d95[_0x45296e(0xdd)]=_0x4fc4b6[_0x45296e(0xaf)]['alias'],_0x586d95[_0x45296e(0xf1)]=_0x4fc4b6[_0x45296e(0xaf)][_0x45296e(0xf1)],_0x586d95['operationType']=_0x4fc4b6[_0x45296e(0xaf)][_0x45296e(0xf8)],_0x586d95[_0x45296e(0xa3)]=_0x4fc4b6[_0x45296e(0xaf)][_0x45296e(0xa3)]),_0x5129fc[_0x45296e(0xcf)][_0x4fc4b6['lockKey']]=_0x586d95,_0x45d29b['push']({'lockKey':_0x4fc4b6[_0x45296e(0x10c)],'remoteId':_0x1ce597['id']});}catch(_0x2d971e){_0x453173[_0x45296e(0xfb)]({'lockKey':_0x4fc4b6[_0x45296e(0x10c)],'error':_0x2d971e instanceof Error?_0x2d971e[_0x45296e(0xe4)]:String(_0x2d971e)});}}_0x5129fc['lastSync']=new Date()[_0x45296e(0xd0)]();try{await writeBffLockFile(_0x1145b6[_0x45296e(0x92)],_0x2ec079);}catch(_0x53bee8){const _0x2a04a9=[...await _0x4890c3[_0x45296e(0x90)](),...await _0x5e8b69?.['rollback']()??[]];throw withRollbackErrors(_0x53bee8,_0x45296e(0x94),_0x2a04a9);}return{'ok':_0x453173[_0x45296e(0xe9)]===0x0,'data':{'pulled':_0x45d29b,'skipped':_0x354e2b,'conflicts':_0x3491c9,'failed':_0x453173},'message':formatPullMessage(_0x45d29b[_0x45296e(0xe9)],_0x354e2b[_0x45296e(0xe9)],_0x3491c9[_0x45296e(0xe9)],_0x453173['length'])};}};function localUnsyncedConflict(_0x1e5792,_0x1bf1d2){const _0xf54cc0=a43_0x15d1eb,_0x1aaae5=_0x1e5792['lockKey'][_0xf54cc0(0xb9)]('/')['at'](-0x1);return{'code':'BFF_LOCAL_UNSYNCED','lockKey':_0x1e5792[_0xf54cc0(0x10c)],'filePath':_0x1e5792[_0xf54cc0(0xf6)],..._0x1bf1d2!=null?{'remoteId':_0x1bf1d2}:{},'message':'Local\x20script\x20differs\x20from\x20the\x20last\x20pulled\x20version.\x20Review\x20it\x20before\x20choosing\x20the\x20source\x20of\x20truth.','nextAction':{'action':_0xf54cc0(0xd7),'command':CLI_BIN_NAME+_0xf54cc0(0x106)+_0x1e5792[_0xf54cc0(0x103)]+'\x20--name\x20'+_0x1aaae5+_0xf54cc0(0xbc),'requiresReview':!![],'message':_0xf54cc0(0xf4)}};}function formatPullMessage(_0x37c4e6,_0x37ab82,_0x27734b,_0x1e37f){const _0xdeaf7=a43_0x15d1eb,_0x24dc8a=[_0xdeaf7(0xb8)+_0x37c4e6+_0xdeaf7(0xb7),_0x37ab82+_0xdeaf7(0x98)];_0x27734b>0x0&&_0x24dc8a['push'](_0x27734b+_0xdeaf7(0xf0)+(_0x27734b===0x1?'':'s')+'\x20'+(_0x27734b===0x1?_0xdeaf7(0xc6):_0xdeaf7(0x8e))+_0xdeaf7(0xee));if(_0x1e37f>0x0)_0x24dc8a['push'](_0x1e37f+_0xdeaf7(0xea));return _0x24dc8a[_0xdeaf7(0xc5)](',\x20');}async function hasUnsyncedLocalChanges(_0x2db74f,_0x2f9336,_0x4f0332){const _0x13f946=a43_0x15d1eb;if(!await fileExists(_0x2db74f))return![];const _0x529b15=await computeFileHash(_0x2db74f);if(!_0x2f9336)return _0x4f0332?_0x529b15!==_0x4f0332:!![];return _0x529b15!==_0x2f9336[_0x13f946(0xab)];}function createPullFileTransaction(){const _0x2ceb3e=new Map(),_0x2a4bae=async(_0x16d4d0,_0x173689)=>{const _0x3164e9=a43_0x25d6;try{if(_0x173689[_0x3164e9(0xb1)])await ensureParentDirectory(_0x16d4d0),await writeFile(_0x16d4d0,_0x173689[_0x3164e9(0x9d)]);else try{await unlink(_0x16d4d0);}catch(_0x4cceb6){if(_0x4cceb6[_0x3164e9(0xc0)]!==_0x3164e9(0xfe))throw _0x4cceb6;}return undefined;}catch(_0x206b13){return _0x206b13 instanceof Error?_0x206b13:new Error(String(_0x206b13));}};return{async 'write'(_0x1afddb,_0xfa4d14){const _0x47d790=a43_0x25d6;if(!_0x2ceb3e[_0x47d790(0xd5)](_0x1afddb))try{_0x2ceb3e[_0x47d790(0x86)](_0x1afddb,{'existed':!![],'content':await readFile(_0x1afddb)});}catch(_0x2366c7){if(_0x2366c7[_0x47d790(0xc0)]!==_0x47d790(0xfe))throw _0x2366c7;_0x2ceb3e[_0x47d790(0x86)](_0x1afddb,{'existed':![]});}try{await ensureParentDirectory(_0x1afddb),await writeFile(_0x1afddb,_0xfa4d14,_0x47d790(0x9c));}catch(_0x41e99f){const _0x4e02ce=await _0x2a4bae(_0x1afddb,_0x2ceb3e['get'](_0x1afddb));if(!_0x4e02ce)_0x2ceb3e[_0x47d790(0xf3)](_0x1afddb);throw withRollbackErrors(_0x41e99f,_0x47d790(0xe7)+_0x1afddb+'\x22.',_0x4e02ce?[_0x4e02ce]:[]);}},async 'rollback'(){const _0x324338=a43_0x25d6,_0x14f72f=[];for(const [_0x18f4cb,_0x4c2e7b]of[..._0x2ceb3e['entries']()]['reverse']()){const _0x4f4dce=await _0x2a4bae(_0x18f4cb,_0x4c2e7b);_0x4f4dce&&_0x14f72f['push'](new Error(_0x324338(0x93)+_0x18f4cb+'\x22:\x20'+_0x4f4dce[_0x324338(0xe4)]));}return _0x14f72f;}};}function withRollbackErrors(_0x125139,_0x2e3d2a,_0x576586){const _0x3fdbe1=a43_0x15d1eb,_0x154380=_0x125139 instanceof Error?_0x125139:new Error(String(_0x125139));if(_0x576586[_0x3fdbe1(0xe9)]===0x0)return _0x154380;return new AggregateError([_0x154380,..._0x576586],_0x2e3d2a+'\x20Recovery\x20errors:\x20'+_0x576586[_0x3fdbe1(0xa1)](_0x3c991b=>_0x3c991b[_0x3fdbe1(0xe4)])[_0x3fdbe1(0xc5)](';\x20'));}function buildDatasetCodeToAliasMap(_0x4f97a2,_0x38a4ef,_0xbff0aa){const _0x3e49d5=a43_0x15d1eb,_0x32122c=resolveApiModelSource(_0x4f97a2,_0x38a4ef,_0xbff0aa),_0x10c2ff=loadAliasMap(_0x4f97a2,undefined,_0x32122c[_0x3e49d5(0xf6)],_0x32122c['profileName']);return assertUnambiguousHookAliases(_0x10c2ff),new Map(_0x10c2ff['map'](_0x44312e=>[_0x44312e[_0x3e49d5(0xf1)][_0x3e49d5(0x8f)](),_0x44312e['alias']]));}async function planHookDirectoryMigration(_0x1b69fe,_0x3f84fe,_0x5f1e18,_0x43922f){const _0x10c65f=a43_0x15d1eb,_0x5d2a21=new Map();for(const [_0x448621,_0x3b9494]of Object[_0x10c65f(0xfc)](_0x3f84fe['functions'])){const [_0x41c108,_0x18279a,_0x2b3be0,_0x456248,_0x59a011,..._0xbace85]=_0x448621[_0x10c65f(0xb9)]('/');if(_0x41c108!==_0x10c65f(0xb2)||!_0x18279a||!_0x2b3be0||!_0x456248||!_0x59a011||_0xbace85['length']>0x0||!_0x3b9494[_0x10c65f(0xf1)])continue;const _0x4c0277=_0x5f1e18[_0x10c65f(0xe0)](_0x3b9494['datasetCode'][_0x10c65f(0x8f)]()),_0xd81679=_0x4c0277??_0x3b9494[_0x10c65f(0xf1)];if(!isSafeHookDirectorySegment(_0x18279a))throw CliErrors[_0x10c65f(0xa8)](_0x10c65f(0xdf)+_0x18279a+_0x10c65f(0x11e));if(!isSafeHookDirectorySegment(_0xd81679))throw CliErrors[_0x10c65f(0xa8)](_0x10c65f(0xff)+_0x18279a+_0x10c65f(0xc3));if(_0x18279a===_0xd81679)continue;const _0x15343b=_0x5d2a21[_0x10c65f(0xe0)](_0x18279a)??{'datasetCode':_0x3b9494[_0x10c65f(0xf1)],'alias':_0x4c0277,'keyChanges':[]};if(_0x15343b['datasetCode']!==_0x3b9494[_0x10c65f(0xf1)])throw CliErrors[_0x10c65f(0xa8)](_0x10c65f(0xff)+_0x18279a+'\x22:\x20it\x20is\x20tracked\x20by\x20multiple\x20Datasets.');const _0x1cf846=_0x10c65f(0x9e)+_0xd81679+'/'+_0x2b3be0+'/'+_0x456248+'/'+_0x59a011;try{resolveLocalFilePathFromLockKey(_0x1b69fe,_0x448621),resolveLocalFilePathFromLockKey(_0x1b69fe,_0x1cf846);}catch(_0x2add80){throw CliErrors['validation'](_0x10c65f(0x116)+_0x448621+_0x10c65f(0xa7)+(_0x2add80 instanceof Error?_0x2add80['message']:String(_0x2add80)));}_0x15343b['keyChanges'][_0x10c65f(0xfb)]({'oldLockKey':_0x448621,'newLockKey':_0x1cf846,'entry':_0x3b9494}),_0x5d2a21['set'](_0x18279a,_0x15343b);}const _0x2402fb=new Set([..._0x5d2a21['values']()][_0x10c65f(0x109)](_0x3fbf31=>_0x3fbf31['keyChanges'][_0x10c65f(0xa1)](_0x198062=>_0x198062['oldLockKey']))),_0x539f59=new Map(),_0x47ea51=new Map();for(const [_0x1d1bdd,_0x4b43fe]of _0x5d2a21){const _0x5dfa04=_0x4b43fe[_0x10c65f(0xdd)]??_0x4b43fe[_0x10c65f(0xf1)],_0x21a734=hookDirectoryIdentity(_0x5dfa04),_0x3b5f6a=_0x539f59['get'](_0x21a734);if(_0x3b5f6a&&_0x3b5f6a!==_0x1d1bdd)throw CliErrors[_0x10c65f(0xa8)](_0x10c65f(0x119)+_0x3b5f6a+'\x22\x20and\x20\x22'+_0x1d1bdd+_0x10c65f(0x112)+_0x5dfa04+'\x22.\x20Resolve\x20the\x20directories\x20manually\x20before\x20retrying.');_0x539f59[_0x10c65f(0x86)](_0x21a734,_0x1d1bdd);for(const _0x43c3d1 of _0x4b43fe[_0x10c65f(0xd8)]){const _0x56c44b=_0x47ea51[_0x10c65f(0xe0)](_0x43c3d1[_0x10c65f(0x8d)]);if(_0x56c44b&&_0x56c44b!==_0x43c3d1[_0x10c65f(0x9b)])throw CliErrors[_0x10c65f(0xa8)]('Cannot\x20migrate\x20HOOK\x20lock\x20keys\x20\x22'+_0x56c44b+_0x10c65f(0xe2)+_0x43c3d1['oldLockKey']+_0x10c65f(0x112)+_0x43c3d1['newLockKey']+_0x10c65f(0x10d));if(_0x2402fb[_0x10c65f(0xd5)](_0x43c3d1['newLockKey']))throw CliErrors[_0x10c65f(0xa8)]('Cannot\x20migrate\x20HOOK\x20lock\x20key\x20\x22'+_0x43c3d1['oldLockKey']+_0x10c65f(0xde)+_0x43c3d1[_0x10c65f(0x8d)]+_0x10c65f(0xd3));_0x47ea51[_0x10c65f(0x86)](_0x43c3d1[_0x10c65f(0x8d)],_0x43c3d1[_0x10c65f(0x9b)]);}}const _0x2b24b4=new Map();for(const [_0x397a2f,_0x13b3b6]of _0x5f1e18){_0x2b24b4[_0x10c65f(0x86)](hookDirectoryIdentity(_0x13b3b6),_0x397a2f);}const _0x8333b0=[];for(const [_0x785ae8,_0x399b5e]of _0x5d2a21){const _0x544427=_0x399b5e['alias']??_0x399b5e[_0x10c65f(0xf1)],_0x14cd6f=join(_0x1b69fe[_0x10c65f(0xfa)],_0x10c65f(0xb2),_0x785ae8),_0x26e670=join(_0x1b69fe[_0x10c65f(0xfa)],_0x10c65f(0xb2),_0x544427),_0x1e3e87=await directoryExists(_0x14cd6f),_0x44fb5f=await directoryExists(_0x26e670),_0x591405=_0x1e3e87?_0x44fb5f?await sameDirectory(_0x14cd6f,_0x26e670)?'case-rename':undefined:_0x10c65f(0xd9):_0x10c65f(0xcb);if(!_0x591405)throw CliErrors[_0x10c65f(0xa8)]('Cannot\x20migrate\x20HOOK\x20directory\x20\x22'+_0x785ae8+_0x10c65f(0xe5)+_0x544427+_0x10c65f(0xe8));const _0x290672=_0x2b24b4['get'](hookDirectoryIdentity(_0x785ae8));if(_0x290672&&_0x290672!==_0x399b5e[_0x10c65f(0xf1)][_0x10c65f(0x8f)]()){const _0x2427f6=new Set(_0x399b5e['keyChanges'][_0x10c65f(0xa1)](_0x15b899=>_0x15b899[_0x10c65f(0x9b)])),_0x40ffe3=_0x43922f[_0x10c65f(0xb6)](_0x4e578c=>_0x4e578c[_0x10c65f(0x103)]===_0x10c65f(0xb2)&&_0x4e578c[_0x10c65f(0xdd)]!=null&&hookDirectoryIdentity(_0x4e578c[_0x10c65f(0xdd)])===hookDirectoryIdentity(_0x785ae8)&&!_0x2427f6[_0x10c65f(0xd5)](_0x4e578c[_0x10c65f(0x10c)]));if(_0x40ffe3[_0x10c65f(0xe9)]>0x0)throw CliErrors[_0x10c65f(0xa8)](_0x10c65f(0xff)+_0x785ae8+_0x10c65f(0xc2));}const _0x43bee7=_0x2b24b4[_0x10c65f(0xe0)](hookDirectoryIdentity(_0x544427));if(_0x43bee7&&_0x43bee7!==_0x399b5e[_0x10c65f(0xf1)][_0x10c65f(0x8f)]())throw CliErrors['validation'](_0x10c65f(0xff)+_0x785ae8+'\x22\x20to\x20\x22'+_0x544427+'\x22:\x20the\x20destination\x20is\x20another\x20Dataset\x20alias.\x20Resolve\x20the\x20directory\x20manually\x20before\x20retrying.');for(const _0x214ac5 of _0x399b5e['keyChanges']){const _0x37acda=_0x3f84fe[_0x10c65f(0xcf)][_0x214ac5[_0x10c65f(0x8d)]];if(_0x37acda&&!_0x2402fb[_0x10c65f(0xd5)](_0x214ac5[_0x10c65f(0x8d)])&&!sameHookIdentity(_0x214ac5[_0x10c65f(0xbe)],_0x37acda))throw CliErrors[_0x10c65f(0xa8)]('Cannot\x20migrate\x20HOOK\x20directory\x20\x22'+_0x785ae8+_0x10c65f(0xe5)+_0x544427+_0x10c65f(0x11b));}_0x8333b0['push']({'oldDirectory':_0x785ae8,'newDirectory':_0x544427,'oldDirectoryPath':_0x14cd6f,'newDirectoryPath':_0x26e670,'mode':_0x591405,'alias':_0x399b5e['alias'],'keyChanges':_0x399b5e[_0x10c65f(0xd8)]});}const _0x22bcca={..._0x3f84fe[_0x10c65f(0xcf)]},_0x56b970=new Map(),_0x49b451=new Map();for(const _0x4dc171 of _0x8333b0){const _0x2f93e5=_0x4dc171[_0x10c65f(0xc8)]!==_0x10c65f(0xcb);_0x2f93e5&&_0x49b451['set'](hookDirectoryIdentity(_0x4dc171[_0x10c65f(0xb0)]),_0x4dc171[_0x10c65f(0x95)]);for(const _0x55d754 of _0x4dc171[_0x10c65f(0xd8)]){const _0x33bf67=_0x22bcca[_0x55d754[_0x10c65f(0x8d)]],_0x4a2971=_0x2f93e5?_0x55d754[_0x10c65f(0xbe)]:_0x33bf67??_0x55d754[_0x10c65f(0xbe)];_0x22bcca[_0x55d754[_0x10c65f(0x8d)]]=canonicalizeHookEntry(_0x4a2971,_0x4dc171[_0x10c65f(0xdd)]),delete _0x22bcca[_0x55d754[_0x10c65f(0x9b)]],_0x2f93e5&&_0x56b970[_0x10c65f(0x86)](_0x55d754['newLockKey'],resolveLocalFilePathFromLockKey(_0x1b69fe,_0x55d754[_0x10c65f(0x9b)]));}}return{'migrations':_0x8333b0,'projectedFunctions':_0x22bcca,'sourceFilePathByNewLockKey':_0x56b970,'sourceDirectoryPathByNewDirectory':_0x49b451};}function resolveMigratedSourceFilePath(_0x5646c6,_0x50e8d6){const _0x44f365=a43_0x15d1eb;if(!_0x5646c6||!_0x50e8d6)return undefined;const _0x129789=_0x5646c6[_0x44f365(0xbd)][_0x44f365(0xe0)](_0x50e8d6[_0x44f365(0x10c)]);if(_0x129789)return _0x129789;if(_0x50e8d6[_0x44f365(0x103)]!==_0x44f365(0xb2))return undefined;const [,_0x55536b,..._0x258241]=_0x50e8d6[_0x44f365(0x10c)][_0x44f365(0xb9)]('/');if(!_0x55536b||_0x258241['length']===0x0)return undefined;const _0x15d452=_0x5646c6[_0x44f365(0xeb)][_0x44f365(0xe0)](hookDirectoryIdentity(_0x55536b));return _0x15d452?join(_0x15d452,..._0x258241)+'.js':undefined;}function sameHookIdentity(_0xd33040,_0x1bba77){const _0x2b4f6d=a43_0x15d1eb;return _0xd33040[_0x2b4f6d(0xcc)]===_0x1bba77[_0x2b4f6d(0xcc)]&&_0xd33040[_0x2b4f6d(0xf1)]===_0x1bba77[_0x2b4f6d(0xf1)]&&_0xd33040[_0x2b4f6d(0xf8)]===_0x1bba77[_0x2b4f6d(0xf8)]&&_0xd33040[_0x2b4f6d(0xa3)]===_0x1bba77[_0x2b4f6d(0xa3)];}function canonicalizeHookEntry(_0x5b475e,_0xea0700){const {alias:_0x44d77f,..._0x25ebac}=_0x5b475e;return _0xea0700?{..._0x25ebac,'alias':_0xea0700}:_0x25ebac;}function hookDirectoryIdentity(_0x4a02aa){const _0x41934a=a43_0x15d1eb;return _0x4a02aa['normalize'](_0x41934a(0xc7))[_0x41934a(0x8f)]();}function isSafeHookDirectorySegment(_0x2d9855){return isSafeLockKeySegment(_0x2d9855);}async function sameDirectory(_0x15b619,_0xd1ecf){const _0x2152c7=a43_0x15d1eb,[_0x2c6966,_0x1c91cd]=await Promise[_0x2152c7(0xb4)]([stat(_0x15b619),stat(_0xd1ecf)]);return _0x2c6966[_0x2152c7(0x11c)]===_0x1c91cd[_0x2152c7(0x11c)]&&_0x2c6966[_0x2152c7(0xd6)]===_0x1c91cd['ino'];}async function applyHookDirectoryMigration(_0x3677dd,_0x2c51d7){const _0x556347=a43_0x15d1eb,_0x17f430=_0x2c51d7[_0x556347(0xcf)],_0x17292d=_0x2c51d7[_0x556347(0xa6)],_0x46d88d=[],_0x482a63=async()=>{const _0x20d198=_0x556347,_0x48506f=[];_0x2c51d7[_0x20d198(0xcf)]=_0x17f430,_0x2c51d7[_0x20d198(0xa6)]=_0x17292d;for(const {migration:_0x68f1ba,temporaryPath:_0x847d86}of[..._0x46d88d][_0x20d198(0xe1)]()){try{_0x847d86?(await rename(_0x68f1ba[_0x20d198(0xd4)],_0x847d86),await rename(_0x847d86,_0x68f1ba[_0x20d198(0x95)])):await rename(_0x68f1ba[_0x20d198(0xd4)],_0x68f1ba[_0x20d198(0x95)]);}catch(_0x525dfd){_0x48506f['push'](new Error(_0x20d198(0xc1)+_0x68f1ba['oldDirectory']+_0x20d198(0xae)+_0x68f1ba['newDirectory']+_0x20d198(0xa7)+(_0x525dfd instanceof Error?_0x525dfd[_0x20d198(0xe4)]:String(_0x525dfd))));}}return _0x48506f;};try{for(const _0x55c77d of _0x3677dd[_0x556347(0x110)]){if(_0x55c77d['mode']===_0x556347(0xd9))await ensureParentDirectory(_0x55c77d['newDirectoryPath']),await rename(_0x55c77d[_0x556347(0x95)],_0x55c77d[_0x556347(0xd4)]),_0x46d88d['push']({'migration':_0x55c77d});else{if(_0x55c77d[_0x556347(0xc8)]===_0x556347(0x114)){const _0x54147c=join(dirname(_0x55c77d[_0x556347(0x95)]),_0x556347(0xa0)+randomUUID());await rename(_0x55c77d[_0x556347(0x95)],_0x54147c);try{await rename(_0x54147c,_0x55c77d[_0x556347(0xd4)]);}catch(_0x1c5d5f){try{await rename(_0x54147c,_0x55c77d[_0x556347(0x95)]);}catch(_0x2754a9){throw withRollbackErrors(_0x1c5d5f,_0x556347(0xa2)+_0x55c77d['oldDirectory']+_0x556347(0xe5)+_0x55c77d[_0x556347(0xb0)]+'\x22;\x20temporary\x20directory\x20\x22'+_0x54147c+_0x556347(0xcd),[new Error(_0x556347(0x97)+_0x54147c+_0x556347(0xe5)+_0x55c77d[_0x556347(0x9f)]+_0x556347(0xa7)+(_0x2754a9 instanceof Error?_0x2754a9[_0x556347(0xe4)]:String(_0x2754a9)))]);}throw _0x1c5d5f;}_0x46d88d[_0x556347(0xfb)]({'migration':_0x55c77d,'temporaryPath':_0x54147c});}}}return _0x2c51d7[_0x556347(0xcf)]=_0x3677dd[_0x556347(0xf2)],{'rollback':_0x482a63};}catch(_0x4f9d52){const _0x380dbb=await _0x482a63();throw withRollbackErrors(_0x4f9d52,_0x556347(0x115),_0x380dbb);}}async function confirmForce(){const _0x1f91d6=a43_0x15d1eb,_0x508fc4=createInterface({'input':process[_0x1f91d6(0xba)],'output':process[_0x1f91d6(0x117)]}),_0xcc4d0e=await new Promise(_0x269479=>{const _0x1ff9d3=_0x1f91d6;_0x508fc4[_0x1ff9d3(0xec)](_0x1ff9d3(0xac),_0x269479);});return _0x508fc4[_0x1f91d6(0xda)](),['y',_0x1f91d6(0xfd)][_0x1f91d6(0x107)](_0xcc4d0e['trim']()[_0x1f91d6(0x8f)]());}
|
|
1
|
+
import{createInterface}from"node:readline";import{readFile,rename,stat,unlink,writeFile}from"node:fs/promises";import{randomUUID}from"node:crypto";import{dirname,join}from"node:path";import{BFF_LIST_PAGE_SIZE,listBffScripts,getBffScriptStatistics}from"../../core/api-client.js";import{loadAliasMap}from"../../core/alias-resolver.js";import{resolveApiModelSource}from"../../api/model-source.js";import{loadBffProjectConfig}from"../../core/bff/config.js";import{createHookLocationMap,directoryExists,ensureParentDirectory,fileExists,isSafeLockKeySegment,normalizeBffType,resolveLocalFilePathFromLockKey,resolveRemoteScriptTarget,scanLocalBffFunctions}from"../../core/bff/file-system.js";import{computeContentHash,computeFileHash}from"../../core/bff/hash.js";import{assertUnambiguousHookAliases}from"../../core/bff/hook-directory.js";import{createEmptyBffLock,ensureLockScope,readBffLockFile,writeBffLockFile}from"../../core/bff/lock.js";import{CliErrors}from"../../errors.js"
|
|
2
|
+
;import{CLI_BIN_NAME}from"../../constant/cli.js";export const bffPull={service:"bff",command:"pull",description:"Pull remote Backend Function scripts to local",risk:"read",structuredErrors:true,flags:[{name:"type",type:"string",description:"Pull only this script type",enum:["COMMON","ENDPOINT","HOOK"]},{name:"force",type:"boolean",description:"Force overwrite local unsynced changes"}],async dryRun(ctx){const config=loadBffProjectConfig(ctx.appCode);const rawLock=await readBffLockFile(config.lockFilePath);const{appLock:appLock}=ensureLockScope(rawLock??createEmptyBffLock(),ctx.appCode,config.scriptsRoot,"pull");const filterType=normalizeBffType(ctx.str("type"))??undefined;const[scripts,statistics]=await Promise.all([listBffScripts(ctx.appCode,filterType),getBffScriptStatistics(ctx.appCode)]);const hasHookScripts=scripts.some(script=>normalizeBffType(script.scriptType)==="HOOK")
|
|
3
|
+
;const datasetCodeToAlias=hasHookScripts?buildDatasetCodeToAliasMap(ctx.apiDir,ctx.appCode,ctx.selectedAppName||ctx.mergedCli?.currentApp||ctx.mergedCli?.defaultApp):new Map;const hookMigrationPlan=hasHookScripts?await planHookDirectoryMigration(config,appLock,datasetCodeToAlias,await scanLocalBffFunctions(config,"HOOK")):undefined;const hookLocationMap=createHookLocationMap(statistics);const preview=[];for(const script of scripts){const target=resolveRemoteScriptTarget(config,script,hookLocationMap,hookMigrationPlan?.projectedFunctions??appLock.functions,datasetCodeToAlias);if(!target){preview.push({scriptType:script.scriptType,functionName:script.functionName??"",status:"skipped",reason:"unresolvable target path"});continue}const lockEntry=(hookMigrationPlan?.projectedFunctions??appLock.functions)[target.lockKey];const remoteHash=script.scriptContent!=null?computeContentHash(script.scriptContent):undefined
|
|
4
|
+
;const hasConflict=await hasUnsyncedLocalChanges(resolveMigratedSourceFilePath(hookMigrationPlan,target)??target.filePath,lockEntry,remoteHash);const conflict=hasConflict?localUnsyncedConflict(target,script.id):undefined;preview.push({lockKey:target.lockKey,filePath:target.filePath,remoteId:script.id??null,status:conflict?"conflict":"would_pull",...conflict?{conflict:conflict}:{},...target.hookLocation?{alias:target.hookLocation.alias??null,datasetCode:target.hookLocation.datasetCode,operationType:target.hookLocation.operationType,functionNode:target.hookLocation.functionNode}:{}})}return{method:"GET",url:`/api/management/library/scripts/list?appCode=${ctx.appCode}${filterType?`&type=${filterType}`:""}¤tPage=1&pageSize=${BFF_LIST_PAGE_SIZE}`,body:{appCode:ctx.appCode,filterType:filterType??null,...hookMigrationPlan&&hookMigrationPlan.migrations.length>0?{hookDirectoryMigrations:hookMigrationPlan.migrations.map(migration=>({from:migration.oldDirectory,to:migration.newDirectory}))
|
|
5
|
+
}:{},files:preview},description:`Would inspect ${preview.length} remote Backend Function script(s) for pull`}},async execute(ctx){const config=loadBffProjectConfig(ctx.appCode);const rawLock=await readBffLockFile(config.lockFilePath);const{lockData:lockData,appLock:appLock}=ensureLockScope(rawLock??createEmptyBffLock(),ctx.appCode,config.scriptsRoot,"pull");const filterType=normalizeBffType(ctx.str("type"))??undefined;if(ctx.str("type")&&!filterType){throw CliErrors.validation("--type must be COMMON, ENDPOINT, or HOOK.")}const[scripts,statistics]=await Promise.all([listBffScripts(ctx.appCode,filterType),getBffScriptStatistics(ctx.appCode)]);if(scripts.length===0){return{ok:true,data:{pulled:[],skipped:[],conflicts:[],failed:[]},message:"No remote Backend Function scripts found."}}const force=ctx.bool("force");if(force&&!ctx.nonInteractive){const confirmed=await confirmForce();if(!confirmed){throw CliErrors.cancelled("Force pull cancelled.")}}if(force&&ctx.nonInteractive){}
|
|
6
|
+
const hasHookScripts=scripts.some(script=>normalizeBffType(script.scriptType)==="HOOK");const datasetCodeToAlias=hasHookScripts?buildDatasetCodeToAliasMap(ctx.apiDir,ctx.appCode,ctx.selectedAppName||ctx.mergedCli?.currentApp||ctx.mergedCli?.defaultApp):new Map;const hookLocationMap=createHookLocationMap(statistics);const nextLockData=JSON.parse(JSON.stringify(lockData));const currentAppCode=ctx.appCode;const nextAppLock=nextLockData.apps[currentAppCode];if(!nextAppLock){throw new Error(`Lock scope for app "${currentAppCode}" not found after ensureLockScope.`)}const hookMigration=hasHookScripts?await applyHookDirectoryMigration(await planHookDirectoryMigration(config,nextAppLock,datasetCodeToAlias,await scanLocalBffFunctions(config,"HOOK")),nextAppLock):undefined;const fileTransaction=createPullFileTransaction();const pulled=[];const skipped=[];const conflicts=[];const failed=[];for(const script of scripts){
|
|
7
|
+
const target=resolveRemoteScriptTarget(config,script,hookLocationMap,nextAppLock.functions,datasetCodeToAlias);if(!target){skipped.push({lockKey:`${script.scriptType}/${script.functionName}`,reason:"unresolvable target path"});continue}const lockEntry=nextAppLock.functions[target.lockKey];try{if(!script.id){throw new Error("Remote script missing id.")}if(script.scriptContent==null){throw new Error("Remote script missing content.")}const content=script.scriptContent;const remoteHash=computeContentHash(content);if(!force){const hasConflict=await hasUnsyncedLocalChanges(target.filePath,lockEntry,remoteHash);if(hasConflict){conflicts.push(localUnsyncedConflict(target,script.id));continue}}await fileTransaction.write(target.filePath,content);const nextEntry={hash:remoteHash,remoteId:script.id,version:script.version};if(target.type==="HOOK"&&target.hookLocation){nextEntry.alias=target.hookLocation.alias;nextEntry.datasetCode=target.hookLocation.datasetCode
|
|
8
|
+
;nextEntry.operationType=target.hookLocation.operationType;nextEntry.functionNode=target.hookLocation.functionNode}nextAppLock.functions[target.lockKey]=nextEntry;pulled.push({lockKey:target.lockKey,remoteId:script.id})}catch(error){failed.push({lockKey:target.lockKey,error:error instanceof Error?error.message:String(error)})}}nextAppLock.lastSync=(new Date).toISOString();try{await writeBffLockFile(config.lockFilePath,nextLockData)}catch(error){const rollbackErrors=[...await fileTransaction.rollback(),...await(hookMigration?.rollback())??[]];throw withRollbackErrors(error,"Failed to write the Backend Function lock file; local changes could not be completely rolled back.",rollbackErrors)}return{ok:failed.length===0,data:{pulled:pulled,skipped:skipped,conflicts:conflicts,failed:failed},message:formatPullMessage(pulled.length,skipped.length,conflicts.length,failed.length)}}};function localUnsyncedConflict(target,remoteId){const functionName=target.lockKey.split("/").at(-1);return{
|
|
9
|
+
code:"BFF_LOCAL_UNSYNCED",lockKey:target.lockKey,filePath:target.filePath,...remoteId!=null?{remoteId:remoteId}:{},message:"Local script differs from the last pulled version. Review it before choosing the source of truth.",nextAction:{action:"push_local",command:`${CLI_BIN_NAME} bff push --type ${target.type} --name ${functionName} --format compress`,requiresReview:true,message:"If the reviewed local script should win, run this command to update the remote script. Do not use --force to resolve a content conflict."}}}function formatPullMessage(pulled,skipped,conflicts,failed){const parts=[`Pull complete: ${pulled} pulled`,`${skipped} skipped`];if(conflicts>0){parts.push(`${conflicts} conflict${conflicts===1?"":"s"} ${conflicts===1?"requires":"require"} resolution`)}if(failed>0)parts.push(`${failed} failed`);return parts.join(", ")}async function hasUnsyncedLocalChanges(filePath,lockEntry,remoteHash){if(!await fileExists(filePath))return false
|
|
10
|
+
;const localHash=await computeFileHash(filePath);if(!lockEntry)return remoteHash?localHash!==remoteHash:true;return localHash!==lockEntry.hash}function createPullFileTransaction(){const snapshots=new Map;const restore=async(filePath,snapshot)=>{try{if(snapshot.existed){await ensureParentDirectory(filePath);await writeFile(filePath,snapshot.content)}else{try{await unlink(filePath)}catch(error){if(error.code!=="ENOENT")throw error}}return undefined}catch(error){return error instanceof Error?error:new Error(String(error))}};return{async write(filePath,content){if(!snapshots.has(filePath)){try{snapshots.set(filePath,{existed:true,content:await readFile(filePath)})}catch(error){if(error.code!=="ENOENT")throw error;snapshots.set(filePath,{existed:false})}}try{await ensureParentDirectory(filePath);await writeFile(filePath,content,"utf8")}catch(error){const rollbackError=await restore(filePath,snapshots.get(filePath));if(!rollbackError)snapshots.delete(filePath)
|
|
11
|
+
;throw withRollbackErrors(error,`Failed to write local script "${filePath}".`,rollbackError?[rollbackError]:[])}},async rollback(){const errors=[];for(const[filePath,snapshot]of[...snapshots.entries()].reverse()){const error=await restore(filePath,snapshot);if(error){errors.push(new Error(`Could not restore local script "${filePath}": ${error.message}`))}}return errors}}}function withRollbackErrors(cause,message,rollbackErrors){const original=cause instanceof Error?cause:new Error(String(cause));if(rollbackErrors.length===0)return original;return new AggregateError([original,...rollbackErrors],`${message} Recovery errors: ${rollbackErrors.map(error=>error.message).join("; ")}`)}function buildDatasetCodeToAliasMap(apiDir,appCode,selectedAppName){const source=resolveApiModelSource(apiDir,appCode,selectedAppName);const entries=loadAliasMap(apiDir,undefined,source.filePath,source.profileName);assertUnambiguousHookAliases(entries)
|
|
12
|
+
;return new Map(entries.map(entry=>[entry.datasetCode.toLowerCase(),entry.alias]))}async function planHookDirectoryMigration(config,appLock,datasetCodeToAlias,localHooks){const grouped=new Map;for(const[oldLockKey,entry]of Object.entries(appLock.functions)){const[type,directoryName,operationType,functionNode,functionName,...rest]=oldLockKey.split("/");if(type!=="HOOK"||!directoryName||!operationType||!functionNode||!functionName||rest.length>0||!entry.datasetCode)continue;const alias=datasetCodeToAlias.get(entry.datasetCode.toLowerCase());const newDirectory=alias??entry.datasetCode;if(!isSafeHookDirectorySegment(directoryName)){throw CliErrors.validation(`Cannot migrate unsafe HOOK directory "${directoryName}" from the lock file.`)}if(!isSafeHookDirectorySegment(newDirectory)){throw CliErrors.validation(`Cannot migrate HOOK directory "${directoryName}": its target directory is unsafe.`)}if(directoryName===newDirectory)continue;const group=grouped.get(directoryName)??{
|
|
13
|
+
datasetCode:entry.datasetCode,alias:alias,keyChanges:[]};if(group.datasetCode!==entry.datasetCode){throw CliErrors.validation(`Cannot migrate HOOK directory "${directoryName}": it is tracked by multiple Datasets.`)}const newLockKey=`HOOK/${newDirectory}/${operationType}/${functionNode}/${functionName}`;try{resolveLocalFilePathFromLockKey(config,oldLockKey);resolveLocalFilePathFromLockKey(config,newLockKey)}catch(error){throw CliErrors.validation(`Cannot migrate unsafe HOOK lock key "${oldLockKey}": ${error instanceof Error?error.message:String(error)}`)}group.keyChanges.push({oldLockKey:oldLockKey,newLockKey:newLockKey,entry:entry});grouped.set(directoryName,group)}const changingOldKeys=new Set([...grouped.values()].flatMap(group=>group.keyChanges.map(change=>change.oldLockKey)));const plannedDirectories=new Map;const plannedLockKeys=new Map;for(const[oldDirectory,group]of grouped){const newDirectory=group.alias??group.datasetCode;const directoryKey=hookDirectoryIdentity(newDirectory)
|
|
14
|
+
;const existingDirectorySource=plannedDirectories.get(directoryKey);if(existingDirectorySource&&existingDirectorySource!==oldDirectory){throw CliErrors.validation(`Cannot migrate HOOK directories "${existingDirectorySource}" and "${oldDirectory}": both target "${newDirectory}". Resolve the directories manually before retrying.`)}plannedDirectories.set(directoryKey,oldDirectory);for(const change of group.keyChanges){const existingKeySource=plannedLockKeys.get(change.newLockKey);if(existingKeySource&&existingKeySource!==change.oldLockKey){throw CliErrors.validation(`Cannot migrate HOOK lock keys "${existingKeySource}" and "${change.oldLockKey}": both target "${change.newLockKey}". Resolve the lock entries manually before retrying.`)}if(changingOldKeys.has(change.newLockKey)){throw CliErrors.validation(`Cannot migrate HOOK lock key "${change.oldLockKey}": its target "${change.newLockKey}" is another legacy key being migrated. Resolve the lock entries manually before retrying.`)}
|
|
15
|
+
plannedLockKeys.set(change.newLockKey,change.oldLockKey)}}const currentAliasOwners=new Map;for(const[datasetCode,alias]of datasetCodeToAlias){currentAliasOwners.set(hookDirectoryIdentity(alias),datasetCode)}const migrations=[];for(const[oldDirectory,group]of grouped){const newDirectory=group.alias??group.datasetCode;const oldDirectoryPath=join(config.scriptsRootDir,"HOOK",oldDirectory);const newDirectoryPath=join(config.scriptsRootDir,"HOOK",newDirectory);const oldExists=await directoryExists(oldDirectoryPath);const newExists=await directoryExists(newDirectoryPath);const mode=oldExists?newExists?await sameDirectory(oldDirectoryPath,newDirectoryPath)?"case-rename":undefined:"move":"rekey";if(!mode){throw CliErrors.validation(`Cannot migrate HOOK directory "${oldDirectory}" to "${newDirectory}": the target directory already exists. Resolve the directories and retry.`)}const owner=currentAliasOwners.get(hookDirectoryIdentity(oldDirectory))
|
|
16
|
+
;if(owner&&owner!==group.datasetCode.toLowerCase()){const trackedKeys=new Set(group.keyChanges.map(change=>change.oldLockKey));const unknownScripts=localHooks.filter(fn=>fn.type==="HOOK"&&fn.alias!=null&&hookDirectoryIdentity(fn.alias)===hookDirectoryIdentity(oldDirectory)&&!trackedKeys.has(fn.lockKey));if(unknownScripts.length>0){throw CliErrors.validation(`Cannot migrate HOOK directory "${oldDirectory}": it is now another Dataset alias and contains untracked scripts. Resolve the directory manually before retrying.`)}}const destinationOwner=currentAliasOwners.get(hookDirectoryIdentity(newDirectory));if(destinationOwner&&destinationOwner!==group.datasetCode.toLowerCase()){throw CliErrors.validation(`Cannot migrate HOOK directory "${oldDirectory}" to "${newDirectory}": the destination is another Dataset alias. Resolve the directory manually before retrying.`)}for(const change of group.keyChanges){const targetEntry=appLock.functions[change.newLockKey]
|
|
17
|
+
;if(targetEntry&&!changingOldKeys.has(change.newLockKey)&&!sameHookIdentity(change.entry,targetEntry)){throw CliErrors.validation(`Cannot migrate HOOK directory "${oldDirectory}" to "${newDirectory}": target lock key is already bound to another script.`)}}migrations.push({oldDirectory:oldDirectory,newDirectory:newDirectory,oldDirectoryPath:oldDirectoryPath,newDirectoryPath:newDirectoryPath,mode:mode,alias:group.alias,keyChanges:group.keyChanges})}const projectedFunctions={...appLock.functions};const sourceFilePathByNewLockKey=new Map;const sourceDirectoryPathByNewDirectory=new Map;for(const migration of migrations){const sourceWins=migration.mode!=="rekey";if(sourceWins){sourceDirectoryPathByNewDirectory.set(hookDirectoryIdentity(migration.newDirectory),migration.oldDirectoryPath)}for(const change of migration.keyChanges){const targetEntry=projectedFunctions[change.newLockKey];const selected=sourceWins?change.entry:targetEntry??change.entry
|
|
18
|
+
;projectedFunctions[change.newLockKey]=canonicalizeHookEntry(selected,migration.alias);delete projectedFunctions[change.oldLockKey];if(sourceWins){sourceFilePathByNewLockKey.set(change.newLockKey,resolveLocalFilePathFromLockKey(config,change.oldLockKey))}}}return{migrations:migrations,projectedFunctions:projectedFunctions,sourceFilePathByNewLockKey:sourceFilePathByNewLockKey,sourceDirectoryPathByNewDirectory:sourceDirectoryPathByNewDirectory}}function resolveMigratedSourceFilePath(plan,target){if(!plan||!target)return undefined;const trackedPath=plan.sourceFilePathByNewLockKey.get(target.lockKey);if(trackedPath)return trackedPath;if(target.type!=="HOOK")return undefined;const[,directoryName,...remainingSegments]=target.lockKey.split("/");if(!directoryName||remainingSegments.length===0)return undefined;const sourceDirectoryPath=plan.sourceDirectoryPathByNewDirectory.get(hookDirectoryIdentity(directoryName))
|
|
19
|
+
;return sourceDirectoryPath?`${join(sourceDirectoryPath,...remainingSegments)}.js`:undefined}function sameHookIdentity(left,right){return left.remoteId===right.remoteId&&left.datasetCode===right.datasetCode&&left.operationType===right.operationType&&left.functionNode===right.functionNode}function canonicalizeHookEntry(entry,alias){const{alias:_oldAlias,...withoutAlias}=entry;return alias?{...withoutAlias,alias:alias}:withoutAlias}function hookDirectoryIdentity(directoryName){return directoryName.normalize("NFC").toLowerCase()}function isSafeHookDirectorySegment(value){return isSafeLockKeySegment(value)}async function sameDirectory(left,right){const[leftStat,rightStat]=await Promise.all([stat(left),stat(right)]);return leftStat.dev===rightStat.dev&&leftStat.ino===rightStat.ino}async function applyHookDirectoryMigration(plan,appLock){const originalFunctions=appLock.functions;const originalLastSync=appLock.lastSync;const completed=[];const rollback=async()=>{const errors=[]
|
|
20
|
+
;appLock.functions=originalFunctions;appLock.lastSync=originalLastSync;for(const{migration:migration,temporaryPath:temporaryPath}of[...completed].reverse()){try{if(temporaryPath){await rename(migration.newDirectoryPath,temporaryPath);await rename(temporaryPath,migration.oldDirectoryPath)}else{await rename(migration.newDirectoryPath,migration.oldDirectoryPath)}}catch(error){errors.push(new Error(`Could not restore HOOK directory "${migration.oldDirectory}" from "${migration.newDirectory}": ${error instanceof Error?error.message:String(error)}`))}}return errors};try{for(const migration of plan.migrations){if(migration.mode==="move"){await ensureParentDirectory(migration.newDirectoryPath);await rename(migration.oldDirectoryPath,migration.newDirectoryPath);completed.push({migration:migration})}else if(migration.mode==="case-rename"){const temporaryPath=join(dirname(migration.oldDirectoryPath),`.hook-directory-migrate-${randomUUID()}`);await rename(migration.oldDirectoryPath,temporaryPath)
|
|
21
|
+
;try{await rename(temporaryPath,migration.newDirectoryPath)}catch(error){try{await rename(temporaryPath,migration.oldDirectoryPath)}catch(rollbackError){throw withRollbackErrors(error,`Failed to rename HOOK directory "${migration.oldDirectory}" to "${migration.newDirectory}"; temporary directory "${temporaryPath}" may remain.`,[new Error(`Could not restore temporary HOOK directory "${temporaryPath}" to "${migration.oldDirectory}": ${rollbackError instanceof Error?rollbackError.message:String(rollbackError)}`)])}throw error}completed.push({migration:migration,temporaryPath:temporaryPath})}}appLock.functions=plan.projectedFunctions;return{rollback:rollback}}catch(error){const rollbackErrors=await rollback();throw withRollbackErrors(error,"Failed to migrate HOOK directories; local changes could not be completely rolled back.",rollbackErrors)}}async function confirmForce(){const rl=createInterface({input:process.stdin,output:process.stderr});const answer=await new Promise(resolve=>{
|
|
22
|
+
rl.question("Force pull will overwrite local unsynced changes. Continue? [y/N] ",resolve)});rl.close();return["y","yes"].includes(answer.trim().toLowerCase())}
|
package/lib/commands/bff/push.js
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
const a44_0xad0615=a44_0x3e85;(function(_0x1960fc,_0x6e2039){const _0x227280=a44_0x3e85,_0x29b8fd=_0x1960fc();while(!![]){try{const _0x32354c=-parseInt(_0x227280(0x1da))/0x1+parseInt(_0x227280(0x21f))/0x2+-parseInt(_0x227280(0x1f4))/0x3+-parseInt(_0x227280(0x206))/0x4*(parseInt(_0x227280(0x201))/0x5)+-parseInt(_0x227280(0x1e1))/0x6+parseInt(_0x227280(0x228))/0x7*(parseInt(_0x227280(0x219))/0x8)+parseInt(_0x227280(0x1bc))/0x9*(parseInt(_0x227280(0x208))/0xa);if(_0x32354c===_0x6e2039)break;else _0x29b8fd['push'](_0x29b8fd['shift']());}catch(_0x5a363c){_0x29b8fd['push'](_0x29b8fd['shift']());}}}(a44_0x3283,0x2ec7f));import{readFile}from'node:fs/promises';import{saveBffScript,getBffScriptInfo,getBffScriptStatistics,getPlatformErrorCode,listDatasets,clearBffScriptCache}from'../../core/api-client.js';import{loadAliasMap}from'../../core/alias-resolver.js';function a44_0x3e85(_0x521c7a,_0x3281db){_0x521c7a=_0x521c7a-0x1b7;const _0x328300=a44_0x3283();let _0x3e855c=_0x328300[_0x521c7a];return _0x3e855c;}import{resolveApiModelSource}from'../../api/model-source.js';import{loadBffProjectConfig}from'../../core/bff/config.js';import{normalizeBffType,scanLocalBffFunctions}from'../../core/bff/file-system.js';import{buildHookDirectoryIndexes,assertUnambiguousHookAliases,assertUnambiguousHookDirectoryMappings,preflightPushHookDirectories,trackedHookDirectoryMappings}from'../../core/bff/hook-directory.js';import{computeFileHash}from'../../core/bff/hash.js';import{createEmptyBffLock,ensureLockScope,readBffLockFile,writeBffLockFile}from'../../core/bff/lock.js';import{extractScriptDescription,snakeToCamel}from'../../core/bff/utils.js';import{sleep}from'../../utils/sleep.js';import{CLI_BIN_NAME}from'../../constant/cli.js';import{CliErrors}from'../../errors.js';const CACHE_CLEAR_ATTEMPTS=0x2,CACHE_CLEAR_INTERVAL_MS=0x12c;export const bffPush={'service':a44_0xad0615(0x20f),'command':a44_0xad0615(0x225),'description':'Push\x20local\x20Backend\x20Function\x20scripts\x20to\x20remote','risk':a44_0xad0615(0x21d),'structuredErrors':!![],'flags':[{'name':a44_0xad0615(0x22b),'type':a44_0xad0615(0x1cd),'description':a44_0xad0615(0x1cc),'enum':['COMMON','ENDPOINT',a44_0xad0615(0x21b)]},{'name':a44_0xad0615(0x1e8),'type':a44_0xad0615(0x1cd),'description':a44_0xad0615(0x1be)},{'name':a44_0xad0615(0x1f9),'type':'boolean','description':'Force\x20push\x20ignoring\x20hash\x20protection'}],async 'dryRun'(_0x1369e3){const _0x3dfc88=a44_0xad0615,_0x43fc33=loadBffProjectConfig(_0x1369e3[_0x3dfc88(0x1fd)]),_0x557633=await readBffLockFile(_0x43fc33['lockFilePath']),{appLock:_0x54a637}=ensureLockScope(_0x557633??createEmptyBffLock(),_0x1369e3[_0x3dfc88(0x1fd)],_0x43fc33[_0x3dfc88(0x1ec)],'push'),_0x4503df=await getTargetFunctions(_0x43fc33,_0x1369e3),_0x148e38=_0x4503df['some'](_0x3757e0=>_0x3757e0[_0x3dfc88(0x22b)]===_0x3dfc88(0x21b))?await scanLocalBffFunctions(_0x43fc33,_0x3dfc88(0x21b)):_0x4503df,_0x2cac38=await buildHookMaps(_0x1369e3[_0x3dfc88(0x1fd)],_0x1369e3[_0x3dfc88(0x1e7)],_0x148e38,_0x54a637,_0x1369e3[_0x3dfc88(0x202)]||_0x1369e3[_0x3dfc88(0x1c1)]?.['currentApp']||_0x1369e3[_0x3dfc88(0x1c1)]?.[_0x3dfc88(0x1db)]),_0x8452e9=_0x1369e3[_0x3dfc88(0x1f5)](_0x3dfc88(0x1f9)),_0x439961=[];for(const _0x290381 of _0x4503df){const _0x4d24b7=await computeFileHash(_0x290381['filePath']),_0xde73e5=_0x54a637['functions'][_0x290381[_0x3dfc88(0x1f3)]],_0x2cd334=!!_0xde73e5&&_0xde73e5[_0x3dfc88(0x220)]===_0x4d24b7,_0x5a30e4=_0x2cac38[_0x3dfc88(0x1c5)]['get'](_0x290381[_0x3dfc88(0x1f3)]),_0x4e2b6f=!!_0xde73e5?.[_0x3dfc88(0x1fa)]&&_0xde73e5[_0x3dfc88(0x1ef)]==null&&(_0x8452e9||!_0x2cd334),_0x5aee6c=_0x4e2b6f?missingRemoteVersionConflict(_0x290381,_0xde73e5):undefined,_0x15d3a6=_0x2cac38[_0x3dfc88(0x1d1)]['has'](_0x290381[_0x3dfc88(0x1f3)])?_0x3dfc88(0x217):!_0x8452e9&&_0x2cd334?_0x3dfc88(0x1d0):_0x5aee6c?_0x3dfc88(0x1fe):_0x3dfc88(0x21c);_0x439961['push']({'lockKey':_0x290381[_0x3dfc88(0x1f3)],'filePath':_0x290381[_0x3dfc88(0x1de)],'remoteId':_0xde73e5?.[_0x3dfc88(0x1fa)]??null,'mode':_0xde73e5?.[_0x3dfc88(0x1fa)]?'update':_0x3dfc88(0x214),'status':_0x15d3a6,..._0x2cac38[_0x3dfc88(0x1d1)]['has'](_0x290381[_0x3dfc88(0x1f3)])?{'error':_0x2cac38[_0x3dfc88(0x1d1)][_0x3dfc88(0x226)](_0x290381[_0x3dfc88(0x1f3)])}:{},..._0x5aee6c?{'conflict':_0x5aee6c}:{},..._0x2cac38['existingHooks']['has'](_0x290381[_0x3dfc88(0x1f3)])?{'datasetCode':_0xde73e5?.[_0x3dfc88(0x1d9)],'bindingPreserved':!![],'warnings':[existingHookWarning(_0x290381['lockKey'])]}:{},..._0x5a30e4?{'alias':_0x5a30e4[_0x3dfc88(0x1e6)]??null,'datasetCode':_0x5a30e4[_0x3dfc88(0x1d9)],'operationType':_0x290381[_0x3dfc88(0x1ed)],'functionNode':_0x290381['functionNode'],'warnings':_0x5a30e4['warnings']}:{}});}return{'method':'POST','url':_0x3dfc88(0x21a),'body':{'appCode':_0x1369e3[_0x3dfc88(0x1fd)],'force':_0x8452e9,'files':_0x439961,'cacheClearAtRuntime':_0x439961[_0x3dfc88(0x223)](_0xf00931=>_0xf00931['status']===_0x3dfc88(0x21c)),'cacheClearAtRuntimeTimes':_0x439961[_0x3dfc88(0x223)](_0x225372=>_0x225372['status']===_0x3dfc88(0x21c))?CACHE_CLEAR_ATTEMPTS:0x0},'description':_0x3dfc88(0x221)+_0x439961[_0x3dfc88(0x1f1)]+_0x3dfc88(0x1f6)};},async 'execute'(_0x546e4d){const _0x4e24bc=a44_0xad0615,_0x1e0fa0=loadBffProjectConfig(_0x546e4d[_0x4e24bc(0x1fd)]),_0x198079=await readBffLockFile(_0x1e0fa0[_0x4e24bc(0x1d2)]),{lockData:_0x5bc079,appLock:_0x11da3e}=ensureLockScope(_0x198079??createEmptyBffLock(),_0x546e4d[_0x4e24bc(0x1fd)],_0x1e0fa0[_0x4e24bc(0x1ec)],_0x4e24bc(0x225)),_0x55b057=await getTargetFunctions(_0x1e0fa0,_0x546e4d);if(_0x55b057[_0x4e24bc(0x1f1)]===0x0)return{'ok':!![],'data':{'uploaded':[],'skipped':[],'conflicts':[],'failed':[]},'message':_0x4e24bc(0x1e0)};const _0x16621e=_0x546e4d[_0x4e24bc(0x1f5)](_0x4e24bc(0x1f9)),_0x1a0147=JSON[_0x4e24bc(0x203)](JSON[_0x4e24bc(0x1c3)](_0x5bc079)),_0x7a9c95=_0x1a0147[_0x4e24bc(0x215)][_0x546e4d[_0x4e24bc(0x1fd)]];if(!_0x7a9c95)throw new Error(_0x4e24bc(0x1bf)+_0x546e4d['appCode']+_0x4e24bc(0x1eb));const _0x175215=_0x55b057[_0x4e24bc(0x223)](_0x32510e=>_0x32510e[_0x4e24bc(0x22b)]==='HOOK')?await scanLocalBffFunctions(_0x1e0fa0,_0x4e24bc(0x21b)):_0x55b057,_0x36bfd1=await buildHookMaps(_0x546e4d['appCode'],_0x546e4d[_0x4e24bc(0x1e7)],_0x175215,_0x7a9c95,_0x546e4d[_0x4e24bc(0x202)]||_0x546e4d[_0x4e24bc(0x1c1)]?.[_0x4e24bc(0x1c0)]||_0x546e4d[_0x4e24bc(0x1c1)]?.[_0x4e24bc(0x1db)]),_0x5c6ab6=[],_0x572eac=[],_0x19e72f=[],_0x47d0cb=[];for(const _0x1d9195 of _0x55b057){const _0x20f35c=_0x36bfd1['failures'][_0x4e24bc(0x226)](_0x1d9195[_0x4e24bc(0x1f3)]);if(_0x20f35c){_0x47d0cb[_0x4e24bc(0x225)]({'lockKey':_0x1d9195[_0x4e24bc(0x1f3)],'error':_0x20f35c});continue;}const _0x2c0d5c=await computeFileHash(_0x1d9195[_0x4e24bc(0x1de)]),_0x57c1f5=_0x7a9c95[_0x4e24bc(0x1e4)][_0x1d9195[_0x4e24bc(0x1f3)]];if(!_0x16621e&&_0x57c1f5&&_0x57c1f5[_0x4e24bc(0x220)]===_0x2c0d5c){_0x572eac[_0x4e24bc(0x225)]({'lockKey':_0x1d9195[_0x4e24bc(0x1f3)],'reason':_0x4e24bc(0x1d0)});continue;}if(_0x57c1f5?.[_0x4e24bc(0x1fa)]&&_0x57c1f5[_0x4e24bc(0x1ef)]==null){_0x19e72f[_0x4e24bc(0x225)](missingRemoteVersionConflict(_0x1d9195,_0x57c1f5));continue;}try{await uploadSingleFunction(_0x546e4d[_0x4e24bc(0x1fd)],_0x1d9195,_0x7a9c95,_0x36bfd1);const _0x1c2659=_0x7a9c95[_0x4e24bc(0x1e4)][_0x1d9195[_0x4e24bc(0x1f3)]];_0x5c6ab6['push']({'lockKey':_0x1d9195['lockKey'],'remoteId':_0x1c2659?.[_0x4e24bc(0x1fa)]??0x0});}catch(_0x214777){const _0x2aa472=remoteVersionChangedConflict(_0x1d9195,_0x57c1f5,_0x214777);if(_0x2aa472){_0x19e72f[_0x4e24bc(0x225)](_0x2aa472);continue;}_0x47d0cb[_0x4e24bc(0x225)]({'lockKey':_0x1d9195[_0x4e24bc(0x1f3)],'error':_0x214777 instanceof Error?_0x214777[_0x4e24bc(0x1df)]:String(_0x214777)});}}_0x7a9c95[_0x4e24bc(0x1dd)]=new Date()['toISOString'](),await writeBffLockFile(_0x1e0fa0[_0x4e24bc(0x1d2)],_0x1a0147),await waitForUploadedLockEntries(_0x1e0fa0[_0x4e24bc(0x1d2)],_0x546e4d[_0x4e24bc(0x1fd)],_0x5c6ab6['map'](_0x13cacb=>_0x13cacb[_0x4e24bc(0x1f3)]));let _0x4447ff={'attempted':![],'cleared':![]};if(_0x5c6ab6['length']>0x0)try{let _0x5198df='';for(let _0x2445eb=0x0;_0x2445eb<CACHE_CLEAR_ATTEMPTS;_0x2445eb+=0x1){_0x5198df=await clearBffScriptCache(),_0x2445eb<CACHE_CLEAR_ATTEMPTS-0x1&&await sleep(CACHE_CLEAR_INTERVAL_MS);}_0x4447ff={'attempted':!![],'cleared':!![],'message':_0x5198df||_0x4e24bc(0x229)};}catch(_0x110e0a){_0x4447ff={'attempted':!![],'cleared':![],'error':_0x110e0a instanceof Error?_0x110e0a[_0x4e24bc(0x1df)]:String(_0x110e0a)};}const _0x29db53=_0x47d0cb[_0x4e24bc(0x1f1)]===0x0&&(_0x4447ff[_0x4e24bc(0x1ff)]?_0x4447ff[_0x4e24bc(0x1e9)]:!![]),_0x41e941=_0x29db53,_0x4d7520=_0x4447ff[_0x4e24bc(0x1ff)]?_0x4447ff[_0x4e24bc(0x1e9)]?_0x4e24bc(0x1dc):_0x4e24bc(0x1bb):_0x4e24bc(0x224);return{'ok':_0x41e941,'data':{'uploaded':_0x5c6ab6,'skipped':_0x572eac,'conflicts':_0x19e72f,'failed':_0x47d0cb,'cacheClear':_0x4447ff,'warnings':[...[..._0x36bfd1[_0x4e24bc(0x1c5)][_0x4e24bc(0x1d8)]()][_0x4e24bc(0x210)](_0x3a5c91=>_0x3a5c91['warnings']),...[..._0x36bfd1[_0x4e24bc(0x1e2)]][_0x4e24bc(0x1c6)](existingHookWarning)]},'message':formatPushMessage(_0x5c6ab6['length'],_0x572eac[_0x4e24bc(0x1f1)],_0x19e72f[_0x4e24bc(0x1f1)],_0x47d0cb['length'],_0x4d7520)};}};function missingRemoteVersionConflict(_0x14251e,_0x5a9afe){const _0x1b47e2=a44_0xad0615;return remoteVersionConflict(_0x14251e,_0x5a9afe,_0x1b47e2(0x212),_0x1b47e2(0x1ea));}function remoteVersionChangedConflict(_0x487e2e,_0x3ad80c,_0x207844){const _0x1c0816=a44_0xad0615;if(!_0x3ad80c?.['remoteId']||_0x3ad80c['version']==null||!isRemoteVersionConflict(_0x207844))return undefined;return remoteVersionConflict(_0x487e2e,_0x3ad80c,_0x1c0816(0x20b),_0x1c0816(0x1fb));}function remoteVersionConflict(_0x17b2e9,_0x2c8b30,_0x483cc0,_0xd1016){const _0x121e43=a44_0xad0615;return{'code':_0x483cc0,'lockKey':_0x17b2e9[_0x121e43(0x1f3)],'filePath':_0x17b2e9[_0x121e43(0x1de)],'remoteId':_0x2c8b30[_0x121e43(0x1fa)],..._0x2c8b30[_0x121e43(0x1ef)]!=null?{'expectedVersion':_0x2c8b30[_0x121e43(0x1ef)]}:{},'message':_0xd1016,'nextAction':{'action':_0x121e43(0x1f0),'command':CLI_BIN_NAME+'\x20bff\x20detail\x20--id\x20'+_0x2c8b30[_0x121e43(0x1fa)]+_0x121e43(0x1bd),'requiresReview':!![],'message':_0x121e43(0x204)}};}function isRemoteVersionConflict(_0x4d094f){const _0x4a53ab=a44_0xad0615,_0x31f6b9=_0x4d094f instanceof Error?_0x4d094f[_0x4a53ab(0x1df)]:String(_0x4d094f),_0x298b6b=getPlatformErrorCode(_0x4d094f)??'';return[_0x31f6b9,_0x298b6b]['some'](_0x3edd7c=>/(?:version|optimistic)[\s_-]*(?:conflict|mismatch|changed|stale|out[\s_-]*of[\s_-]*date)|(?:conflict|mismatch|changed|stale|out[\s_-]*of[\s_-]*date)[\s_-]*(?:version|optimistic)/i[_0x4a53ab(0x200)](_0x3edd7c));}function a44_0x3283(){const _0x204300=['9EpSqmE','\x20--format\x20compress','Push\x20only\x20the\x20named\x20function\x20(requires\x20--type)','Lock\x20scope\x20for\x20app\x20\x22','currentApp','mergedCli','afterScriptId','stringify','description','resolutions','map','--name\x20requires\x20--type\x20to\x20identify\x20the\x20function.','size','dataset','functionName','\x20conflict','Push\x20only\x20this\x20script\x20type','string','before','script','unchanged','failures','lockFilePath','profileName','set','filter','Local\x20function\x20not\x20found:\x20','startsWith','values','datasetCode','58685kRCirP','defaultApp','runtime\x20cache\x20cleared','lastSync','filePath','message','No\x20local\x20Backend\x20Function\x20scripts\x20found.','1515840KRLRnj','existingHooks','\x20uploaded','functions','scriptType','alias','apiDir','name','cleared','The\x20local\x20sync\x20lock\x20has\x20no\x20remote\x20version\x20for\x20this\x20script.','\x22\x20not\x20found\x20after\x20ensureLockScope.','scriptsRoot','operationType','HOOK_DATASET_NOT_FOUND:','version','review_remote_and_merge','length','datasetId','lockKey','326082OWseyF','bool','\x20local\x20Backend\x20Function\x20script(s)\x20for\x20push\x20and\x20clear\x20runtime\x20cache\x20if\x20files\x20are\x20uploaded','Incomplete\x20HOOK\x20path:\x20','str','force','remoteId','Remote\x20script\x20version\x20changed\x20since\x20the\x20last\x20pull.','Dataset\x20metadata\x20is\x20unavailable;\x20the\x20existing\x20script\x20and\x20binding\x20were\x20verified.\x20Update\x20by\x20script\x20ID\x20without\x20rebinding.','appCode','conflict','attempted','test','15INZrch','selectedAppName','parse','Review\x20the\x20current\x20remote\x20source,\x20merge\x20it\x20into\x20the\x20local\x20script,\x20then\x20retry\x20push.\x20Do\x20not\x20use\x20--force\x20unless\x20you\x20intentionally\x20discard\x20local\x20changes.','every','283924OZkqOX','Cannot\x20verify\x20existing\x20HOOK\x20binding:\x20','5985680ADfByf','requires','Multiple\x20HOOK\x20directories\x20reference\x20the\x20same\x20missing\x20Dataset.\x20Resolve\x20duplicate\x20directories\x20before\x20pushing.','BFF_REMOTE_VERSION_CHANGED','Lock\x20file\x20not\x20settled\x20after\x20push\x20for\x20','functionNode','Existing\x20HOOK\x20identity,\x20version\x20or\x20binding\x20does\x20not\x20match\x20the\x20local\x20lock.\x20Pull\x20and\x20review\x20before\x20pushing.','bff','flatMap','delete','BFF_REMOTE_VERSION_MISSING','\x20resolution','create','apps',':\x20missing\x20remote\x20version.\x20Run\x20`push`\x20after\x20`pull`\x20to\x20sync\x20version\x20info.','failed','join','22736BNgSkk','/api/management/library/scripts/save','HOOK','would_push','write','add','25718QDfpqc','hash','Would\x20inspect\x20','require','some','runtime\x20cache\x20not\x20needed','push','get','beforeScriptId','525OqukVa','Runtime\x20script\x20cache\x20cleared.','Push\x20complete:\x20','type','has','EXISTING_HOOK_BINDING_PRESERVED','utf8','validation','runtime\x20cache\x20clear\x20failed'];a44_0x3283=function(){return _0x204300;};return a44_0x3283();}function formatPushMessage(_0x5e031d,_0x3e1fda,_0x1a3e8f,_0x4054c5,_0x2140ed){const _0x35676c=a44_0xad0615,_0x116840=[_0x35676c(0x22a)+_0x5e031d+_0x35676c(0x1e3),_0x3e1fda+'\x20skipped'];_0x1a3e8f>0x0&&_0x116840[_0x35676c(0x225)](_0x1a3e8f+_0x35676c(0x1cb)+(_0x1a3e8f===0x1?'':'s')+'\x20'+(_0x1a3e8f===0x1?_0x35676c(0x209):_0x35676c(0x222))+_0x35676c(0x213));if(_0x4054c5>0x0)_0x116840['push'](_0x4054c5+'\x20failed');return _0x116840[_0x35676c(0x225)](_0x2140ed),_0x116840[_0x35676c(0x218)](',\x20');}async function getTargetFunctions(_0x2eaa5b,_0x448ab0){const _0x5243ea=a44_0xad0615,_0x337f17=_0x448ab0[_0x5243ea(0x1f8)]('type'),_0x1488bd=_0x448ab0[_0x5243ea(0x1f8)](_0x5243ea(0x1e8)),_0x27d159=normalizeBffType(_0x337f17)??undefined;if(_0x1488bd&&!_0x27d159)throw CliErrors[_0x5243ea(0x1ba)](_0x5243ea(0x1c7));const _0x330b0d=await scanLocalBffFunctions(_0x2eaa5b,_0x27d159);if(_0x1488bd){const _0x234dec=_0x330b0d[_0x5243ea(0x1d5)](_0x8968ee=>_0x8968ee[_0x5243ea(0x1e8)]===_0x1488bd);if(_0x234dec[_0x5243ea(0x1f1)]===0x0)throw CliErrors['validation'](_0x5243ea(0x1d6)+_0x27d159+'/'+_0x1488bd);return _0x234dec;}return _0x330b0d;}function existingHookWarning(_0x4719e7){const _0x48f89b=a44_0xad0615;return{'code':_0x48f89b(0x1b8),'lockKey':_0x4719e7,'message':_0x48f89b(0x1fc)};}async function buildHookMaps(_0x4e2b8f,_0x2624d1,_0x272340,_0x18d400,_0x3bbf26){const _0x199866=a44_0xad0615,_0x17c5a0=_0x272340[_0x199866(0x223)](_0x3f0f24=>_0x3f0f24[_0x199866(0x22b)]==='HOOK');if(!_0x17c5a0)return{'resolutions':new Map(),'failures':new Map(),'existingHooks':new Set()};const _0x2d6e2e=resolveApiModelSource(_0x2624d1,_0x4e2b8f,_0x3bbf26),_0x1ce584=loadAliasMap(_0x2624d1,undefined,_0x2d6e2e['filePath'],_0x2d6e2e[_0x199866(0x1d3)]);assertUnambiguousHookAliases(_0x1ce584);const _0x54c25c=[..._0x1ce584[_0x199866(0x1c6)](_0x525ebc=>[_0x525ebc[_0x199866(0x1e6)],_0x525ebc[_0x199866(0x1d9)]]),...trackedHookDirectoryMappings(_0x18d400)[_0x199866(0x1c6)](_0x4fafe8=>[_0x4fafe8[_0x199866(0x1e6)],_0x4fafe8[_0x199866(0x1d9)]])],_0x3077b7=await listDatasets(_0x4e2b8f);assertUnambiguousHookDirectoryMappings(_0x54c25c[_0x199866(0x1c6)](([_0x41f303,_0x13f596])=>({'alias':_0x41f303,'datasetCode':_0x13f596})));const _0x348128=buildHookDirectoryIndexes(_0x3077b7,_0x54c25c),_0x3c9795=new Map(),_0x57af78=preflightPushHookDirectories(_0x272340,_0x18d400,_0x348128,_0x3c9795),_0x3a5b80=new Set(),_0x373b2d=_0x272340['filter'](_0x16a75a=>_0x3c9795[_0x199866(0x226)](_0x16a75a[_0x199866(0x1f3)])?.[_0x199866(0x1d7)](_0x199866(0x1ee))&&_0x18d400[_0x199866(0x1e4)][_0x16a75a[_0x199866(0x1f3)]]?.[_0x199866(0x1fa)]&&_0x18d400[_0x199866(0x1e4)][_0x16a75a[_0x199866(0x1f3)]]?.[_0x199866(0x1d9)]);if(_0x373b2d[_0x199866(0x1f1)]>0x0){let _0x445a60;try{_0x445a60=await getBffScriptStatistics(_0x4e2b8f);}catch(_0x317dd4){for(const _0x4ace7d of _0x373b2d)_0x3c9795['set'](_0x4ace7d[_0x199866(0x1f3)],_0x199866(0x207)+(_0x317dd4 instanceof Error?_0x317dd4[_0x199866(0x1df)]:String(_0x317dd4)));return{'resolutions':_0x57af78,'failures':_0x3c9795,'existingHooks':_0x3a5b80};}for(const _0x15e312 of _0x373b2d){const _0x1af62c=_0x18d400[_0x199866(0x1e4)][_0x15e312['lockKey']];try{const _0xb71ffd=new Set(_0x272340[_0x199866(0x1d5)](_0x2f18b7=>_0x2f18b7[_0x199866(0x22b)]===_0x199866(0x21b)&&_0x18d400[_0x199866(0x1e4)][_0x2f18b7['lockKey']]?.['datasetCode']===_0x1af62c[_0x199866(0x1d9)])[_0x199866(0x1c6)](_0x20fe21=>_0x20fe21[_0x199866(0x1e6)]));if(_0xb71ffd[_0x199866(0x1c8)]>0x1)throw CliErrors[_0x199866(0x1ba)](_0x199866(0x20a));const _0x3a6a08=_0x445a60[_0x199866(0x210)](_0x26f7a2=>[{'datasetCode':_0x26f7a2['datasetCode'],'operationType':snakeToCamel(_0x26f7a2[_0x199866(0x1ed)]),'functionNode':_0x199866(0x1ce),'id':_0x26f7a2[_0x199866(0x227)]},{'datasetCode':_0x26f7a2['datasetCode'],'operationType':snakeToCamel(_0x26f7a2['operationType']),'functionNode':'after','id':_0x26f7a2[_0x199866(0x1c2)]}])[_0x199866(0x1d5)](_0x31f27d=>_0x31f27d['id']===_0x1af62c[_0x199866(0x1fa)]),_0x68a49b=await getBffScriptInfo(_0x1af62c[_0x199866(0x1fa)]);if(_0x68a49b['id']!==_0x1af62c['remoteId']||_0x68a49b[_0x199866(0x1fd)]!==_0x4e2b8f||_0x68a49b[_0x199866(0x1e5)]!==_0x199866(0x21b)||_0x68a49b[_0x199866(0x1ca)]!==_0x15e312[_0x199866(0x1e8)]||_0x1af62c['version']==null||_0x68a49b[_0x199866(0x1ef)]!==_0x1af62c['version']||_0x3a6a08[_0x199866(0x1f1)]!==0x1||_0x3a6a08[0x0]['datasetCode']!==_0x1af62c[_0x199866(0x1d9)]||_0x3a6a08[0x0][_0x199866(0x1ed)]!==_0x15e312[_0x199866(0x1ed)]||_0x3a6a08[0x0][_0x199866(0x20d)]!==_0x15e312[_0x199866(0x20d)]||_0x1af62c[_0x199866(0x1ed)]!==_0x15e312[_0x199866(0x1ed)]||_0x1af62c['functionNode']!==_0x15e312['functionNode'])throw CliErrors['validation'](_0x199866(0x20e));_0x3a5b80[_0x199866(0x21e)](_0x15e312['lockKey']),_0x3c9795[_0x199866(0x211)](_0x15e312[_0x199866(0x1f3)]);}catch(_0x1421b3){_0x3c9795[_0x199866(0x1d4)](_0x15e312[_0x199866(0x1f3)],_0x1421b3 instanceof Error?_0x1421b3[_0x199866(0x1df)]:String(_0x1421b3));}}}return{'resolutions':_0x57af78,'failures':_0x3c9795,'existingHooks':_0x3a5b80};}async function uploadSingleFunction(_0x41082a,_0x252b88,_0xcae50b,_0x504c0e){const _0x818bb1=a44_0xad0615,_0x20081f=await readFile(_0x252b88[_0x818bb1(0x1de)],_0x818bb1(0x1b9)),_0x5ac78e=await computeFileHash(_0x252b88[_0x818bb1(0x1de)]),_0x11d353=_0xcae50b[_0x818bb1(0x1e4)][_0x252b88['lockKey']];if(_0x11d353?.[_0x818bb1(0x1fa)]&&_0x11d353[_0x818bb1(0x1ef)]==null)throw CliErrors[_0x818bb1(0x1ba)](_0x252b88[_0x818bb1(0x1f3)]+_0x818bb1(0x216));let _0x20e499=extractScriptDescription(_0x20081f);if(!_0x20e499&&_0x11d353?.['remoteId']){const _0x437872=await getBffScriptInfo(_0x11d353['remoteId']);_0x20e499=_0x437872[_0x818bb1(0x1c4)]||undefined;}const _0x1413f1={'appCode':_0x41082a,'functionName':_0x252b88[_0x818bb1(0x1e8)],'scriptType':_0x252b88[_0x818bb1(0x22b)],'scriptContent':_0x20081f};if(_0x11d353?.['remoteId'])_0x1413f1['id']=_0x11d353[_0x818bb1(0x1fa)];if(_0x11d353?.[_0x818bb1(0x1ef)]!=null)_0x1413f1[_0x818bb1(0x1ef)]=_0x11d353[_0x818bb1(0x1ef)];if(_0x20e499)_0x1413f1[_0x818bb1(0x1c4)]=_0x20e499;if(_0x252b88[_0x818bb1(0x22b)]==='HOOK'){const _0x43ed73=_0x504c0e['resolutions'][_0x818bb1(0x226)](_0x252b88[_0x818bb1(0x1f3)]);if(!_0x43ed73&&!_0x504c0e['existingHooks'][_0x818bb1(0x1b7)](_0x252b88[_0x818bb1(0x1f3)])||!_0x252b88[_0x818bb1(0x1ed)]||!_0x252b88[_0x818bb1(0x20d)])throw CliErrors['validation'](_0x818bb1(0x1f7)+_0x252b88[_0x818bb1(0x1f3)]);_0x43ed73&&(_0x1413f1[_0x818bb1(0x1f2)]=_0x43ed73[_0x818bb1(0x1c9)]['id'],_0x1413f1[_0x818bb1(0x1ed)]=_0x252b88[_0x818bb1(0x1ed)]),_0x1413f1[_0x818bb1(0x20d)]=_0x252b88[_0x818bb1(0x20d)];}const _0x4d3495=await saveBffScript(_0x1413f1),_0x3b295a=_0x4d3495['id'],_0x364f97=_0x4d3495[_0x818bb1(0x1cf)]??await getBffScriptInfo(_0x3b295a),_0x12c99d={'hash':_0x5ac78e,'remoteId':_0x3b295a,'version':_0x364f97[_0x818bb1(0x1ef)]};if(_0x252b88[_0x818bb1(0x22b)]===_0x818bb1(0x21b)){const _0x556d1a=_0x504c0e[_0x818bb1(0x1c5)][_0x818bb1(0x226)](_0x252b88[_0x818bb1(0x1f3)]);if(!_0x556d1a){_0xcae50b[_0x818bb1(0x1e4)][_0x252b88[_0x818bb1(0x1f3)]]={..._0x11d353,..._0x12c99d};return;}_0x12c99d[_0x818bb1(0x1e6)]=_0x556d1a[_0x818bb1(0x1e6)]??_0x11d353?.[_0x818bb1(0x1e6)],_0x12c99d[_0x818bb1(0x1d9)]=_0x556d1a['datasetCode'],_0x12c99d[_0x818bb1(0x1ed)]=_0x252b88[_0x818bb1(0x1ed)],_0x12c99d[_0x818bb1(0x20d)]=_0x252b88[_0x818bb1(0x20d)];}_0xcae50b[_0x818bb1(0x1e4)][_0x252b88[_0x818bb1(0x1f3)]]=_0x12c99d;}const LOCK_SETTLE_RETRY_COUNT=0x14,LOCK_SETTLE_DELAY_MS=0x64;async function waitForUploadedLockEntries(_0x16b99b,_0x15fac8,_0x2cc9f0){const _0x1f9fc7=a44_0xad0615;if(_0x2cc9f0[_0x1f9fc7(0x1f1)]===0x0)return;for(let _0x1b8dfa=0x0;_0x1b8dfa<LOCK_SETTLE_RETRY_COUNT;_0x1b8dfa+=0x1){const _0x13eed1=await readBffLockFile(_0x16b99b),_0x545abe=_0x13eed1?.['apps']?.[_0x15fac8]?.['functions']??{},_0x59d6f7=_0x2cc9f0[_0x1f9fc7(0x205)](_0x2ea208=>!!_0x545abe[_0x2ea208]?.[_0x1f9fc7(0x1fa)]);if(_0x59d6f7)return;await sleep(LOCK_SETTLE_DELAY_MS);}throw new Error(_0x1f9fc7(0x20c)+_0x2cc9f0['join'](',\x20')+'.');}
|
|
1
|
+
import{readFile}from"node:fs/promises";import{saveBffScript,getBffScriptInfo,getBffScriptStatistics,getPlatformErrorCode,listDatasets,clearBffScriptCache}from"../../core/api-client.js";import{loadAliasMap}from"../../core/alias-resolver.js";import{resolveApiModelSource}from"../../api/model-source.js";import{loadBffProjectConfig}from"../../core/bff/config.js";import{normalizeBffType,scanLocalBffFunctions}from"../../core/bff/file-system.js";import{buildHookDirectoryIndexes,assertUnambiguousHookAliases,assertUnambiguousHookDirectoryMappings,preflightPushHookDirectories,trackedHookDirectoryMappings}from"../../core/bff/hook-directory.js";import{computeFileHash}from"../../core/bff/hash.js";import{createEmptyBffLock,ensureLockScope,readBffLockFile,writeBffLockFile}from"../../core/bff/lock.js";import{extractScriptDescription,snakeToCamel}from"../../core/bff/utils.js";import{sleep}from"../../utils/sleep.js";import{CLI_BIN_NAME}from"../../constant/cli.js";import{CliErrors}from"../../errors.js"
|
|
2
|
+
;const CACHE_CLEAR_ATTEMPTS=2;const CACHE_CLEAR_INTERVAL_MS=300;export const bffPush={service:"bff",command:"push",description:"Push local Backend Function scripts to remote",risk:"write",structuredErrors:true,flags:[{name:"type",type:"string",description:"Push only this script type",enum:["COMMON","ENDPOINT","HOOK"]},{name:"name",type:"string",description:"Push only the named function (requires --type)"},{name:"force",type:"boolean",description:"Force push ignoring hash protection"}],async dryRun(ctx){const config=loadBffProjectConfig(ctx.appCode);const rawLock=await readBffLockFile(config.lockFilePath);const{appLock:appLock}=ensureLockScope(rawLock??createEmptyBffLock(),ctx.appCode,config.scriptsRoot,"push");const localFunctions=await getTargetFunctions(config,ctx);const preflightFunctions=localFunctions.some(fn=>fn.type==="HOOK")?await scanLocalBffFunctions(config,"HOOK"):localFunctions
|
|
3
|
+
;const hookMaps=await buildHookMaps(ctx.appCode,ctx.apiDir,preflightFunctions,appLock,ctx.selectedAppName||ctx.mergedCli?.currentApp||ctx.mergedCli?.defaultApp);const force=ctx.bool("force");const preview=[];for(const fn of localFunctions){const localHash=await computeFileHash(fn.filePath);const lockEntry=appLock.functions[fn.lockKey];const unchanged=!!lockEntry&&lockEntry.hash===localHash;const hook=hookMaps.resolutions.get(fn.lockKey);const missingRemoteVersion=!!lockEntry?.remoteId&&lockEntry.version==null&&(force||!unchanged);const conflict=missingRemoteVersion?missingRemoteVersionConflict(fn,lockEntry):undefined;const status=hookMaps.failures.has(fn.lockKey)?"failed":!force&&unchanged?"unchanged":conflict?"conflict":"would_push";preview.push({lockKey:fn.lockKey,filePath:fn.filePath,remoteId:lockEntry?.remoteId??null,mode:lockEntry?.remoteId?"update":"create",status:status,...hookMaps.failures.has(fn.lockKey)?{error:hookMaps.failures.get(fn.lockKey)}:{},...conflict?{
|
|
4
|
+
conflict:conflict}:{},...hookMaps.existingHooks.has(fn.lockKey)?{datasetCode:lockEntry?.datasetCode,bindingPreserved:true,warnings:[existingHookWarning(fn.lockKey)]}:{},...hook?{alias:hook.alias??null,datasetCode:hook.datasetCode,operationType:fn.operationType,functionNode:fn.functionNode,warnings:hook.warnings}:{}})}return{method:"POST",url:"/api/management/library/scripts/save",body:{appCode:ctx.appCode,force:force,files:preview,cacheClearAtRuntime:preview.some(item=>item.status==="would_push"),cacheClearAtRuntimeTimes:preview.some(item=>item.status==="would_push")?CACHE_CLEAR_ATTEMPTS:0},description:`Would inspect ${preview.length} local Backend Function script(s) for push and clear runtime cache if files are uploaded`}},async execute(ctx){const config=loadBffProjectConfig(ctx.appCode);const rawLock=await readBffLockFile(config.lockFilePath);const{lockData:lockData,appLock:appLock}=ensureLockScope(rawLock??createEmptyBffLock(),ctx.appCode,config.scriptsRoot,"push")
|
|
5
|
+
;const localFunctions=await getTargetFunctions(config,ctx);if(localFunctions.length===0){return{ok:true,data:{uploaded:[],skipped:[],conflicts:[],failed:[]},message:"No local Backend Function scripts found."}}const force=ctx.bool("force");const nextLockData=JSON.parse(JSON.stringify(lockData));const nextAppLock=nextLockData.apps[ctx.appCode];if(!nextAppLock){throw new Error(`Lock scope for app "${ctx.appCode}" not found after ensureLockScope.`)}const preflightFunctions=localFunctions.some(fn=>fn.type==="HOOK")?await scanLocalBffFunctions(config,"HOOK"):localFunctions;const hookMaps=await buildHookMaps(ctx.appCode,ctx.apiDir,preflightFunctions,nextAppLock,ctx.selectedAppName||ctx.mergedCli?.currentApp||ctx.mergedCli?.defaultApp);const uploaded=[];const skipped=[];const conflicts=[];const failed=[];for(const fn of localFunctions){const preflightError=hookMaps.failures.get(fn.lockKey);if(preflightError){failed.push({lockKey:fn.lockKey,error:preflightError});continue}
|
|
6
|
+
const localHash=await computeFileHash(fn.filePath);const lockEntry=nextAppLock.functions[fn.lockKey];if(!force&&lockEntry&&lockEntry.hash===localHash){skipped.push({lockKey:fn.lockKey,reason:"unchanged"});continue}if(lockEntry?.remoteId&&lockEntry.version==null){conflicts.push(missingRemoteVersionConflict(fn,lockEntry));continue}try{await uploadSingleFunction(ctx.appCode,fn,nextAppLock,hookMaps);const entry=nextAppLock.functions[fn.lockKey];uploaded.push({lockKey:fn.lockKey,remoteId:entry?.remoteId??0})}catch(error){const conflict=remoteVersionChangedConflict(fn,lockEntry,error);if(conflict){conflicts.push(conflict);continue}failed.push({lockKey:fn.lockKey,error:error instanceof Error?error.message:String(error)})}}nextAppLock.lastSync=(new Date).toISOString();await writeBffLockFile(config.lockFilePath,nextLockData);await waitForUploadedLockEntries(config.lockFilePath,ctx.appCode,uploaded.map(item=>item.lockKey));let cacheClear={attempted:false,cleared:false};if(uploaded.length>0){try{
|
|
7
|
+
let message="";for(let attempt=0;attempt<CACHE_CLEAR_ATTEMPTS;attempt+=1){message=await clearBffScriptCache();if(attempt<CACHE_CLEAR_ATTEMPTS-1){await sleep(CACHE_CLEAR_INTERVAL_MS)}}cacheClear={attempted:true,cleared:true,message:message||"Runtime script cache cleared."}}catch(error){cacheClear={attempted:true,cleared:false,error:error instanceof Error?error.message:String(error)}}}const primarySucceeded=failed.length===0&&(cacheClear.attempted?cacheClear.cleared:true);const ok=primarySucceeded;const cacheMessage=cacheClear.attempted?cacheClear.cleared?"runtime cache cleared":"runtime cache clear failed":"runtime cache not needed";return{ok:ok,data:{uploaded:uploaded,skipped:skipped,conflicts:conflicts,failed:failed,cacheClear:cacheClear,warnings:[...[...hookMaps.resolutions.values()].flatMap(item=>item.warnings),...[...hookMaps.existingHooks].map(existingHookWarning)]},message:formatPushMessage(uploaded.length,skipped.length,conflicts.length,failed.length,cacheMessage)}}}
|
|
8
|
+
;function missingRemoteVersionConflict(fn,lockEntry){return remoteVersionConflict(fn,lockEntry,"BFF_REMOTE_VERSION_MISSING","The local sync lock has no remote version for this script.")}function remoteVersionChangedConflict(fn,lockEntry,error){if(!lockEntry?.remoteId||lockEntry.version==null||!isRemoteVersionConflict(error)){return undefined}return remoteVersionConflict(fn,lockEntry,"BFF_REMOTE_VERSION_CHANGED","Remote script version changed since the last pull.")}function remoteVersionConflict(fn,lockEntry,code,message){return{code:code,lockKey:fn.lockKey,filePath:fn.filePath,remoteId:lockEntry.remoteId,...lockEntry.version!=null?{expectedVersion:lockEntry.version}:{},message:message,nextAction:{action:"review_remote_and_merge",command:`${CLI_BIN_NAME} bff detail --id ${lockEntry.remoteId} --format compress`,requiresReview:true,message:"Review the current remote source, merge it into the local script, then retry push. Do not use --force unless you intentionally discard local changes."
|
|
9
|
+
}}}function isRemoteVersionConflict(error){const message=error instanceof Error?error.message:String(error);const remoteCode=getPlatformErrorCode(error)??"";return[message,remoteCode].some(value=>/(?:version|optimistic)[\s_-]*(?:conflict|mismatch|changed|stale|out[\s_-]*of[\s_-]*date)|(?:conflict|mismatch|changed|stale|out[\s_-]*of[\s_-]*date)[\s_-]*(?:version|optimistic)/i.test(value))}function formatPushMessage(uploaded,skipped,conflicts,failed,cacheMessage){const parts=[`Push complete: ${uploaded} uploaded`,`${skipped} skipped`];if(conflicts>0){parts.push(`${conflicts} conflict${conflicts===1?"":"s"} ${conflicts===1?"requires":"require"} resolution`)}if(failed>0)parts.push(`${failed} failed`);parts.push(cacheMessage);return parts.join(", ")}async function getTargetFunctions(config,ctx){const typeFlag=ctx.str("type");const nameFlag=ctx.str("name");const filterType=normalizeBffType(typeFlag)??undefined;if(nameFlag&&!filterType){
|
|
10
|
+
throw CliErrors.validation("--name requires --type to identify the function.")}const allFunctions=await scanLocalBffFunctions(config,filterType);if(nameFlag){const matches=allFunctions.filter(fn=>fn.name===nameFlag);if(matches.length===0){throw CliErrors.validation(`Local function not found: ${filterType}/${nameFlag}`)}return matches}return allFunctions}function existingHookWarning(lockKey){return{code:"EXISTING_HOOK_BINDING_PRESERVED",lockKey:lockKey,message:"Dataset metadata is unavailable; the existing script and binding were verified. Update by script ID without rebinding."}}async function buildHookMaps(appCode,apiDir,localFunctions,appLock,selectedAppName){const hasHooks=localFunctions.some(fn=>fn.type==="HOOK");if(!hasHooks)return{resolutions:new Map,failures:new Map,existingHooks:new Set};const source=resolveApiModelSource(apiDir,appCode,selectedAppName);const aliasEntries=loadAliasMap(apiDir,undefined,source.filePath,source.profileName)
|
|
11
|
+
;assertUnambiguousHookAliases(aliasEntries);const aliasToDatasetCode=[...aliasEntries.map(entry=>[entry.alias,entry.datasetCode]),...trackedHookDirectoryMappings(appLock).map(entry=>[entry.alias,entry.datasetCode])];const datasets=await listDatasets(appCode);assertUnambiguousHookDirectoryMappings(aliasToDatasetCode.map(([alias,datasetCode])=>({alias:alias,datasetCode:datasetCode})));const indexes=buildHookDirectoryIndexes(datasets,aliasToDatasetCode);const failures=new Map;const resolutions=preflightPushHookDirectories(localFunctions,appLock,indexes,failures);const existingHooks=new Set;const candidates=localFunctions.filter(fn=>failures.get(fn.lockKey)?.startsWith("HOOK_DATASET_NOT_FOUND:")&&appLock.functions[fn.lockKey]?.remoteId&&appLock.functions[fn.lockKey]?.datasetCode);if(candidates.length>0){let statistics;try{statistics=await getBffScriptStatistics(appCode)}catch(error){
|
|
12
|
+
for(const fn of candidates)failures.set(fn.lockKey,`Cannot verify existing HOOK binding: ${error instanceof Error?error.message:String(error)}`);return{resolutions:resolutions,failures:failures,existingHooks:existingHooks}}for(const fn of candidates){const entry=appLock.functions[fn.lockKey];try{const directories=new Set(localFunctions.filter(item=>item.type==="HOOK"&&appLock.functions[item.lockKey]?.datasetCode===entry.datasetCode).map(item=>item.alias));if(directories.size>1){throw CliErrors.validation("Multiple HOOK directories reference the same missing Dataset. Resolve duplicate directories before pushing.")}const bindings=statistics.flatMap(item=>[{datasetCode:item.datasetCode,operationType:snakeToCamel(item.operationType),functionNode:"before",id:item.beforeScriptId},{datasetCode:item.datasetCode,operationType:snakeToCamel(item.operationType),functionNode:"after",id:item.afterScriptId}]).filter(item=>item.id===entry.remoteId);const remote=await getBffScriptInfo(entry.remoteId)
|
|
13
|
+
;if(remote.id!==entry.remoteId||remote.appCode!==appCode||remote.scriptType!=="HOOK"||remote.functionName!==fn.name||entry.version==null||remote.version!==entry.version||bindings.length!==1||bindings[0].datasetCode!==entry.datasetCode||bindings[0].operationType!==fn.operationType||bindings[0].functionNode!==fn.functionNode||entry.operationType!==fn.operationType||entry.functionNode!==fn.functionNode){throw CliErrors.validation("Existing HOOK identity, version or binding does not match the local lock. Pull and review before pushing.")}existingHooks.add(fn.lockKey);failures.delete(fn.lockKey)}catch(error){failures.set(fn.lockKey,error instanceof Error?error.message:String(error))}}}return{resolutions:resolutions,failures:failures,existingHooks:existingHooks}}async function uploadSingleFunction(appCode,fn,appLock,hookMaps){const sourceCode=await readFile(fn.filePath,"utf8");const hash=await computeFileHash(fn.filePath);const lockEntry=appLock.functions[fn.lockKey]
|
|
14
|
+
;if(lockEntry?.remoteId&&lockEntry.version==null){throw CliErrors.validation(`${fn.lockKey}: missing remote version. Run \`push\` after \`pull\` to sync version info.`)}let descriptionToSend=extractScriptDescription(sourceCode);if(!descriptionToSend&&lockEntry?.remoteId){const remote=await getBffScriptInfo(lockEntry.remoteId);descriptionToSend=remote.description||undefined}const payload={appCode:appCode,functionName:fn.name,scriptType:fn.type,scriptContent:sourceCode};if(lockEntry?.remoteId)payload["id"]=lockEntry.remoteId;if(lockEntry?.version!=null)payload["version"]=lockEntry.version;if(descriptionToSend)payload["description"]=descriptionToSend;if(fn.type==="HOOK"){const hook=hookMaps.resolutions.get(fn.lockKey);if(!hook&&!hookMaps.existingHooks.has(fn.lockKey)||!fn.operationType||!fn.functionNode){throw CliErrors.validation(`Incomplete HOOK path: ${fn.lockKey}`)}if(hook){payload["datasetId"]=hook.dataset.id;payload["operationType"]=fn.operationType}
|
|
15
|
+
payload["functionNode"]=fn.functionNode}const saved=await saveBffScript(payload);const remoteId=saved.id;const latestScript=saved.script??await getBffScriptInfo(remoteId);const nextEntry={hash:hash,remoteId:remoteId,version:latestScript.version};if(fn.type==="HOOK"){const hook=hookMaps.resolutions.get(fn.lockKey);if(!hook){appLock.functions[fn.lockKey]={...lockEntry,...nextEntry};return}nextEntry.alias=hook.alias??lockEntry?.alias;nextEntry.datasetCode=hook.datasetCode;nextEntry.operationType=fn.operationType;nextEntry.functionNode=fn.functionNode}appLock.functions[fn.lockKey]=nextEntry}const LOCK_SETTLE_RETRY_COUNT=20;const LOCK_SETTLE_DELAY_MS=100;async function waitForUploadedLockEntries(lockFilePath,appCode,lockKeys){if(lockKeys.length===0)return;for(let i=0;i<LOCK_SETTLE_RETRY_COUNT;i+=1){const latestLock=await readBffLockFile(lockFilePath);const functions=latestLock?.apps?.[appCode]?.functions??{};const allPresent=lockKeys.every(lockKey=>!!functions[lockKey]?.remoteId)
|
|
16
|
+
;if(allPresent)return;await sleep(LOCK_SETTLE_DELAY_MS)}throw new Error(`Lock file not settled after push for ${lockKeys.join(", ")}.`)}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import{listBffScripts,getBffScriptStatistics}from"../../core/api-client.js";import{loadAliasMap}from"../../core/alias-resolver.js";import{resolveApiModelSource}from"../../api/model-source.js";import{loadBffProjectConfig}from"../../core/bff/config.js";import{createHookLocationMap,resolveRemoteScriptTarget,scanLocalBffFunctions}from"../../core/bff/file-system.js";import{computeFileHash}from"../../core/bff/hash.js";import{createEmptyBffLock,ensureLockScope,readBffLockFile}from"../../core/bff/lock.js";export const bffStatus={service:"bff",command:"status",description:"Check local Backend Function sync status against lock file",risk:"read",flags:[{name:"remote",type:"boolean",description:"Also check for remote-only scripts not present locally"}],async execute(ctx){const config=loadBffProjectConfig(ctx.appCode);const rawLock=await readBffLockFile(config.lockFilePath);const{appLock:appLock}=ensureLockScope(rawLock??createEmptyBffLock(),ctx.appCode,config.scriptsRoot,"status")
|
|
2
|
+
;const localFunctions=await scanLocalBffFunctions(config);const added=[];const modified=[];const unchanged=[];for(const fn of localFunctions){const localHash=await computeFileHash(fn.filePath);const lockEntry=appLock.functions[fn.lockKey];if(!lockEntry){added.push(fn.lockKey)}else if(lockEntry.hash!==localHash){modified.push(fn.lockKey)}else{unchanged.push(fn.lockKey)}}const remoteOnly=[];if(ctx.bool("remote")){const source=resolveApiModelSource(ctx.apiDir,ctx.appCode,ctx.selectedAppName||ctx.mergedCli?.currentApp||ctx.mergedCli?.defaultApp);const aliasEntries=loadAliasMap(ctx.apiDir,undefined,source.filePath,source.profileName);const datasetCodeToAlias=new Map(aliasEntries.map(e=>[e.datasetCode,e.alias]));const[scripts,statistics]=await Promise.all([listBffScripts(ctx.appCode),getBffScriptStatistics(ctx.appCode)]);const hookLocationMap=createHookLocationMap(statistics);const localKeys=new Set(localFunctions.map(fn=>fn.lockKey));for(const script of scripts){
|
|
3
|
+
const target=resolveRemoteScriptTarget(config,script,hookLocationMap,appLock.functions,datasetCodeToAlias);if(target&&!localKeys.has(target.lockKey)){remoteOnly.push(target.lockKey)}}}const synced=added.length===0&&modified.length===0&&remoteOnly.length===0;return{ok:true,data:{added:added,modified:modified,unchanged:unchanged,remoteOnly:remoteOnly},message:synced?"All Backend Function scripts are in sync.":`${added.length} added, ${modified.length} modified, ${unchanged.length} unchanged`+(remoteOnly.length>0?`, ${remoteOnly.length} remote-only`:"")}}};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{CliErrors}from"../../errors.js";import{installBuiltinSkill}from"../../skills/builtin-skill.js";import{logger}from"../../utils/logger.js";export const cliSkillDefinitions=[{service:"cli-skill",command:"install",description:"Install or refresh the Rabetbase CLI Built-in Skill",risk:"read",requiresAuth:false,requiresAppCode:false,hasFormat:false,flags:[],async execute(ctx){logger.setLogPath(process.cwd());logger.info("cli-skill-install","Installing CLI Built-in Skill from the current package.");const result=installBuiltinSkill({stdio:ctx.nonInteractive?"pipe":"inherit"});if(!result.ok){throw CliErrors.apiError(`Built-in Skill install failed [${result.code}]: ${result.error||"unknown"}`,`Resolve the Skills CLI installation issue and run: ${result.repairCommand}`)}
|
|
2
|
+
console.log(result.changed?`CLI Built-in Skill ${result.skillVersion} installed${result.installedPath?` at ${result.installedPath}`:" via local skills installer"}`:`CLI Built-in Skill ${result.skillVersion} is already current${result.installedPath?` at ${result.installedPath}`:""}`);return{ok:true}}}];
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
const a47_0x5bb842=a47_0x107d;(function(_0x3e79cb,_0x23ea10){const _0x5be222=a47_0x107d,_0x1d64a9=_0x3e79cb();while(!![]){try{const _0x2160bb=parseInt(_0x5be222(0xf7))/0x1+parseInt(_0x5be222(0xeb))/0x2*(parseInt(_0x5be222(0xb1))/0x3)+-parseInt(_0x5be222(0xed))/0x4+-parseInt(_0x5be222(0xba))/0x5+-parseInt(_0x5be222(0xe8))/0x6*(parseInt(_0x5be222(0xf1))/0x7)+parseInt(_0x5be222(0xad))/0x8+parseInt(_0x5be222(0xc8))/0x9;if(_0x2160bb===_0x23ea10)break;else _0x1d64a9['push'](_0x1d64a9['shift']());}catch(_0x438460){_0x1d64a9['push'](_0x1d64a9['shift']());}}}(a47_0xf05d,0x495fe));import a47_0x378bf7 from'chalk';import a47_0xf35b70 from'ora';import a47_0x353f3f from'semver';import{execa}from'execa';function a47_0x107d(_0x47ccbe,_0x2c5152){_0x47ccbe=_0x47ccbe-0xac;const _0xf05d67=a47_0xf05d();let _0x107d2a=_0xf05d67[_0x47ccbe];return _0x107d2a;}import{CLI_BIN_NAME,NPM_PACKAGE_NAME}from'../constant/cli.js';import{VERSION,GIT_COMMIT,BUILD_TIME}from'../generated/build-info.js';import{CliErrors}from'../errors.js';import{inspectInstalledBuiltinSkillVersion,installBuiltinSkill}from'../skills/builtin-skill.js';import{resolveNpmBin}from'../utils/platform.js';function getCurrentVersion(){const _0xea799e=a47_0x107d;return GIT_COMMIT!==_0xea799e(0xdb)?VERSION+'\x20('+GIT_COMMIT+',\x20'+BUILD_TIME[_0xea799e(0xb7)](0x0,0xa)+')':VERSION;}function detectPackageManager(){const _0x5c6c72=a47_0x107d,_0x57f798=process['execPath'][_0x5c6c72(0xc6)]();if(_0x57f798['includes']('bun'))return'bun';return _0x5c6c72(0xbf);}const updateFlags=[{'name':'beta','type':a47_0x5bb842(0xe0),'description':a47_0x5bb842(0xb9),'default':![]},{'name':a47_0x5bb842(0xdd),'type':a47_0x5bb842(0xb6),'description':'Install\x20a\x20specific\x20CLI\x20version'}];function getRequestedVersion(_0x9241d5){const _0x4bc17b=a47_0x5bb842;return _0x9241d5[_0x4bc17b(0x100)](_0x4bc17b(0xdd))[_0x4bc17b(0xe9)]();}function a47_0xf05d(){const _0x361814=['Try\x20manually:\x20','Unable\x20to\x20resolve\x20beta\x20version\x20from\x20npm','source','Run:\x20','expected\x20','state','/dist-tags','Current\x20version:\x20',',\x20then\x20verify\x20with:\x20','beta','unknown','Update\x20failed','version','start','valid','boolean','repairCommand',',\x20state\x20','CLI\x20Built-in\x20Skill\x20repair\x20failed\x20[','read','Unable\x20to\x20check\x20for\x20updates\x20(network\x20error)','--beta\x20and\x20--version\x20cannot\x20be\x20used\x20together.','object','1223058FIbCAI','trim','Beta\x20version:\x20','186qaVulK','fail','418996cwcdjk','\x20doctor','message','run','7zwVwnS','Already\x20on\x20requested\x20version\x20(v','\x20→\x20','Update\x20available:\x20','json','Requested\x20version:\x20','306549GFULoI','current','Try\x20manually:\x20npm\x20install\x20-g\x20','map','\x20update\x20--version\x20<version>','CLI\x20updated\x20to\x20v','bool','length','Updating\x20via\x20','str','validation','skillVersion','272624GKWcSN','pipe','Update\x20rabetbase\x20CLI\x20to\x20the\x20latest\x20version','filter','3447rCvIuN','update','Checking\x20for\x20updates...','green','Invalid\x20version:\x20','string','slice','\x20install\x20-g\x20','Install\x20the\x20version\x20from\x20npm\x20beta\x20dist-tag','1433920BAuhSN','\x20is\x20newer\x20than\x20npm\x20latest\x20v','yellow','Choose\x20either\x20npm\x20beta\x20dist-tag\x20or\x20an\x20exact\x20version.','code','npm','succeed','...','https://registry.npmjs.org/-/package/','error','latest','\x20\x20CLI\x20Built-in\x20Skill\x20','toLowerCase','Already\x20up\x20to\x20date\x20(v','4035906cptpAc','log','apiError','gray','timeout',',\x20found\x20','Updated\x20to\x20v','Version\x20comparison\x20failed','\x20is\x20up\x20to\x20date.'];a47_0xf05d=function(){return _0x361814;};return a47_0xf05d();}async function validateUpdateFlags(_0x409ba7){const _0x270042=a47_0x5bb842,_0x45e429=_0x409ba7[_0x270042(0xfd)](_0x270042(0xda)),_0x3b50eb=getRequestedVersion(_0x409ba7);if(_0x45e429&&_0x3b50eb)throw CliErrors['validation'](_0x270042(0xe6),_0x270042(0xbd));if(_0x3b50eb&&!a47_0x353f3f[_0x270042(0xdf)](_0x3b50eb))throw CliErrors[_0x270042(0x101)](_0x270042(0xb5)+_0x3b50eb,'Use\x20a\x20full\x20semver\x20such\x20as\x202.1.6\x20or\x202.1.6-beta.1.');}async function fetchNpmDistTags(){const _0x478dd0=a47_0x5bb842;try{const _0x574525=await fetch(_0x478dd0(0xc2)+encodeURIComponent(NPM_PACKAGE_NAME)+_0x478dd0(0xd7),{'signal':AbortSignal[_0x478dd0(0xcc)](0x2710)});if(!_0x574525['ok'])return null;const _0x3514d2=await _0x574525[_0x478dd0(0xf5)]();if(!_0x3514d2||typeof _0x3514d2!==_0x478dd0(0xe7))return null;return Object['fromEntries'](Object['entries'](_0x3514d2)[_0x478dd0(0xb0)](([,_0x312e0a])=>typeof _0x312e0a===_0x478dd0(0xb6)&&_0x312e0a['trim']()[_0x478dd0(0xfe)]>0x0)[_0x478dd0(0xfa)](([_0x4e8de,_0x2dc194])=>[_0x4e8de,String(_0x2dc194)[_0x478dd0(0xe9)]()]));}catch{return null;}}async function fetchNpmDistTagVersion(_0x589d90){const _0x21dbc2=await fetchNpmDistTags();return _0x21dbc2?.[_0x589d90]??null;}async function fetchLatestVersion(){return fetchNpmDistTagVersion('latest');}async function resolveTargetVersion(_0x1e90ea){const _0x4a2615=a47_0x5bb842,_0x24dcde=getRequestedVersion(_0x1e90ea);if(_0x24dcde)return{'version':_0x24dcde,'source':_0x4a2615(0xdd)};if(_0x1e90ea[_0x4a2615(0xfd)](_0x4a2615(0xda))){const _0x97a04a=await fetchNpmDistTagVersion(_0x4a2615(0xda));if(!_0x97a04a)return null;return{'version':_0x97a04a,'source':_0x4a2615(0xda)};}const _0x1db257=await fetchLatestVersion();if(!_0x1db257)return null;return{'version':_0x1db257,'source':_0x4a2615(0xc4)};}function shouldInstallTarget(_0x111c93,_0x1940be){const _0xa90901=a47_0x5bb842;if(_0x1940be[_0xa90901(0xd3)]===_0xa90901(0xdd)||_0x1940be[_0xa90901(0xd3)]==='beta')return!a47_0x353f3f['eq'](_0x111c93,_0x1940be[_0xa90901(0xdd)]);return a47_0x353f3f['lt'](_0x111c93,_0x1940be[_0xa90901(0xdd)]);}function getInstallPlanLabel(_0xca0e0f,_0x105160){const _0x303131=a47_0x5bb842;switch(_0x105160['source']){case _0x303131(0xda):return _0x303131(0xea)+a47_0x378bf7[_0x303131(0xbc)](_0xca0e0f)+'\x20→\x20'+a47_0x378bf7[_0x303131(0xb4)](_0x105160[_0x303131(0xdd)]);case'version':return _0x303131(0xf6)+a47_0x378bf7[_0x303131(0xbc)](_0xca0e0f)+_0x303131(0xf3)+a47_0x378bf7['green'](_0x105160['version']);case _0x303131(0xc4):default:return _0x303131(0xf4)+a47_0x378bf7[_0x303131(0xbc)](_0xca0e0f)+'\x20→\x20'+a47_0x378bf7['green'](_0x105160[_0x303131(0xdd)]);}}function repairCurrentBuiltinSkill(){const _0x58eec5=a47_0x5bb842;console[_0x58eec5(0xc9)](a47_0x378bf7[_0x58eec5(0xcb)]('Checking\x20CLI\x20Built-in\x20Skill...'));const _0x581ad7=installBuiltinSkill();if(_0x581ad7['ok']){console['log'](a47_0x378bf7[_0x58eec5(0xcb)](_0x58eec5(0xc5)+_0x581ad7[_0x58eec5(0xac)]+_0x58eec5(0xd0)));return;}throw CliErrors[_0x58eec5(0xca)](_0x58eec5(0xe3)+_0x581ad7[_0x58eec5(0xbe)]+']:\x20'+(_0x581ad7[_0x58eec5(0xc3)]||'unknown'),_0x58eec5(0xd4)+_0x581ad7[_0x58eec5(0xe1)]+',\x20then\x20verify\x20with:\x20'+CLI_BIN_NAME+_0x58eec5(0xee));}function verifyUpdatedBuiltinSkill(_0x37fba0){const _0x32f171=a47_0x5bb842,_0x42476e=inspectInstalledBuiltinSkillVersion(_0x37fba0);if(_0x42476e[_0x32f171(0xd6)]===_0x32f171(0xf8)){console['log'](a47_0x378bf7[_0x32f171(0xcb)](_0x32f171(0xc5)+_0x37fba0+_0x32f171(0xd0)));return;}const _0x183b5b=_0x42476e[_0x32f171(0xac)]?_0x32f171(0xd5)+_0x37fba0+_0x32f171(0xcd)+_0x42476e[_0x32f171(0xac)]:_0x32f171(0xd5)+_0x37fba0+_0x32f171(0xe2)+_0x42476e[_0x32f171(0xd6)];throw CliErrors['apiError'](_0x32f171(0xfc)+_0x37fba0+',\x20but\x20Built-in\x20Skill\x20verification\x20failed:\x20'+_0x183b5b,'Run:\x20'+_0x42476e['repairCommand']+_0x32f171(0xd9)+CLI_BIN_NAME+_0x32f171(0xee));}async function execute(_0x316267){const _0x6939a4=a47_0x5bb842;await validateUpdateFlags(_0x316267);const _0x289679=getCurrentVersion();console[_0x6939a4(0xc9)](_0x6939a4(0xd8)+_0x289679);const _0x4aab4c=a47_0xf35b70(_0x6939a4(0xb3))['start'](),_0xd1855=await resolveTargetVersion(_0x316267);if(!_0xd1855){const _0x4bac05=_0x316267[_0x6939a4(0xfd)](_0x6939a4(0xda))?_0x6939a4(0xd2):_0x6939a4(0xe5);_0x4aab4c[_0x6939a4(0xec)](_0x4bac05);throw CliErrors[_0x6939a4(0xca)](_0x4bac05,_0x6939a4(0xf9)+NPM_PACKAGE_NAME+'@'+(_0x316267[_0x6939a4(0xfd)](_0x6939a4(0xda))?_0x6939a4(0xda):_0x6939a4(0xc4)));}const _0x2cc82c=a47_0x353f3f[_0x6939a4(0xdf)](VERSION),_0x4cbffd=a47_0x353f3f['valid'](_0xd1855[_0x6939a4(0xdd)]);if(!_0x2cc82c||!_0x4cbffd){_0x4aab4c[_0x6939a4(0xec)](_0x6939a4(0xcf));throw CliErrors[_0x6939a4(0xca)]('Version\x20comparison\x20failed','Check\x20the\x20CLI\x20and\x20npm\x20versions,\x20then\x20retry:\x20'+CLI_BIN_NAME+_0x6939a4(0xfb));}if(!shouldInstallTarget(_0x2cc82c,_0xd1855)){const _0x19517f=_0xd1855[_0x6939a4(0xd3)]===_0x6939a4(0xdd)?_0x6939a4(0xf2)+_0xd1855[_0x6939a4(0xdd)]+')':a47_0x353f3f['gt'](_0x2cc82c,_0x4cbffd)?'Current\x20version\x20v'+_0x289679+_0x6939a4(0xbb)+_0xd1855['version']:_0x6939a4(0xc7)+_0xd1855[_0x6939a4(0xdd)]+')';return _0x4aab4c[_0x6939a4(0xc0)](_0x19517f),repairCurrentBuiltinSkill(),{'ok':!![]};}_0x4aab4c['info'](getInstallPlanLabel(_0x289679,_0xd1855));const _0x451be4=detectPackageManager(),_0x9920c1=_0x451be4===_0x6939a4(0xbf)?resolveNpmBin(_0x6939a4(0xbf)):_0x451be4,_0x33b9b6=a47_0xf35b70(_0x6939a4(0xff)+_0x451be4+_0x6939a4(0xc1))[_0x6939a4(0xde)]();try{await execa(_0x9920c1,['install','-g',NPM_PACKAGE_NAME+'@'+_0xd1855[_0x6939a4(0xdd)]],{'stdio':_0x6939a4(0xae)}),_0x33b9b6['succeed'](_0x6939a4(0xce)+_0xd1855[_0x6939a4(0xdd)]),console['log'](a47_0x378bf7[_0x6939a4(0xcb)]('\x20\x20Restart\x20your\x20terminal\x20to\x20use\x20the\x20new\x20version.'));}catch(_0x5b0382){_0x33b9b6[_0x6939a4(0xec)](_0x6939a4(0xdc));throw CliErrors['apiError']('Update\x20failed:\x20'+(_0x5b0382 instanceof Error?_0x5b0382[_0x6939a4(0xef)]:String(_0x5b0382)),_0x6939a4(0xd1)+_0x451be4+_0x6939a4(0xb8)+NPM_PACKAGE_NAME+'@'+_0xd1855['version']);}return verifyUpdatedBuiltinSkill(_0xd1855[_0x6939a4(0xdd)]),{'ok':!![]};}export const updateDefinition={'service':a47_0x5bb842(0xb2),'command':a47_0x5bb842(0xf0),'description':a47_0x5bb842(0xaf),'risk':a47_0x5bb842(0xe4),'requiresAuth':![],'requiresAppCode':![],'hasFormat':![],'flags':updateFlags,'validate':validateUpdateFlags,'execute':execute};
|
|
1
|
+
import chalk from"chalk";import ora from"ora";import semver from"semver";import{execa}from"execa";import{CLI_BIN_NAME,NPM_PACKAGE_NAME}from"../constant/cli.js";import{VERSION,GIT_COMMIT,BUILD_TIME}from"../generated/build-info.js";import{CliErrors}from"../errors.js";import{installBuiltinSkill}from"../skills/builtin-skill.js";import{installUpdatedBuiltinSkill}from"../skills/install-updated-skill.js";import{resolveNpmBin}from"../utils/platform.js";function getCurrentVersion(){return GIT_COMMIT!=="unknown"?`${VERSION} (${GIT_COMMIT}, ${BUILD_TIME.slice(0,10)})`:VERSION}function detectPackageManager(){const execPath=process.execPath.toLowerCase();if(execPath.includes("bun"))return"bun";return"npm"}const updateFlags=[{name:"beta",type:"boolean",description:"Install the version from npm beta dist-tag",default:false},{name:"version",type:"string",description:"Install a specific CLI version"}];function getRequestedVersion(ctx){return ctx.str("version").trim()}
|
|
2
|
+
async function validateUpdateFlags(ctx){const wantsBeta=ctx.bool("beta");const requestedVersion=getRequestedVersion(ctx);if(wantsBeta&&requestedVersion){throw CliErrors.validation("--beta and --version cannot be used together.","Choose either npm beta dist-tag or an exact version.")}if(requestedVersion&&!semver.valid(requestedVersion)){throw CliErrors.validation(`Invalid version: ${requestedVersion}`,"Use a full semver such as 2.1.6 or 2.1.6-beta.1.")}}async function fetchNpmDistTags(){try{const res=await fetch(`https://registry.npmjs.org/-/package/${encodeURIComponent(NPM_PACKAGE_NAME)}/dist-tags`,{signal:AbortSignal.timeout(1e4)});if(!res.ok)return null;const data=await res.json();if(!data||typeof data!=="object")return null;return Object.fromEntries(Object.entries(data).filter(([,value])=>typeof value==="string"&&value.trim().length>0).map(([key,value])=>[key,String(value).trim()]))}catch{return null}}async function fetchNpmDistTagVersion(tag){const tags=await fetchNpmDistTags()
|
|
3
|
+
;return tags?.[tag]??null}async function fetchLatestVersion(){return fetchNpmDistTagVersion("latest")}async function resolveTargetVersion(ctx){const requestedVersion=getRequestedVersion(ctx);if(requestedVersion){return{version:requestedVersion,source:"version"}}if(ctx.bool("beta")){const betaVersion=await fetchNpmDistTagVersion("beta");if(!betaVersion)return null;return{version:betaVersion,source:"beta"}}const latestVersion=await fetchLatestVersion();if(!latestVersion)return null;return{version:latestVersion,source:"latest"}}function shouldInstallTarget(currentVersion,target){if(target.source==="version"||target.source==="beta"){return!semver.eq(currentVersion,target.version)}return semver.lt(currentVersion,target.version)}function getInstallPlanLabel(currentVersion,target){switch(target.source){case"beta":return`Beta version: ${chalk.yellow(currentVersion)} → ${chalk.green(target.version)}`;case"version":
|
|
4
|
+
return`Requested version: ${chalk.yellow(currentVersion)} → ${chalk.green(target.version)}`;case"latest":default:return`Update available: ${chalk.yellow(currentVersion)} → ${chalk.green(target.version)}`}}function repairCurrentBuiltinSkill(){console.log(chalk.gray("Checking CLI Built-in Skill..."));const result=installBuiltinSkill();if(result.ok){console.log(chalk.gray(` CLI Built-in Skill ${result.skillVersion} is up to date.`));return}throw CliErrors.apiError(`CLI Built-in Skill repair failed [${result.code}]: ${result.error||"unknown"}`,`Run: ${result.repairCommand}, then verify with: ${CLI_BIN_NAME} doctor`)}async function execute(ctx){await validateUpdateFlags(ctx);const currentVersion=getCurrentVersion();console.log(`Current version: ${currentVersion}`);const spinner=ora("Checking for updates...").start();const target=await resolveTargetVersion(ctx);if(!target){
|
|
5
|
+
const failureMessage=ctx.bool("beta")?"Unable to resolve beta version from npm":"Unable to check for updates (network error)";spinner.fail(failureMessage);throw CliErrors.apiError(failureMessage,`Try manually: npm install -g ${NPM_PACKAGE_NAME}@${ctx.bool("beta")?"beta":"latest"}`)}const currentSemver=semver.valid(VERSION);const targetSemver=semver.valid(target.version);if(!currentSemver||!targetSemver){spinner.fail("Version comparison failed");throw CliErrors.apiError("Version comparison failed",`Check the CLI and npm versions, then retry: ${CLI_BIN_NAME} update --version <version>`)}if(!shouldInstallTarget(currentSemver,target)){const successMessage=target.source==="version"?`Already on requested version (v${target.version})`:semver.gt(currentSemver,targetSemver)?`Current version v${currentVersion} is newer than npm latest v${target.version}`:`Already up to date (v${target.version})`;repairCurrentBuiltinSkill();spinner.succeed(successMessage);return{ok:true}}
|
|
6
|
+
spinner.info(getInstallPlanLabel(currentVersion,target));const pm=detectPackageManager();const pmCmd=pm==="npm"?resolveNpmBin("npm"):pm;const installSpinner=ora(`Updating via ${pm}...`).start();try{await execa(pmCmd,["install","-g",`${NPM_PACKAGE_NAME}@${target.version}`],{stdio:"pipe"})}catch(err){installSpinner.fail("Update failed");throw CliErrors.apiError(`Update failed: ${err instanceof Error?err.message:String(err)}`,`Try manually: ${pm} install -g ${NPM_PACKAGE_NAME}@${target.version}`)}try{installUpdatedBuiltinSkill({version:target.version,packageManager:pm,packageManagerCommand:pmCmd})}catch(error){installSpinner.fail("CLI installed, but Built-in Skill installation failed");throw CliErrors.apiError(`CLI updated to v${target.version}, but Built-in Skill installation failed: ${error instanceof Error?error.message:String(error)}`,`Run: ${CLI_BIN_NAME} cli-skill install, then verify with: ${CLI_BIN_NAME} doctor`)}
|
|
7
|
+
installSpinner.succeed(`Updated CLI and Built-in Skill to v${target.version}`);console.log(chalk.gray(" Restart your terminal to use the new version."));return{ok:true}}export const updateDefinition={service:"update",command:"run",description:"Update rabetbase CLI to the latest version",risk:"read",requiresAuth:false,requiresAppCode:false,hasFormat:false,flags:updateFlags,validate:validateUpdateFlags,execute:execute};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{codegenSdk}from"../../commands/codegen/sdk.js";import{codegenSql}from"../../commands/codegen/sql.js";export const codegenDefinitions=[codegenSdk,codegenSql];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{getOperationDetail,generateSdkCode}from"../../core/api-client.js";import{CODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";export const codegenSdk={service:"codegen",command:"sdk",description:"Generate TypeScript SDK code for a dataset operation",risk:"read",flags:[CODE_FLAG_OPTIONAL,{name:"alias",type:"string",description:"Dataset alias defined in api.ts (e.g. order, coupon)"},{name:"operation",type:"string",required:true,description:"Operation name (e.g. filter, getOne, create, update)"},{name:"skip-imports",type:"boolean",description:"Omit import statements from generated code"}],async execute(ctx){const{dataset:dataset,operation:operation}=await getOperationDetail(ctx.appCode,ctx.str("code"),ctx.str("operation"));const code=generateSdkCode(dataset,operation,{includeImports:!ctx.bool("skip-imports")});return{ok:true,data:{dataset:{name:dataset.name,code:dataset.code,tableName:dataset.tableName},operation:ctx.str("operation"),code:code}}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{getSqlQueryInfo,generateSqlCodeTemplate}from"../../core/api-client.js";import{SQLCODE_FLAG}from"../../commands/common/flags.js";export const codegenSql={service:"codegen",command:"sql",description:"Generate TypeScript code for a custom SQL query",risk:"read",flags:[SQLCODE_FLAG,{name:"target",type:"string",description:"Code target: sdk (default) or bff",default:"sdk",enum:["sdk","bff"]},{name:"no-imports",type:"boolean",description:"Omit import statements from generated code"}],async execute(ctx){const sql=await getSqlQueryInfo(ctx.appCode,ctx.str("sqlcode"));const target=ctx.str("target")||"sdk";const code=generateSqlCodeTemplate(sql,{target:target,includeImports:!ctx.bool("no-imports")});return{ok:true,data:{sqlCode:sql.sqlCode,sqlName:sql.sqlName,target:target,code:code}}}};
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import{CliErrors}from"../../errors.js";import{CLI_BIN_NAME}from"../../constant/cli.js";import{collectAppProfileOverrides,getAppProfileFlagDefs,normalizeStoredDefaultApp}from"../../config/schema.js";import{readRawConfigWithLayers}from"../../context.js";import{readConfig,writeConfig,scopeLabel,resolveAppScopeForWrite,appDefinedIn}from"../../commands/app/shared.js";export function buildAppAddFlags(){return[{name:"appcode",type:"string",description:"App code",required:true},{name:"global",type:"boolean",description:"Use global config scope",default:false},...getAppProfileFlagDefs()]}export function buildAppRemoveFlags(){return[{name:"global",type:"boolean",description:"Use global config scope",default:false}]}export async function validateAppName(ctx,usageCmd){const name=ctx.args[0]?.trim();if(!name){throw CliErrors.validation("Missing app name.",`Usage: ${CLI_BIN_NAME} ${usageCmd} <name>`)}}export async function runAppAdd(ctx,usageCmd){const name=ctx.args[0]?.trim();if(!name){
|
|
2
|
+
throw CliErrors.validation("Missing app name.",`Usage: ${CLI_BIN_NAME} ${usageCmd} <name> --appcode <code>`)}const appcode=ctx.str("appcode");if(!appcode){throw CliErrors.flagMissing("appcode",`Usage: ${CLI_BIN_NAME} ${usageCmd} <name> --appcode <code>`)}const flags={global:ctx.bool("global")};const config=readConfig(flags);if(!config.apps)config.apps={};const profile={appcode:appcode,...collectAppProfileOverrides(flagName=>ctx.str(flagName))};const apps=config.apps;const previousNames=Object.keys(apps);const previousSelection=typeof config.defaultApp==="string"&&apps[config.defaultApp]?config.defaultApp:previousNames.length===1?previousNames[0]:undefined;const isUpdate=!!apps[name];apps[name]=profile;const storedDefault=normalizeStoredDefaultApp(config,previousSelection);writeConfig(config,flags);const extraMsg=!isUpdate&&storedDefault?` Default app is "${storedDefault}".`:""
|
|
3
|
+
;const mainMsg=`${isUpdate?"Updated":"Added"} app "${name}" (appcode: ${appcode})${scopeLabel(flags)}.${extraMsg}`;return{ok:true,message:mainMsg}}export async function runAppRemove(ctx,usageCmd){const name=ctx.args[0]?.trim();if(!name){throw CliErrors.validation("Missing app name.",`Usage: ${CLI_BIN_NAME} ${usageCmd} <name> [--global]`)}const explicitGlobal=ctx.bool("global");const{config:merged,layers:layers}=readRawConfigWithLayers();const mergedApps=merged.apps??{};if(!mergedApps[name]){throw CliErrors.validation(`App "${name}" not found.`)}const globalApps=layers.globalConfig.apps&&typeof layers.globalConfig.apps==="object"?layers.globalConfig.apps:{};const projectApps=layers.projectConfig.apps&&typeof layers.projectConfig.apps==="object"?layers.projectConfig.apps:{};const definedIn=appDefinedIn(name,globalApps,projectApps);const scope=resolveAppScopeForWrite(name,explicitGlobal,layers);const targetFlags={global:scope==="global"};const config=readConfig(targetFlags)
|
|
4
|
+
;const apps=config.apps;if(!apps||!apps[name]){throw CliErrors.validation(`App "${name}" not found.`)}delete apps[name];let extraMsg="";const previousDefault=typeof config.defaultApp==="string"?config.defaultApp:undefined;const remaining=Object.keys(apps);const preferred=previousDefault===name?remaining[0]:previousDefault;const storedDefault=normalizeStoredDefaultApp(config,preferred);if(previousDefault===name&&remaining.length===1){extraMsg=` Remaining app "${remaining[0]}" is selected automatically.`}else if(previousDefault===name&&storedDefault){extraMsg=` Default app changed to "${storedDefault}".`}if(Object.keys(apps).length===0){delete config.apps;delete config.defaultApp}writeConfig(config,targetFlags);const stillExistsNote=definedIn==="both"?` Note: app "${name}" still defined in ${scope==="project"?"global":"project"} config.`:"";return{ok:true,message:`Removed app "${name}"${scopeLabel(targetFlags)}.${extraMsg}${stillExistsNote}`}}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import{input,checkbox,select}from"@inquirer/prompts";import chalk from"chalk";import{validateAppcode}from"../../commands/common/validate.js";import{listRemoteApps}from"../../core/api-client.js";import{withActiveCookie}from"../../utils/with-active-cookie.js";import{writeCliSideChannelLine}from"../../utils/write-cli-side-channel.js";export async function promptCustomAppcode(){const code=await input({message:"App Code:",validate:value=>{const v=validateAppcode(value.trim());return v.valid||v.message||"Invalid App Code"}});return code.trim()}export async function promptAppSelection(apps){const choices=[{name:chalk.yellow("✎ Enter appcode manually"),value:-1},...apps.map((app,i)=>({name:`${app.appName} ${chalk.gray(`(${app.appCode})`)}`,value:i}))];const selected=await checkbox({message:`Found ${chalk.cyan(apps.length)} apps. Select with space, a=all, i=invert:`,choices:choices,loop:false});if(selected.includes(-1))return"custom";if(selected.length===0)return"custom"
|
|
2
|
+
;return selected.map(i=>apps[i])}export async function promptSingleAppSelection(apps){const choices=[{name:chalk.gray("(Skip; configure later with config set appcode)"),value:"skip"},{name:chalk.yellow("✎ Enter appcode manually"),value:"custom"},...apps.map(app=>({name:`${app.appName} ${chalk.gray(`(${app.appCode})`)}`,value:app.appCode}))];const selected=await select({message:"Select the app to bind:",choices:choices});if(selected==="skip")return"skip";if(selected==="custom")return"custom";return apps.find(a=>a.appCode===selected)}export async function selectSingleAppcode(cookie){if(!cookie){writeCliSideChannelLine(chalk.gray("(No login session. Enter an App Code manually or skip.)"));return _fallbackOrSkip()}writeCliSideChannelLine("Fetching available apps...");let apps;try{apps=await withActiveCookie(cookie,()=>listRemoteApps())}catch(err){writeCliSideChannelLine(chalk.yellow("Could not fetch the remote app list. Enter an App Code manually."))
|
|
3
|
+
;if(err instanceof Error)writeCliSideChannelLine(chalk.gray(` (${err.message})`));return _fallbackOrSkip()}if(apps.length===0){writeCliSideChannelLine(chalk.yellow("No available apps found."));return _fallbackOrSkip()}const result=await promptSingleAppSelection(apps);if(result==="skip")return"";if(result==="custom")return promptCustomAppcode();return result.appCode}export async function selectMultipleApps(cookie){writeCliSideChannelLine("Fetching available apps...");let apps;try{apps=await withActiveCookie(cookie,()=>listRemoteApps())}catch(err){writeCliSideChannelLine("\nCould not fetch the remote app list. Enter an App Code manually.");if(err instanceof Error)writeCliSideChannelLine(` (${err.message})`);return"custom"}if(apps.length===0){writeCliSideChannelLine("\nNo available apps found.");return"custom"}return promptAppSelection(apps)}async function _fallbackOrSkip(){const choice=await select({message:"App Code:",choices:[{name:chalk.gray("(Skip; configure later)"),value:"skip"
|
|
4
|
+
},{name:chalk.yellow("✎ Enter manually"),value:"manual"}]});if(choice==="skip")return"";return promptCustomAppcode()}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{CLI_BIN_NAME}from"../../constant/cli.js";import{CliErrors}from"../../errors.js";const TERMINAL_STATUSES=new Set(["SUCCESS","FAILED"]);const NON_TERMINAL_STATUSES=new Set(["PENDING","PROCESSING"]);export function normalizeAsyncTask(task){const taskId=typeof task?.taskId==="string"?task.taskId.trim():"";if(!taskId){throw CliErrors.apiError("Async task response did not contain a taskId.")}const status=typeof task.status==="string"?task.status.trim().toUpperCase():"";if(!status){throw CliErrors.apiError(`Async task ${taskId} response did not contain a status.`)}return{taskId:taskId,status:status,errorMessage:typeof task.errorMessage==="string"&&task.errorMessage.trim()?task.errorMessage.trim():null,isTerminal:TERMINAL_STATUSES.has(status),knownStatus:TERMINAL_STATUSES.has(status)||NON_TERMINAL_STATUSES.has(status)}}export function buildAsyncTaskStatusCommand(taskId,appCode){
|
|
2
|
+
return`${CLI_BIN_NAME} task status --task-id ${quoteShellArg(taskId)} --appcode ${quoteShellArg(appCode)} --format compress`}export function asyncTaskMessage(task){switch(task.status){case"PENDING":return`Task ${task.taskId} is pending.`;case"PROCESSING":return`Task ${task.taskId} is processing.`;case"SUCCESS":return`Task ${task.taskId} completed successfully.`;case"FAILED":return task.errorMessage?`Task ${task.taskId} failed: ${task.errorMessage}`:`Task ${task.taskId} failed.`;default:return`Task ${task.taskId} returned unknown status ${task.status}.`}}function quoteShellArg(value){return`'${value.replace(/'/g,`'\\''`)}'`}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export function asDryRunResult(data,backend){return Object.defineProperties(data,{method:{value:backend.method,enumerable:false},url:{value:backend.url,enumerable:false},...backend.description?{description:{value:backend.description,enumerable:false}}:{}})}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
export const CROSS_RELATION_FROM_DATASET_FLAG={name:"from-datasetcode",type:"string",required:true,description:"Source DB_TABLE dataset code"};export const CROSS_RELATION_FROM_COLUMN_FLAG={name:"from-column",type:"string",required:true,description:"Source field name used to locate the relation"};export const CROSS_RELATION_TO_DATASET_FLAG={name:"to-datasetcode",type:"string",required:true,description:"Target DB_TABLE dataset code"};export const CROSS_RELATION_TO_COLUMN_FLAG={name:"to-column",type:"string",required:true,description:"Target field name"};export const CROSS_RELATION_DBLINK_FLAG={name:"from-dblink-id",type:"number",description:"Source database connection ID; derived from the source dataset when omitted"};export const CROSS_RELATION_LABEL_FLAG={name:"to-label-column",type:"string",description:"Target display field; create defaults to the target field, update keeps the current value"};export const CROSS_RELATION_CARDINALITY_FLAG={name:"cardinality",type:"string",
|
|
2
|
+
enum:["ONE_TO_ONE","ONE_TO_MANY","MANY_TO_ONE","MANY_TO_MANY"],description:"Relation cardinality; create leaves it unset when omitted, update keeps the current value"};export const GLOBAL_SCOPE_FLAG={name:"global",type:"boolean",default:false,description:"Write to the global configuration"};export const DATASET_CODE_PATTERN={regex:/^[a-f0-9]{32}(?:_[^_\s]+_[^_\s]+)?$/i,description:"a 32-character hex code, optionally with `_xx_xx` suffix (e.g. 99a909313f1fa7153186431e1c551588 or 99a909313f1fa7153186431e1c551588_75_3c7120aa)"};export const CODE_FLAG={name:"code",type:"string",required:true,description:"Dataset code (32-char hex, optionally with _xx_xx suffix)",pattern:DATASET_CODE_PATTERN};export const CODE_FLAG_OPTIONAL={...CODE_FLAG,required:false};export const DATASETCODE_FLAG_OPTIONAL={...CODE_FLAG_OPTIONAL,name:"datasetcode",description:"Dataset code (32-char hex, optionally with _xx_xx suffix)"};export const SQLCODE_FLAG={name:"sqlcode",type:"string",required:true,
|
|
3
|
+
description:"SQL code identifier (format: xxxxxxxx-xxxxxxxx, e.g. 2305f915-dd48cd4c)",pattern:{regex:/^[a-f0-9]{8}-[a-f0-9]{8}$/i,description:"SQL code in format xxxxxxxx-xxxxxxxx (e.g. 2305f915-dd48cd4c)"}};export const APPCODE_FLAG_OPTIONAL={name:"appcode",type:"string",required:false,description:"App code (overrides config file, e.g. app-xxxxx)"};export const APPCODE_FLAG={...APPCODE_FLAG_OPTIONAL,required:true,description:"App code (e.g. app-xxxxx)"};export const SQLCODE_FLAG_OPTIONAL={...SQLCODE_FLAG,required:false};export const DBLINK_ID_FLAG={name:"id",type:"number",required:true,description:"Database connection ID (dblink id from db list)"};export const DB_TYPE_FLAG={name:"dbtype",type:"string",required:true,description:"Database product type",enum:["MYSQL","POSTGRESQL"]};export const SKIP_CONNECTION_TEST_FLAG={name:"skip-connection-test",type:"boolean",description:"Skip testing the unsaved database configuration before create/update"};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{existsSync,statSync}from"node:fs";import{CliErrors}from"../../errors.js";const BYTES_PER_MB=1024*1024;export const DEVELOPMENT_UPLOAD_MAX_BYTES=50*BYTES_PER_MB;function formatBytes(bytes){if(bytes>=BYTES_PER_MB){const megabytes=Math.ceil(bytes/BYTES_PER_MB*100)/100;return`${megabytes.toFixed(2)} MB`}return`${bytes} B`}export function requireDevelopmentUploadFile(filePath,label){const normalized=filePath.trim();if(!normalized){throw CliErrors.validation(`${label} path is required.`)}if(!existsSync(normalized)){throw CliErrors.validation(`File not found: ${normalized}`)}const stats=statSync(normalized);if(!stats.isFile()){throw CliErrors.validation(`File is not a regular file: ${normalized}`)}if(stats.size>DEVELOPMENT_UPLOAD_MAX_BYTES){throw CliErrors.validation(`File exceeds the development upload limit of 50 MB: ${normalized} (${formatBytes(stats.size)})`)}return{path:normalized,size:stats.size}}
|