@lovrabet/rabetbase-cli 2.5.13-beta.1 → 2.6.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -17
- package/lib/api/api-doc.js +3 -1
- package/lib/api/api-group.js +3 -1
- package/lib/api/fetch-model-list.js +1 -1
- package/lib/api/generate-api-file.js +8 -1
- package/lib/api/generate-sdk-config-file.js +1 -1
- package/lib/api/legacy-api-file.js +2 -1
- package/lib/api/model-registry-file.js +11 -1
- package/lib/api/model-registry-scaffold.js +2 -1
- package/lib/api/model-source.js +3 -1
- package/lib/auth/auth-server-ui.js +2 -1
- package/lib/auth/auth-server.js +5 -1
- package/lib/auth/constant.js +1 -1
- package/lib/auth/get-cookie.js +1 -1
- package/lib/auth/get-session-user.js +1 -1
- package/lib/auth/is-session-valid.js +1 -1
- package/lib/auth/login-success-html.js +3 -1
- package/lib/auth/logout.js +1 -1
- package/lib/cli-flags.js +1 -1
- package/lib/cli.js +5 -1
- package/lib/commands/api/generate.js +4 -1
- package/lib/commands/api/index.js +1 -1
- package/lib/commands/api/list.js +2 -1
- package/lib/commands/api/pull.js +10 -1
- package/lib/commands/api/shared.js +1 -1
- package/lib/commands/app/detail.js +1 -1
- package/lib/commands/app/index.js +1 -1
- package/lib/commands/app/list.js +5 -1
- package/lib/commands/app/members-list.js +1 -1
- package/lib/commands/app/remote-directory.js +1 -1
- package/lib/commands/app/shared.js +4 -1
- package/lib/commands/app-config/delete.js +2 -1
- package/lib/commands/app-config/get.js +2 -1
- package/lib/commands/app-config/index.js +1 -1
- package/lib/commands/app-config/list.js +2 -1
- package/lib/commands/app-config/set.js +3 -1
- package/lib/commands/app-config/shared.d.ts +9 -2
- package/lib/commands/app-config/shared.js +6 -1
- package/lib/commands/auth/index.js +1 -1
- package/lib/commands/bff/create.js +11 -1
- package/lib/commands/bff/delete.js +6 -1
- package/lib/commands/bff/detail.js +1 -1
- package/lib/commands/bff/index.js +1 -1
- package/lib/commands/bff/list.js +1 -1
- package/lib/commands/bff/logs.js +4 -1
- package/lib/commands/bff/pull.js +22 -1
- package/lib/commands/bff/push.js +16 -1
- package/lib/commands/bff/status.js +3 -1
- package/lib/commands/cli-skill/index.js +2 -1
- package/lib/commands/cli-update.js +7 -1
- package/lib/commands/codegen/index.js +1 -1
- package/lib/commands/codegen/sdk.js +1 -1
- package/lib/commands/codegen/sql.js +1 -1
- package/lib/commands/common/app-registry.js +4 -1
- package/lib/commands/common/app-selector.js +4 -1
- package/lib/commands/common/async-task.js +2 -1
- package/lib/commands/common/dry-run.js +1 -1
- package/lib/commands/common/flags.js +3 -1
- package/lib/commands/common/local-file.js +1 -1
- package/lib/commands/common/validate.js +1 -1
- package/lib/commands/config/delete.js +2 -1
- package/lib/commands/config/get.js +1 -1
- package/lib/commands/config/index.js +1 -1
- package/lib/commands/config/init.js +5 -1
- package/lib/commands/config/list.js +1 -1
- package/lib/commands/config/set.js +4 -1
- package/lib/commands/config/shared.js +2 -1
- package/lib/commands/dataset/batch-design.js +9 -1
- package/lib/commands/dataset/business-group-update.js +10 -1
- package/lib/commands/dataset/business-groups.js +1 -1
- package/lib/commands/dataset/capability.js +3 -1
- package/lib/commands/dataset/cross-relation-create.js +2 -1
- package/lib/commands/dataset/cross-relation-delete.js +1 -1
- package/lib/commands/dataset/cross-relation-list.js +2 -1
- package/lib/commands/dataset/cross-relation-shared.js +10 -1
- package/lib/commands/dataset/cross-relation-update.js +2 -1
- package/lib/commands/dataset/delete.js +6 -1
- package/lib/commands/dataset/design-context.js +1 -1
- package/lib/commands/dataset/design-start.js +1 -1
- package/lib/commands/dataset/design-status.js +1 -1
- package/lib/commands/dataset/design-sync-retry.js +1 -1
- package/lib/commands/dataset/design-sync-status.js +1 -1
- package/lib/commands/dataset/design-validate.js +1 -1
- package/lib/commands/dataset/detail.js +5 -1
- package/lib/commands/dataset/extend-update.js +7 -1
- package/lib/commands/dataset/field-restore.js +7 -1
- package/lib/commands/dataset/field-update.js +7 -1
- package/lib/commands/dataset/generate.js +19 -1
- package/lib/commands/dataset/index.js +3 -1
- package/lib/commands/dataset/list.js +2 -1
- package/lib/commands/dataset/operations.js +2 -1
- package/lib/commands/dataset/relation-audit.js +7 -1
- package/lib/commands/dataset/relation-create.js +3 -1
- package/lib/commands/dataset/relation-delete.js +3 -1
- package/lib/commands/dataset/relation-shared.js +21 -1
- package/lib/commands/dataset/relation-update.js +4 -1
- package/lib/commands/dataset/relations.js +7 -1
- package/lib/commands/dataset/rename.js +4 -1
- package/lib/commands/dataset/restore.js +7 -1
- package/lib/commands/dataset/user-deleted-field-list.js +3 -1
- package/lib/commands/db/analysis-batching.js +3 -1
- package/lib/commands/db/analyze-batch-plan.js +2 -1
- package/lib/commands/db/analyze-cancel.js +1 -1
- package/lib/commands/db/analyze-start.js +3 -1
- package/lib/commands/db/analyze-status.js +6 -1
- package/lib/commands/db/create.js +4 -1
- package/lib/commands/db/cross-db-analysis-shared.js +3 -1
- package/lib/commands/db/cross-db-analyze-latest.js +1 -1
- package/lib/commands/db/cross-db-analyze-start.js +2 -1
- package/lib/commands/db/cross-db-analyze-status.js +1 -1
- package/lib/commands/db/delete.js +3 -1
- package/lib/commands/db/detail.js +1 -1
- package/lib/commands/db/diff-refresh-start.js +1 -1
- package/lib/commands/db/diff-refresh-status.js +2 -1
- package/lib/commands/db/diff.js +3 -1
- package/lib/commands/db/index.js +2 -1
- package/lib/commands/db/list.js +2 -1
- package/lib/commands/db/shared.js +3 -1
- package/lib/commands/db/table-diff-shared.js +2 -1
- package/lib/commands/db/tables.js +2 -1
- package/lib/commands/db/test.js +2 -1
- package/lib/commands/db/update.js +4 -1
- package/lib/commands/deployment/index.js +1 -1
- package/lib/commands/deployment/sync-all.js +3 -1
- package/lib/commands/deployment/sync-jobs.js +2 -1
- package/lib/commands/deployment/sync-status.js +2 -1
- package/lib/commands/doctor.js +12 -1
- package/lib/commands/file/index.js +3 -1
- package/lib/commands/flow/create.js +2 -1
- package/lib/commands/flow/detail.js +3 -1
- package/lib/commands/flow/index.js +1 -1
- package/lib/commands/flow/list.js +2 -1
- package/lib/commands/flow/page-list.js +2 -1
- package/lib/commands/flow/publish.js +2 -1
- package/lib/commands/flow/runtime-resources-shared.js +3 -1
- package/lib/commands/flow/runtime-role-list.js +2 -1
- package/lib/commands/flow/runtime-role-user-list.js +2 -1
- package/lib/commands/flow/runtime-user-search.js +2 -1
- package/lib/commands/flow/shared.js +6 -1
- package/lib/commands/flow/update.js +4 -1
- package/lib/commands/flow/validate.js +2 -1
- package/lib/commands/instant-api-policy/current.js +1 -1
- package/lib/commands/instant-api-policy/index.js +1 -1
- package/lib/commands/instant-api-policy/init.js +2 -1
- package/lib/commands/instant-api-policy/publish.js +5 -1
- package/lib/commands/instant-api-policy/pull.js +2 -1
- package/lib/commands/instant-api-policy/revision.js +1 -1
- package/lib/commands/instant-api-policy/revisions.js +1 -1
- package/lib/commands/instant-api-policy/rollback.js +5 -1
- package/lib/commands/instant-api-policy/shared.js +5 -1
- package/lib/commands/instant-api-policy/validate.js +1 -1
- package/lib/commands/issue/context.js +1 -1
- package/lib/commands/issue/index.js +1 -1
- package/lib/commands/issue/nudge.js +2 -1
- package/lib/commands/issue/report.js +5 -1
- package/lib/commands/kb/create.js +5 -1
- package/lib/commands/kb/delete.js +5 -1
- package/lib/commands/kb/detail.js +1 -1
- package/lib/commands/kb/import-api.d.ts +3 -0
- package/lib/commands/kb/import-api.js +1 -0
- package/lib/commands/kb/import-resume.d.ts +2 -0
- package/lib/commands/kb/import-resume.js +2 -0
- package/lib/commands/kb/import-shared.d.ts +69 -0
- package/lib/commands/kb/import-shared.js +9 -0
- package/lib/commands/kb/import-status.d.ts +2 -0
- package/lib/commands/kb/import-status.js +1 -0
- package/lib/commands/kb/import.d.ts +2 -0
- package/lib/commands/kb/import.js +3 -0
- package/lib/commands/kb/index.js +1 -1
- package/lib/commands/kb/list.js +1 -1
- package/lib/commands/kb/search.js +3 -1
- package/lib/commands/kb/shared.js +9 -1
- package/lib/commands/kb/update.js +7 -1
- package/lib/commands/logs/index.js +2 -1
- package/lib/commands/menu/asset-update.js +8 -1
- package/lib/commands/menu/delete.js +15 -1
- package/lib/commands/menu/external-link-create.js +16 -1
- package/lib/commands/menu/external-link-update.js +10 -1
- package/lib/commands/menu/group-create.js +8 -1
- package/lib/commands/menu/group-update.js +6 -1
- package/lib/commands/menu/index.js +2 -1
- package/lib/commands/menu/list.js +1 -1
- package/lib/commands/menu/move.js +6 -1
- package/lib/commands/menu/regroup-start.js +11 -1
- package/lib/commands/menu/rename.js +9 -1
- package/lib/commands/menu/shared/compare-table.js +2 -1
- package/lib/commands/menu/shared/delete-plan.js +13 -1
- package/lib/commands/menu/shared/facts.js +5 -1
- package/lib/commands/menu/shared/index.js +1 -1
- package/lib/commands/menu/shared/inquirer.js +4 -1
- package/lib/commands/menu/shared/local-pages.js +5 -1
- package/lib/commands/menu/shared/logic.js +3 -1
- package/lib/commands/menu/shared/mutations.js +9 -1
- package/lib/commands/menu/shared/path.js +1 -1
- package/lib/commands/menu/shared/service.js +4 -1
- package/lib/commands/menu/shared/subapp-assets.js +4 -1
- package/lib/commands/menu/shared/sync-core.js +7 -1
- package/lib/commands/menu/shared/types.js +1 -1
- package/lib/commands/menu/shared/update-core.js +8 -1
- package/lib/commands/menu/shared/valid-url.js +1 -1
- package/lib/commands/menu/subapp-assets-status.js +1 -1
- package/lib/commands/menu/subapp-assets-update.js +7 -1
- package/lib/commands/menu/sync.js +7 -1
- package/lib/commands/menu/visibility-update.js +13 -1
- package/lib/commands/metric/contract.d.ts +8 -0
- package/lib/commands/metric/contract.js +5 -0
- package/lib/commands/metric/definition.d.ts +43 -0
- package/lib/commands/metric/definition.js +4 -0
- package/lib/commands/metric/delete.d.ts +2 -0
- package/lib/commands/metric/delete.js +3 -0
- package/lib/commands/metric/detail.d.ts +2 -0
- package/lib/commands/metric/detail.js +1 -0
- package/lib/commands/metric/example.d.ts +2 -0
- package/lib/commands/metric/example.js +1 -0
- package/lib/commands/metric/index.d.ts +2 -0
- package/lib/commands/metric/index.js +1 -0
- package/lib/commands/metric/list.d.ts +2 -0
- package/lib/commands/metric/list.js +2 -0
- package/lib/commands/metric/publication-diff.d.ts +8 -0
- package/lib/commands/metric/publication-diff.js +1 -0
- package/lib/commands/metric/publish.d.ts +2 -0
- package/lib/commands/metric/publish.js +4 -0
- package/lib/commands/metric/schema.d.ts +2 -0
- package/lib/commands/metric/schema.js +1 -0
- package/lib/commands/metric/shared.d.ts +14 -0
- package/lib/commands/metric/shared.js +2 -0
- package/lib/commands/metric/validate.d.ts +2 -0
- package/lib/commands/metric/validate.js +1 -0
- package/lib/commands/notification/config-create.js +4 -1
- package/lib/commands/notification/config-delete.js +4 -1
- package/lib/commands/notification/config-list.js +2 -1
- package/lib/commands/notification/config-update.js +4 -1
- package/lib/commands/notification/index.js +1 -1
- package/lib/commands/notification/shared.js +18 -1
- package/lib/commands/ocr/index.js +4 -1
- package/lib/commands/page/create.js +6 -1
- package/lib/commands/page/custom/detail.js +2 -1
- package/lib/commands/page/custom/list.js +2 -1
- package/lib/commands/page/custom/publish.js +3 -1
- package/lib/commands/page/custom/shared.js +3 -1
- package/lib/commands/page/custom/syntax.js +2 -1
- package/lib/commands/page/custom/update.js +3 -1
- package/lib/commands/page/data-list-status.js +2 -1
- package/lib/commands/page/generate-start.js +5 -1
- package/lib/commands/page/generate-status.js +4 -1
- package/lib/commands/page/index.js +2 -1
- package/lib/commands/page/pull.js +6 -1
- package/lib/commands/page/push.js +11 -1
- package/lib/commands/page/relation-audit.js +15 -1
- package/lib/commands/page/restore.js +5 -1
- package/lib/commands/page/shared.js +16 -1
- package/lib/commands/page/sync.js +2 -1
- package/lib/commands/project/api-architecture-upgrade.js +11 -1
- package/lib/commands/project/create/enhanced-guided-create.js +2 -1
- package/lib/commands/project/create/format-elapsed.js +1 -1
- package/lib/commands/project/create/main.js +13 -1
- package/lib/commands/project/create/materialize-project-template.js +12 -1
- package/lib/commands/project/create/project-name.js +1 -1
- package/lib/commands/project/create/project-template-archive.js +5 -1
- package/lib/commands/project/create/project-template-path.js +1 -1
- package/lib/commands/project/create/use-copy-project-template.js +2 -1
- package/lib/commands/project/create/use-format-code.js +1 -1
- package/lib/commands/project/create/use-install-dependencies.js +1 -1
- package/lib/commands/project/domain-routing-sync.js +1 -1
- package/lib/commands/project/index.js +4 -1
- package/lib/commands/project/upgrade.js +7 -1
- package/lib/commands/registry.js +10 -1
- package/lib/commands/role/delete.js +2 -1
- package/lib/commands/role/detail.js +1 -1
- package/lib/commands/role/index.js +1 -1
- package/lib/commands/role/list.js +2 -1
- package/lib/commands/role/shared.js +8 -1
- package/lib/commands/role/update.js +3 -1
- package/lib/commands/role/user-add.js +2 -1
- package/lib/commands/role/user-remove.js +2 -1
- package/lib/commands/role/user-resolve.js +1 -1
- package/lib/commands/rule/get.js +1 -1
- package/lib/commands/rule/index.js +1 -1
- package/lib/commands/rule/list.js +1 -1
- package/lib/commands/rule/set.js +7 -1
- package/lib/commands/rule/shared.js +4 -1
- package/lib/commands/run/index.js +5 -1
- package/lib/commands/schema.js +1 -1
- package/lib/commands/sql/create.js +7 -1
- package/lib/commands/sql/delete.js +4 -1
- package/lib/commands/sql/detail.js +1 -1
- package/lib/commands/sql/exec.js +1 -1
- package/lib/commands/sql/index.js +1 -1
- package/lib/commands/sql/list.js +2 -1
- package/lib/commands/sql/pull.js +10 -1
- package/lib/commands/sql/push.js +9 -1
- package/lib/commands/sql/shared.js +5 -1
- package/lib/commands/sql/status.js +3 -1
- package/lib/commands/sql/validate.js +5 -1
- package/lib/commands/task/index.js +1 -1
- package/lib/commands/task/status.js +2 -1
- package/lib/commands/tenant/index.js +1 -1
- package/lib/commands/tenant/members-list.js +2 -1
- package/lib/commands/tenant/shared.js +2 -1
- package/lib/commands/user-account/dingding-sandbox-bind.js +2 -1
- package/lib/commands/user-account/feishu-bind.js +2 -1
- package/lib/commands/user-account/index.js +1 -1
- package/lib/commands/workspace/add.js +1 -1
- package/lib/commands/workspace/index.js +7 -1
- package/lib/commands/workspace/remove.js +1 -1
- package/lib/config/domain-config.js +8 -1
- package/lib/config/project-domain-routing.js +3 -1
- package/lib/config/region-config.js +2 -1
- package/lib/config/schema.js +7 -1
- package/lib/constant/cdn.js +2 -1
- package/lib/constant/cli.js +8 -1
- package/lib/constant/defaults.js +1 -1
- package/lib/constant/domain.js +4 -1
- package/lib/constant/env.js +1 -1
- package/lib/constant/output.js +1 -1
- package/lib/constant/paths.js +1 -1
- package/lib/constant/region.js +1 -1
- package/lib/constant/risk.js +1 -1
- package/lib/constant/routing-profile.js +1 -1
- package/lib/context/app-resolver.js +7 -1
- package/lib/context/auth-resolver.js +1 -1
- package/lib/context/config-loader.js +7 -1
- package/lib/context.js +9 -1
- package/lib/core/alias-resolver.js +5 -1
- package/lib/core/api-client.d.ts +14 -7
- package/lib/core/api-client.js +69 -1
- package/lib/core/bff/config.js +1 -1
- package/lib/core/bff/file-system.js +6 -1
- package/lib/core/bff/hash.js +1 -1
- package/lib/core/bff/hook-directory.js +9 -1
- package/lib/core/bff/lock.js +2 -1
- package/lib/core/bff/types.js +1 -1
- package/lib/core/bff/utils.js +3 -1
- package/lib/core/cross-db-analysis.js +1 -1
- package/lib/core/cross-db-relation.js +1 -1
- package/lib/core/db-resolver.js +2 -1
- package/lib/core/flow-config.js +49 -1
- package/lib/core/instant-api-policy/config.js +7 -1
- package/lib/core/instant-api-policy/endpoints.js +1 -1
- package/lib/core/kb-management-client.d.ts +11 -0
- package/lib/core/kb-management-client.js +4 -1
- package/lib/core/kb-search-client.js +3 -1
- package/lib/core/page/file-system.js +2 -1
- package/lib/core/page/hash.js +1 -1
- package/lib/core/page/lock.js +2 -1
- package/lib/core/page/lr-smart-jsx.js +4 -1
- package/lib/core/page/types.js +1 -1
- package/lib/core/sql-index-auditor.js +14 -1
- package/lib/core/sql-sync/config.js +1 -1
- package/lib/core/sql-sync/file-system.js +3 -1
- package/lib/core/sql-sync/hash.js +1 -1
- package/lib/core/sql-sync/lock.js +2 -1
- package/lib/core/sql-sync/types.js +1 -1
- package/lib/core/sql-sync/utils.js +2 -1
- package/lib/core/sql-validator.js +15 -1
- package/lib/errors.js +3 -1
- package/lib/framework/build-all-flags.js +1 -1
- package/lib/framework/error-output.js +1 -1
- package/lib/framework/explicit-yes.js +1 -1
- package/lib/framework/flags.js +1 -1
- package/lib/framework/help.js +2 -1
- package/lib/framework/index.js +1 -1
- package/lib/framework/output.js +2 -1
- package/lib/framework/response.js +1 -1
- package/lib/framework/runner-alias.js +2 -1
- package/lib/framework/runner.js +9 -1
- package/lib/framework/schema-export.js +1 -1
- package/lib/framework/supported-flags.js +2 -1
- package/lib/framework/types.js +1 -1
- package/lib/generated/build-info.d.ts +4 -4
- package/lib/generated/build-info.js +1 -1
- package/lib/generated/official-routing.js +3 -1
- package/lib/generated/routing-contract.js +1 -1
- package/lib/help.js +1 -1
- package/lib/runtime/confirmation.js +2 -1
- package/lib/runtime/event.js +1 -1
- package/lib/runtime/index.js +4 -1
- package/lib/runtime/queue.js +1 -1
- package/lib/runtime/resolve.js +2 -1
- package/lib/runtime/types.js +1 -1
- package/lib/services/dataset-design/checkpoint.js +2 -1
- package/lib/services/dataset-design/commands.js +14 -1
- package/lib/services/dataset-design/contract.js +8 -1
- package/lib/skills/builtin-skill.js +8 -1
- package/lib/skills/install-updated-skill.d.ts +8 -0
- package/lib/skills/install-updated-skill.js +3 -0
- package/lib/skills/local-skills-installer.d.ts +2 -0
- package/lib/skills/local-skills-installer.js +1 -0
- package/lib/skills/main.js +2 -1
- package/lib/skills/npx-skills-add.d.ts +6 -6
- package/lib/skills/npx-skills-add.js +5 -1
- package/lib/skills/skill-presence.d.ts +1 -30
- package/lib/skills/skill-presence.js +2 -1
- package/lib/telemetry/cli-command-trace.js +2 -1
- package/lib/telemetry/cli-help-trace.js +1 -1
- package/lib/telemetry/ensure-cli-otel-config.js +1 -1
- package/lib/telemetry/register-otel-exit-shutdown.js +1 -1
- package/lib/telemetry/send-cli-trace-log.js +1 -1
- package/lib/types/index.js +1 -1
- package/lib/utils/ai_config.js +3 -1
- package/lib/utils/apply-jq-filter.js +1 -1
- package/lib/utils/cdn-config.js +1 -1
- package/lib/utils/check-sdk-version.js +5 -1
- package/lib/utils/cli-version-check.js +4 -1
- package/lib/utils/cli-version-policy.js +3 -1
- package/lib/utils/config.js +1 -1
- package/lib/utils/entity-with-id.js +1 -1
- package/lib/utils/file-utils.js +1 -1
- package/lib/utils/guides-cdn.js +3 -1
- package/lib/utils/http-client.js +2 -1
- package/lib/utils/is-non-interactive.js +1 -1
- package/lib/utils/logger.js +3 -1
- package/lib/utils/params.js +1 -1
- package/lib/utils/platform.js +1 -1
- package/lib/utils/sleep.js +1 -1
- package/lib/utils/template-replacer.js +5 -1
- package/lib/utils/update-notice.js +3 -1
- package/lib/utils/version.js +1 -1
- package/lib/utils/with-active-cookie.js +1 -1
- package/lib/utils/write-cli-side-channel.js +1 -1
- package/package.json +10 -7
- package/skills/rabetbase/SKILL.md +11 -7
- package/skills/rabetbase/guides/backend-function.md +3 -1
- package/skills/rabetbase/guides/data-api-guidelines.md +1 -1
- package/skills/rabetbase/guides/frontend-development.md +1 -0
- package/skills/rabetbase/guides/metric-development.md +185 -0
- package/skills/rabetbase/references/rabetbase-app-config.md +4 -3
- package/skills/rabetbase/references/rabetbase-cli-skill-install.md +5 -5
- package/skills/rabetbase/references/rabetbase-dataset-design.md +1 -1
- package/skills/rabetbase/references/rabetbase-kb.md +16 -0
- package/skills/rabetbase/references/rabetbase-metric.md +119 -0
- package/skills/rabetbase/references/rabetbase-update.md +7 -5
- package/skills/rabetbase-dataset-generation/SKILL.md +1 -1
- package/skills/rabetbase-dataset-generation/references/workflow.md +1 -1
- package/skills/rabetbase-metrics-generation/SKILL.md +22 -0
- package/skills/rabetbase-metrics-generation/references/verification.md +19 -0
- package/skills/rabetbase-metrics-generation/references/workflow.md +41 -0
- package/skills/rabetbase-metrics-generation/templates/statistics-delivery.md +11 -0
- package/skills/rabetbase-page-generation/SKILL.md +1 -1
- package/skills/rabetbase-page-generation/references/generation.md +1 -1
- package/skills/rabetbase.manifest.json +5 -3
- package/templates/metrics/definition.json +78 -0
- package/templates/metrics/metric-definition.schema.json +136 -0
- package/lib/postinstall.d.ts +0 -3
- package/lib/postinstall.js +0 -1
- package/scripts/postinstall.mjs +0 -24
|
@@ -1 +1,15 @@
|
|
|
1
|
-
const a212_0x869e48=a212_0x38cb;(function(_0x118671,_0x4449dc){const _0x1720eb=a212_0x38cb,_0x2723ad=_0x118671();while(!![]){try{const _0x44f495=parseInt(_0x1720eb(0xcc))/0x1+parseInt(_0x1720eb(0x119))/0x2*(parseInt(_0x1720eb(0xcb))/0x3)+parseInt(_0x1720eb(0x11c))/0x4+-parseInt(_0x1720eb(0x122))/0x5+-parseInt(_0x1720eb(0xee))/0x6+-parseInt(_0x1720eb(0xdf))/0x7+parseInt(_0x1720eb(0xe6))/0x8;if(_0x44f495===_0x4449dc)break;else _0x2723ad['push'](_0x2723ad['shift']());}catch(_0x1efe26){_0x2723ad['push'](_0x2723ad['shift']());}}}(a212_0x347a,0xd933d));import{APPCODE_FLAG_OPTIONAL,DATASETCODE_FLAG_OPTIONAL}from'../../commands/common/flags.js';import{datasetRelations}from'../../commands/dataset/relations.js';import{loadDatasetDetailForPage,loadPageDetailForPage,validateDatasetSelector}from'../../commands/page/shared.js';const MAIN_SUB_FORM_COMPONENTS=new Set([a212_0x869e48(0xf4),a212_0x869e48(0x103),a212_0x869e48(0x102)]),MAIN_SUB_PAGE_TYPES=new Set([a212_0x869e48(0xf2),'UPDATE',a212_0x869e48(0xf5)]);export const pageRelationAudit={'service':a212_0x869e48(0xe8),'command':a212_0x869e48(0xff),'description':'Audit\x20Data\x20List\x20Page\x20option\x20bindings\x20against\x20dataset\x20relations','risk':a212_0x869e48(0xfb),'defaultOutputFormat':a212_0x869e48(0x123),'flags':[APPCODE_FLAG_OPTIONAL,DATASETCODE_FLAG_OPTIONAL,{'name':a212_0x869e48(0xd1),'type':'string','description':a212_0x869e48(0xfc)}],async 'validate'(_0x48b8b4){validateDatasetSelector(_0x48b8b4);},async 'execute'(_0x288d5d){const _0x43c236=a212_0x869e48,_0x35155f=await loadDatasetDetailForPage(_0x288d5d),_0x3bee7c=await datasetRelations['execute'](_0x288d5d),_0x3cd29d=(_0x3bee7c[_0x43c236(0xf0)]?.[_0x43c236(0x11a)]??[])[_0x43c236(0xdc)](_0xa80656=>_0xa80656[_0x43c236(0xea)]?.[_0x43c236(0xf7)]===_0x35155f[_0x43c236(0x10d)]),_0x499ce4=_0x35155f['relatedPages'][_0x43c236(0xdc)](_0x1539f3=>!_0x1539f3[_0x43c236(0xdd)]),_0x418328=await Promise[_0x43c236(0x124)](_0x499ce4[_0x43c236(0xcf)](async _0x19762d=>auditPage(_0x288d5d,_0x19762d,_0x35155f,_0x3cd29d))),_0x36bb58=_0x418328[_0x43c236(0xfe)]();return{'ok':!![],'message':_0x43c236(0x10f)+_0x36bb58['length']+_0x43c236(0x101),'data':{'appCode':_0x288d5d[_0x43c236(0xd2)],'datasetCode':_0x35155f[_0x43c236(0x10d)],'total':_0x36bb58[_0x43c236(0xd9)],'items':_0x36bb58}};}};function a212_0x38cb(_0x502603,_0x46b963){_0x502603=_0x502603-0xcb;const _0x347ad7=a212_0x347a();let _0x38cb04=_0x347ad7[_0x502603];return _0x38cb04;}function a212_0x347a(){const _0x3aff93=['flatMap','explicitOptionsType','name','status','displayName','value','uri','optionsType','code','properties','Page\x20relation\x20audit:\x20','toLowerCase','ambiguousDataSources','dataType','find','parse','bizRelationType','expectedBinding','missing','wrong_code','436rcfuzw','relations','formatOptions','4820840FdpQHh','options','column','dataSource','form','location','6611755aMWZMi','compress','all','url','object','label','relation','includes','componentName','key','pageStatus','isArray','some','raw','props','11820oGQFkO','603775UHuprd','field','set','map','/getSelectOptions','alias','appCode','/api/','string','prop','add','fields','custom_options','length','pageId','push','filter','deleted','search','6028694FcBxRh','candidate','params','custom','pageType','wrong_label','sub_info','4530592gKioih','stateKey','page','has','from','ambiguous_binding','table','main_sub','965850UxhCPg','type','data','trim','CREATE','labelField','LrSmartCreate','DETAIL','doType','datasetCode','list','paramsArr','selectItems','read','Dataset\x20alias\x20from\x20api.ts\x20(resolves\x20to\x20dataset\x20code\x20automatically)','unknown','flat','relation-audit','wrong_state','\x20item(s)','LrSmartUpdate','LrSmartDetail','relation_options'];a212_0x347a=function(){return _0x3aff93;};return a212_0x347a();}async function auditPage(_0xe5dc3,_0x40c0a1,_0x492c45,_0xa8d60e){const _0x4f6e28=a212_0x869e48,_0x204e02=await loadPageDetailForPage(_0xe5dc3,_0x40c0a1['id']),_0x148689=parsePageSchema(_0x204e02[_0x4f6e28(0x10d)]),_0x375349=collectDataSources(_0x148689),_0x5ede49=buildFromFieldAuditMap(_0x492c45),_0xe0cd86=MAIN_SUB_PAGE_TYPES[_0x4f6e28(0xe9)](_0x204e02[_0x4f6e28(0xef)])&&_0xa8d60e[_0x4f6e28(0x12e)](_0x3d181b=>_0x3d181b[_0x4f6e28(0x128)]?.[_0x4f6e28(0x115)]===_0x4f6e28(0xed))&&!hasSubInfoConfig(_0x148689);return _0xa8d60e['map'](_0x54609b=>{const _0x30d903=_0x4f6e28,_0x2b8370=buildExpectedBinding(_0xe5dc3[_0x30d903(0xd2)],_0x54609b),_0x5ae9d8=_0x5ede49['get'](_0x54609b[_0x30d903(0xea)][_0x30d903(0xcd)])??buildFallbackFromFieldAudit(_0x54609b[_0x30d903(0xea)][_0x30d903(0xcd)]),_0x537de1=_0x54609b[_0x30d903(0x128)]?.[_0x30d903(0x115)]===_0x30d903(0xed)&&_0xe0cd86?'main_sub_missing':undefined,_0x4b95bd=collectFieldCandidates(_0x148689,_0x54609b[_0x30d903(0xea)][_0x30d903(0xcd)]),_0x1ee12a=selectFieldCandidate(_0x4b95bd,_0x375349,_0x54609b);if(_0x1ee12a[_0x30d903(0x111)])return buildAuditItem({'pageId':_0x204e02[_0x30d903(0xda)],'pageType':_0x204e02['type'],'datasetCode':_0x492c45[_0x30d903(0x10d)],'relation':_0x54609b,'location':_0x4b95bd[0x0]?.[_0x30d903(0x121)]??'form','currentBinding':{'optionsType':_0x30d903(0x128),'candidates':_0x1ee12a[_0x30d903(0x111)][_0x30d903(0xcf)](summarizeDataSource)},'expectedBinding':_0x2b8370,'fromField':_0x5ae9d8,'status':_0x30d903(0xeb),'pageStatus':_0x537de1});const _0x23f82c=_0x1ee12a['candidate']??findDataSourceCandidate(_0x375349,_0x54609b[_0x30d903(0xea)]['field']);if(!_0x23f82c)return buildAuditItem({'pageId':_0x204e02[_0x30d903(0xda)],'pageType':_0x204e02['type'],'datasetCode':_0x492c45[_0x30d903(0x10d)],'relation':_0x54609b,'location':'form','currentBinding':null,'expectedBinding':_0x2b8370,'fromField':_0x5ae9d8,'status':'missing','pageStatus':_0x537de1});if(_0x23f82c[_0x30d903(0x10c)]==='custom'){const _0x2eb583=classifyCustomOptions(_0x5ae9d8);return buildAuditItem({'pageId':_0x204e02[_0x30d903(0xda)],'pageType':_0x204e02[_0x30d903(0xef)],'datasetCode':_0x492c45['code'],'relation':_0x54609b,'location':_0x23f82c[_0x30d903(0x121)],'currentBinding':{'optionsType':'custom'},'expectedBinding':_0x2b8370,'fromField':_0x5ae9d8,'status':_0x2eb583,'pageStatus':_0x537de1});}const _0x2f9ee5=selectDataSourceForCandidate(_0x375349,_0x23f82c,_0x54609b[_0x30d903(0xea)][_0x30d903(0xcd)],_0x54609b);if(_0x2f9ee5[_0x30d903(0x111)])return buildAuditItem({'pageId':_0x204e02[_0x30d903(0xda)],'pageType':_0x204e02[_0x30d903(0xef)],'datasetCode':_0x492c45[_0x30d903(0x10d)],'relation':_0x54609b,'location':_0x23f82c[_0x30d903(0x121)],'currentBinding':{'optionsType':_0x30d903(0x128),'candidates':_0x2f9ee5[_0x30d903(0x111)]['map'](summarizeDataSource)},'expectedBinding':_0x2b8370,'fromField':_0x5ae9d8,'status':_0x30d903(0xeb),'pageStatus':_0x537de1});const _0x370aad=_0x2f9ee5[_0x30d903(0x11f)],_0x2b27cc=_0x370aad?{'optionsType':'relation','dataSourceId':_0x370aad['id'],..._0x370aad[_0x30d903(0x10b)]?{'uri':_0x370aad['uri']}:{},..._0x370aad['code']?{'code':_0x370aad[_0x30d903(0x10d)]}:{},..._0x370aad[_0x30d903(0x127)]?{'label':_0x370aad['label']}:{},..._0x23f82c[_0x30d903(0xe7)]?{'stateKey':_0x23f82c['stateKey']}:{}}:_0x23f82c[_0x30d903(0xe7)]?{'optionsType':_0x30d903(0x128),'stateKey':_0x23f82c[_0x30d903(0xe7)]}:null,_0x2be463=classifyBinding(_0x23f82c,_0x370aad,_0x54609b);return buildAuditItem({'pageId':_0x204e02[_0x30d903(0xda)],'pageType':_0x204e02[_0x30d903(0xef)],'datasetCode':_0x492c45[_0x30d903(0x10d)],'relation':_0x54609b,'location':_0x23f82c[_0x30d903(0x121)],'currentBinding':_0x2b27cc,'expectedBinding':_0x2b8370,'fromField':_0x5ae9d8,'status':_0x2be463,'pageStatus':_0x537de1});});}function buildAuditItem(_0x28ada9){const _0x291ef5=a212_0x869e48;return{'pageId':_0x28ada9[_0x291ef5(0xda)],'pageType':_0x28ada9[_0x291ef5(0xe3)],'datasetCode':_0x28ada9[_0x291ef5(0xf7)],'field':_0x28ada9[_0x291ef5(0x128)]['from'][_0x291ef5(0xcd)],'location':_0x28ada9[_0x291ef5(0x121)],'currentBinding':_0x28ada9['currentBinding'],'expectedBinding':_0x28ada9[_0x291ef5(0x116)],'fromField':_0x28ada9['fromField'],'status':_0x28ada9[_0x291ef5(0x108)],..._0x28ada9[_0x291ef5(0x12c)]?{'pageStatus':_0x28ada9['pageStatus']}:{}};}function buildFromFieldAuditMap(_0x1e0d44){const _0x33c1fd=a212_0x869e48,_0x4875cd=Array[_0x33c1fd(0x12d)](_0x1e0d44[_0x33c1fd(0x12f)]?.[_0x33c1fd(0xd7)])?_0x1e0d44[_0x33c1fd(0x12f)]['fields']:Array[_0x33c1fd(0x12d)](_0x1e0d44[_0x33c1fd(0x12f)]?.[_0x33c1fd(0x10e)])?_0x1e0d44['raw'][_0x33c1fd(0x10e)]:[],_0x43dfc0=new Map();for(const _0x152f5c of _0x4875cd){const _0x30e79d=normalizeFromFieldAudit(_0x152f5c);if(_0x30e79d)_0x43dfc0[_0x33c1fd(0xce)](_0x30e79d[_0x33c1fd(0x107)],_0x30e79d);}return _0x43dfc0;}function normalizeFromFieldAudit(_0x3812ef){const _0x34c7b3=a212_0x869e48;if(!isRecord(_0x3812ef)||_0x3812ef[_0x34c7b3(0xdd)]===!![])return null;const _0x507b9b=_0x3812ef[_0x34c7b3(0x109)]!==undefined||_0x3812ef[_0x34c7b3(0xf6)]!==undefined,_0x17c130=text(_0x507b9b?_0x3812ef[_0x34c7b3(0x107)]??_0x3812ef[_0x34c7b3(0x10d)]??_0x3812ef[_0x34c7b3(0xcd)]??_0x3812ef['key']:_0x3812ef[_0x34c7b3(0x10d)]??_0x3812ef['name']??_0x3812ef[_0x34c7b3(0xcd)]??_0x3812ef[_0x34c7b3(0x12b)]);if(!_0x17c130)return null;const _0x4f1251=text(_0x507b9b?_0x3812ef[_0x34c7b3(0x109)]:_0x3812ef[_0x34c7b3(0x107)]),_0x17cbeb=parseObjectMaybe(_0x3812ef['extend']),_0x589968=text(_0x3812ef[_0x34c7b3(0xf6)]),_0x599f95=text(_0x3812ef[_0x34c7b3(0xef)]??_0x3812ef[_0x34c7b3(0x112)]),_0x70d28d=hasOptionsArray(_0x3812ef[_0x34c7b3(0x11d)])||hasOptionsArray(_0x17cbeb?.[_0x34c7b3(0x11d)])||hasOptionsArray(_0x17cbeb?.[_0x34c7b3(0xfa)]),_0x2da1f2=classifyFromFieldOptionsType({'explicitOptionsType':normalizeOptionsType(_0x3812ef[_0x34c7b3(0x10c)]??_0x17cbeb?.[_0x34c7b3(0x10c)]),'hasOptions':_0x70d28d});return{'name':_0x17c130,..._0x4f1251?{'displayName':_0x4f1251}:{},..._0x589968?{'doType':_0x589968}:{},..._0x599f95?{'type':_0x599f95}:{},'optionsType':_0x2da1f2,'hasOptions':_0x70d28d};}function buildFallbackFromFieldAudit(_0x554ce9){const _0x11db26=a212_0x869e48;return{'name':_0x554ce9,'optionsType':_0x11db26(0xfd),'hasOptions':![]};}function normalizeOptionsType(_0x134710){const _0x3d0889=a212_0x869e48;if(typeof _0x134710!==_0x3d0889(0xd4))return null;const _0x5b4f11=_0x134710[_0x3d0889(0xf1)]()[_0x3d0889(0x110)]();if(_0x5b4f11==='relation'||_0x5b4f11===_0x3d0889(0xe2))return _0x5b4f11;return null;}function classifyFromFieldOptionsType(_0x299edf){const _0x41f785=a212_0x869e48;if(_0x299edf[_0x41f785(0x106)])return _0x299edf[_0x41f785(0x106)];return _0x299edf['hasOptions']?_0x41f785(0xe2):_0x41f785(0xfd);}function hasOptionsArray(_0x5b4f23){const _0x255278=a212_0x869e48;return Array[_0x255278(0x12d)](_0x5b4f23)&&_0x5b4f23[_0x255278(0xd9)]>0x0;}function parseObjectMaybe(_0x432810){if(isRecord(_0x432810))return _0x432810;if(typeof _0x432810!=='string'||!_0x432810['trim']())return null;try{const _0x23c967=JSON['parse'](_0x432810);return isRecord(_0x23c967)?_0x23c967:null;}catch{return null;}}function parsePageSchema(_0x5461e3){const _0x4bcc18=a212_0x869e48;if(!_0x5461e3[_0x4bcc18(0xf1)]())return{};try{return JSON[_0x4bcc18(0x114)](_0x5461e3);}catch{return{};}}function collectDataSources(_0x3dce94){const _0x28563a=[];return walk(_0x3dce94,[],(_0xb2cfde,_0x1f62e9)=>{const _0x28d1de=a212_0x38cb;if(!isRecord(_0xb2cfde))return;const _0x22f364=isRecord(_0xb2cfde[_0x28d1de(0x11f)])&&Array['isArray'](_0xb2cfde['dataSource'][_0x28d1de(0xf8)])?_0xb2cfde[_0x28d1de(0x11f)][_0x28d1de(0xf8)]:_0x1f62e9[_0x1f62e9[_0x28d1de(0xd9)]-0x1]==='dataSource'&&Array[_0x28d1de(0x12d)](_0xb2cfde[_0x28d1de(0xf8)])?_0xb2cfde[_0x28d1de(0xf8)]:[];for(const _0x380f99 of _0x22f364){const _0x412e61=normalizeDataSource(_0x380f99);if(_0x412e61)_0x28563a[_0x28d1de(0xdb)](_0x412e61);}}),uniqueById(_0x28563a);}function normalizeDataSource(_0x220a4e){const _0x1198e8=a212_0x869e48;if(!isRecord(_0x220a4e))return null;const _0x86d4e9=text(_0x220a4e['id']??_0x220a4e[_0x1198e8(0x107)]??_0x220a4e[_0x1198e8(0x12b)]);if(!_0x86d4e9)return null;const _0x1c4a64=isRecord(_0x220a4e[_0x1198e8(0x11d)])?_0x220a4e[_0x1198e8(0x11d)]:{},_0x46dbb8=isRecord(_0x1c4a64['params'])?_0x1c4a64[_0x1198e8(0xe1)]:isRecord(_0x220a4e[_0x1198e8(0xe1)])?_0x220a4e[_0x1198e8(0xe1)]:{},_0x61d287=_0x1c4a64[_0x1198e8(0xf9)]??_0x220a4e[_0x1198e8(0xf9)];return{'id':_0x86d4e9,'uri':text(_0x1c4a64[_0x1198e8(0x10b)]??_0x1c4a64[_0x1198e8(0x125)]??_0x220a4e[_0x1198e8(0x10b)]??_0x220a4e[_0x1198e8(0x125)]),'code':text(_0x46dbb8['code']??readParamFromArray(_0x61d287,_0x1198e8(0x10d))),'label':text(_0x46dbb8[_0x1198e8(0x127)]??readParamFromArray(_0x61d287,_0x1198e8(0x127)))};}function readParamFromArray(_0x8cc634,_0x290d4d){const _0x18d531=a212_0x869e48;if(!Array[_0x18d531(0x12d)](_0x8cc634))return undefined;return _0x8cc634[_0x18d531(0x113)](_0x1b19f7=>isRecord(_0x1b19f7)&&_0x1b19f7['name']===_0x290d4d)?.['value'];}function collectFieldCandidates(_0x184fb9,_0x517134){const _0x59174a=[];return walk(_0x184fb9,[],(_0x13e952,_0x31fd34)=>{const _0x78acf0=a212_0x38cb;if(!isRecord(_0x13e952))return;if(!objectTargetsField(_0x13e952,_0x517134))return;const _0x4ea5a9=readStateKey(_0x13e952);_0x59174a['push']({'field':_0x517134,'location':inferLocation(_0x31fd34),'optionsType':hasPageOptionsArray(_0x13e952)?_0x78acf0(0xe2):_0x78acf0(0x128),'stateKey':_0x4ea5a9});}),_0x59174a;}function selectFieldCandidate(_0x3a77c1,_0x1aca46,_0x254244){const _0x560f76=a212_0x869e48;if(_0x3a77c1[_0x560f76(0xd9)]===0x0)return{};const _0xd31a1f=_0x3a77c1[_0x560f76(0xdc)](_0x28d09a=>_0x28d09a[_0x560f76(0x10c)]===_0x560f76(0x128));if(_0xd31a1f['length']===0x0)return{'candidate':_0x3a77c1[0x0]};const _0xe9ef77=_0xd31a1f[_0x560f76(0x105)](_0xbd1fe2=>{const _0x23925f=_0x560f76;if(!_0xbd1fe2[_0x23925f(0xe7)])return[];const _0x664268=_0x1aca46[_0x23925f(0x113)](_0x5edbb9=>_0x5edbb9['id']===_0xbd1fe2[_0x23925f(0xe7)]);return _0x664268?[{'candidate':_0xbd1fe2,'dataSource':_0x664268}]:[];}),_0x97c2de=_0xe9ef77[_0x560f76(0xdc)](({dataSource:_0x3fe77b})=>dataSourceTargetsDataset(_0x3fe77b,_0x254244['to'][_0x560f76(0xf7)])),_0x356f11=uniqueById(_0x97c2de[_0x560f76(0xcf)](({dataSource:_0x5e56b0})=>_0x5e56b0));if(_0x356f11['length']>0x1)return{'ambiguousDataSources':_0x356f11};const [_0x3fc120]=_0x356f11;if(_0x3fc120)return{'candidate':_0x97c2de[_0x560f76(0x113)](({dataSource:_0x567166})=>_0x567166['id']===_0x3fc120['id'])?.[_0x560f76(0xe0)]};const _0xb7ac46=uniqueById(_0xe9ef77['map'](({dataSource:_0x2ebe2b})=>_0x2ebe2b));if(_0xb7ac46[_0x560f76(0xd9)]>0x1)return{'ambiguousDataSources':_0xb7ac46};const [_0x5acbe1]=_0xe9ef77;if(_0x5acbe1)return{'candidate':_0x5acbe1['candidate']};return{'candidate':_0xd31a1f[0x0]};}function hasSubInfoConfig(_0x4d3f99){let _0x9abbc0=![];return walk(_0x4d3f99,[],_0x45f9a3=>{const _0x3471ee=a212_0x38cb;if(_0x9abbc0||!isRecord(_0x45f9a3))return;if(!MAIN_SUB_FORM_COMPONENTS[_0x3471ee(0xe9)](text(_0x45f9a3[_0x3471ee(0x12a)])))return;const _0x738035=isRecord(_0x45f9a3[_0x3471ee(0x130)])?_0x45f9a3['props']:{};_0x9abbc0=isRecord(_0x738035[_0x3471ee(0xe5)]);}),_0x9abbc0;}function objectTargetsField(_0xfc8427,_0x3766d2){const _0x12f5f8=a212_0x869e48;return[_0x12f5f8(0xcd),'dataIndex',_0x12f5f8(0x107),'id','key',_0x12f5f8(0xd5)][_0x12f5f8(0x12e)](_0x4bc216=>text(_0xfc8427[_0x4bc216])===_0x3766d2);}function hasPageOptionsArray(_0x879b06){const _0x15dda3=a212_0x869e48,_0x58a0a5=isRecord(_0x879b06[_0x15dda3(0x11b)])?_0x879b06['formatOptions']:{};return Array[_0x15dda3(0x12d)](_0x879b06[_0x15dda3(0x11d)])||Array[_0x15dda3(0x12d)](_0x58a0a5[_0x15dda3(0x11d)]);}function readStateKey(_0x5ed295){const _0x12cc62=a212_0x869e48,_0x2804a5=isRecord(_0x5ed295['formatOptions'])?_0x5ed295[_0x12cc62(0x11b)]:{};return readStateKeyFromUnknown(_0x5ed295[_0x12cc62(0x11d)])??readStateKeyFromUnknown(_0x2804a5[_0x12cc62(0x11d)]);}function readStateKeyFromUnknown(_0x3764a1){const _0x24a9ef=a212_0x869e48;if(isRecord(_0x3764a1)&&_0x3764a1[_0x24a9ef(0xef)]==='JSExpression')return readStateKeyFromUnknown(_0x3764a1[_0x24a9ef(0x10a)]);if(typeof _0x3764a1!=='string')return undefined;const _0x5daeaa=_0x3764a1['match'](/(?:this\.)?state\.([A-Za-z0-9_-]+)/);return _0x5daeaa?.[0x1];}function inferLocation(_0x1e2b9f){const _0x341a93=a212_0x869e48,_0x259fd4=_0x1e2b9f[_0x341a93(0xcf)](_0x1911d1=>_0x1911d1['toLowerCase']());if(_0x259fd4[_0x341a93(0x12e)](_0x194350=>_0x194350[_0x341a93(0x129)]('datasource')))return _0x341a93(0x11f);if(_0x259fd4['some'](_0xb7b13b=>_0xb7b13b[_0x341a93(0x129)](_0x341a93(0x11e))||_0xb7b13b[_0x341a93(0x129)]('table')))return _0x341a93(0xec);if(_0x259fd4['some'](_0x53d634=>_0x53d634['includes']('filter')||_0x53d634[_0x341a93(0x129)](_0x341a93(0xde))))return _0x341a93(0xdc);return _0x341a93(0x120);}function findDataSourceCandidate(_0x115e84,_0x16ccad){const _0x3aeb8d=a212_0x869e48;return _0x115e84[_0x3aeb8d(0x12e)](_0x441af0=>_0x441af0['id'][_0x3aeb8d(0x129)](_0x16ccad))?{'field':_0x16ccad,'location':_0x3aeb8d(0x11f),'optionsType':_0x3aeb8d(0x128)}:undefined;}function selectDataSourceForCandidate(_0x468345,_0x5683da,_0x4e4ae6,_0x313f94){const _0x54f575=a212_0x869e48;if(_0x5683da[_0x54f575(0xe7)])return{'dataSource':_0x468345[_0x54f575(0x113)](_0x2cebe3=>_0x2cebe3['id']===_0x5683da['stateKey'])};const _0x1ca176=_0x468345[_0x54f575(0xdc)](_0x2fc749=>dataSourceTargetsDataset(_0x2fc749,_0x313f94['to'][_0x54f575(0xf7)]));if(_0x1ca176['length']===0x1)return{'dataSource':_0x1ca176[0x0]};if(_0x1ca176[_0x54f575(0xd9)]>0x1)return{'ambiguousDataSources':_0x1ca176};const _0x54a5fc=_0x468345[_0x54f575(0xdc)](_0xa223c5=>_0xa223c5['id'][_0x54f575(0x129)](_0x4e4ae6));if(_0x54a5fc[_0x54f575(0xd9)]===0x1)return{'dataSource':_0x54a5fc[0x0]};if(_0x54a5fc[_0x54f575(0xd9)]>0x1)return{'ambiguousDataSources':_0x54a5fc};return{};}function dataSourceTargetsDataset(_0xe16a12,_0x241bb2){const _0x305eec=a212_0x869e48;return _0xe16a12['id'][_0x305eec(0x129)](_0x241bb2)||Boolean(_0xe16a12[_0x305eec(0x10b)]?.['includes']('/'+_0x241bb2+_0x305eec(0xd0)));}function summarizeDataSource(_0x18b81f){const _0x4f6b37=a212_0x869e48;return{'dataSourceId':_0x18b81f['id'],..._0x18b81f[_0x4f6b37(0x10b)]?{'uri':_0x18b81f[_0x4f6b37(0x10b)]}:{},..._0x18b81f[_0x4f6b37(0x10d)]?{'code':_0x18b81f[_0x4f6b37(0x10d)]}:{},..._0x18b81f['label']?{'label':_0x18b81f[_0x4f6b37(0x127)]}:{}};}function classifyBinding(_0x48eca4,_0x2dee12,_0xc5fa4e){const _0x2b9431=a212_0x869e48;if(!_0x2dee12)return _0x48eca4[_0x2b9431(0xe7)]?_0x2b9431(0x100):_0x2b9431(0x117);if(_0x48eca4[_0x2b9431(0xe7)]&&_0x2dee12['id']!==_0x48eca4[_0x2b9431(0xe7)])return _0x2b9431(0x100);if(_0x2dee12[_0x2b9431(0x10d)]&&_0x2dee12[_0x2b9431(0x10d)]!==_0xc5fa4e['to'][_0x2b9431(0xcd)])return _0x2b9431(0x118);const _0x43c4dd=readRelationLabel(_0xc5fa4e);if(_0x43c4dd&&_0x2dee12['label']!==_0x43c4dd)return _0x2b9431(0xe4);return _0x2b9431(0x104);}function classifyCustomOptions(_0x2fe170){const _0x18499c=a212_0x869e48;if(_0x2fe170['optionsType']===_0x18499c(0x128))return _0x18499c(0x117);return _0x18499c(0xd8);}function buildExpectedBinding(_0x1fa729,_0x367394){const _0x705820=a212_0x869e48,_0x440ce9=readRelationLabel(_0x367394);return{'toDatasetCode':_0x367394['to']['datasetCode'],'code':_0x367394['to'][_0x705820(0xcd)],..._0x440ce9?{'label':_0x440ce9}:{},'uri':_0x705820(0xd3)+_0x1fa729+'/'+_0x367394['to'][_0x705820(0xf7)]+_0x705820(0xd0)};}function readRelationLabel(_0x4448cf){const _0x2bfe95=a212_0x869e48;return text(_0x4448cf['to'][_0x2bfe95(0xf3)])||undefined;}function uniqueById(_0x3f4ea5){const _0x33e7a9=new Set();return _0x3f4ea5['filter'](_0x41c77d=>{const _0x2d9447=a212_0x38cb;if(_0x33e7a9[_0x2d9447(0xe9)](_0x41c77d['id']))return![];return _0x33e7a9[_0x2d9447(0xd6)](_0x41c77d['id']),!![];});}function walk(_0x1bbbb9,_0x1c5113,_0x511850){const _0x32910c=a212_0x869e48;_0x511850(_0x1bbbb9,_0x1c5113);if(Array[_0x32910c(0x12d)](_0x1bbbb9)){_0x1bbbb9['forEach']((_0x89e49,_0x541d60)=>walk(_0x89e49,[..._0x1c5113,String(_0x541d60)],_0x511850));return;}if(!isRecord(_0x1bbbb9))return;for(const [_0x3ed82e,_0x25861a]of Object['entries'](_0x1bbbb9)){walk(_0x25861a,[..._0x1c5113,_0x3ed82e],_0x511850);}}function isRecord(_0x34bc62){const _0x13fcab=a212_0x869e48;return Boolean(_0x34bc62)&&typeof _0x34bc62===_0x13fcab(0x126)&&!Array[_0x13fcab(0x12d)](_0x34bc62);}function text(_0x19f085){const _0x368130=a212_0x869e48;return typeof _0x19f085===_0x368130(0xd4)?_0x19f085[_0x368130(0xf1)]():'';}
|
|
1
|
+
import{APPCODE_FLAG_OPTIONAL,DATASETCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{datasetRelations}from"../../commands/dataset/relations.js";import{loadDatasetDetailForPage,loadPageDetailForPage,validateDatasetSelector}from"../../commands/page/shared.js";const MAIN_SUB_FORM_COMPONENTS=new Set(["LrSmartCreate","LrSmartDetail","LrSmartUpdate"]);const MAIN_SUB_PAGE_TYPES=new Set(["CREATE","UPDATE","DETAIL"]);export const pageRelationAudit={service:"page",command:"relation-audit",description:"Audit Data List Page option bindings against dataset relations",risk:"read",defaultOutputFormat:"compress",flags:[APPCODE_FLAG_OPTIONAL,DATASETCODE_FLAG_OPTIONAL,{name:"alias",type:"string",description:"Dataset alias from api.ts (resolves to dataset code automatically)"}],async validate(ctx){validateDatasetSelector(ctx)},async execute(ctx){const dataset=await loadDatasetDetailForPage(ctx);const relationResult=await datasetRelations.execute(ctx)
|
|
2
|
+
;const relations=(relationResult.data?.relations??[]).filter(relation=>relation.from?.datasetCode===dataset.code);const pages=dataset.relatedPages.filter(page=>!page.deleted);const auditedPages=await Promise.all(pages.map(async page=>auditPage(ctx,page,dataset,relations)));const items=auditedPages.flat();return{ok:true,message:`Page relation audit: ${items.length} item(s)`,data:{appCode:ctx.appCode,datasetCode:dataset.code,total:items.length,items:items}}}};async function auditPage(ctx,page,dataset,relations){const detail=await loadPageDetailForPage(ctx,page.id);const schema=parsePageSchema(detail.code);const dataSources=collectDataSources(schema);const fromFieldMap=buildFromFieldAuditMap(dataset);const shouldReportMainSubMissing=MAIN_SUB_PAGE_TYPES.has(detail.type)&&relations.some(relation=>relation.relation?.bizRelationType==="main_sub")&&!hasSubInfoConfig(schema);return relations.map(relation=>{const expectedBinding=buildExpectedBinding(ctx.appCode,relation)
|
|
3
|
+
;const fromField=fromFieldMap.get(relation.from.field)??buildFallbackFromFieldAudit(relation.from.field);const pageStatus=relation.relation?.bizRelationType==="main_sub"&&shouldReportMainSubMissing?"main_sub_missing":undefined;const candidates=collectFieldCandidates(schema,relation.from.field);const candidateSelection=selectFieldCandidate(candidates,dataSources,relation);if(candidateSelection.ambiguousDataSources){return buildAuditItem({pageId:detail.pageId,pageType:detail.type,datasetCode:dataset.code,relation:relation,location:candidates[0]?.location??"form",currentBinding:{optionsType:"relation",candidates:candidateSelection.ambiguousDataSources.map(summarizeDataSource)},expectedBinding:expectedBinding,fromField:fromField,status:"ambiguous_binding",pageStatus:pageStatus})}const candidate=candidateSelection.candidate??findDataSourceCandidate(dataSources,relation.from.field);if(!candidate){return buildAuditItem({pageId:detail.pageId,pageType:detail.type,datasetCode:dataset.code,
|
|
4
|
+
relation:relation,location:"form",currentBinding:null,expectedBinding:expectedBinding,fromField:fromField,status:"missing",pageStatus:pageStatus})}if(candidate.optionsType==="custom"){const status=classifyCustomOptions(fromField);return buildAuditItem({pageId:detail.pageId,pageType:detail.type,datasetCode:dataset.code,relation:relation,location:candidate.location,currentBinding:{optionsType:"custom"},expectedBinding:expectedBinding,fromField:fromField,status:status,pageStatus:pageStatus})}const dataSourceSelection=selectDataSourceForCandidate(dataSources,candidate,relation.from.field,relation);if(dataSourceSelection.ambiguousDataSources){return buildAuditItem({pageId:detail.pageId,pageType:detail.type,datasetCode:dataset.code,relation:relation,location:candidate.location,currentBinding:{optionsType:"relation",candidates:dataSourceSelection.ambiguousDataSources.map(summarizeDataSource)},expectedBinding:expectedBinding,fromField:fromField,status:"ambiguous_binding",pageStatus:pageStatus
|
|
5
|
+
})}const dataSource=dataSourceSelection.dataSource;const currentBinding=dataSource?{optionsType:"relation",dataSourceId:dataSource.id,...dataSource.uri?{uri:dataSource.uri}:{},...dataSource.code?{code:dataSource.code}:{},...dataSource.label?{label:dataSource.label}:{},...candidate.stateKey?{stateKey:candidate.stateKey}:{}}:candidate.stateKey?{optionsType:"relation",stateKey:candidate.stateKey}:null;const status=classifyBinding(candidate,dataSource,relation);return buildAuditItem({pageId:detail.pageId,pageType:detail.type,datasetCode:dataset.code,relation:relation,location:candidate.location,currentBinding:currentBinding,expectedBinding:expectedBinding,fromField:fromField,status:status,pageStatus:pageStatus})})}function buildAuditItem(input){return{pageId:input.pageId,pageType:input.pageType,datasetCode:input.datasetCode,field:input.relation.from.field,location:input.location,currentBinding:input.currentBinding,expectedBinding:input.expectedBinding,fromField:input.fromField,
|
|
6
|
+
status:input.status,...input.pageStatus?{pageStatus:input.pageStatus}:{}}}function buildFromFieldAuditMap(dataset){const rawFields=Array.isArray(dataset.raw?.fields)?dataset.raw.fields:Array.isArray(dataset.raw?.properties)?dataset.raw.properties:[];const fields=new Map;for(const rawField of rawFields){const field=normalizeFromFieldAudit(rawField);if(field)fields.set(field.name,field)}return fields}function normalizeFromFieldAudit(value){if(!isRecord(value)||value.deleted===true)return null;const isV2Field=value.displayName!==undefined||value.doType!==undefined;const name=text(isV2Field?value.name??value.code??value.field??value.key:value.code??value.name??value.field??value.key);if(!name)return null;const displayName=text(isV2Field?value.displayName:value.name);const extend=parseObjectMaybe(value.extend);const doType=text(value.doType);const type=text(value.type??value.dataType)
|
|
7
|
+
;const hasOptions=hasOptionsArray(value.options)||hasOptionsArray(extend?.options)||hasOptionsArray(extend?.selectItems);const optionsType=classifyFromFieldOptionsType({explicitOptionsType:normalizeOptionsType(value.optionsType??extend?.optionsType),hasOptions:hasOptions});return{name:name,...displayName?{displayName:displayName}:{},...doType?{doType:doType}:{},...type?{type:type}:{},optionsType:optionsType,hasOptions:hasOptions}}function buildFallbackFromFieldAudit(name){return{name:name,optionsType:"unknown",hasOptions:false}}function normalizeOptionsType(value){if(typeof value!=="string")return null;const normalized=value.trim().toLowerCase();if(normalized==="relation"||normalized==="custom")return normalized;return null}function classifyFromFieldOptionsType(input){if(input.explicitOptionsType)return input.explicitOptionsType;return input.hasOptions?"custom":"unknown"}function hasOptionsArray(value){return Array.isArray(value)&&value.length>0}function parseObjectMaybe(value){
|
|
8
|
+
if(isRecord(value))return value;if(typeof value!=="string"||!value.trim())return null;try{const parsed=JSON.parse(value);return isRecord(parsed)?parsed:null}catch{return null}}function parsePageSchema(code){if(!code.trim())return{};try{return JSON.parse(code)}catch{return{}}}function collectDataSources(root){const result=[];walk(root,[],(value,path)=>{if(!isRecord(value))return;const list=isRecord(value.dataSource)&&Array.isArray(value.dataSource.list)?value.dataSource.list:path[path.length-1]==="dataSource"&&Array.isArray(value.list)?value.list:[];for(const item of list){const normalized=normalizeDataSource(item);if(normalized)result.push(normalized)}});return uniqueById(result)}function normalizeDataSource(value){if(!isRecord(value))return null;const id=text(value.id??value.name??value.key);if(!id)return null;const options=isRecord(value.options)?value.options:{};const params=isRecord(options.params)?options.params:isRecord(value.params)?value.params:{}
|
|
9
|
+
;const paramsArr=options.paramsArr??value.paramsArr;return{id:id,uri:text(options.uri??options.url??value.uri??value.url),code:text(params.code??readParamFromArray(paramsArr,"code")),label:text(params.label??readParamFromArray(paramsArr,"label"))}}function readParamFromArray(value,name){if(!Array.isArray(value))return undefined;return value.find(item=>isRecord(item)&&item.name===name)?.value}function collectFieldCandidates(root,field){const candidates=[];walk(root,[],(value,path)=>{if(!isRecord(value))return;if(!objectTargetsField(value,field))return;const stateKey=readStateKey(value);candidates.push({field:field,location:inferLocation(path),optionsType:hasPageOptionsArray(value)?"custom":"relation",stateKey:stateKey})});return candidates}function selectFieldCandidate(candidates,dataSources,relation){if(candidates.length===0)return{};const relationCandidates=candidates.filter(candidate=>candidate.optionsType==="relation");if(relationCandidates.length===0){return{candidate:candidates[0]
|
|
10
|
+
}}const resolvedBindings=relationCandidates.flatMap(candidate=>{if(!candidate.stateKey)return[];const dataSource=dataSources.find(item=>item.id===candidate.stateKey);return dataSource?[{candidate:candidate,dataSource:dataSource}]:[]});const targetBindings=resolvedBindings.filter(({dataSource:dataSource})=>dataSourceTargetsDataset(dataSource,relation.to.datasetCode));const targetDataSources=uniqueById(targetBindings.map(({dataSource:dataSource})=>dataSource));if(targetDataSources.length>1){return{ambiguousDataSources:targetDataSources}}const[targetDataSource]=targetDataSources;if(targetDataSource){return{candidate:targetBindings.find(({dataSource:dataSource})=>dataSource.id===targetDataSource.id)?.candidate}}const resolvedDataSources=uniqueById(resolvedBindings.map(({dataSource:dataSource})=>dataSource));if(resolvedDataSources.length>1){return{ambiguousDataSources:resolvedDataSources}}const[resolvedBinding]=resolvedBindings;if(resolvedBinding)return{candidate:resolvedBinding.candidate}
|
|
11
|
+
;return{candidate:relationCandidates[0]}}function hasSubInfoConfig(root){let found=false;walk(root,[],value=>{if(found||!isRecord(value))return;if(!MAIN_SUB_FORM_COMPONENTS.has(text(value.componentName)))return;const props=isRecord(value.props)?value.props:{};found=isRecord(props.sub_info)});return found}function objectTargetsField(value,field){return["field","dataIndex","name","id","key","prop"].some(key=>text(value[key])===field)}function hasPageOptionsArray(value){const formatOptions=isRecord(value.formatOptions)?value.formatOptions:{};return Array.isArray(value.options)||Array.isArray(formatOptions.options)}function readStateKey(value){const formatOptions=isRecord(value.formatOptions)?value.formatOptions:{};return readStateKeyFromUnknown(value.options)??readStateKeyFromUnknown(formatOptions.options)}function readStateKeyFromUnknown(value){if(isRecord(value)&&value.type==="JSExpression"){return readStateKeyFromUnknown(value.value)}if(typeof value!=="string")return undefined
|
|
12
|
+
;const match=value.match(/(?:this\.)?state\.([A-Za-z0-9_-]+)/);return match?.[1]}function inferLocation(path){const normalized=path.map(item=>item.toLowerCase());if(normalized.some(item=>item.includes("datasource")))return"dataSource";if(normalized.some(item=>item.includes("column")||item.includes("table"))){return"table"}if(normalized.some(item=>item.includes("filter")||item.includes("search"))){return"filter"}return"form"}function findDataSourceCandidate(dataSources,field){return dataSources.some(item=>item.id.includes(field))?{field:field,location:"dataSource",optionsType:"relation"}:undefined}function selectDataSourceForCandidate(dataSources,candidate,field,relation){if(candidate.stateKey){return{dataSource:dataSources.find(item=>item.id===candidate.stateKey)}}const targetDataSources=dataSources.filter(item=>dataSourceTargetsDataset(item,relation.to.datasetCode));if(targetDataSources.length===1){return{dataSource:targetDataSources[0]}}if(targetDataSources.length>1){return{
|
|
13
|
+
ambiguousDataSources:targetDataSources}}const fieldDataSources=dataSources.filter(item=>item.id.includes(field));if(fieldDataSources.length===1){return{dataSource:fieldDataSources[0]}}if(fieldDataSources.length>1){return{ambiguousDataSources:fieldDataSources}}return{}}function dataSourceTargetsDataset(dataSource,datasetCode){return dataSource.id.includes(datasetCode)||Boolean(dataSource.uri?.includes(`/${datasetCode}/getSelectOptions`))}function summarizeDataSource(dataSource){return{dataSourceId:dataSource.id,...dataSource.uri?{uri:dataSource.uri}:{},...dataSource.code?{code:dataSource.code}:{},...dataSource.label?{label:dataSource.label}:{}}}function classifyBinding(candidate,dataSource,relation){if(!dataSource)return candidate.stateKey?"wrong_state":"missing";if(candidate.stateKey&&dataSource.id!==candidate.stateKey)return"wrong_state";if(dataSource.code&&dataSource.code!==relation.to.field)return"wrong_code";const relationLabel=readRelationLabel(relation)
|
|
14
|
+
;if(relationLabel&&dataSource.label!==relationLabel){return"wrong_label"}return"relation_options"}function classifyCustomOptions(fromField){if(fromField.optionsType==="relation")return"missing";return"custom_options"}function buildExpectedBinding(appCode,relation){const relationLabel=readRelationLabel(relation);return{toDatasetCode:relation.to.datasetCode,code:relation.to.field,...relationLabel?{label:relationLabel}:{},uri:`/api/${appCode}/${relation.to.datasetCode}/getSelectOptions`}}function readRelationLabel(relation){return text(relation.to.labelField)||undefined}function uniqueById(values){const seen=new Set;return values.filter(value=>{if(seen.has(value.id))return false;seen.add(value.id);return true})}function walk(value,path,visitor){visitor(value,path);if(Array.isArray(value)){value.forEach((item,index)=>walk(item,[...path,String(index)],visitor));return}if(!isRecord(value))return;for(const[key,child]of Object.entries(value)){walk(child,[...path,key],visitor)}}
|
|
15
|
+
function isRecord(value){return Boolean(value)&&typeof value==="object"&&!Array.isArray(value)}function text(value){return typeof value==="string"?value.trim():""}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import{APPCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{listDeletedPages,restoreCustomPage,restoreDataListPage}from"../../core/api-client.js";import{CliErrors}from"../../errors.js";const PAGE_SIZE=100;const PAGE_TYPES=["DATA_LIST","CUSTOM"];const ID_FLAG={name:"id",type:"number",description:"Deleted page id"};const PAGE_TYPE_FLAG={name:"page-type",type:"string",description:"Deleted page product type (narrows automatic discovery)",enum:PAGE_TYPES};export const pageRestore={service:"page",command:"restore",description:"Restore one deleted Data List Page or Custom Page",risk:"write",defaultOutputFormat:"compress",flags:[APPCODE_FLAG_OPTIONAL,ID_FLAG,PAGE_TYPE_FLAG],async validate(ctx){readInput(ctx)},async dryRun(ctx){const target=await resolveTarget(ctx);const request=restoreRequest(ctx.appCode,target);return{method:"POST",url:request.path,body:request.body,description:`Would restore deleted ${displayPageType(target.pageType)} ${target.page.id} (${target.page.name}).`}},
|
|
2
|
+
async execute(ctx){const target=await resolveTarget(ctx);const request=restoreRequest(ctx.appCode,target);if(target.pageType==="DATA_LIST"){await restoreDataListPage(target.page.id)}else{const restored=await restoreCustomPage(ctx.appCode,target.page.id);if(!restored){throw CliErrors.validation(`Deleted Custom Page ${target.page.id} was not restored because its state changed or it was already restored.`,"The page state changed or it was already restored. Query the deleted page list and try again.")}}return{ok:true,message:`Restored ${displayPageType(target.pageType)} ${target.page.id}`,data:{operation:"page.restore",appCode:ctx.appCode,selector:{id:target.page.id,pageType:target.pageType},page:{id:target.page.id,name:target.page.name,pageType:target.pageType,type:target.page.type??null,datasetIds:target.page.datasetIds??null},restored:true,dryRun:false,backend:{method:"POST",path:request.path}}}}};function readInput(ctx){const pageId=ctx.num("id")
|
|
3
|
+
;if(!Number.isInteger(pageId)||pageId<=0){throw CliErrors.validation("--id must be a positive integer.")}const rawPageType=ctx.str("page-type")?.trim().toUpperCase();if(!rawPageType)return{pageId:pageId};if(!PAGE_TYPES.includes(rawPageType)){throw CliErrors.validation("--page-type must be DATA_LIST or CUSTOM.")}return{pageId:pageId,pageType:rawPageType}}async function resolveTarget(ctx){const{pageId:pageId,pageType:pageType}=readInput(ctx);const pageTypes=pageType?[pageType]:PAGE_TYPES;const matches=(await Promise.all(pageTypes.map(async candidateType=>{const page=await findDeletedPage(ctx.appCode,candidateType,pageId);return page?{pageType:candidateType,page:page}:null}))).filter(target=>target!==null);if(matches.length===0){
|
|
4
|
+
throw CliErrors.validation(`Deleted page not found: ${pageId}.`,pageType?`No deleted ${pageType} page with this id exists in app ${ctx.appCode}. Remove --page-type to search both types.`:`No deleted Data List Page or Custom Page with this id exists in app ${ctx.appCode}.`)}if(matches.length>1){throw CliErrors.validation(`Deleted page id ${pageId} exists in both Data List Page and Custom Page stores; pass --page-type to select one.`,"Pass --page-type DATA_LIST or --page-type CUSTOM to select one explicitly.")}return matches[0]}async function findDeletedPage(appCode,pageType,pageId){let currentPage=1;while(true){const result=await listDeletedPages(appCode,pageType,{currentPage:currentPage,pageSize:PAGE_SIZE});const pages=Array.isArray(result.tableData)?result.tableData:[];const match=pages.find(page=>page.id===pageId);if(match)return match;const responsePage=result.paging?.currentPage??currentPage;const responsePageSize=result.paging?.pageSize??PAGE_SIZE
|
|
5
|
+
;const totalCount=result.paging?.totalCount??0;if(pages.length===0||responsePageSize<=0||responsePage*responsePageSize>=totalCount){return null}const nextPage=responsePage+1;if(nextPage<=currentPage)return null;currentPage=nextPage}}function restoreRequest(appCode,target){if(target.pageType==="DATA_LIST"){return{path:"/smartapi/page/restore",body:{id:target.page.id}}}return{path:"/smartapi/webcode/page/restore",body:{appCode:appCode,id:target.page.id}}}function displayPageType(pageType){return pageType==="DATA_LIST"?"Data List Page":"Custom Page"}
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
(function(_0x42d783,_0x2ca277){const _0x16bf1a=a214_0x4bf7,_0x2498b1=_0x42d783();while(!![]){try{const _0x4ccc55=-parseInt(_0x16bf1a(0x114))/0x1+-parseInt(_0x16bf1a(0xe5))/0x2*(parseInt(_0x16bf1a(0x12d))/0x3)+-parseInt(_0x16bf1a(0xc4))/0x4+-parseInt(_0x16bf1a(0xcb))/0x5*(parseInt(_0x16bf1a(0xc3))/0x6)+parseInt(_0x16bf1a(0xcc))/0x7+-parseInt(_0x16bf1a(0xd2))/0x8*(-parseInt(_0x16bf1a(0x11c))/0x9)+-parseInt(_0x16bf1a(0xc1))/0xa*(-parseInt(_0x16bf1a(0x117))/0xb);if(_0x4ccc55===_0x2ca277)break;else _0x2498b1['push'](_0x2498b1['shift']());}catch(_0x37a9fd){_0x2498b1['push'](_0x2498b1['shift']());}}}(a214_0x1944,0x33d37));import{randomUUID}from'node:crypto';function a214_0x4bf7(_0x3a0675,_0x3407d7){_0x3a0675=_0x3a0675-0xa7;const _0x1944ee=a214_0x1944();let _0x4bf768=_0x1944ee[_0x3a0675];return _0x4bf768;}import{CLI_BIN_NAME}from'../../constant/cli.js';import{getDatasetDetail,getPageDetail,tryGetDataListPageStatus}from'../../core/api-client.js';import{loadAliasMap,resolveAlias}from'../../core/alias-resolver.js';import{resolveApiModelSource}from'../../api/model-source.js';import{CliErrors}from'../../errors.js';export function getPageIdFlag(_0x7eadf2){const _0x217418=a214_0x4bf7,_0x4b3495=_0x7eadf2['flag']('id');if(typeof _0x4b3495===_0x217418(0x122)&&Number['isFinite'](_0x4b3495)&&_0x4b3495>0x0)return _0x4b3495;return undefined;}export function validateDatasetSelector(_0x53c651){const _0x745b76=a214_0x4bf7,_0x185dee=Boolean(_0x53c651['str']('datasetcode')),_0x566308=Boolean(_0x53c651[_0x745b76(0xf5)]('alias'));if(_0x185dee&&_0x566308)throw CliErrors[_0x745b76(0x113)](_0x745b76(0xbc));if(!_0x185dee&&!_0x566308)throw CliErrors[_0x745b76(0x113)](_0x745b76(0x118));}export function validateGenerateOperationSelector(_0x551327){const _0x2f53d5=a214_0x4bf7,_0x4a1ca7=Boolean(_0x551327[_0x2f53d5(0xf5)](_0x2f53d5(0x101))),_0x5389a1=Boolean(_0x551327['str'](_0x2f53d5(0x131))),_0x2b2b67=Boolean(_0x551327[_0x2f53d5(0xf5)](_0x2f53d5(0x103))),_0x40f019=[_0x4a1ca7,_0x5389a1,_0x2b2b67][_0x2f53d5(0xb4)](Boolean)[_0x2f53d5(0xb5)];if(_0x40f019>0x1)throw CliErrors[_0x2f53d5(0x113)]('Use\x20exactly\x20one\x20of\x20--task-id,\x20--operation-id,\x20or\x20--client-operation-id.');if(_0x40f019===0x0)throw CliErrors[_0x2f53d5(0x113)]('One\x20of\x20--task-id,\x20--operation-id,\x20or\x20--client-operation-id\x20is\x20required.');}export function validatePageTargetSelector(_0x119dec){const _0x3d2d64=a214_0x4bf7,_0x3f9892=getPageIdFlag(_0x119dec)!==undefined,_0x2b8019=Boolean(_0x119dec[_0x3d2d64(0xf5)](_0x3d2d64(0x132))||_0x119dec[_0x3d2d64(0xf5)](_0x3d2d64(0xeb)));if(_0x3f9892&&_0x2b8019)throw CliErrors['validation']('Use\x20either\x20--id\x20or\x20--datasetcode/--alias,\x20not\x20both.');if(!_0x3f9892&&!_0x2b8019)throw CliErrors['validation']('One\x20of\x20--id\x20or\x20--datasetcode/--alias\x20is\x20required.');if(_0x119dec[_0x3d2d64(0xf5)](_0x3d2d64(0xf6))&&!_0x2b8019)throw CliErrors['validation'](_0x3d2d64(0xb2));}export function resolveDatasetCode(_0x25818e){const _0x145b4c=a214_0x4bf7;validateDatasetSelector(_0x25818e);const _0x264349=_0x25818e[_0x145b4c(0xf5)](_0x145b4c(0x132));if(_0x264349)return _0x264349;const _0x46517b=_0x25818e[_0x145b4c(0xf5)](_0x145b4c(0xeb)),_0x338520=resolveApiModelSource(_0x25818e[_0x145b4c(0xcf)],_0x25818e[_0x145b4c(0x115)],_0x25818e[_0x145b4c(0xab)]||_0x25818e[_0x145b4c(0xfb)]?.[_0x145b4c(0xc8)]||_0x25818e[_0x145b4c(0xfb)]?.[_0x145b4c(0xd4)]),_0x3c02e6=resolveAlias(_0x25818e[_0x145b4c(0xcf)],_0x46517b,undefined,_0x338520[_0x145b4c(0xaa)],_0x338520['profileName']);if(_0x3c02e6)return _0x3c02e6;const _0x4cfd0d=loadAliasMap(_0x25818e[_0x145b4c(0xcf)],undefined,_0x338520[_0x145b4c(0xaa)],_0x338520['profileName']),_0x58cdbb=_0x4cfd0d[_0x145b4c(0xb5)]>0x0?'Available\x20aliases:\x20'+_0x4cfd0d[_0x145b4c(0x12e)](_0x51fa4b=>_0x51fa4b[_0x145b4c(0xeb)])['join'](',\x20'):_0x145b4c(0xbb)+CLI_BIN_NAME+'\x20api\x20pull`\x20to\x20refresh\x20model\x20aliases,\x20or\x20pass\x20--datasetcode\x20directly.';throw CliErrors[_0x145b4c(0x113)]('Alias\x20\x22'+_0x46517b+_0x145b4c(0xf2)+_0x58cdbb);}export async function loadDatasetDetailForPage(_0x5822dd){const _0x1a9c99=a214_0x4bf7,_0x4c4ff5=resolveDatasetCode(_0x5822dd),_0x44651a=await getDatasetDetail(_0x4c4ff5),_0x394d2f=normalizeDatasetDetail(_0x44651a,_0x4c4ff5);return ensureAppOwnership(_0x5822dd[_0x1a9c99(0x115)],_0x394d2f[_0x1a9c99(0x115)],_0x1a9c99(0xe6)+_0x394d2f[_0x1a9c99(0xa7)]+_0x1a9c99(0xb8)+_0x394d2f['appCode']+_0x1a9c99(0xb1)+_0x5822dd[_0x1a9c99(0x115)]+'\x22.'),_0x394d2f;}export async function loadPageDetailForPage(_0x32ecfb,_0x5ba4ba){const _0x7c6584=a214_0x4bf7,_0x5503d7=await getPageDetail(_0x5ba4ba),_0x477b2b=normalizePageDetail(_0x5503d7);return ensureAppOwnership(_0x32ecfb[_0x7c6584(0x115)],_0x477b2b[_0x7c6584(0x115)],_0x7c6584(0x102)+_0x5ba4ba+_0x7c6584(0xb8)+_0x477b2b[_0x7c6584(0x115)]+'\x22,\x20not\x20current\x20app\x20\x22'+_0x32ecfb[_0x7c6584(0x115)]+'\x22.'),_0x477b2b;}export function getUndeletedRelatedPages(_0x2acb70){const _0x627e4b=a214_0x4bf7;return _0x2acb70['relatedPages'][_0x627e4b(0xb4)](_0xd9b1d7=>!_0xd9b1d7[_0x627e4b(0xb3)]);}export function buildPageGenerateOperationStatusQueryCommand(_0x48d72e,_0x396d12){const _0x3d7a12=a214_0x4bf7,_0x59cddb=_0x396d12?.['appCode']&&_0x396d12['appCode']['trim']()!==''?_0x3d7a12(0xda)+_0x396d12['appCode']:'',_0x1bd47a=_0x396d12?.[_0x3d7a12(0xfc)]&&_0x396d12[_0x3d7a12(0xfc)][_0x3d7a12(0x11d)]()!==''?'\x20--task-id\x20'+_0x396d12[_0x3d7a12(0xfc)]:_0x396d12?.[_0x3d7a12(0xcd)]&&_0x396d12[_0x3d7a12(0xcd)][_0x3d7a12(0x11d)]()!==''?'\x20--operation-id\x20'+_0x396d12['operationId']:_0x396d12?.[_0x3d7a12(0x11e)]&&_0x396d12[_0x3d7a12(0x11e)][_0x3d7a12(0x11d)]()!==''?_0x3d7a12(0x127)+_0x396d12[_0x3d7a12(0x11e)]:'';return CLI_BIN_NAME+_0x3d7a12(0xd9)+_0x48d72e+_0x59cddb+_0x1bd47a+_0x3d7a12(0xdf);}export function createPageGenerateClientOperationId(){const _0x569795=a214_0x4bf7;return _0x569795(0xd0)+randomUUID();}export function buildDataListPageStatusQueryCommand(_0x229188,_0x360b49){const _0x4e4c26=a214_0x4bf7,_0x4fe0b2=_0x360b49&&_0x360b49['trim']()!==''?'\x20--appcode\x20'+_0x360b49:'';return CLI_BIN_NAME+_0x4e4c26(0x11a)+_0x229188+_0x4fe0b2+_0x4e4c26(0xdf);}export function prepareDatasetAction(_0x411346,_0x49d706){const _0x74d8d7=a214_0x4bf7,_0x496de0=getUndeletedRelatedPages(_0x411346);if(_0x49d706===_0x74d8d7(0xff)&&_0x496de0[_0x74d8d7(0xb5)]>0x0)throw CliErrors[_0x74d8d7(0x113)](_0x74d8d7(0xe6)+_0x411346['code']+_0x74d8d7(0xe1),_0x74d8d7(0xbb)+CLI_BIN_NAME+_0x74d8d7(0xc6)+_0x411346[_0x74d8d7(0xa7)]+_0x74d8d7(0xed));if(_0x49d706===_0x74d8d7(0xee)&&_0x496de0[_0x74d8d7(0xb5)]===0x0)throw CliErrors[_0x74d8d7(0x113)](_0x74d8d7(0xe6)+_0x411346[_0x74d8d7(0xa7)]+_0x74d8d7(0xd7),_0x74d8d7(0xbb)+CLI_BIN_NAME+'\x20page\x20generate-start\x20--datasetcode\x20'+_0x411346[_0x74d8d7(0xa7)]+_0x74d8d7(0xc9)+CLI_BIN_NAME+_0x74d8d7(0xd9)+_0x411346['code']+_0x74d8d7(0xac));return{'dataset':_0x411346,'undeletedPages':_0x496de0};}export function prepareGenerateDatasetAction(_0x3046dd,_0x372de7){const _0x43266b=a214_0x4bf7,_0x227a8b=getUndeletedRelatedPages(_0x3046dd);if(!_0x372de7){if(_0x227a8b['length']>0x0)throw CliErrors[_0x43266b(0x113)](_0x43266b(0xe6)+_0x3046dd[_0x43266b(0xa7)]+_0x43266b(0xe1),_0x43266b(0xbb)+CLI_BIN_NAME+_0x43266b(0xc6)+_0x3046dd[_0x43266b(0xa7)]+_0x43266b(0xed));return{'dataset':_0x3046dd,'undeletedPages':_0x227a8b,'dataListPageStatus':null};}const _0x102a15=_0x372de7[_0x43266b(0x119)],_0x590e40=_0x372de7['incompleteSets'],_0x249afd=_0x372de7['residualPages'][_0x43266b(0xb5)];if(_0x102a15===0x0&&_0x590e40===0x0&&_0x249afd===0x0)return{'dataset':_0x3046dd,'undeletedPages':_0x227a8b,'dataListPageStatus':_0x372de7};if(_0x102a15===0x1&&_0x590e40===0x0&&_0x249afd===0x0)throw CliErrors[_0x43266b(0x113)](_0x43266b(0xe6)+_0x3046dd[_0x43266b(0xa7)]+'\x22\x20already\x20has\x20one\x20complete\x20Data\x20List\x20Page\x20set.',_0x43266b(0xbb)+CLI_BIN_NAME+_0x43266b(0xc6)+_0x3046dd[_0x43266b(0xa7)]+_0x43266b(0xed));throw CliErrors[_0x43266b(0x113)](_0x43266b(0xe6)+_0x3046dd[_0x43266b(0xa7)]+'\x22\x20has\x20multiple\x20or\x20incomplete\x20Data\x20List\x20Page\x20sets.','Query\x20the\x20page\x20facts\x20first\x20and\x20resolve\x20manually\x20before\x20retrying\x20generate.');}export function assessDataListPageState(_0x446ec5,_0x329e69,_0x2a0c91){const _0x1b98fc=a214_0x4bf7,_0x1b64c1=_0x2a0c91?.[_0x1b98fc(0xc2)]??'already_exists_complete_set',_0x5a49a0=_0x2a0c91?.['fallbackUndeletedPages']??[];if(!_0x329e69){if(_0x5a49a0['length']>0x0)return{'status':'blocked_incomplete_sets','allowGenerate':![],'manualResolutionRequired':!![],'message':_0x1b98fc(0xe6)+_0x446ec5+_0x1b98fc(0xfa),'nextAction':_0x1b98fc(0xe3)};return{'status':_0x1b98fc(0x11b),'allowGenerate':!![],'manualResolutionRequired':![],'message':_0x1b98fc(0xe6)+_0x446ec5+_0x1b98fc(0xe7),'nextAction':'run_generate_start'};}const _0x5a579c=_0x329e69[_0x1b98fc(0x119)],_0x4e2535=_0x329e69[_0x1b98fc(0xdd)],_0x271c80=_0x329e69[_0x1b98fc(0xfd)][_0x1b98fc(0xb5)];if(_0x5a579c===0x0&&_0x4e2535===0x0&&_0x271c80===0x0)return{'status':_0x1b98fc(0x11b),'allowGenerate':!![],'manualResolutionRequired':![],'message':_0x1b98fc(0xe6)+_0x446ec5+'\x22\x20has\x20no\x20Data\x20List\x20Pages\x20yet.','nextAction':_0x1b98fc(0x121)};if(_0x5a579c>0x1)return{'status':_0x1b98fc(0xf7),'allowGenerate':![],'manualResolutionRequired':!![],'message':_0x1b98fc(0xe6)+_0x446ec5+_0x1b98fc(0xe9),'nextAction':_0x1b98fc(0xe3)};if(_0x4e2535>0x0)return{'status':_0x1b98fc(0xf4),'allowGenerate':![],'manualResolutionRequired':!![],'message':_0x1b98fc(0xe6)+_0x446ec5+_0x1b98fc(0xbd),'nextAction':'manual_resolution_required'};if(_0x5a579c===0x1&&_0x271c80>0x0)return{'status':_0x1b98fc(0x111),'allowGenerate':![],'manualResolutionRequired':!![],'message':'Dataset\x20\x22'+_0x446ec5+_0x1b98fc(0x124),'nextAction':'manual_resolution_required'};if(_0x5a579c===0x1)return{'status':_0x1b64c1,'allowGenerate':![],'manualResolutionRequired':![],'message':_0x1b64c1==='generated_complete_set'?_0x1b98fc(0xe6)+_0x446ec5+_0x1b98fc(0x12f):_0x1b98fc(0xe6)+_0x446ec5+_0x1b98fc(0x108),'nextAction':_0x1b64c1==='generated_complete_set'?undefined:_0x1b98fc(0x107)};return{'status':'unknown_reconcile_failed','allowGenerate':![],'manualResolutionRequired':![],'message':'Dataset\x20\x22'+_0x446ec5+'\x22\x20returned\x20an\x20unsupported\x20Data\x20List\x20Page\x20state.','nextAction':_0x1b98fc(0xba)};}export function assessGenerateOperationState(_0x154a1e,_0x2fdd64,_0x408ab8){const _0x76f4ec=a214_0x4bf7,_0x23c0cf=String(_0x2fdd64||'')[_0x76f4ec(0x11d)]()['toUpperCase']();if(_0x23c0cf===_0x76f4ec(0xc7))return{'status':_0x76f4ec(0x10d),'manualResolutionRequired':![],'message':_0x76f4ec(0x10b)+_0x154a1e+'\x22.','nextAction':_0x76f4ec(0xba)};if(_0x23c0cf===_0x76f4ec(0x10c)||_0x23c0cf===_0x76f4ec(0xef)||_0x23c0cf===_0x76f4ec(0xbe))return{'status':'operation_running','manualResolutionRequired':![],'message':_0x76f4ec(0x123)+_0x154a1e+'\x22.','nextAction':'query_operation_status'};if(_0x23c0cf==='SUCCESS'||_0x23c0cf===_0x76f4ec(0x106)){if(!_0x408ab8)return{'status':_0x76f4ec(0xfe),'manualResolutionRequired':![],'message':_0x76f4ec(0x104)+_0x154a1e+_0x76f4ec(0xc5),'nextAction':'query_operation_status'};const _0x429ff2=assessDataListPageState(_0x154a1e,_0x408ab8,{'successStatus':_0x76f4ec(0xd1)});if(_0x429ff2['status']===_0x76f4ec(0x11b))return{'status':_0x76f4ec(0xfe),'manualResolutionRequired':![],'message':_0x76f4ec(0x104)+_0x154a1e+_0x76f4ec(0xe8),'nextAction':'query_operation_status'};return _0x429ff2;}if(_0x23c0cf===_0x76f4ec(0xbf)||_0x23c0cf===_0x76f4ec(0x112)||_0x23c0cf==='')return{'status':_0x76f4ec(0xe0),'manualResolutionRequired':![],'message':_0x76f4ec(0xf8)+_0x154a1e+'\x22.','nextAction':'query_operation_status'};return{'status':_0x76f4ec(0xfe),'manualResolutionRequired':![],'message':_0x76f4ec(0xe6)+_0x154a1e+_0x76f4ec(0x128)+_0x23c0cf+'\x22.','nextAction':_0x76f4ec(0xba)};}export function normalizePageDetail(_0x2207d3){const _0x3c2506=a214_0x4bf7;return{'pageId':Number(_0x2207d3[_0x3c2506(0xde)]),'appCode':_0x2207d3['appCode'],'name':_0x2207d3['name']||_0x3c2506(0xf9)+_0x2207d3['pageId'],'code':_0x2207d3[_0x3c2506(0xa7)]||'','type':_0x2207d3['type']?String(_0x2207d3['type']):_0x3c2506(0xe2),'datasetIds':Array[_0x3c2506(0x133)](_0x2207d3[_0x3c2506(0xc0)])?_0x2207d3[_0x3c2506(0xc0)][_0x3c2506(0x12e)](_0x1cd3c4=>Number(_0x1cd3c4))[_0x3c2506(0xb4)](_0x547da0=>Number[_0x3c2506(0xb6)](_0x547da0)):[],'pageVersion':_0x2207d3[_0x3c2506(0x109)]&&typeof _0x2207d3['config'][_0x3c2506(0xca)]===_0x3c2506(0x122)?_0x2207d3[_0x3c2506(0x109)]['pageVersion']:null,'versionTag':_0x2207d3[_0x3c2506(0x109)]&&typeof _0x2207d3['config'][_0x3c2506(0x125)]==='string'&&_0x2207d3[_0x3c2506(0x109)][_0x3c2506(0x125)][_0x3c2506(0x11d)]()!==''?_0x2207d3['config'][_0x3c2506(0x125)]:null,'relatedPages':normalizeRelatedPages(_0x2207d3['relatedPageInfoList']),'raw':_0x2207d3};}export function serializeDryRunDescription(_0x4f9967){const _0x5c9bb1=a214_0x4bf7;return JSON[_0x5c9bb1(0xa9)](_0x4f9967,null,0x2);}export async function loadDataListPageStatusForGenerate(_0x22e000,_0x4182d2){const _0x12153c=a214_0x4bf7,_0x8a3bf5=await tryGetDataListPageStatus(_0x22e000[_0x12153c(0x115)],_0x4182d2);if(!_0x8a3bf5)return null;return normalizeDataListPageStatus(_0x8a3bf5,_0x4182d2);}export function selectVersionTagGroup(_0x11f154,_0x5dac9d,_0x154a32){const _0x2b4bed=a214_0x4bf7,_0x47d9c3=new Map();for(const _0x349e71 of _0x11f154){const _0x37442c=normalizeVersionTag(_0x5dac9d(_0x349e71)),_0x198330=_0x47d9c3[_0x2b4bed(0xb0)](_0x37442c)??[];_0x198330[_0x2b4bed(0x129)](_0x349e71),_0x47d9c3['set'](_0x37442c,_0x198330);}const _0x525b9f=Array[_0x2b4bed(0xdc)](_0x47d9c3['keys']());if(_0x525b9f['length']<=0x1&&!_0x154a32)return{'items':_0x11f154,'availableTags':_0x525b9f};if(_0x154a32){const _0x7b909=normalizeVersionTag(_0x154a32),_0x5826f7=_0x47d9c3['get'](_0x7b909);if(!_0x5826f7)throw CliErrors[_0x2b4bed(0x113)](_0x2b4bed(0x10f)+_0x154a32+_0x2b4bed(0x120),buildVersionTagHint(_0x525b9f));return{'items':_0x5826f7,'availableTags':_0x525b9f};}throw CliErrors[_0x2b4bed(0x113)](_0x2b4bed(0xaf),buildVersionTagHint(_0x525b9f));}function a214_0x1944(){const _0x38e2de=['task-id','Page\x20\x22','client-operation-id','Operation\x20finished\x20for\x20dataset\x20\x22','join','PARTIAL_SUCCESS','run_sync','\x22\x20already\x20has\x20one\x20complete\x20Data\x20List\x20Page\x20set.','config','Switch\x20app\x20with\x20`','Data\x20List\x20Page\x20generation\x20is\x20pending\x20for\x20dataset\x20\x22','RUNNING','operation_pending','name','Version\x20tag\x20\x22','menuPath','blocked_complete_plus_residual_sets','CANCELLED','validation','265761tUJQOo','appCode','datasetId','33SdzFJe','One\x20of\x20--datasetcode\x20or\x20--alias\x20is\x20required.','completeSets','\x20page\x20data-list-status\x20--datasetcode\x20','no_data_list_pages_found','1512jHNJTr','trim','clientOperationId','type','\x22\x20not\x20found.','run_generate_start','number','Data\x20List\x20Page\x20generation\x20is\x20running\x20for\x20dataset\x20\x22','\x22\x20has\x20one\x20complete\x20set\x20plus\x20residual\x20pages.','versionTag','modelId','\x20--client-operation-id\x20','\x22\x20returned\x20unsupported\x20operation\x20status\x20\x22','push','pages','data-list-status','properties','3fEWLGM','map','\x22\x20now\x20has\x20one\x20complete\x20Data\x20List\x20Page\x20set.','unknown','operation-id','datasetcode','isArray','code','string','stringify','filePath','selectedAppName','\x20--operation-id\x20<id>`\x20until\x20it\x20reaches\x20a\x20terminal\x20state.','pageSets','<empty>','Multiple\x20page\x20groups\x20found\x20for\x20this\x20dataset.','get','\x22,\x20not\x20current\x20app\x20\x22','--version-tag\x20is\x20only\x20supported\x20with\x20--datasetcode\x20or\x20--alias.','deleted','filter','length','isFinite','Use\x20`--version-tag\x20<tag>`.\x20Available\x20groups:\x20','\x22\x20belongs\x20to\x20app\x20\x22','boolean','query_operation_status','Run\x20`','Use\x20either\x20--datasetcode\x20or\x20--alias,\x20not\x20both.','\x22\x20has\x20incomplete\x20Data\x20List\x20Page\x20sets.','CANCELING','FAILED','datasetIds','1792430UIJWLd','successStatus','17634OsKYZI','1217160OqnZiL','\x22,\x20but\x20Data\x20List\x20Page\x20facts\x20are\x20unavailable.','\x20page\x20sync\x20--datasetcode\x20','PENDING','currentApp','`\x20first,\x20then\x20poll\x20`','pageVersion','120ausRIM','2101512kgzpuz','operationId','\x20workspace\x20use\x20--app\x20<name>`\x20or\x20pass\x20--appcode.','apiDir','page-generate-','generated_complete_set','1824WNukrv','totalSets','defaultApp','menuPages','fields','\x22\x20has\x20no\x20undeleted\x20related\x20pages.','dataset','\x20page\x20generate-status\x20--datasetcode\x20','\x20--appcode\x20','datasetCode','from','incompleteSets','pageId','\x20--format\x20json','operation_failed','\x22\x20already\x20has\x20undeleted\x20related\x20pages.','UNKNOWN','manual_resolution_required','modelCode','46766wVKCGi','Dataset\x20\x22','\x22\x20has\x20no\x20Data\x20List\x20Pages\x20yet.','\x22,\x20but\x20no\x20Data\x20List\x20Pages\x20were\x20found\x20during\x20reconcile.','\x22\x20has\x20multiple\x20complete\x20Data\x20List\x20Page\x20sets.','__EMPTY__','alias','relatedPageInfoList','`\x20instead.','sync','RETRYING','title','complete','\x22\x20not\x20found.\x20','menuVisible','blocked_incomplete_sets','str','version-tag','blocked_multiple_complete_sets','Data\x20List\x20Page\x20generation\x20failed\x20for\x20dataset\x20\x22','page-','\x22\x20has\x20undeleted\x20related\x20pages\x20under\x20legacy\x20fallback\x20precheck.','mergedCli','taskId','residualPages','unknown_reconcile_failed','generate','hasMenu'];a214_0x1944=function(){return _0x38e2de;};return a214_0x1944();}function normalizeDatasetDetail(_0x399eaf,_0xfcbd4b){const _0x14b78c=a214_0x4bf7,_0x22062c=Array[_0x14b78c(0x133)](_0x399eaf[_0x14b78c(0xd6)])?_0x399eaf[_0x14b78c(0xd6)]:Array[_0x14b78c(0x133)](_0x399eaf[_0x14b78c(0x12c)])?_0x399eaf['properties']:[];return{'id':Number(_0x399eaf['id']??_0x399eaf[_0x14b78c(0x126)]??0x0),'code':String(_0x399eaf[_0x14b78c(0xa7)]||_0x399eaf[_0x14b78c(0xe4)]||_0xfcbd4b),'name':String(_0x399eaf[_0x14b78c(0x10e)]||_0xfcbd4b),'appCode':_0x399eaf['appCode']||_0x399eaf[_0x14b78c(0xd8)]?.[_0x14b78c(0x115)],'fieldCount':_0x22062c[_0x14b78c(0xb5)],'relatedPages':normalizeRelatedPages(_0x399eaf[_0x14b78c(0xec)]),'raw':_0x399eaf};}function normalizeDataListPageStatus(_0x2759b2,_0xc547c9){const _0x25dace=a214_0x4bf7,_0x4a23de=_0x2de78a=>({'pageId':Number(_0x2de78a[_0x25dace(0xde)]??_0x2de78a['id']??0x0),'title':String(_0x2de78a[_0x25dace(0xf0)]||_0x2de78a[_0x25dace(0x10e)]||_0x25dace(0xf9)+(_0x2de78a[_0x25dace(0xde)]??_0x2de78a['id']??_0x25dace(0x130))),'type':_0x2de78a[_0x25dace(0x11f)]?String(_0x2de78a[_0x25dace(0x11f)]):_0x25dace(0xe2),'deleted':_0x2de78a['deleted']===!![],'hasMenu':_0x2de78a[_0x25dace(0x100)]===!![],'menuVisible':typeof _0x2de78a[_0x25dace(0xf3)]===_0x25dace(0xb9)?_0x2de78a[_0x25dace(0xf3)]:null,'menuPath':typeof _0x2de78a['menuPath']===_0x25dace(0xa8)&&_0x2de78a[_0x25dace(0x110)][_0x25dace(0x11d)]()!==''?_0x2de78a['menuPath']:null}),_0x54d5cc=Array[_0x25dace(0x133)](_0x2759b2[_0x25dace(0xad)])?_0x2759b2['pageSets'][_0x25dace(0x12e)](_0x5f440d=>({'versionTag':typeof _0x5f440d[_0x25dace(0x125)]===_0x25dace(0xa8)&&_0x5f440d[_0x25dace(0x125)]['trim']()!==''?_0x5f440d[_0x25dace(0x125)]:null,'complete':_0x5f440d[_0x25dace(0xf1)]===!![],'pages':Array[_0x25dace(0x133)](_0x5f440d[_0x25dace(0x12a)])?_0x5f440d[_0x25dace(0x12a)][_0x25dace(0x12e)](_0x4a23de):[]})):[];return{'datasetId':typeof _0x2759b2[_0x25dace(0x116)]===_0x25dace(0x122)&&Number['isFinite'](_0x2759b2[_0x25dace(0x116)])?_0x2759b2[_0x25dace(0x116)]:null,'datasetCode':typeof _0x2759b2[_0x25dace(0xdb)]===_0x25dace(0xa8)&&_0x2759b2[_0x25dace(0xdb)][_0x25dace(0x11d)]()!==''?_0x2759b2[_0x25dace(0xdb)]:_0xc547c9,'pageSets':_0x54d5cc,'totalSets':typeof _0x2759b2[_0x25dace(0xd3)]===_0x25dace(0x122)&&Number['isFinite'](_0x2759b2[_0x25dace(0xd3)])?_0x2759b2[_0x25dace(0xd3)]:_0x54d5cc[_0x25dace(0xb5)],'completeSets':typeof _0x2759b2[_0x25dace(0x119)]===_0x25dace(0x122)&&Number[_0x25dace(0xb6)](_0x2759b2[_0x25dace(0x119)])?_0x2759b2[_0x25dace(0x119)]:_0x54d5cc['filter'](_0x21278d=>_0x21278d[_0x25dace(0xf1)])[_0x25dace(0xb5)],'incompleteSets':typeof _0x2759b2[_0x25dace(0xdd)]===_0x25dace(0x122)&&Number['isFinite'](_0x2759b2[_0x25dace(0xdd)])?_0x2759b2['incompleteSets']:_0x54d5cc[_0x25dace(0xb4)](_0x4e82fc=>!_0x4e82fc[_0x25dace(0xf1)]&&_0x4e82fc[_0x25dace(0x12a)]['length']>0x0)[_0x25dace(0xb5)],'residualPages':Array[_0x25dace(0x133)](_0x2759b2['residualPages'])?_0x2759b2[_0x25dace(0xfd)][_0x25dace(0x12e)](_0x4a23de):[],'menuPages':Array['isArray'](_0x2759b2[_0x25dace(0xd5)])?_0x2759b2[_0x25dace(0xd5)]['map'](_0x4a23de):[],'source':_0x25dace(0x12b)};}function normalizeRelatedPages(_0x59919c){const _0x1f2633=a214_0x4bf7;if(!Array[_0x1f2633(0x133)](_0x59919c))return[];return _0x59919c[_0x1f2633(0xb4)](_0x145479=>_0x145479&&typeof _0x145479==='object')['map'](_0x17d2e7=>({'id':Number(_0x17d2e7['id']),'type':_0x17d2e7['type']?String(_0x17d2e7[_0x1f2633(0x11f)]):_0x1f2633(0xe2),'code':_0x17d2e7[_0x1f2633(0xa7)]||undefined,'title':_0x17d2e7[_0x1f2633(0xf0)]||_0x17d2e7[_0x1f2633(0x10e)]||_0x1f2633(0xf9)+_0x17d2e7['id'],'deleted':_0x17d2e7[_0x1f2633(0xb3)]===!![]}))['filter'](_0x25bd01=>Number['isFinite'](_0x25bd01['id']));}function ensureAppOwnership(_0x125719,_0x4f0986,_0x169ada){const _0x4e8e96=a214_0x4bf7;if(!_0x4f0986)return;if(_0x4f0986!==_0x125719)throw CliErrors['validation'](_0x169ada,_0x4e8e96(0x10a)+CLI_BIN_NAME+_0x4e8e96(0xce));}function normalizeVersionTag(_0x5a881f){return _0x5a881f&&_0x5a881f['trim']()!==''?_0x5a881f:'__EMPTY__';}function buildVersionTagHint(_0x23e277){const _0x37cb3a=a214_0x4bf7,_0x37b07e=_0x23e277[_0x37cb3a(0x12e)](_0x532750=>_0x532750===_0x37cb3a(0xea)?_0x37cb3a(0xae):_0x532750)[_0x37cb3a(0x105)](',\x20');return _0x37cb3a(0xb7)+_0x37b07e;}
|
|
1
|
+
import{randomUUID}from"node:crypto";import{CLI_BIN_NAME}from"../../constant/cli.js";import{getDatasetDetail,getPageDetail,tryGetDataListPageStatus}from"../../core/api-client.js";import{loadAliasMap,resolveAlias}from"../../core/alias-resolver.js";import{resolveApiModelSource}from"../../api/model-source.js";import{CliErrors}from"../../errors.js";export function getPageIdFlag(ctx){const value=ctx.flag("id");if(typeof value==="number"&&Number.isFinite(value)&&value>0){return value}return undefined}export function validateDatasetSelector(ctx){const hasDatasetCode=Boolean(ctx.str("datasetcode"));const hasAlias=Boolean(ctx.str("alias"));if(hasDatasetCode&&hasAlias){throw CliErrors.validation("Use either --datasetcode or --alias, not both.")}if(!hasDatasetCode&&!hasAlias){throw CliErrors.validation("One of --datasetcode or --alias is required.")}}export function validateGenerateOperationSelector(ctx){const hasTaskId=Boolean(ctx.str("task-id"))
|
|
2
|
+
;const hasOperationId=Boolean(ctx.str("operation-id"));const hasClientOperationId=Boolean(ctx.str("client-operation-id"));const selectorCount=[hasTaskId,hasOperationId,hasClientOperationId].filter(Boolean).length;if(selectorCount>1){throw CliErrors.validation("Use exactly one of --task-id, --operation-id, or --client-operation-id.")}if(selectorCount===0){throw CliErrors.validation("One of --task-id, --operation-id, or --client-operation-id is required.")}}export function validatePageTargetSelector(ctx){const hasId=getPageIdFlag(ctx)!==undefined;const hasDatasetSelector=Boolean(ctx.str("datasetcode")||ctx.str("alias"));if(hasId&&hasDatasetSelector){throw CliErrors.validation("Use either --id or --datasetcode/--alias, not both.")}if(!hasId&&!hasDatasetSelector){throw CliErrors.validation("One of --id or --datasetcode/--alias is required.")}if(ctx.str("version-tag")&&!hasDatasetSelector){throw CliErrors.validation("--version-tag is only supported with --datasetcode or --alias.")}}
|
|
3
|
+
export function resolveDatasetCode(ctx){validateDatasetSelector(ctx);const datasetCode=ctx.str("datasetcode");if(datasetCode)return datasetCode;const alias=ctx.str("alias");const source=resolveApiModelSource(ctx.apiDir,ctx.appCode,ctx.selectedAppName||ctx.mergedCli?.currentApp||ctx.mergedCli?.defaultApp);const resolved=resolveAlias(ctx.apiDir,alias,undefined,source.filePath,source.profileName);if(resolved)return resolved;const aliasEntries=loadAliasMap(ctx.apiDir,undefined,source.filePath,source.profileName);const hint=aliasEntries.length>0?`Available aliases: ${aliasEntries.map(entry=>entry.alias).join(", ")}`:`Run \`${CLI_BIN_NAME} api pull\` to refresh model aliases, or pass --datasetcode directly.`;throw CliErrors.validation(`Alias "${alias}" not found. ${hint}`)}export async function loadDatasetDetailForPage(ctx){const datasetCode=resolveDatasetCode(ctx);const detail=await getDatasetDetail(datasetCode);const normalized=normalizeDatasetDetail(detail,datasetCode)
|
|
4
|
+
;ensureAppOwnership(ctx.appCode,normalized.appCode,`Dataset "${normalized.code}" belongs to app "${normalized.appCode}", not current app "${ctx.appCode}".`);return normalized}export async function loadPageDetailForPage(ctx,pageId){const detail=await getPageDetail(pageId);const normalized=normalizePageDetail(detail);ensureAppOwnership(ctx.appCode,normalized.appCode,`Page "${pageId}" belongs to app "${normalized.appCode}", not current app "${ctx.appCode}".`);return normalized}export function getUndeletedRelatedPages(detail){return detail.relatedPages.filter(page=>!page.deleted)}export function buildPageGenerateOperationStatusQueryCommand(datasetCode,options){const appPart=options?.appCode&&options.appCode.trim()!==""?` --appcode ${options.appCode}`:""
|
|
5
|
+
;const operationPart=options?.taskId&&options.taskId.trim()!==""?` --task-id ${options.taskId}`:options?.operationId&&options.operationId.trim()!==""?` --operation-id ${options.operationId}`:options?.clientOperationId&&options.clientOperationId.trim()!==""?` --client-operation-id ${options.clientOperationId}`:"";return`${CLI_BIN_NAME} page generate-status --datasetcode ${datasetCode}${appPart}${operationPart} --format json`}export function createPageGenerateClientOperationId(){return`page-generate-${randomUUID()}`}export function buildDataListPageStatusQueryCommand(datasetCode,appCode){const appPart=appCode&&appCode.trim()!==""?` --appcode ${appCode}`:"";return`${CLI_BIN_NAME} page data-list-status --datasetcode ${datasetCode}${appPart} --format json`}export function prepareDatasetAction(dataset,action){const undeletedPages=getUndeletedRelatedPages(dataset);if(action==="generate"&&undeletedPages.length>0){
|
|
6
|
+
throw CliErrors.validation(`Dataset "${dataset.code}" already has undeleted related pages.`,`Run \`${CLI_BIN_NAME} page sync --datasetcode ${dataset.code}\` instead.`)}if(action==="sync"&&undeletedPages.length===0){throw CliErrors.validation(`Dataset "${dataset.code}" has no undeleted related pages.`,`Run \`${CLI_BIN_NAME} page generate-start --datasetcode ${dataset.code}\` first, then poll \`${CLI_BIN_NAME} page generate-status --datasetcode ${dataset.code} --operation-id <id>\` until it reaches a terminal state.`)}return{dataset:dataset,undeletedPages:undeletedPages}}export function prepareGenerateDatasetAction(dataset,dataListPageStatus){const undeletedPages=getUndeletedRelatedPages(dataset);if(!dataListPageStatus){if(undeletedPages.length>0){throw CliErrors.validation(`Dataset "${dataset.code}" already has undeleted related pages.`,`Run \`${CLI_BIN_NAME} page sync --datasetcode ${dataset.code}\` instead.`)}return{dataset:dataset,undeletedPages:undeletedPages,dataListPageStatus:null
|
|
7
|
+
}}const completeSets=dataListPageStatus.completeSets;const incompleteSets=dataListPageStatus.incompleteSets;const residualPageCount=dataListPageStatus.residualPages.length;if(completeSets===0&&incompleteSets===0&&residualPageCount===0){return{dataset:dataset,undeletedPages:undeletedPages,dataListPageStatus:dataListPageStatus}}if(completeSets===1&&incompleteSets===0&&residualPageCount===0){throw CliErrors.validation(`Dataset "${dataset.code}" already has one complete Data List Page set.`,`Run \`${CLI_BIN_NAME} page sync --datasetcode ${dataset.code}\` instead.`)}throw CliErrors.validation(`Dataset "${dataset.code}" has multiple or incomplete Data List Page sets.`,`Query the page facts first and resolve manually before retrying generate.`)}export function assessDataListPageState(datasetCode,dataListPageStatus,options){const successStatus=options?.successStatus??"already_exists_complete_set";const fallbackUndeletedPages=options?.fallbackUndeletedPages??[];if(!dataListPageStatus){
|
|
8
|
+
if(fallbackUndeletedPages.length>0){return{status:"blocked_incomplete_sets",allowGenerate:false,manualResolutionRequired:true,message:`Dataset "${datasetCode}" has undeleted related pages under legacy fallback precheck.`,nextAction:"manual_resolution_required"}}return{status:"no_data_list_pages_found",allowGenerate:true,manualResolutionRequired:false,message:`Dataset "${datasetCode}" has no Data List Pages yet.`,nextAction:"run_generate_start"}}const completeSets=dataListPageStatus.completeSets;const incompleteSets=dataListPageStatus.incompleteSets;const residualPageCount=dataListPageStatus.residualPages.length;if(completeSets===0&&incompleteSets===0&&residualPageCount===0){return{status:"no_data_list_pages_found",allowGenerate:true,manualResolutionRequired:false,message:`Dataset "${datasetCode}" has no Data List Pages yet.`,nextAction:"run_generate_start"}}if(completeSets>1){return{status:"blocked_multiple_complete_sets",allowGenerate:false,manualResolutionRequired:true,
|
|
9
|
+
message:`Dataset "${datasetCode}" has multiple complete Data List Page sets.`,nextAction:"manual_resolution_required"}}if(incompleteSets>0){return{status:"blocked_incomplete_sets",allowGenerate:false,manualResolutionRequired:true,message:`Dataset "${datasetCode}" has incomplete Data List Page sets.`,nextAction:"manual_resolution_required"}}if(completeSets===1&&residualPageCount>0){return{status:"blocked_complete_plus_residual_sets",allowGenerate:false,manualResolutionRequired:true,message:`Dataset "${datasetCode}" has one complete set plus residual pages.`,nextAction:"manual_resolution_required"}}if(completeSets===1){return{status:successStatus,allowGenerate:false,manualResolutionRequired:false,message:successStatus==="generated_complete_set"?`Dataset "${datasetCode}" now has one complete Data List Page set.`:`Dataset "${datasetCode}" already has one complete Data List Page set.`,nextAction:successStatus==="generated_complete_set"?undefined:"run_sync"}}return{
|
|
10
|
+
status:"unknown_reconcile_failed",allowGenerate:false,manualResolutionRequired:false,message:`Dataset "${datasetCode}" returned an unsupported Data List Page state.`,nextAction:"query_operation_status"}}export function assessGenerateOperationState(datasetCode,jobStatus,dataListPageStatus){const normalizedStatus=String(jobStatus||"").trim().toUpperCase();if(normalizedStatus==="PENDING"){return{status:"operation_pending",manualResolutionRequired:false,message:`Data List Page generation is pending for dataset "${datasetCode}".`,nextAction:"query_operation_status"}}if(normalizedStatus==="RUNNING"||normalizedStatus==="RETRYING"||normalizedStatus==="CANCELING"){return{status:"operation_running",manualResolutionRequired:false,message:`Data List Page generation is running for dataset "${datasetCode}".`,nextAction:"query_operation_status"}}if(normalizedStatus==="SUCCESS"||normalizedStatus==="PARTIAL_SUCCESS"){if(!dataListPageStatus){return{status:"unknown_reconcile_failed",
|
|
11
|
+
manualResolutionRequired:false,message:`Operation finished for dataset "${datasetCode}", but Data List Page facts are unavailable.`,nextAction:"query_operation_status"}}const factAssessment=assessDataListPageState(datasetCode,dataListPageStatus,{successStatus:"generated_complete_set"});if(factAssessment.status==="no_data_list_pages_found"){return{status:"unknown_reconcile_failed",manualResolutionRequired:false,message:`Operation finished for dataset "${datasetCode}", but no Data List Pages were found during reconcile.`,nextAction:"query_operation_status"}}return factAssessment}if(normalizedStatus==="FAILED"||normalizedStatus==="CANCELLED"||normalizedStatus===""){return{status:"operation_failed",manualResolutionRequired:false,message:`Data List Page generation failed for dataset "${datasetCode}".`,nextAction:"query_operation_status"}}return{status:"unknown_reconcile_failed",manualResolutionRequired:false,
|
|
12
|
+
message:`Dataset "${datasetCode}" returned unsupported operation status "${normalizedStatus}".`,nextAction:"query_operation_status"}}export function normalizePageDetail(detail){return{pageId:Number(detail.pageId),appCode:detail.appCode,name:detail.name||`page-${detail.pageId}`,code:detail.code||"",type:detail.type?String(detail.type):"UNKNOWN",datasetIds:Array.isArray(detail.datasetIds)?detail.datasetIds.map(value=>Number(value)).filter(value=>Number.isFinite(value)):[],pageVersion:detail.config&&typeof detail.config.pageVersion==="number"?detail.config.pageVersion:null,versionTag:detail.config&&typeof detail.config.versionTag==="string"&&detail.config.versionTag.trim()!==""?detail.config.versionTag:null,relatedPages:normalizeRelatedPages(detail.relatedPageInfoList),raw:detail}}export function serializeDryRunDescription(value){return JSON.stringify(value,null,2)}export async function loadDataListPageStatusForGenerate(ctx,datasetCode){
|
|
13
|
+
const status=await tryGetDataListPageStatus(ctx.appCode,datasetCode);if(!status){return null}return normalizeDataListPageStatus(status,datasetCode)}export function selectVersionTagGroup(items,getVersionTag,requestedTag){const groups=new Map;for(const item of items){const tag=normalizeVersionTag(getVersionTag(item));const bucket=groups.get(tag)??[];bucket.push(item);groups.set(tag,bucket)}const availableTags=Array.from(groups.keys());if(availableTags.length<=1&&!requestedTag){return{items:items,availableTags:availableTags}}if(requestedTag){const normalizedRequested=normalizeVersionTag(requestedTag);const selected=groups.get(normalizedRequested);if(!selected){throw CliErrors.validation(`Version tag "${requestedTag}" not found.`,buildVersionTagHint(availableTags))}return{items:selected,availableTags:availableTags}}throw CliErrors.validation("Multiple page groups found for this dataset.",buildVersionTagHint(availableTags))}function normalizeDatasetDetail(detail,fallbackCode){
|
|
14
|
+
const rawFields=Array.isArray(detail.fields)?detail.fields:Array.isArray(detail.properties)?detail.properties:[];return{id:Number(detail.id??detail.modelId??0),code:String(detail.code||detail.modelCode||fallbackCode),name:String(detail.name||fallbackCode),appCode:detail.appCode||detail.dataset?.appCode,fieldCount:rawFields.length,relatedPages:normalizeRelatedPages(detail.relatedPageInfoList),raw:detail}}function normalizeDataListPageStatus(status,fallbackDatasetCode){const normalizeFact=item=>({pageId:Number(item.pageId??item.id??0),title:String(item.title||item.name||`page-${item.pageId??item.id??"unknown"}`),type:item.type?String(item.type):"UNKNOWN",deleted:item.deleted===true,hasMenu:item.hasMenu===true,menuVisible:typeof item.menuVisible==="boolean"?item.menuVisible:null,menuPath:typeof item.menuPath==="string"&&item.menuPath.trim()!==""?item.menuPath:null});const pageSets=Array.isArray(status.pageSets)?status.pageSets.map(group=>({
|
|
15
|
+
versionTag:typeof group.versionTag==="string"&&group.versionTag.trim()!==""?group.versionTag:null,complete:group.complete===true,pages:Array.isArray(group.pages)?group.pages.map(normalizeFact):[]})):[];return{datasetId:typeof status.datasetId==="number"&&Number.isFinite(status.datasetId)?status.datasetId:null,datasetCode:typeof status.datasetCode==="string"&&status.datasetCode.trim()!==""?status.datasetCode:fallbackDatasetCode,pageSets:pageSets,totalSets:typeof status.totalSets==="number"&&Number.isFinite(status.totalSets)?status.totalSets:pageSets.length,completeSets:typeof status.completeSets==="number"&&Number.isFinite(status.completeSets)?status.completeSets:pageSets.filter(group=>group.complete).length,incompleteSets:typeof status.incompleteSets==="number"&&Number.isFinite(status.incompleteSets)?status.incompleteSets:pageSets.filter(group=>!group.complete&&group.pages.length>0).length,residualPages:Array.isArray(status.residualPages)?status.residualPages.map(normalizeFact):[],
|
|
16
|
+
menuPages:Array.isArray(status.menuPages)?status.menuPages.map(normalizeFact):[],source:"data-list-status"}}function normalizeRelatedPages(raw){if(!Array.isArray(raw))return[];return raw.filter(item=>item&&typeof item==="object").map(item=>({id:Number(item.id),type:item.type?String(item.type):"UNKNOWN",code:item.code||undefined,title:item.title||item.name||`page-${item.id}`,deleted:item.deleted===true})).filter(item=>Number.isFinite(item.id))}function ensureAppOwnership(currentAppCode,resourceAppCode,message){if(!resourceAppCode)return;if(resourceAppCode!==currentAppCode){throw CliErrors.validation(message,`Switch app with \`${CLI_BIN_NAME} workspace use --app <name>\` or pass --appcode.`)}}function normalizeVersionTag(value){return value&&value.trim()!==""?value:"__EMPTY__"}function buildVersionTagHint(tags){const rendered=tags.map(tag=>tag==="__EMPTY__"?"<empty>":tag).join(", ");return`Use \`--version-tag <tag>\`. Available groups: ${rendered}`}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{APPCODE_FLAG_OPTIONAL,DATASETCODE_FLAG_OPTIONAL}from"../../commands/common/flags.js";import{loadDatasetDetailForPage,prepareDatasetAction,serializeDryRunDescription,validateDatasetSelector}from"../../commands/page/shared.js";import{syncDataListPages}from"../../core/api-client.js";export const pageSync={service:"page",command:"sync",description:"Sync dataset changes to related Data List Pages",risk:"write",defaultOutputFormat:"compress",flags:[APPCODE_FLAG_OPTIONAL,DATASETCODE_FLAG_OPTIONAL,{name:"alias",type:"string",description:"Dataset alias from api.ts (resolves to dataset code automatically)"}],async validate(ctx){validateDatasetSelector(ctx)},async dryRun(ctx){const prepared=await prepare(ctx);return{method:"POST",url:`/smartapi/lovrabet/dataset/${prepared.dataset.code}/sync-to-pages`,body:{appCode:ctx.appCode},description:serializeDryRunDescription({dataset:{id:prepared.dataset.id,code:prepared.dataset.code,name:prepared.dataset.name,fieldCount:prepared.dataset.fieldCount
|
|
2
|
+
},relatedPages:{total:prepared.dataset.relatedPages.length,undeletedCount:prepared.undeletedPages.length},action:"sync",reason:`${prepared.undeletedPages.length} undeleted related page(s) found`})}},async execute(ctx){const prepared=await prepare(ctx);const result=await syncDataListPages(ctx.appCode,prepared.dataset.code);const hasFailed=Array.isArray(result.failedPages)&&result.failedPages.length>0;const message=hasFailed?"Some pages failed to sync":"Sync succeeded";return{ok:true,message:message,data:{datasetCode:prepared.dataset.code,...result}}}};async function prepare(ctx){const dataset=await loadDatasetDetailForPage(ctx);return prepareDatasetAction(dataset,"sync")}
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
const a216_0x37c50f=a216_0x16e3;function a216_0x16e3(_0x39c5cc,_0x2ba077){_0x39c5cc=_0x39c5cc-0x18a;const _0x5bbfcb=a216_0x5bbf();let _0x16e379=_0x5bbfcb[_0x39c5cc];return _0x16e379;}(function(_0x113937,_0x2c65b6){const _0x5dd9fc=a216_0x16e3,_0x2a06ba=_0x113937();while(!![]){try{const _0x37df47=parseInt(_0x5dd9fc(0x199))/0x1*(-parseInt(_0x5dd9fc(0x1b3))/0x2)+parseInt(_0x5dd9fc(0x1c7))/0x3+-parseInt(_0x5dd9fc(0x1bc))/0x4*(parseInt(_0x5dd9fc(0x19e))/0x5)+-parseInt(_0x5dd9fc(0x18d))/0x6*(-parseInt(_0x5dd9fc(0x197))/0x7)+parseInt(_0x5dd9fc(0x1c2))/0x8+-parseInt(_0x5dd9fc(0x18a))/0x9*(-parseInt(_0x5dd9fc(0x1cd))/0xa)+-parseInt(_0x5dd9fc(0x1a9))/0xb;if(_0x37df47===_0x2c65b6)break;else _0x2a06ba['push'](_0x2a06ba['shift']());}catch(_0x8203ea){_0x2a06ba['push'](_0x2a06ba['shift']());}}}(a216_0x5bbf,0xb5dea));import{copyFileSync,existsSync,mkdirSync,readFileSync,writeFileSync}from'node:fs';import a216_0x364295 from'node:path';import{getMultiAppConfigs,initMultiAppEnvironment,readConfigFile,writeConfigFile}from'../../context.js';import{DEFAULT_API_DIR}from'../../constant/paths.js';import{getRuntimeDomain}from'../../constant/domain.js';import{getRegistryGroup,resolveApiProfileLayouts}from'../../api/api-group.js';import{MODEL_REGISTRY_FILE_NAME,MODEL_RUNTIME_FILE_NAME,readModelRegistry,updateModelRegistry}from'../../api/model-registry-file.js';import{isLegacyGeneratedApiScaffold,isLegacyGeneratedClientScaffold,parseLegacyApiModels}from'../../api/legacy-api-file.js';import{renderModelRegistryScaffold}from'../../api/model-registry-scaffold.js';import{writeProjectDomainRoutingManifest}from'../../config/project-domain-routing.js';const MIGRATION_ID='api-model-registry-v2',SDK_CONFIG_SOURCE=a216_0x37c50f(0x1aa);function relativeMigrationDir(_0xfa8149,_0x13a671){const _0x27e182=a216_0x37c50f,_0x48a412=a216_0x364295[_0x27e182(0x1ce)](_0xfa8149,_0x13a671);return _0x48a412&&!_0x48a412[_0x27e182(0x1c6)]('..')?_0x48a412:_0x27e182(0x1a7);}function candidatePath(_0x3b3fdc,_0x1e8de6,_0x26d37c){const _0xbd9c81=a216_0x37c50f;return a216_0x364295['join'](_0x3b3fdc,_0xbd9c81(0x19c),_0xbd9c81(0x1ae),MIGRATION_ID,_0xbd9c81(0x19b),relativeMigrationDir(_0x3b3fdc,_0x1e8de6),_0x26d37c);}function backupPath(_0x4e4950,_0x302f3a,_0x250d58){const _0x3ddac3=a216_0x37c50f;return a216_0x364295[_0x3ddac3(0x1ac)](_0x4e4950,'.rabetbase',_0x3ddac3(0x1ae),MIGRATION_ID,_0x3ddac3(0x19a),relativeMigrationDir(_0x4e4950,_0x302f3a),_0x250d58);}function readOptional(_0x2448d6){const _0x476638=a216_0x37c50f;try{return readFileSync(_0x2448d6,_0x476638(0x198));}catch{return undefined;}}function readJsonObject(_0x5c5309){try{const _0x109be4=JSON['parse'](readFileSync(_0x5c5309,'utf8'));return _0x109be4&&typeof _0x109be4==='object'?_0x109be4:{};}catch{return{};}}function planEntrypoint(_0x56920d,_0x486b6c,_0x1750ab,_0x19b3e1){const _0x180294=a216_0x37c50f,_0x467275=a216_0x364295[_0x180294(0x1ac)](_0x486b6c,_0x1750ab),_0x4c01e4=readOptional(_0x467275);if(_0x4c01e4===undefined)return{'path':_0x467275,'action':_0x180294(0x1a6)};if(_0x1750ab===_0x180294(0x1a8)?_0x4c01e4[_0x180294(0x190)]('./models.generated')&&_0x4c01e4['includes'](_0x180294(0x19d)):_0x4c01e4[_0x180294(0x190)](_0x180294(0x1bf)))return{'path':_0x467275,'action':_0x180294(0x18c)};if(_0x19b3e1(_0x4c01e4))return{'path':_0x467275,'action':_0x180294(0x1a5),'reason':_0x180294(0x1b7)};return{'path':_0x467275,'action':'manual-merge','reason':'The\x20file\x20contains\x20project-owned\x20code\x20and\x20will\x20not\x20be\x20overwritten.','candidatePath':candidatePath(_0x56920d,_0x486b6c,_0x1750ab)};}function syntheticApps(_0x301292){const _0x46b21a=a216_0x37c50f,_0x4a7fb5=_0x301292[_0x46b21a(0x1c3)]&&typeof _0x301292[_0x46b21a(0x1c3)]===_0x46b21a(0x1b2)?_0x301292[_0x46b21a(0x1c3)]:undefined;if(_0x4a7fb5&&Object[_0x46b21a(0x1c0)](_0x4a7fb5)[_0x46b21a(0x1a1)]>0x0){const _0x163026=typeof _0x301292[_0x46b21a(0x193)]===_0x46b21a(0x1c1)?_0x301292[_0x46b21a(0x193)]:Object[_0x46b21a(0x1c0)](_0x4a7fb5)[_0x46b21a(0x1a1)]===0x1?Object[_0x46b21a(0x1c0)](_0x4a7fb5)[0x0]:undefined;return Object[_0x46b21a(0x18b)](_0x4a7fb5)[_0x46b21a(0x1ca)](([_0x4c1904,_0x32f910])=>{const _0x297d2c=_0x46b21a,_0x3a6db6=_0x32f910,_0x2a5d4d=typeof _0x3a6db6[_0x297d2c(0x1bb)]===_0x297d2c(0x1c1)?_0x3a6db6[_0x297d2c(0x1bb)]:'';return _0x2a5d4d?[{'name':_0x4c1904,'appcode':_0x2a5d4d,'apiGroup':typeof _0x3a6db6[_0x297d2c(0x1be)]==='string'?_0x3a6db6[_0x297d2c(0x1be)]:undefined,'isDefault':_0x4c1904===_0x163026,'region':'cn','regionSource':'default','apiDir':typeof _0x3a6db6[_0x297d2c(0x1a0)]==='string'?_0x3a6db6['apiDir']:typeof _0x301292['apiDir']==='string'?_0x301292['apiDir']:undefined,'routingConfig':{}}]:[];});}const _0x98769d=typeof _0x301292[_0x46b21a(0x1bb)]===_0x46b21a(0x1c1)?_0x301292[_0x46b21a(0x1bb)]:typeof _0x301292['app']==='string'?_0x301292[_0x46b21a(0x196)]:undefined;if(!_0x98769d)return[];return[{'name':_0x98769d,'appcode':_0x98769d,'isDefault':!![],'region':'cn','regionSource':_0x46b21a(0x1b1),'apiDir':typeof _0x301292[_0x46b21a(0x1a0)]===_0x46b21a(0x1c1)?_0x301292[_0x46b21a(0x1a0)]:undefined,'routingConfig':{}}];}function configuredLayouts(_0x127b80,_0x2531a7){const _0x251b41=a216_0x37c50f;return resolveApiProfileLayouts(_0x2531a7,_0x52c44d=>a216_0x364295[_0x251b41(0x195)](_0x127b80,_0x52c44d['apiDir']||DEFAULT_API_DIR),_0x127b80);}function a216_0x5bbf(){const _0x3c1d02=['./model-runtime','10PxTaxr','modelRuntime','apiDir','length','migrate-single-app','path','dirname','replace-generated','create','external-api-dir','api.ts','14722851PYohtl','/**\x0a\x20*\x20Lovrabet\x20SDK\x20runtime\x20routing.\x0a\x20*\x20Generated\x20by\x20Rabetbase\x20CLI.\x20Do\x20not\x20add\x20credentials\x20to\x20this\x20file.\x0a\x20*/\x0aexport\x20const\x20LOVRABET_SDK_CONFIG\x20=\x20{}\x20as\x20const;\x0a','basename','join','unconfigured','project-upgrade','.rabetbase.json','some','default','object','381974PldRPp','single','name','add','Recognized\x20legacy\x20CLI\x20scaffold;\x20a\x20backup\x20will\x20be\x20retained.','profiles','manualMergeRequired','find','appcode','854812NOBEWw','manual-merge','apiGroup','LOVRABET_RUNTIME_DOMAIN','keys','string','4786616GQWYAG','apps','normalizedApiDir','client.ts','startsWith','4122852COCRJC','map','No\x20Lovrabet\x20model\x20profile\x20matches\x20Runtime\x20Domain','flatMap','Multiple\x20Lovrabet\x20model\x20profiles\x20match\x20Runtime\x20Domain','files','2945980oWBGvB','relative','The\x20existing\x20runtime\x20selector\x20is\x20not\x20a\x20recognized\x20current\x20generated\x20file.','has','27pblafO','entries','unchanged','14922sBaaWo','preserve','action','includes','-api.ts','isDefault','defaultApp','outputDir','resolve','app','1715EqsyfF','utf8','5LpzbfY','backups','candidates','.rabetbase'];a216_0x5bbf=function(){return _0x3c1d02;};return a216_0x5bbf();}function uniqueRegistryGroups(_0x191df8){const _0x32bb9b=a216_0x37c50f,_0x11294f=[],_0x26fcfd=new Set(),_0x48d25a=new Set();for(const _0x3ef74b of _0x191df8){const _0x1f0a0d=getRegistryGroup(_0x191df8,_0x3ef74b);if(!_0x1f0a0d){_0x26fcfd[_0x32bb9b(0x1b6)](_0x3ef74b[_0x32bb9b(0x194)]);continue;}const _0x3240cc=_0x3ef74b[_0x32bb9b(0x1c4)]+'\x00'+(_0x3ef74b[_0x32bb9b(0x1be)]??_0x32bb9b(0x1b4));!_0x48d25a[_0x32bb9b(0x1d0)](_0x3240cc)&&(_0x11294f['push'](_0x1f0a0d),_0x48d25a[_0x32bb9b(0x1b6)](_0x3240cc));}return{'groups':_0x11294f,'skipped':[..._0x26fcfd]};}function planGroup(_0x1dfc3a,_0x5b8439){const _0x10f0cb=a216_0x37c50f,_0x19e68e=_0x5b8439[0x0][_0x10f0cb(0x1c4)],_0x12ee79=a216_0x364295[_0x10f0cb(0x1ac)](_0x19e68e,MODEL_RUNTIME_FILE_NAME),_0x2d0cdc=readOptional(_0x12ee79),_0x1d7c62=_0x2d0cdc!==undefined&&_0x2d0cdc[_0x10f0cb(0x190)]('Profile-aware\x20model\x20selection\x20generated\x20by\x20Rabetbase\x20CLI')&&_0x2d0cdc[_0x10f0cb(0x190)](_0x10f0cb(0x1cb))&&_0x2d0cdc[_0x10f0cb(0x190)](_0x10f0cb(0x1c9)),_0x57df51=a216_0x364295[_0x10f0cb(0x1ac)](_0x19e68e,MODEL_REGISTRY_FILE_NAME),_0x302155=a216_0x364295[_0x10f0cb(0x1ac)](_0x19e68e,'sdk-config.ts'),_0x134369=[planEntrypoint(_0x1dfc3a,_0x19e68e,_0x10f0cb(0x1a8),isLegacyGeneratedApiScaffold),planEntrypoint(_0x1dfc3a,_0x19e68e,_0x10f0cb(0x1c5),isLegacyGeneratedClientScaffold),{'path':_0x12ee79,'action':_0x2d0cdc===undefined?_0x10f0cb(0x1a6):_0x1d7c62?'unchanged':'manual-merge','reason':_0x2d0cdc===undefined?undefined:_0x10f0cb(0x1cf),..._0x2d0cdc!==undefined&&!_0x1d7c62?{'candidatePath':candidatePath(_0x1dfc3a,_0x19e68e,MODEL_RUNTIME_FILE_NAME)}:{}},{'path':_0x57df51,'action':existsSync(_0x57df51)?_0x10f0cb(0x18e):_0x10f0cb(0x1a6),'reason':'Model\x20facts\x20are\x20preserved\x20and\x20completed\x20from\x20legacy\x20generated\x20files\x20when\x20possible.'},{'path':_0x302155,'action':existsSync(_0x302155)?_0x10f0cb(0x18e):_0x10f0cb(0x1a6)}];return{'apiDir':_0x19e68e,'profiles':_0x5b8439[_0x10f0cb(0x1c8)](_0x2c2dba=>_0x2c2dba['app'][_0x10f0cb(0x1b5)]),'files':_0x134369};}export function analyzeProjectApiArchitecture(_0x4bf11d,_0x1909f7){const _0x35b314=a216_0x37c50f,_0x2b28e1=a216_0x364295[_0x35b314(0x1ac)](_0x4bf11d,_0x35b314(0x1af)),_0x510cd9=_0x1909f7??(existsSync(_0x2b28e1)?readJsonObject(_0x2b28e1):{}),_0xd4ceac=syntheticApps(_0x510cd9);if(_0xd4ceac[_0x35b314(0x1a1)]===0x0)return{'migration':MIGRATION_ID,'needed':![],'configAction':_0x35b314(0x1ad),'groups':[],'skippedLegacyDirectories':[],'manualMergeRequired':![]};const _0x1e13b3=_0x510cd9[_0x35b314(0x1c3)]?'unchanged':_0x35b314(0x1a2),{groups:_0x44c2db,skipped:_0x29e459}=uniqueRegistryGroups(configuredLayouts(_0x4bf11d,_0xd4ceac)),_0x3146ea=_0x44c2db[_0x35b314(0x1c8)](_0x2c3035=>planGroup(_0x4bf11d,_0x2c3035)),_0x2e36e3=_0x3146ea['some'](_0x2c0857=>_0x2c0857['files'][_0x35b314(0x1b0)](_0x1b1f74=>_0x1b1f74['action']===_0x35b314(0x1bd))),_0x43f40=_0x1e13b3===_0x35b314(0x1a2)||_0x3146ea['some'](_0x521c3e=>_0x521c3e['files'][_0x35b314(0x1b0)](_0x3cf29e=>![_0x35b314(0x18c),_0x35b314(0x18e)]['includes'](_0x3cf29e[_0x35b314(0x18f)])));return{'migration':MIGRATION_ID,'needed':_0x43f40,'configAction':_0x1e13b3,'groups':_0x3146ea,'skippedLegacyDirectories':_0x29e459,'manualMergeRequired':_0x2e36e3};}function migrateSingleAppConfig(_0x1fe31f){const _0x53b08b=a216_0x37c50f,_0x2e9137=a216_0x364295[_0x53b08b(0x1ac)](_0x1fe31f,_0x53b08b(0x1af));if(!existsSync(_0x2e9137))return;const _0x184ee2=readConfigFile(_0x2e9137);if(_0x184ee2[_0x53b08b(0x1c3)]&&typeof _0x184ee2['apps']===_0x53b08b(0x1b2))return;const _0x4e4bbe=typeof _0x184ee2[_0x53b08b(0x1bb)]==='string'?_0x184ee2[_0x53b08b(0x1bb)]:typeof _0x184ee2[_0x53b08b(0x196)]===_0x53b08b(0x1c1)?_0x184ee2[_0x53b08b(0x196)]:undefined;if(!_0x4e4bbe)return;_0x184ee2[_0x53b08b(0x1c3)]={[_0x4e4bbe]:{'appcode':_0x4e4bbe}},_0x184ee2[_0x53b08b(0x193)]=_0x4e4bbe,delete _0x184ee2[_0x53b08b(0x196)],delete _0x184ee2['appcode'],writeConfigFile(_0x2e9137,_0x184ee2);}function legacyApiPath(_0x1374fa,_0xe7439){const _0x444741=a216_0x37c50f,_0x164386=_0xe7439[_0x444741(0x1c4)],_0x511b18=_0x1374fa[_0x444741(0x1a1)]===0x1||_0xe7439[_0x444741(0x196)][_0x444741(0x192)]?[a216_0x364295[_0x444741(0x1ac)](_0x164386,'api.ts'),a216_0x364295[_0x444741(0x1ac)](_0x164386,_0xe7439[_0x444741(0x196)]['name']+_0x444741(0x191))]:[a216_0x364295[_0x444741(0x1ac)](_0x164386,_0xe7439[_0x444741(0x196)][_0x444741(0x1b5)]+'-api.ts')];return _0x511b18[_0x444741(0x1ba)](existsSync);}function writeCandidateOrEntrypoint(_0x35fe2d,_0x2ab38f,_0xe27f2b,_0x24ea4b){const _0x2b2d6e=a216_0x37c50f;if(_0xe27f2b[_0x2b2d6e(0x18f)]==='unchanged'||_0xe27f2b[_0x2b2d6e(0x18f)]==='preserve')return;if(_0xe27f2b['action']===_0x2b2d6e(0x1bd)){const _0x44bf7c=_0xe27f2b['candidatePath'];mkdirSync(a216_0x364295[_0x2b2d6e(0x1a4)](_0x44bf7c),{'recursive':!![]}),writeFileSync(_0x44bf7c,_0x24ea4b,'utf8');return;}if(_0xe27f2b[_0x2b2d6e(0x18f)]===_0x2b2d6e(0x1a5)){const _0x29cc90=backupPath(_0x35fe2d,_0x2ab38f,a216_0x364295[_0x2b2d6e(0x1ab)](_0xe27f2b[_0x2b2d6e(0x1a3)]));mkdirSync(a216_0x364295[_0x2b2d6e(0x1a4)](_0x29cc90),{'recursive':!![]}),copyFileSync(_0xe27f2b[_0x2b2d6e(0x1a3)],_0x29cc90);}mkdirSync(a216_0x364295['dirname'](_0xe27f2b[_0x2b2d6e(0x1a3)]),{'recursive':!![]}),writeFileSync(_0xe27f2b['path'],_0x24ea4b,_0x2b2d6e(0x198));}export async function upgradeProjectApiArchitecture(_0x430940){const _0x49acab=a216_0x37c50f,_0x446ded=analyzeProjectApiArchitecture(_0x430940);migrateSingleAppConfig(_0x430940);const _0x352aa6=getMultiAppConfigs('project',_0x430940)??[],_0x3b9816=configuredLayouts(_0x430940,_0x352aa6),{groups:_0x2392ff}=uniqueRegistryGroups(_0x3b9816);let _0x462964;for(const _0x3053c2 of _0x2392ff){const _0xa0bc=_0x3053c2[0x0][_0x49acab(0x1c4)];mkdirSync(_0xa0bc,{'recursive':!![]});const _0x1e44fe=_0x3053c2[_0x49acab(0x1ba)](_0x1c7905=>_0x1c7905['app'][_0x49acab(0x192)])??_0x3053c2[0x0];for(const _0x3ed811 of _0x3053c2){const _0x266c25=a216_0x364295['join'](_0xa0bc,MODEL_REGISTRY_FILE_NAME),_0x3b16f3=readModelRegistry(_0x266c25);if(_0x3b16f3?.[_0x49acab(0x1b8)][_0x3ed811[_0x49acab(0x196)][_0x49acab(0x1b5)]])continue;const _0x322dc9=legacyApiPath(_0x3053c2,_0x3ed811),_0x30689e=_0x322dc9?readOptional(_0x322dc9):undefined;await initMultiAppEnvironment(_0x3ed811['app']),updateModelRegistry({'outputDir':_0xa0bc,'profileName':_0x3ed811[_0x49acab(0x196)][_0x49acab(0x1b5)],'defaultProfile':_0x1e44fe[_0x49acab(0x196)]['name'],'appCode':_0x3ed811[_0x49acab(0x196)][_0x49acab(0x1bb)],'runtimeDomain':getRuntimeDomain(),'models':_0x30689e?parseLegacyApiModels(_0x30689e):[]});}const _0x563b4f=await renderModelRegistryScaffold(_0xa0bc,_0x430940),_0x412c0d=planGroup(_0x430940,_0x3053c2);for(const _0x179830 of _0x412c0d[_0x49acab(0x1cc)]){const _0x287591=a216_0x364295[_0x49acab(0x1ab)](_0x179830[_0x49acab(0x1a3)]);if(_0x287591===_0x49acab(0x1a8))writeCandidateOrEntrypoint(_0x430940,_0xa0bc,_0x179830,_0x563b4f['api']);else{if(_0x287591==='client.ts')writeCandidateOrEntrypoint(_0x430940,_0xa0bc,_0x179830,_0x563b4f['client']);else{if(_0x287591===MODEL_RUNTIME_FILE_NAME)writeCandidateOrEntrypoint(_0x430940,_0xa0bc,_0x179830,_0x563b4f[_0x49acab(0x19f)]);else _0x287591==='sdk-config.ts'&&_0x179830['action']==='create'&&writeCandidateOrEntrypoint(_0x430940,_0xa0bc,_0x179830,SDK_CONFIG_SOURCE);}}}}const _0x207531=_0x352aa6[_0x49acab(0x1ba)](_0x5e2fe0=>_0x5e2fe0[_0x49acab(0x192)])??_0x352aa6[0x0];_0x207531&&(await initMultiAppEnvironment(_0x207531),_0x462964=writeProjectDomainRoutingManifest(_0x430940)[_0x49acab(0x1a3)]);const _0x31dfda=analyzeProjectApiArchitecture(_0x430940);return{..._0x446ded,'completed':!_0x31dfda[_0x49acab(0x1b9)],'manualMergeRequired':_0x31dfda['manualMergeRequired'],'routingPath':_0x462964};}
|
|
1
|
+
import{copyFileSync,existsSync,mkdirSync,readFileSync,writeFileSync}from"node:fs";import path from"node:path";import{getMultiAppConfigs,initMultiAppEnvironment,readConfigFile,writeConfigFile}from"../../context.js";import{DEFAULT_API_DIR}from"../../constant/paths.js";import{getRuntimeDomain}from"../../constant/domain.js";import{getRegistryGroup,resolveApiProfileLayouts}from"../../api/api-group.js";import{MODEL_REGISTRY_FILE_NAME,MODEL_RUNTIME_FILE_NAME,readModelRegistry,updateModelRegistry}from"../../api/model-registry-file.js";import{isLegacyGeneratedApiScaffold,isLegacyGeneratedClientScaffold,parseLegacyApiModels}from"../../api/legacy-api-file.js";import{renderModelRegistryScaffold}from"../../api/model-registry-scaffold.js";import{writeProjectDomainRoutingManifest}from"../../config/project-domain-routing.js";const MIGRATION_ID="api-model-registry-v2"
|
|
2
|
+
;const SDK_CONFIG_SOURCE=`/**\n * Lovrabet SDK runtime routing.\n * Generated by Rabetbase CLI. Do not add credentials to this file.\n */\nexport const LOVRABET_SDK_CONFIG = {} as const;\n`;function relativeMigrationDir(projectRoot,outputDir){const relative=path.relative(projectRoot,outputDir);return relative&&!relative.startsWith("..")?relative:"external-api-dir"}function candidatePath(projectRoot,outputDir,fileName){return path.join(projectRoot,".rabetbase","project-upgrade",MIGRATION_ID,"candidates",relativeMigrationDir(projectRoot,outputDir),fileName)}function backupPath(projectRoot,outputDir,fileName){return path.join(projectRoot,".rabetbase","project-upgrade",MIGRATION_ID,"backups",relativeMigrationDir(projectRoot,outputDir),fileName)}function readOptional(filePath){try{return readFileSync(filePath,"utf8")}catch{return undefined}}function readJsonObject(filePath){try{const parsed=JSON.parse(readFileSync(filePath,"utf8"));return parsed&&typeof parsed==="object"?parsed:{}}catch{
|
|
3
|
+
return{}}}function planEntrypoint(projectRoot,outputDir,fileName,isLegacyGenerated){const filePath=path.join(outputDir,fileName);const content=readOptional(filePath);if(content===undefined)return{path:filePath,action:"create"};if(fileName==="api.ts"?content.includes("./models.generated")&&content.includes("./model-runtime"):content.includes("LOVRABET_RUNTIME_DOMAIN")){return{path:filePath,action:"unchanged"}}if(isLegacyGenerated(content)){return{path:filePath,action:"replace-generated",reason:"Recognized legacy CLI scaffold; a backup will be retained."}}return{path:filePath,action:"manual-merge",reason:"The file contains project-owned code and will not be overwritten.",candidatePath:candidatePath(projectRoot,outputDir,fileName)}}function syntheticApps(config){const apps=config.apps&&typeof config.apps==="object"?config.apps:undefined;if(apps&&Object.keys(apps).length>0){
|
|
4
|
+
const defaultName=typeof config.defaultApp==="string"?config.defaultApp:Object.keys(apps).length===1?Object.keys(apps)[0]:undefined;return Object.entries(apps).flatMap(([name,value])=>{const profile=value;const appcode=typeof profile.appcode==="string"?profile.appcode:"";return appcode?[{name:name,appcode:appcode,apiGroup:typeof profile.apiGroup==="string"?profile.apiGroup:undefined,isDefault:name===defaultName,region:"cn",regionSource:"default",apiDir:typeof profile.apiDir==="string"?profile.apiDir:typeof config.apiDir==="string"?config.apiDir:undefined,routingConfig:{}}]:[]})}const appcode=typeof config.appcode==="string"?config.appcode:typeof config.app==="string"?config.app:undefined;if(!appcode)return[];return[{name:appcode,appcode:appcode,isDefault:true,region:"cn",regionSource:"default",apiDir:typeof config.apiDir==="string"?config.apiDir:undefined,routingConfig:{}}]}function configuredLayouts(projectRoot,apps){
|
|
5
|
+
return resolveApiProfileLayouts(apps,app=>path.resolve(projectRoot,app.apiDir||DEFAULT_API_DIR),projectRoot)}function uniqueRegistryGroups(layouts){const groups=[];const skipped=new Set;const seen=new Set;for(const layout of layouts){const group=getRegistryGroup(layouts,layout);if(!group){skipped.add(layout.outputDir);continue}const key=`${layout.normalizedApiDir}\0${layout.apiGroup??"single"}`;if(!seen.has(key)){groups.push(group);seen.add(key)}}return{groups:groups,skipped:[...skipped]}}function planGroup(projectRoot,group){const outputDir=group[0].normalizedApiDir;const runtimePath=path.join(outputDir,MODEL_RUNTIME_FILE_NAME);const runtimeContent=readOptional(runtimePath);const runtimeCurrent=runtimeContent!==undefined&&runtimeContent.includes("Profile-aware model selection generated by Rabetbase CLI")&&runtimeContent.includes("Multiple Lovrabet model profiles match Runtime Domain")&&runtimeContent.includes("No Lovrabet model profile matches Runtime Domain")
|
|
6
|
+
;const registryPath=path.join(outputDir,MODEL_REGISTRY_FILE_NAME);const sdkConfigPath=path.join(outputDir,"sdk-config.ts");const files=[planEntrypoint(projectRoot,outputDir,"api.ts",isLegacyGeneratedApiScaffold),planEntrypoint(projectRoot,outputDir,"client.ts",isLegacyGeneratedClientScaffold),{path:runtimePath,action:runtimeContent===undefined?"create":runtimeCurrent?"unchanged":"manual-merge",reason:runtimeContent===undefined?undefined:"The existing runtime selector is not a recognized current generated file.",...runtimeContent!==undefined&&!runtimeCurrent?{candidatePath:candidatePath(projectRoot,outputDir,MODEL_RUNTIME_FILE_NAME)}:{}},{path:registryPath,action:existsSync(registryPath)?"preserve":"create",reason:"Model facts are preserved and completed from legacy generated files when possible."},{path:sdkConfigPath,action:existsSync(sdkConfigPath)?"preserve":"create"}];return{apiDir:outputDir,profiles:group.map(item=>item.app.name),files:files}}
|
|
7
|
+
export function analyzeProjectApiArchitecture(projectRoot,configOverride){const configPath=path.join(projectRoot,".rabetbase.json");const config=configOverride??(existsSync(configPath)?readJsonObject(configPath):{});const apps=syntheticApps(config);if(apps.length===0){return{migration:MIGRATION_ID,needed:false,configAction:"unconfigured",groups:[],skippedLegacyDirectories:[],manualMergeRequired:false}}const configAction=config.apps?"unchanged":"migrate-single-app";const{groups:groups,skipped:skipped}=uniqueRegistryGroups(configuredLayouts(projectRoot,apps));const groupPlans=groups.map(group=>planGroup(projectRoot,group));const manualMergeRequired=groupPlans.some(group=>group.files.some(file=>file.action==="manual-merge"));const needed=configAction==="migrate-single-app"||groupPlans.some(group=>group.files.some(file=>!["unchanged","preserve"].includes(file.action)));return{migration:MIGRATION_ID,needed:needed,configAction:configAction,groups:groupPlans,skippedLegacyDirectories:skipped,
|
|
8
|
+
manualMergeRequired:manualMergeRequired}}function migrateSingleAppConfig(projectRoot){const configPath=path.join(projectRoot,".rabetbase.json");if(!existsSync(configPath))return;const config=readConfigFile(configPath);if(config.apps&&typeof config.apps==="object")return;const appcode=typeof config.appcode==="string"?config.appcode:typeof config.app==="string"?config.app:undefined;if(!appcode)return;config.apps={[appcode]:{appcode:appcode}};config.defaultApp=appcode;delete config.app;delete config.appcode;writeConfigFile(configPath,config)}function legacyApiPath(group,selected){const outputDir=selected.normalizedApiDir;const candidates=group.length===1||selected.app.isDefault?[path.join(outputDir,"api.ts"),path.join(outputDir,`${selected.app.name}-api.ts`)]:[path.join(outputDir,`${selected.app.name}-api.ts`)];return candidates.find(existsSync)}function writeCandidateOrEntrypoint(projectRoot,outputDir,plan,desired){if(plan.action==="unchanged"||plan.action==="preserve")return
|
|
9
|
+
;if(plan.action==="manual-merge"){const target=plan.candidatePath;mkdirSync(path.dirname(target),{recursive:true});writeFileSync(target,desired,"utf8");return}if(plan.action==="replace-generated"){const backup=backupPath(projectRoot,outputDir,path.basename(plan.path));mkdirSync(path.dirname(backup),{recursive:true});copyFileSync(plan.path,backup)}mkdirSync(path.dirname(plan.path),{recursive:true});writeFileSync(plan.path,desired,"utf8")}export async function upgradeProjectApiArchitecture(projectRoot){const initialPlan=analyzeProjectApiArchitecture(projectRoot);migrateSingleAppConfig(projectRoot);const apps=getMultiAppConfigs("project",projectRoot)??[];const layouts=configuredLayouts(projectRoot,apps);const{groups:groups}=uniqueRegistryGroups(layouts);let routingPath;for(const group of groups){const outputDir=group[0].normalizedApiDir;mkdirSync(outputDir,{recursive:true});const defaultProfile=group.find(item=>item.app.isDefault)??group[0];for(const item of group){
|
|
10
|
+
const registryPath=path.join(outputDir,MODEL_REGISTRY_FILE_NAME);const registry=readModelRegistry(registryPath);if(registry?.profiles[item.app.name])continue;const sourcePath=legacyApiPath(group,item);const source=sourcePath?readOptional(sourcePath):undefined;await initMultiAppEnvironment(item.app);updateModelRegistry({outputDir:outputDir,profileName:item.app.name,defaultProfile:defaultProfile.app.name,appCode:item.app.appcode,runtimeDomain:getRuntimeDomain(),models:source?parseLegacyApiModels(source):[]})}const scaffold=await renderModelRegistryScaffold(outputDir,projectRoot);const groupPlan=planGroup(projectRoot,group);for(const file of groupPlan.files){const name=path.basename(file.path);if(name==="api.ts"){writeCandidateOrEntrypoint(projectRoot,outputDir,file,scaffold.api)}else if(name==="client.ts"){writeCandidateOrEntrypoint(projectRoot,outputDir,file,scaffold.client)}else if(name===MODEL_RUNTIME_FILE_NAME){
|
|
11
|
+
writeCandidateOrEntrypoint(projectRoot,outputDir,file,scaffold.modelRuntime)}else if(name==="sdk-config.ts"&&file.action==="create"){writeCandidateOrEntrypoint(projectRoot,outputDir,file,SDK_CONFIG_SOURCE)}}}const defaultApp=apps.find(app=>app.isDefault)??apps[0];if(defaultApp){await initMultiAppEnvironment(defaultApp);routingPath=writeProjectDomainRoutingManifest(projectRoot).path}const finalPlan=analyzeProjectApiArchitecture(projectRoot);return{...initialPlan,completed:!finalPlan.manualMergeRequired,manualMergeRequired:finalPlan.manualMergeRequired,routingPath:routingPath}}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{existsSync}from"node:fs";import path from"node:path";import chalk from"chalk";import{input,confirm}from"@inquirer/prompts";import{getIsSessionValid}from"../../../auth/is-session-valid.js";import{authServer}from"../../../auth/auth-server.js";import{readConfig}from"../../../utils/config.js";import{selectSingleAppcode}from"../../../commands/common/app-selector.js";import{getProjectNameValidationError}from"../../../commands/project/create/project-name.js";export async function guidedCreateProject(onCreate,cliEnv,cookie){const defaultProjectName="my-app";const globalConfig=readConfig();const globalEnv=typeof globalConfig.env==="string"?globalConfig.env:undefined;const projectName=await input({message:"Project name:",default:defaultProjectName,validate:value=>{const name=value.trim()||defaultProjectName;const validationError=getProjectNameValidationError(name);if(validationError)return validationError;const projectDir=path.resolve(process.cwd(),name);if(existsSync(projectDir)){
|
|
2
|
+
return`Directory "${name}" already exists`}return true}});console.log(chalk.green(`√ Project Name: ${chalk.cyan(projectName)}`));const code=await selectSingleAppcode(cookie);console.log(chalk.green(`√ App Code: ${chalk.cyan(code||"Not set")}`));if(code){const loginValid=await getIsSessionValid();if(!loginValid){const shouldLogin=await confirm({message:"No valid login detected. Login first to pull API config?",default:true});if(shouldLogin){const success=await authServer({silent:true});console.log(chalk.green(`√ Login status: ${chalk.cyan(success?"Logged in":"Login failed")}`))}else{console.log(chalk.green(`√ Login status: ${chalk.cyan("Skipped")}`))}}await onCreate({projectName:projectName,appCode:code,env:cliEnv||globalEnv||"production"})}else{await onCreate({projectName:projectName,env:cliEnv||globalEnv||"production"})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export function formatElapsed(start){const ms=Date.now()-start;if(ms<1e3)return`${ms}ms`;const seconds=(ms/1e3).toFixed(2);const trimmed=seconds.replace(/\.?0+$/u,"");return`${trimmed}s`}
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
(function(_0x599038,_0x4a3957){const _0x29c9c=a219_0x5c81,_0x4dc73e=_0x599038();while(!![]){try{const _0xd41eab=parseInt(_0x29c9c(0x1bd))/0x1+parseInt(_0x29c9c(0x214))/0x2*(parseInt(_0x29c9c(0x1e7))/0x3)+parseInt(_0x29c9c(0x1d0))/0x4+-parseInt(_0x29c9c(0x1dc))/0x5*(parseInt(_0x29c9c(0x1d4))/0x6)+parseInt(_0x29c9c(0x1bc))/0x7+parseInt(_0x29c9c(0x1e3))/0x8*(-parseInt(_0x29c9c(0x1ee))/0x9)+parseInt(_0x29c9c(0x1a9))/0xa*(parseInt(_0x29c9c(0x1de))/0xb);if(_0xd41eab===_0x4a3957)break;else _0x4dc73e['push'](_0x4dc73e['shift']());}catch(_0x40b669){_0x4dc73e['push'](_0x4dc73e['shift']());}}}(a219_0xd5ab,0x7baf3));import a219_0x3777c7 from'path';import a219_0x47c222 from'fs';import a219_0x4e60c9 from'chalk';import a219_0x4bfeb4 from'ora';import{guidedCreateProject}from'../../../commands/project/create/enhanced-guided-create.js';import{fetchModelList}from'../../../core/api-client.js';import{generateApiFile}from'../../../api/generate-api-file.js';import{initEnv}from'../../../constant/env.js';import{CLI_BIN_NAME}from'../../../constant/cli.js';import{DEFAULT_API_DIR}from'../../../constant/paths.js';import{loadRawConfigLayers,writeConfigFile,NEW_CONFIG_NAME}from'../../../context.js';import{copyProjectTemplate}from'../../../commands/project/create/use-copy-project-template.js';import{installDependencies}from'../../../commands/project/create/use-install-dependencies.js';import{formatProjectCode}from'../../../commands/project/create/use-format-code.js';import{logger}from'../../../utils/logger.js';import{assertCliVersionSupported,checkCliVersion,printCliUpgradeWarning}from'../../../utils/cli-version-check.js';import{PROJECT_CREATE_INHERITABLE_KEYS,buildCanonicalProjectConfig}from'../../../config/schema.js';import{selectSingleAppcode}from'../../../commands/common/app-selector.js';import{getRabetbaseCliPackageRoot}from'../../../commands/project/create/project-template-path.js';function a219_0x5c81(_0x16681d,_0x3d629e){_0x16681d=_0x16681d-0x1a8;const _0xd5abcd=a219_0xd5ab();let _0x5c81dc=_0xd5abcd[_0x16681d];return _0x5c81dc;}import{validateProjectName}from'../../../commands/project/create/project-name.js';import{getRuntimeDomain,getSdkClientRoutingConfig}from'../../../constant/domain.js';import{generateSdkConfigFile}from'../../../api/generate-sdk-config-file.js';import{writeProjectDomainRoutingManifest}from'../../../config/project-domain-routing.js';import{CliErrors}from'../../../errors.js';function readDirectoryIdentity(_0x1f0729){const _0x4576c0=a219_0x5c81;try{const _0x200e26=a219_0x47c222[_0x4576c0(0x1b2)](_0x1f0729);if(!_0x200e26[_0x4576c0(0x1aa)]())return null;return{'dev':_0x200e26[_0x4576c0(0x211)],'ino':_0x200e26[_0x4576c0(0x1f1)]};}catch{return null;}}function isSameDirectory(_0x1ea47a,_0xe2bc8d){const _0x42f96a=a219_0x5c81;return!!_0x1ea47a&&!!_0xe2bc8d&&_0x1ea47a[_0x42f96a(0x211)]===_0xe2bc8d[_0x42f96a(0x211)]&&_0x1ea47a['ino']===_0xe2bc8d[_0x42f96a(0x1f1)];}function commitCurrentDirectoryProject(_0x231999,_0x31a5c3,_0x511522){const _0x297d0a=a219_0x5c81;if(!isSameDirectory(readDirectoryIdentity(_0x231999),_0x511522))throw new Error(_0x297d0a(0x1b9));const _0x384f9f=a219_0x3777c7['basename'](_0x31a5c3),_0x5cf1a4=a219_0x47c222[_0x297d0a(0x1ea)](_0x231999);if(_0x5cf1a4[_0x297d0a(0x1ae)]!==0x1||_0x5cf1a4[0x0]!==_0x384f9f)throw CliErrors[_0x297d0a(0x1e2)](_0x297d0a(0x200),'Remove\x20the\x20new\x20files\x20and\x20retry\x20from\x20an\x20empty\x20directory.');const _0x43efce=a219_0x3777c7[_0x297d0a(0x1ff)](_0x31a5c3,_0x297d0a(0x21a)),_0x142885=[];try{for(const _0x146dcc of a219_0x47c222[_0x297d0a(0x1ea)](_0x43efce)){a219_0x47c222['renameSync'](a219_0x3777c7[_0x297d0a(0x1ff)](_0x43efce,_0x146dcc),a219_0x3777c7[_0x297d0a(0x1ff)](_0x231999,_0x146dcc)),_0x142885[_0x297d0a(0x1f3)](_0x146dcc);}a219_0x47c222[_0x297d0a(0x20f)](_0x31a5c3,{'recursive':!![],'force':!![]});}catch(_0x4649d4){for(const _0x4ca141 of _0x142885[_0x297d0a(0x1c8)]()){const _0x5acc50=a219_0x3777c7[_0x297d0a(0x1ff)](_0x231999,_0x4ca141);if(!a219_0x47c222[_0x297d0a(0x206)](_0x5acc50))continue;a219_0x47c222[_0x297d0a(0x1ce)](_0x5acc50,a219_0x3777c7[_0x297d0a(0x1ff)](_0x43efce,_0x4ca141));}throw _0x4649d4;}}export async function createApp(_0x1e6565){const _0x3713c4=a219_0x5c81,_0x323418=await checkCliVersion();(_0x323418[_0x3713c4(0x1b1)]||_0x323418['belowMinimum'])&&(printCliUpgradeWarning(_0x323418),assertCliVersionSupported(_0x323418),logger['info'](_0x3713c4(0x208),'CLI\x20version\x20check',{'currentVersion':_0x323418[_0x3713c4(0x1c5)],'stableVersion':_0x323418['stableVersion'],'minimumVersion':_0x323418['minimumVersion'],'needsUpgrade':_0x323418[_0x3713c4(0x1b1)],'belowMinimum':_0x323418[_0x3713c4(0x209)]}));const _0x2b455f=_0x1e6565['currentDir']?a219_0x3777c7['basename'](process[_0x3713c4(0x1f9)]()):_0x1e6565[_0x3713c4(0x21c)];if(_0x2b455f&&(_0x1e6565[_0x3713c4(0x1c1)]||_0x1e6565[_0x3713c4(0x1e1)]))await runCreate({'projectName':_0x2b455f,'appCode':_0x1e6565[_0x3713c4(0x1c1)],'env':_0x1e6565[_0x3713c4(0x1cd)]},_0x1e6565);else{if(_0x2b455f){const _0x327554=await selectSingleAppcode(_0x1e6565['cookie']);await runCreate({'projectName':_0x2b455f,'appCode':_0x327554||undefined,'env':_0x1e6565[_0x3713c4(0x1cd)]},_0x1e6565);}else await guidedCreateProject(_0x1de1f6=>runCreate(_0x1de1f6,_0x1e6565),_0x1e6565[_0x3713c4(0x1cd)],_0x1e6565['cookie']);}}async function runCreate(_0x456228,_0x145a99){const _0x3de9d3=a219_0x5c81;_0x456228[_0x3de9d3(0x1be)]=validateProjectName(_0x456228[_0x3de9d3(0x1be)]);const _0x40f935=_0x145a99[_0x3de9d3(0x1ba)]?process[_0x3de9d3(0x1f9)]():a219_0x3777c7[_0x3de9d3(0x1ef)](process[_0x3de9d3(0x1f9)](),_0x456228[_0x3de9d3(0x1be)]);if(_0x145a99[_0x3de9d3(0x1ba)]){if(a219_0x47c222[_0x3de9d3(0x1ea)](_0x40f935)[_0x3de9d3(0x1ae)]>0x0)throw CliErrors[_0x3de9d3(0x1e2)](_0x3de9d3(0x1fb),_0x3de9d3(0x1b5));}else{if(a219_0x47c222[_0x3de9d3(0x206)](_0x40f935))throw new Error(_0x3de9d3(0x21b)+_0x456228[_0x3de9d3(0x1be)]+_0x3de9d3(0x205));}let _0x411c81=null;const _0x521379=_0x145a99[_0x3de9d3(0x1ba)]?readDirectoryIdentity(_0x40f935):null;let _0x3f586f=null;try{a219_0x47c222[_0x3de9d3(0x202)](a219_0x3777c7[_0x3de9d3(0x1df)](_0x40f935),a219_0x47c222[_0x3de9d3(0x1d3)][_0x3de9d3(0x1ca)]);}catch{throw new Error(_0x3de9d3(0x1e9));}logger[_0x3de9d3(0x1d1)](_0x3de9d3(0x208),'Starting\x20project\x20creation:\x20'+_0x456228[_0x3de9d3(0x1be)],{'projectDir':_0x40f935,'appCode':_0x456228['appCode']}),console[_0x3de9d3(0x1c0)](),console['log'](a219_0x4e60c9[_0x3de9d3(0x1b3)](_0x3de9d3(0x203))+'Project\x20name:\x20'+a219_0x4e60c9['green'](_0x456228[_0x3de9d3(0x1be)])+(_0x456228['appCode']?'\x20|\x20AppCode:\x20'+a219_0x4e60c9[_0x3de9d3(0x220)](_0x456228[_0x3de9d3(0x1c1)]):''));try{let _0x5dd8cf=_0x456228[_0x3de9d3(0x1be)];_0x145a99['currentDir']&&(_0x3f586f=a219_0x47c222['mkdtempSync'](a219_0x3777c7[_0x3de9d3(0x1ff)](_0x40f935,_0x3de9d3(0x1c6))),_0x5dd8cf=a219_0x3777c7[_0x3de9d3(0x1fd)](process[_0x3de9d3(0x1f9)](),a219_0x3777c7[_0x3de9d3(0x1ff)](_0x3f586f,'project')));const _0x30265a=a219_0x3777c7['resolve'](process[_0x3de9d3(0x1f9)](),_0x5dd8cf);await runTask(_0x3de9d3(0x1ad),_0xe27da=>copyProjectTemplate(_0x5dd8cf,_0xff0788=>_0xe27da(projectTemplateStageLabel(_0xff0788)),_0x145a99[_0x3de9d3(0x21e)]),_0x3de9d3(0x1f5)),_0x411c81=_0x145a99['currentDir']?null:readDirectoryIdentity(_0x40f935);if(!_0x145a99[_0x3de9d3(0x1ba)]&&!_0x411c81)throw new Error('Unable\x20to\x20verify\x20ownership\x20of\x20the\x20created\x20project\x20directory');await updatePackageJsonName(_0x5dd8cf,_0x456228[_0x3de9d3(0x1be)]),await runTask(_0x3de9d3(0x213),()=>installDependencies(_0x5dd8cf)),await runTask(_0x3de9d3(0x1cc),()=>formatProjectCode(_0x5dd8cf)),await configureAppCode(_0x5dd8cf,_0x456228[_0x3de9d3(0x1be)],_0x456228[_0x3de9d3(0x1c1)]||'',_0x456228['env']);let _0x12d249=![];if(_0x456228[_0x3de9d3(0x1c1)]){console['log'](_0x3de9d3(0x1eb));const _0x3e51e9=process['cwd']();try{process['chdir'](_0x30265a);const _0x21b0d1=_0x456228['env']||_0x3de9d3(0x217);initEnv(_0x21b0d1);const {configArray:_0x5f30d4}=await fetchModelList(_0x456228['appCode'],_0x145a99[_0x3de9d3(0x20d)]||''),_0x3bc1ec=DEFAULT_API_DIR,_0x1104a3=await generateApiFile(_0x5f30d4,'',_0x456228[_0x3de9d3(0x1c1)],!![],_0x21b0d1,_0x3bc1ec,undefined,getSdkClientRoutingConfig(),{'overwriteTypescript':!![],'modelProfile':{'name':_0x456228['appCode'],'defaultName':_0x456228[_0x3de9d3(0x1c1)],'runtimeDomain':getRuntimeDomain()}});console['log'](_0x3de9d3(0x1fc)+_0x5f30d4[_0x3de9d3(0x1ae)]+'\x20dataset(s),\x20generated\x20'+_0x1104a3[_0x3de9d3(0x216)]+'\x20model(s)'),logger[_0x3de9d3(0x1d1)](_0x3de9d3(0x208),_0x3de9d3(0x1bf)+_0x456228[_0x3de9d3(0x1c1)]);}catch(_0x4ed071){_0x12d249=!![],console[_0x3de9d3(0x1c0)]('!\x20API\x20configuration\x20pull\x20error,\x20you\x20can\x20manually\x20run:\x20'+CLI_BIN_NAME+_0x3de9d3(0x1ab)),logger[_0x3de9d3(0x210)]('create',_0x3de9d3(0x1f4),{'error':_0x4ed071 instanceof Error?_0x4ed071[_0x3de9d3(0x1ed)]:String(_0x4ed071)});}finally{process[_0x3de9d3(0x1da)](_0x3e51e9);}}if(_0x145a99[_0x3de9d3(0x1ba)]){if(!_0x3f586f||!_0x521379)throw new Error(_0x3de9d3(0x1e5));commitCurrentDirectoryProject(_0x40f935,_0x3f586f,_0x521379),_0x3f586f=null;}try{logger[_0x3de9d3(0x219)](_0x40f935),logger[_0x3de9d3(0x1fa)](_0x3de9d3(0x208),_0x3de9d3(0x1b4)+_0x456228[_0x3de9d3(0x1be)]);}catch(_0x512c41){console[_0x3de9d3(0x210)](_0x3de9d3(0x20a)+(_0x512c41 instanceof Error?_0x512c41[_0x3de9d3(0x1ed)]:String(_0x512c41)));}console[_0x3de9d3(0x1c0)](),console[_0x3de9d3(0x1c0)](a219_0x4e60c9[_0x3de9d3(0x1b3)]('─'[_0x3de9d3(0x1d9)](0x3c))),console[_0x3de9d3(0x1c0)](a219_0x4e60c9[_0x3de9d3(0x220)][_0x3de9d3(0x1ac)](_0x3de9d3(0x1c9))),console[_0x3de9d3(0x1c0)]();const _0x5e0783=_0x145a99['currentDir']?CLI_BIN_NAME+_0x3de9d3(0x1c7):_0x3de9d3(0x1f2)+_0x456228[_0x3de9d3(0x1be)]+_0x3de9d3(0x1f0)+CLI_BIN_NAME+_0x3de9d3(0x1c7);console['log'](_0x3de9d3(0x1b8)+a219_0x4e60c9[_0x3de9d3(0x220)]['bold'](_0x5e0783)),_0x12d249&&console[_0x3de9d3(0x1c0)](_0x3de9d3(0x1e8)+a219_0x4e60c9[_0x3de9d3(0x220)][_0x3de9d3(0x1ac)](CLI_BIN_NAME+_0x3de9d3(0x1ab))),console[_0x3de9d3(0x1c0)](a219_0x4e60c9[_0x3de9d3(0x1b3)]('─'[_0x3de9d3(0x1d9)](0x3c)));}catch(_0x1bbfa1){logger[_0x3de9d3(0x1a8)](_0x3de9d3(0x208),_0x3de9d3(0x1d8)+_0x456228['projectName'],{'error':_0x1bbfa1 instanceof Error?_0x1bbfa1[_0x3de9d3(0x1ed)]:String(_0x1bbfa1)});try{const _0x485375=readDirectoryIdentity(_0x40f935);if(_0x145a99['currentDir']&&_0x3f586f)a219_0x47c222[_0x3de9d3(0x20f)](_0x3f586f,{'recursive':!![],'force':!![]});else{if(_0x411c81&&_0x485375?.['dev']===_0x411c81[_0x3de9d3(0x211)]&&_0x485375[_0x3de9d3(0x1f1)]===_0x411c81['ino'])console[_0x3de9d3(0x1c0)]('*\x20Cleaning\x20up\x20failed\x20project\x20directory:\x20'+_0x40f935),a219_0x47c222[_0x3de9d3(0x20f)](_0x40f935,{'recursive':!![],'force':!![]});else _0x485375&&logger[_0x3de9d3(0x210)](_0x3de9d3(0x208),'Skip\x20cleanup:\x20project\x20directory\x20ownership\x20changed:\x20'+_0x40f935);}}catch{logger[_0x3de9d3(0x210)]('create',_0x3de9d3(0x20b)+_0x40f935);}throw _0x1bbfa1;}}async function runTask(_0x5b4e7d,_0x3dceff,_0x5ab4be=_0x5b4e7d){const _0x2d3127=a219_0x5c81,_0x15c582=a219_0x4bfeb4(_0x5b4e7d+'...')['start']();try{const _0xc2e9c0=await _0x3dceff(_0x1c7671=>{const _0x41e685=a219_0x5c81;_0x15c582[_0x41e685(0x218)]=_0x1c7671+_0x41e685(0x1af);});_0x15c582[_0x2d3127(0x207)](),console[_0x2d3127(0x1c0)](''+a219_0x4e60c9['green'](_0x2d3127(0x203))+_0x5ab4be+'\x20'+a219_0x4e60c9[_0x2d3127(0x1e0)]('['+_0xc2e9c0+']'));}catch(_0x121195){_0x15c582[_0x2d3127(0x1c3)](_0x5b4e7d);throw _0x121195;}}function a219_0xd5ab(){const _0x11498=['green','Project\x20created:\x20','Remove\x20or\x20move\x20the\x20existing\x20files,\x20then\x20retry\x20with\x20--current-dir.','Verifying\x20project\x20template','resolving','\x20\x201.\x20Start\x20project:\x20','Current\x20directory\x20identity\x20changed\x20during\x20project\x20creation','currentDir','extracting','1379231jzJpdn','379273GcBffT','projectName','API\x20configuration\x20pulled:\x20','log','appCode','copying','fail','\x20|\x20Default:\x20implicit\x20(single\x20app)','currentVersion','.rabetbase-create-','\x20run\x20start','reverse','🚀\x20Next\x20Steps:','W_OK','Extracting\x20project\x20template','Format\x20code','env','renameSync','*\x20Updating\x20package.json\x20name\x20and\x20description\x20fields','921280BZUoxK','info','√\x20Configuration\x20file\x20created,\x20you\x20can\x20configure\x20later\x20with\x20\x27','constants','6MlBnme','utf8','description','√\x20package.json\x20updated:\x20name=','Project\x20creation\x20failed:\x20','repeat','chdir','stringify','211710JRxQmh','verifying','2475385LSxxxv','dirname','gray','nonInteractive','validation','8knPcXM','apps','Unable\x20to\x20prepare\x20the\x20current\x20directory\x20workspace','1.0.0','9kDjRkU','\x20\x202.\x20Pull\x20API\x20configuration:\x20','Cannot\x20create\x20project\x20in\x20current\x20directory,\x20please\x20check\x20directory\x20permissions','readdirSync','*\x20Pulling\x20API\x20configuration...','version','message','4463091TYhfqy','resolve','\x20&&\x20','ino','cd\x20','push','API\x20configuration\x20pull\x20failed','Project\x20template\x20ready','parse','Updating\x20package.json\x20name','\x20Generated\x20by\x20rabetbase\x20cli\x20','cwd','success','The\x20current\x20directory\x20must\x20be\x20empty.','√\x20Pulled\x20','relative','downloading','join','The\x20current\x20directory\x20changed\x20during\x20project\x20creation.','Failed\x20to\x20update\x20package.json','accessSync','\x20√\x20','Copying\x20local\x20template\x20source','\x20already\x20exists','existsSync','stop','create','belowMinimum','!\x20Project\x20created,\x20but\x20local\x20logging\x20could\x20not\x20be\x20initialized:\x20','Failed\x20to\x20clean\x20up\x20project\x20directory:\x20','Downloading\x20project\x20template','cookie','readFileSync','rmSync','warn','dev','string','Install\x20dependencies','8794rKODAr','name','modelCount','production','text','setLogPath','project','Project\x20directory\x20','projectCode','keys','templateSource','*\x20Creating\x20configuration\x20file\x20for\x20project\x20','cyan','error','10SgiGLe','isDirectory','\x20api\x20pull\x20--force\x20--yes','bold','Resolving\x20project\x20template','length','...','package.json','needsUpgrade','lstatSync'];a219_0xd5ab=function(){return _0x11498;};return a219_0xd5ab();}function projectTemplateStageLabel(_0x457afb){const _0x2d9da3=a219_0x5c81;switch(_0x457afb){case _0x2d9da3(0x1b7):return'Resolving\x20project\x20template';case _0x2d9da3(0x1fe):return _0x2d9da3(0x20c);case _0x2d9da3(0x1dd):return _0x2d9da3(0x1b6);case _0x2d9da3(0x1bb):return _0x2d9da3(0x1cb);case _0x2d9da3(0x1c2):return _0x2d9da3(0x204);}}async function updatePackageJsonName(_0x48901c,_0x4fa8d2){const _0x41ce77=a219_0x5c81,_0x546db4=a219_0x3777c7['resolve'](process['cwd'](),_0x48901c),_0x2d6eff=a219_0x3777c7[_0x41ce77(0x1ff)](_0x546db4,'package.json');try{console[_0x41ce77(0x1c0)](_0x41ce77(0x1cf));const _0x412039=getRabetbaseCliPackageRoot(),_0x4096a7=a219_0x3777c7['join'](_0x412039,'package.json');let _0x2e2fa5='1.0.0';try{const _0x5236b8=JSON['parse'](a219_0x47c222['readFileSync'](_0x4096a7,_0x41ce77(0x1d5)));_0x2e2fa5=_0x5236b8[_0x41ce77(0x1ec)]||_0x41ce77(0x1e6);}catch{}const _0x5e564d=a219_0x47c222[_0x41ce77(0x20e)](_0x2d6eff,'utf8'),_0x4cdca3=JSON[_0x41ce77(0x1f6)](_0x5e564d);_0x4cdca3[_0x41ce77(0x215)]=_0x4fa8d2,_0x4cdca3[_0x41ce77(0x1d6)]=_0x4fa8d2+_0x41ce77(0x1f8)+_0x2e2fa5,a219_0x47c222['writeFileSync'](_0x2d6eff,JSON[_0x41ce77(0x1db)](_0x4cdca3,null,0x2)+'\x0a',_0x41ce77(0x1d5)),console[_0x41ce77(0x1c0)](_0x41ce77(0x1d7)+_0x4fa8d2),logger['info'](_0x41ce77(0x208),_0x41ce77(0x1f7));}catch(_0x1cd327){logger[_0x41ce77(0x1a8)]('create',_0x41ce77(0x201));throw _0x1cd327;}}async function configureAppCode(_0x13999f,_0x1d8a35,_0x3caf6b,_0x33d45d){const _0x37dde8=a219_0x5c81,_0x1e0bc7=a219_0x3777c7[_0x37dde8(0x1ef)](process[_0x37dde8(0x1f9)](),_0x13999f),_0x1b7a30=a219_0x3777c7[_0x37dde8(0x1ff)](_0x1e0bc7,NEW_CONFIG_NAME);try{_0x3caf6b?console['log']('*\x20Configuring\x20AppCode\x20for\x20project\x20'+_0x1d8a35+':\x20'+_0x3caf6b):console[_0x37dde8(0x1c0)](_0x37dde8(0x21f)+_0x1d8a35);const _0x1e6029=getRabetbaseCliPackageRoot(),_0x409172=a219_0x3777c7[_0x37dde8(0x1ff)](_0x1e6029,_0x37dde8(0x1b0));let _0x56f2a='1.0.0';try{const _0x325eb4=JSON[_0x37dde8(0x1f6)](a219_0x47c222[_0x37dde8(0x20e)](_0x409172,_0x37dde8(0x1d5)));_0x56f2a=_0x325eb4[_0x37dde8(0x1ec)]||_0x37dde8(0x1e6);}catch{}const {globalConfig:_0x3b5b2c}=loadRawConfigLayers(),_0x17e571=typeof _0x3b5b2c[_0x37dde8(0x1cd)]===_0x37dde8(0x212)?_0x3b5b2c[_0x37dde8(0x1cd)]:undefined,_0x58cc74={};for(const _0x4e2b2a of PROJECT_CREATE_INHERITABLE_KEYS){if(_0x3b5b2c[_0x4e2b2a]!=null)_0x58cc74[_0x4e2b2a]=_0x3b5b2c[_0x4e2b2a];}const _0x26453f=buildCanonicalProjectConfig(_0x58cc74,{'appCodes':_0x3caf6b?[_0x3caf6b]:[],'env':_0x33d45d||_0x17e571||_0x37dde8(0x217),'metadata':{'createdAt':new Date()['toLocaleString'](),'version':_0x56f2a}});writeConfigFile(_0x1b7a30,_0x26453f),await generateSdkConfigFile(a219_0x3777c7[_0x37dde8(0x1ff)](_0x1e0bc7,DEFAULT_API_DIR),getSdkClientRoutingConfig()),writeProjectDomainRoutingManifest(_0x1e0bc7),_0x3caf6b?console[_0x37dde8(0x1c0)]('√\x20Configuration\x20file\x20created,\x20Apps:\x20'+Object[_0x37dde8(0x21d)](_0x26453f[_0x37dde8(0x1e4)]||{})['join'](',\x20')+_0x37dde8(0x1c4)):console['log'](_0x37dde8(0x1d2)+CLI_BIN_NAME+'\x20config\x20set\x20appcode\x20<app-code>\x27'),logger[_0x37dde8(0x1d1)](_0x37dde8(0x208),'Configured\x20app\x20AppCode:\x20'+_0x3caf6b);}catch(_0x180c8d){logger[_0x37dde8(0x1a8)](_0x37dde8(0x208),'Failed\x20to\x20configure\x20app\x20AppCode');throw _0x180c8d;}}
|
|
1
|
+
import path from"path";import fs from"fs";import chalk from"chalk";import ora from"ora";import{guidedCreateProject}from"../../../commands/project/create/enhanced-guided-create.js";import{fetchModelList}from"../../../core/api-client.js";import{generateApiFile}from"../../../api/generate-api-file.js";import{initEnv}from"../../../constant/env.js";import{CLI_BIN_NAME}from"../../../constant/cli.js";import{DEFAULT_API_DIR}from"../../../constant/paths.js";import{loadRawConfigLayers,writeConfigFile,NEW_CONFIG_NAME}from"../../../context.js";import{copyProjectTemplate}from"../../../commands/project/create/use-copy-project-template.js";import{installDependencies}from"../../../commands/project/create/use-install-dependencies.js";import{formatProjectCode}from"../../../commands/project/create/use-format-code.js";import{logger}from"../../../utils/logger.js";import{assertCliVersionSupported,checkCliVersion,printCliUpgradeWarning}from"../../../utils/cli-version-check.js"
|
|
2
|
+
;import{PROJECT_CREATE_INHERITABLE_KEYS,buildCanonicalProjectConfig}from"../../../config/schema.js";import{selectSingleAppcode}from"../../../commands/common/app-selector.js";import{getRabetbaseCliPackageRoot}from"../../../commands/project/create/project-template-path.js";import{validateProjectName}from"../../../commands/project/create/project-name.js";import{getRuntimeDomain,getSdkClientRoutingConfig}from"../../../constant/domain.js";import{generateSdkConfigFile}from"../../../api/generate-sdk-config-file.js";import{writeProjectDomainRoutingManifest}from"../../../config/project-domain-routing.js";import{CliErrors}from"../../../errors.js";function readDirectoryIdentity(directory){try{const stats=fs.lstatSync(directory);if(!stats.isDirectory())return null;return{dev:stats.dev,ino:stats.ino}}catch{return null}}function isSameDirectory(actual,expected){return!!actual&&!!expected&&actual.dev===expected.dev&&actual.ino===expected.ino}
|
|
3
|
+
function commitCurrentDirectoryProject(projectDir,workRoot,expectedIdentity){if(!isSameDirectory(readDirectoryIdentity(projectDir),expectedIdentity)){throw new Error("Current directory identity changed during project creation")}const workRootName=path.basename(workRoot);const currentEntries=fs.readdirSync(projectDir);if(currentEntries.length!==1||currentEntries[0]!==workRootName){throw CliErrors.validation("The current directory changed during project creation.","Remove the new files and retry from an empty directory.")}const stagedProjectDir=path.join(workRoot,"project");const movedEntries=[];try{for(const entry of fs.readdirSync(stagedProjectDir)){fs.renameSync(path.join(stagedProjectDir,entry),path.join(projectDir,entry));movedEntries.push(entry)}fs.rmSync(workRoot,{recursive:true,force:true})}catch(error){for(const entry of movedEntries.reverse()){const committedPath=path.join(projectDir,entry);if(!fs.existsSync(committedPath))continue
|
|
4
|
+
;fs.renameSync(committedPath,path.join(stagedProjectDir,entry))}throw error}}export async function createApp(props){const cliCheck=await checkCliVersion();if(cliCheck.needsUpgrade||cliCheck.belowMinimum){printCliUpgradeWarning(cliCheck);assertCliVersionSupported(cliCheck);logger.info("create","CLI version check",{currentVersion:cliCheck.currentVersion,stableVersion:cliCheck.stableVersion,minimumVersion:cliCheck.minimumVersion,needsUpgrade:cliCheck.needsUpgrade,belowMinimum:cliCheck.belowMinimum})}const projectCode=props.currentDir?path.basename(process.cwd()):props.projectCode;if(projectCode&&(props.appCode||props.nonInteractive)){await runCreate({projectName:projectCode,appCode:props.appCode,env:props.env},props)}else if(projectCode){const code=await selectSingleAppcode(props.cookie);await runCreate({projectName:projectCode,appCode:code||undefined,env:props.env},props)}else{await guidedCreateProject(config=>runCreate(config,props),props.env,props.cookie)}}
|
|
5
|
+
async function runCreate(config,props){config.projectName=validateProjectName(config.projectName);const projectDir=props.currentDir?process.cwd():path.resolve(process.cwd(),config.projectName);if(props.currentDir){if(fs.readdirSync(projectDir).length>0){throw CliErrors.validation("The current directory must be empty.","Remove or move the existing files, then retry with --current-dir.")}}else if(fs.existsSync(projectDir)){throw new Error(`Project directory ${config.projectName} already exists`)}let ownedProjectDirectory=null;const currentDirectoryIdentity=props.currentDir?readDirectoryIdentity(projectDir):null;let currentDirectoryWorkRoot=null;try{fs.accessSync(path.dirname(projectDir),fs.constants.W_OK)}catch{throw new Error("Cannot create project in current directory, please check directory permissions")}logger.info("create",`Starting project creation: ${config.projectName}`,{projectDir:projectDir,appCode:config.appCode});console.log()
|
|
6
|
+
;console.log(chalk.green(" √ ")+"Project name: "+chalk.green(config.projectName)+(config.appCode?` | AppCode: ${chalk.cyan(config.appCode)}`:""));try{let workingProjectCode=config.projectName;if(props.currentDir){currentDirectoryWorkRoot=fs.mkdtempSync(path.join(projectDir,".rabetbase-create-"));workingProjectCode=path.relative(process.cwd(),path.join(currentDirectoryWorkRoot,"project"))}const workingProjectDir=path.resolve(process.cwd(),workingProjectCode);await runTask("Resolving project template",update=>copyProjectTemplate(workingProjectCode,stage=>update(projectTemplateStageLabel(stage)),props.templateSource),"Project template ready");ownedProjectDirectory=props.currentDir?null:readDirectoryIdentity(projectDir);if(!props.currentDir&&!ownedProjectDirectory){throw new Error("Unable to verify ownership of the created project directory")}await updatePackageJsonName(workingProjectCode,config.projectName);await runTask("Install dependencies",()=>installDependencies(workingProjectCode))
|
|
7
|
+
;await runTask("Format code",()=>formatProjectCode(workingProjectCode));await configureAppCode(workingProjectCode,config.projectName,config.appCode||"",config.env);let apiPullFailed=false;if(config.appCode){console.log("* Pulling API configuration...");const originalCwd=process.cwd();try{process.chdir(workingProjectDir);const targetEnv=config.env||"production";initEnv(targetEnv);const{configArray:configArray}=await fetchModelList(config.appCode,props.cookie||"");const outputDir=DEFAULT_API_DIR;const result=await generateApiFile(configArray,"",config.appCode,true,targetEnv,outputDir,undefined,getSdkClientRoutingConfig(),{overwriteTypescript:true,modelProfile:{name:config.appCode,defaultName:config.appCode,runtimeDomain:getRuntimeDomain()}});console.log(`√ Pulled ${configArray.length} dataset(s), generated ${result.modelCount} model(s)`);logger.info("create",`API configuration pulled: ${config.appCode}`)}catch(apiError){apiPullFailed=true
|
|
8
|
+
;console.log(`! API configuration pull error, you can manually run: ${CLI_BIN_NAME} api pull --force --yes`);logger.warn("create","API configuration pull failed",{error:apiError instanceof Error?apiError.message:String(apiError)})}finally{process.chdir(originalCwd)}}if(props.currentDir){if(!currentDirectoryWorkRoot||!currentDirectoryIdentity){throw new Error("Unable to prepare the current directory workspace")}commitCurrentDirectoryProject(projectDir,currentDirectoryWorkRoot,currentDirectoryIdentity);currentDirectoryWorkRoot=null}try{logger.setLogPath(projectDir);logger.success("create",`Project created: ${config.projectName}`)}catch(logError){console.warn(`! Project created, but local logging could not be initialized: ${logError instanceof Error?logError.message:String(logError)}`)}console.log();console.log(chalk.green("─".repeat(60)));console.log(chalk.cyan.bold("🚀 Next Steps:"));console.log()
|
|
9
|
+
;const startCommand=props.currentDir?`${CLI_BIN_NAME} run start`:`cd ${config.projectName} && ${CLI_BIN_NAME} run start`;console.log(` 1. Start project: ${chalk.cyan.bold(startCommand)}`);if(apiPullFailed){console.log(` 2. Pull API configuration: ${chalk.cyan.bold(`${CLI_BIN_NAME} api pull --force --yes`)}`)}console.log(chalk.green("─".repeat(60)))}catch(error){logger.error("create",`Project creation failed: ${config.projectName}`,{error:error instanceof Error?error.message:String(error)});try{const currentIdentity=readDirectoryIdentity(projectDir);if(props.currentDir&¤tDirectoryWorkRoot){fs.rmSync(currentDirectoryWorkRoot,{recursive:true,force:true})}else if(ownedProjectDirectory&¤tIdentity?.dev===ownedProjectDirectory.dev&¤tIdentity.ino===ownedProjectDirectory.ino){console.log(`* Cleaning up failed project directory: ${projectDir}`);fs.rmSync(projectDir,{recursive:true,force:true})}else if(currentIdentity){
|
|
10
|
+
logger.warn("create",`Skip cleanup: project directory ownership changed: ${projectDir}`)}}catch{logger.warn("create",`Failed to clean up project directory: ${projectDir}`)}throw error}}async function runTask(name,fn,successName=name){const spinner=ora(name+"...").start();try{const elapsed=await fn(nextName=>{spinner.text=`${nextName}...`});spinner.stop();console.log(`${chalk.green(" √ ")}${successName} ${chalk.gray(`[${elapsed}]`)}`)}catch(err){spinner.fail(name);throw err}}function projectTemplateStageLabel(stage){switch(stage){case"resolving":return"Resolving project template";case"downloading":return"Downloading project template";case"verifying":return"Verifying project template";case"extracting":return"Extracting project template";case"copying":return"Copying local template source"}}async function updatePackageJsonName(projectCode,projectName){const projectDir=path.resolve(process.cwd(),projectCode);const packageJsonPath=path.join(projectDir,"package.json");try{
|
|
11
|
+
console.log("* Updating package.json name and description fields");const cliRootDir=getRabetbaseCliPackageRoot();const cliPackageJsonPath=path.join(cliRootDir,"package.json");let cliVersion="1.0.0";try{const cliPackageJson=JSON.parse(fs.readFileSync(cliPackageJsonPath,"utf8"));cliVersion=cliPackageJson.version||"1.0.0"}catch{}const packageJsonContent=fs.readFileSync(packageJsonPath,"utf8");const packageJson=JSON.parse(packageJsonContent);packageJson.name=projectName;packageJson.description=`${projectName} Generated by rabetbase cli ${cliVersion}`;fs.writeFileSync(packageJsonPath,JSON.stringify(packageJson,null,2)+"\n","utf8");console.log(`√ package.json updated: name=${projectName}`);logger.info("create","Updating package.json name")}catch(error){logger.error("create","Failed to update package.json");throw error}}async function configureAppCode(projectCode,projectName,appCode,env){const projectDir=path.resolve(process.cwd(),projectCode)
|
|
12
|
+
;const configFile=path.join(projectDir,NEW_CONFIG_NAME);try{if(appCode){console.log(`* Configuring AppCode for project ${projectName}: ${appCode}`)}else{console.log(`* Creating configuration file for project ${projectName}`)}const cliRootDir=getRabetbaseCliPackageRoot();const cliPackageJsonPath=path.join(cliRootDir,"package.json");let cliVersion="1.0.0";try{const packageJson=JSON.parse(fs.readFileSync(cliPackageJsonPath,"utf8"));cliVersion=packageJson.version||"1.0.0"}catch{}const{globalConfig:globalConfig}=loadRawConfigLayers();const globalEnv=typeof globalConfig.env==="string"?globalConfig.env:undefined;const inheritedFields={};for(const key of PROJECT_CREATE_INHERITABLE_KEYS){if(globalConfig[key]!=null)inheritedFields[key]=globalConfig[key]}const config=buildCanonicalProjectConfig(inheritedFields,{appCodes:appCode?[appCode]:[],env:env||globalEnv||"production",metadata:{createdAt:(new Date).toLocaleString(),version:cliVersion}});writeConfigFile(configFile,config)
|
|
13
|
+
;await generateSdkConfigFile(path.join(projectDir,DEFAULT_API_DIR),getSdkClientRoutingConfig());writeProjectDomainRoutingManifest(projectDir);if(appCode){console.log(`√ Configuration file created, Apps: ${Object.keys(config.apps||{}).join(", ")} | Default: implicit (single app)`)}else{console.log(`√ Configuration file created, you can configure later with '${CLI_BIN_NAME} config set appcode <app-code>'`)}logger.info("create",`Configured app AppCode: ${appCode}`)}catch(error){logger.error("create","Failed to configure app AppCode");throw error}}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
const a220_0x354b7a=a220_0x328f;(function(_0x5d427f,_0x56b480){const _0x368a1=a220_0x328f,_0x4be438=_0x5d427f();while(!![]){try{const _0x4ccb3d=-parseInt(_0x368a1(0x1a1))/0x1+parseInt(_0x368a1(0x186))/0x2*(-parseInt(_0x368a1(0x163))/0x3)+-parseInt(_0x368a1(0x19f))/0x4*(parseInt(_0x368a1(0x171))/0x5)+-parseInt(_0x368a1(0x1bc))/0x6*(parseInt(_0x368a1(0x18b))/0x7)+-parseInt(_0x368a1(0x181))/0x8*(parseInt(_0x368a1(0x1a8))/0x9)+-parseInt(_0x368a1(0x1b7))/0xa*(-parseInt(_0x368a1(0x149))/0xb)+parseInt(_0x368a1(0x1b3))/0xc;if(_0x4ccb3d===_0x56b480)break;else _0x4be438['push'](_0x4be438['shift']());}catch(_0x5f4151){_0x4be438['push'](_0x4be438['shift']());}}}(a220_0x13af,0x74b2a));import{createHash}from'node:crypto';import a220_0x29be86 from'node:fs/promises';import a220_0x134e45 from'node:path';import a220_0x8d9eb5 from'semver';import{getProjectTemplateRelativeUrl}from'../../../constant/cdn.js';import{extractProjectTemplateArchive}from'../../../commands/project/create/project-template-archive.js';import{fetchProjectTemplateCdnConfig,isBetaCliVersion,resolveProjectTemplateDescriptor}from'../../../utils/cli-version-policy.js';function a220_0x328f(_0x48c8b9,_0x5aa496){_0x48c8b9=_0x48c8b9-0x149;const _0x13afe7=a220_0x13af();let _0x328fa8=_0x13afe7[_0x48c8b9];return _0x328fa8;}import{getCliVersion}from'../../../utils/version.js';import{CliErrors}from'../../../errors.js';const TEMPLATE_ID='sub-app-react-demo',ARCHIVE_TIMEOUT_MS=0x3a98,MAX_ARCHIVE_SIZE=0x14*0x400*0x400;function nonEmptyString(_0x2dd12a){const _0x5b4648=a220_0x328f;return typeof _0x2dd12a===_0x5b4648(0x196)&&_0x2dd12a['trim']()?_0x2dd12a[_0x5b4648(0x19b)]():null;}function parseDescriptor(_0xc7d9ad){const _0x52543e=a220_0x328f;if(!_0xc7d9ad||typeof _0xc7d9ad!=='object')throw new Error('CDN\x20config\x20does\x20not\x20define\x20template\x20\x22'+TEMPLATE_ID+'\x22.');const _0x3761d6=_0xc7d9ad,_0x56da6a=nonEmptyString(_0x3761d6['version']),_0xf61a3=nonEmptyString(_0x3761d6['name']),_0x25b4b9=_0x3761d6['url']===undefined?undefined:nonEmptyString(_0x3761d6[_0x52543e(0x14a)])||undefined,_0x4f47e7=nonEmptyString(_0x3761d6[_0x52543e(0x18a)])?.[_0x52543e(0x1a7)](),_0x3e40d6=_0x3761d6[_0x52543e(0x177)];if(!_0x56da6a||!a220_0x8d9eb5['valid'](_0x56da6a)||!_0xf61a3||_0xf61a3!==a220_0x134e45['posix'][_0x52543e(0x1a3)](_0xf61a3)||_0xf61a3[_0x52543e(0x178)]('\x5c')||_0x3761d6[_0x52543e(0x14a)]!==undefined&&!_0x25b4b9||!_0x4f47e7||!/^sha256:[a-f0-9]{64}$/[_0x52543e(0x1b9)](_0x4f47e7)||typeof _0x3e40d6!=='number'||!Number[_0x52543e(0x19c)](_0x3e40d6)||_0x3e40d6<=0x0||_0x3e40d6>MAX_ARCHIVE_SIZE)throw new Error(_0x52543e(0x176)+TEMPLATE_ID+'\x22.');return{'version':_0x56da6a,'name':_0xf61a3,'url':_0x25b4b9,'sha256':_0x4f47e7,'size':_0x3e40d6};}async function fetchWithTimeout(_0x3c6798,_0x598faa,_0x2655f0,_0x3f9a8f){const _0x4195e5=a220_0x328f,_0x39fe00=new AbortController(),_0x34ca94=setTimeout(()=>_0x39fe00[_0x4195e5(0x189)](),_0x598faa);try{const _0x4a80b3=await fetch(_0x3c6798,{'headers':{'Accept':_0x2655f0},'redirect':_0x4195e5(0x199),'signal':_0x39fe00[_0x4195e5(0x167)]});return await _0x3f9a8f(_0x4a80b3);}finally{clearTimeout(_0x34ca94);}}async function fetchTemplateDescriptor(){const _0x507b35=a220_0x328f,_0x29735b=getCliVersion(),_0x2c35d6=isBetaCliVersion(_0x29735b)?'beta':'release',_0x11cb84=await fetchProjectTemplateCdnConfig();if(!_0x11cb84)throw new Error(_0x507b35(0x154));const _0x3e6307=parseDescriptor(resolveProjectTemplateDescriptor(_0x11cb84['config'],_0x29735b));return{'descriptor':_0x3e6307,'channel':_0x2c35d6,'assetBaseUrl':_0x11cb84[_0x507b35(0x15d)],'legacyAssetBaseUrl':_0x11cb84[_0x507b35(0x1aa)]};}function resolveArchiveUrl(_0x2f3f19,_0x185142,_0x180ef0,_0x3a456f){const _0x9a4f1=a220_0x328f,_0x405f99=new URL(_0x180ef0+'/'),_0x3295e0=[getProjectTemplateRelativeUrl(_0x185142),getProjectTemplateRelativeUrl(_0x185142,_0x2f3f19[_0x9a4f1(0x14b)])];if(_0x2f3f19[_0x9a4f1(0x14a)]&&!_0x3295e0[_0x9a4f1(0x178)](_0x2f3f19[_0x9a4f1(0x14a)]))throw new Error(_0x9a4f1(0x1bd));const _0x315bc4=new URL(_0x3a456f+'/'),_0x37639d=_0x2f3f19[_0x9a4f1(0x14a)]?new URL(_0x2f3f19['url'],_0x405f99['origin']):new URL(_0x2f3f19[_0x9a4f1(0x1b1)],_0x315bc4),_0x4bcc45=_0x2f3f19[_0x9a4f1(0x14a)]?_0x405f99[_0x9a4f1(0x1b5)]:_0x315bc4[_0x9a4f1(0x1b5)];if(_0x37639d[_0x9a4f1(0x172)]!==_0x9a4f1(0x1ac)||_0x37639d[_0x9a4f1(0x1b5)]!==_0x4bcc45||a220_0x134e45[_0x9a4f1(0x192)][_0x9a4f1(0x1a3)](decodeURIComponent(_0x37639d[_0x9a4f1(0x17e)]))!==_0x2f3f19[_0x9a4f1(0x1b1)]||!_0x2f3f19[_0x9a4f1(0x14a)]&&!_0x37639d['pathname']['startsWith'](_0x315bc4[_0x9a4f1(0x17e)]))throw new Error(_0x9a4f1(0x1a6));return _0x37639d[_0x9a4f1(0x16b)];}async function readResponseBytes(_0x174020,_0xd27374){const _0x300b98=a220_0x328f;if(!_0x174020['body']){const _0x3c049a=Buffer[_0x300b98(0x15f)](await _0x174020[_0x300b98(0x1b4)]());if(_0x3c049a['length']>_0xd27374)throw new Error('CDN\x20project\x20template\x20exceeds\x20its\x20declared\x20download\x20size.');return _0x3c049a;}const _0x246047=_0x174020[_0x300b98(0x155)][_0x300b98(0x16a)](),_0x4a603d=[];let _0x37dcc7=0x0;try{while(!![]){const {done:_0x425b6a,value:_0x41c0c8}=await _0x246047[_0x300b98(0x182)]();if(_0x425b6a)break;_0x37dcc7+=_0x41c0c8[_0x300b98(0x18f)];if(_0x37dcc7>_0xd27374){await _0x246047[_0x300b98(0x19e)]();throw new Error(_0x300b98(0x166));}_0x4a603d[_0x300b98(0x15e)](Buffer[_0x300b98(0x15f)](_0x41c0c8));}}finally{_0x246047[_0x300b98(0x198)]();}return Buffer['concat'](_0x4a603d,_0x37dcc7);}async function downloadArchive(_0x23a8b8,_0x2fb5cc,_0x4ece76,_0x2cac6b,_0x632408,_0x3350d6){const _0x1425e3=a220_0x328f,_0x1d3d5e=await fetchWithTimeout(resolveArchiveUrl(_0x23a8b8,_0x2fb5cc,_0x4ece76,_0x2cac6b),ARCHIVE_TIMEOUT_MS,_0x1425e3(0x183),async _0x3b9bc4=>{const _0x3a2f4f=_0x1425e3;if(!_0x3b9bc4['ok'])throw new Error(_0x3a2f4f(0x1a2)+_0x3b9bc4[_0x3a2f4f(0x1b8)]+'.');const _0x1fc289=Number(_0x3b9bc4[_0x3a2f4f(0x185)]['get'](_0x3a2f4f(0x175)));if(Number[_0x3a2f4f(0x159)](_0x1fc289)&&_0x1fc289>MAX_ARCHIVE_SIZE)throw new Error(_0x3a2f4f(0x1b2));return readResponseBytes(_0x3b9bc4,_0x23a8b8[_0x3a2f4f(0x177)]);});if(_0x1d3d5e['length']!==_0x23a8b8[_0x1425e3(0x177)])throw new Error('CDN\x20project\x20template\x20size\x20mismatch:\x20expected\x20'+_0x23a8b8[_0x1425e3(0x177)]+_0x1425e3(0x160)+_0x1d3d5e[_0x1425e3(0x165)]+'.');_0x3350d6?.(_0x1425e3(0x191));const _0x1a2cf5=_0x1425e3(0x1b6)+createHash(_0x1425e3(0x18a))['update'](_0x1d3d5e)[_0x1425e3(0x16d)](_0x1425e3(0x1a4));if(_0x1a2cf5!==_0x23a8b8[_0x1425e3(0x18a)])throw new Error('CDN\x20project\x20template\x20checksum\x20verification\x20failed.');await a220_0x29be86[_0x1425e3(0x16f)](_0x632408,_0x1d3d5e,{'flag':'wx'});}function a220_0x13af(){const _0x3eb0fb=['node_modules','length','CDN\x20project\x20template\x20exceeds\x20its\x20declared\x20download\x20size.','signal','lstat','cdn','getReader','href','Project\x20directory\x20already\x20exists:\x20','digest','chmod','writeFile','relative','1631315MzZXhE','protocol','message','readFile','content-length','CDN\x20config\x20contains\x20an\x20invalid\x20descriptor\x20for\x20\x22','size','includes','realpath','.DS_Store','Use\x20a\x20different\x20project\x20name.','mkdir','mkdtemp','pathname','.rabetbase','copying','1768oqHlsL','read','application/zip','isSymbolicLink','headers','24868InmSrm','Choose\x20an\x20output\x20directory\x20outside\x20the\x20template\x20source.','code','abort','sha256','812791nnShpo','ENOENT','sep','mode','byteLength','Unable\x20to\x20claim\x20the\x20project\x20directory.','verifying','posix','.rabetbase-create-','utf8','resolve','string','Choose\x20a\x20different\x20project\x20name\x20or\x20remove\x20the\x20directory\x20first.','releaseLock','error','.idea','trim','isSafeInteger','parse','cancel','8nSrZlc','Local\x20template\x20source\x20does\x20not\x20exist:\x20','97744HlpbHf','CDN\x20project\x20template\x20request\x20failed\x20with\x20HTTP\x20','basename','hex','Local\x20template\x20source\x20and\x20project\x20output\x20must\x20not\x20overlap.','CDN\x20project\x20template\x20URL\x20must\x20use\x20the\x20trusted\x20HTTPS\x20origin.','toLowerCase','21771SRwHTX','Check\x20your\x20network\x20and\x20retry.\x20Details:\x20','legacyAssetBaseUrl','downloading','https:','project','package.json','EEXIST','Unable\x20to\x20download\x20a\x20valid\x20project\x20template\x20from\x20CDN.','name','CDN\x20project\x20template\x20exceeds\x20the\x2020\x20MB\x20download\x20limit.','26996292bvLrZp','arrayBuffer','origin','sha256:','10qtGNuF','status','test','dist','join','12sXpNtz','CDN\x20project\x20template\x20relative\x20URL\x20must\x20match\x20its\x20release\x20channel\x20or\x20version.','validation','dev','6363236PiefqW','url','version','.rabetbase.json','.env','local','.env.','template.zip','Local\x20project\x20template\x20must\x20not\x20contain\x20symlinks:\x20','isDirectory','ino','Rabetbase\x20CDN\x20config\x20is\x20unavailable.','body','Pass\x20a\x20directory\x20containing\x20the\x20template\x20source\x20package.json.','dirname','readdir','isFinite','startsWith','extracting','has','assetBaseUrl','push','from',',\x20received\x20','.lovrabet.log','.env.example','201MGgxmB'];a220_0x13af=function(){return _0x3eb0fb;};return a220_0x13af();}async function assertTemplateRoot(_0x337ba5){const _0x498e0d=a220_0x328f,_0xeb3e0a=a220_0x134e45[_0x498e0d(0x1bb)](_0x337ba5,_0x498e0d(0x1ae)),_0x1d3f53=JSON[_0x498e0d(0x19d)](await a220_0x29be86[_0x498e0d(0x174)](_0xeb3e0a,'utf8'));if(!_0x1d3f53||typeof _0x1d3f53!=='object')throw new Error('Project\x20template\x20package.json\x20is\x20invalid.');}const LOCAL_FORBIDDEN_NAMES=new Set([a220_0x354b7a(0x17a),'.codegraph','.git',a220_0x354b7a(0x19a),'.lovrabet.json',a220_0x354b7a(0x161),a220_0x354b7a(0x17f),a220_0x354b7a(0x14c),a220_0x354b7a(0x1ba),a220_0x354b7a(0x164)]);function isForbiddenTemplateEntry(_0x56dd8a){const _0x4721bd=a220_0x354b7a;if(LOCAL_FORBIDDEN_NAMES[_0x4721bd(0x15c)](_0x56dd8a))return!![];return _0x56dd8a===_0x4721bd(0x14d)||_0x56dd8a[_0x4721bd(0x15a)](_0x4721bd(0x14f))&&_0x56dd8a!==_0x4721bd(0x162);}function containsPath(_0x383c09,_0x31c983){const _0x53e063=a220_0x354b7a,_0x184eac=a220_0x134e45[_0x53e063(0x170)](_0x383c09,_0x31c983);return _0x184eac===''||!_0x184eac[_0x53e063(0x15a)]('..'+a220_0x134e45[_0x53e063(0x18d)])&&_0x184eac!=='..'&&!a220_0x134e45['isAbsolute'](_0x184eac);}async function copyLocalTemplateDirectory(_0x20eb23,_0x4471ba){const _0x29b482=a220_0x354b7a;await a220_0x29be86[_0x29b482(0x17c)](_0x4471ba,{'recursive':!![]});for(const _0x5b1289 of await a220_0x29be86[_0x29b482(0x158)](_0x20eb23,{'withFileTypes':!![]})){const _0x55b412=a220_0x134e45[_0x29b482(0x1bb)](_0x20eb23,_0x5b1289[_0x29b482(0x1b1)]),_0x36e0a7=a220_0x134e45[_0x29b482(0x1bb)](_0x4471ba,_0x5b1289[_0x29b482(0x1b1)]);if(isForbiddenTemplateEntry(_0x5b1289[_0x29b482(0x1b1)]))throw new Error('Local\x20project\x20template\x20contains\x20a\x20local-only\x20entry:\x20'+_0x55b412);const _0x30cc7a=await a220_0x29be86[_0x29b482(0x168)](_0x55b412);if(_0x30cc7a[_0x29b482(0x184)]())throw new Error(_0x29b482(0x151)+_0x55b412);if(_0x30cc7a[_0x29b482(0x152)]()){await copyLocalTemplateDirectory(_0x55b412,_0x36e0a7);continue;}if(!_0x30cc7a['isFile']())continue;await a220_0x29be86['copyFile'](_0x55b412,_0x36e0a7),await a220_0x29be86[_0x29b482(0x16e)](_0x36e0a7,_0x30cc7a[_0x29b482(0x18e)]&0x1ff);}}async function readTemplateVersion(_0x524c33){const _0x571fb5=a220_0x354b7a,_0x60dd58=JSON['parse'](await a220_0x29be86[_0x571fb5(0x174)](a220_0x134e45[_0x571fb5(0x1bb)](_0x524c33,_0x571fb5(0x1ae)),_0x571fb5(0x194)));return nonEmptyString(_0x60dd58[_0x571fb5(0x14b)])||_0x571fb5(0x14e);}async function readDirectoryIdentity(_0x452ef0){const _0x335468=a220_0x354b7a;try{const _0x35bfc9=await a220_0x29be86['lstat'](_0x452ef0);if(!_0x35bfc9[_0x335468(0x152)]())return null;return{'dev':_0x35bfc9['dev'],'ino':_0x35bfc9['ino']};}catch{return null;}}async function commitStagedProject(_0x5a8d8f,_0x462cca){const _0x5ded00=a220_0x354b7a;await a220_0x29be86[_0x5ded00(0x17c)](_0x462cca);const _0xa21782=await readDirectoryIdentity(_0x462cca);if(!_0xa21782)throw new Error(_0x5ded00(0x190));try{for(const _0x246f5c of await a220_0x29be86['readdir'](_0x5a8d8f)){await a220_0x29be86['rename'](a220_0x134e45[_0x5ded00(0x1bb)](_0x5a8d8f,_0x246f5c),a220_0x134e45[_0x5ded00(0x1bb)](_0x462cca,_0x246f5c));}}catch(_0x570d8c){const _0x31d7a9=await readDirectoryIdentity(_0x462cca);_0x31d7a9?.[_0x5ded00(0x1bf)]===_0xa21782[_0x5ded00(0x1bf)]&&_0x31d7a9[_0x5ded00(0x153)]===_0xa21782[_0x5ded00(0x153)]&&await a220_0x29be86['rm'](_0x462cca,{'recursive':!![],'force':!![]});throw _0x570d8c;}}export async function materializeProjectTemplate(_0x28d5e1,_0x1c6831){const _0x434f4e=a220_0x354b7a,_0x3ae59d=a220_0x134e45['resolve'](_0x28d5e1),_0x2537e3=a220_0x134e45[_0x434f4e(0x157)](_0x3ae59d);try{await a220_0x29be86[_0x434f4e(0x168)](_0x3ae59d);throw new Error(_0x434f4e(0x16c)+_0x3ae59d);}catch(_0x309efa){if(_0x309efa[_0x434f4e(0x188)]!==_0x434f4e(0x18c))throw _0x309efa;}const _0xe0bcf5=await a220_0x29be86[_0x434f4e(0x17d)](a220_0x134e45[_0x434f4e(0x1bb)](_0x2537e3,_0x434f4e(0x193))),_0x168435=a220_0x134e45[_0x434f4e(0x1bb)](_0xe0bcf5,_0x434f4e(0x1ad)),_0x172488=a220_0x134e45[_0x434f4e(0x1bb)](_0xe0bcf5,_0x434f4e(0x150));try{try{_0x1c6831?.('resolving');const {descriptor:_0x1b7032,channel:_0x5c12f6,assetBaseUrl:_0x2ed8ec,legacyAssetBaseUrl:_0x1c9e38}=await fetchTemplateDescriptor();return _0x1c6831?.(_0x434f4e(0x1ab)),await downloadArchive(_0x1b7032,_0x5c12f6,_0x2ed8ec,_0x1c9e38,_0x172488,_0x1c6831),_0x1c6831?.(_0x434f4e(0x15b)),await extractProjectTemplateArchive(_0x172488,_0x168435),await assertTemplateRoot(_0x168435),await commitStagedProject(_0x168435,_0x3ae59d),{'source':_0x434f4e(0x169),'version':_0x1b7032['version']};}catch(_0x37d1a7){if(_0x37d1a7[_0x434f4e(0x188)]===_0x434f4e(0x1af))throw CliErrors[_0x434f4e(0x1be)]('Project\x20directory\x20already\x20exists:\x20'+_0x3ae59d,_0x434f4e(0x17b));const _0x829a34=_0x37d1a7 instanceof Error?_0x37d1a7[_0x434f4e(0x173)]:String(_0x37d1a7);throw CliErrors[_0x434f4e(0x1be)](_0x434f4e(0x1b0),_0x434f4e(0x1a9)+_0x829a34);}}finally{await a220_0x29be86['rm'](_0xe0bcf5,{'recursive':!![],'force':!![]});}}export async function materializeLocalProjectTemplate(_0x3ad583,_0x19e336,_0x3d0a07){const _0x11211c=a220_0x354b7a;let _0x23ae3d;try{_0x23ae3d=await a220_0x29be86[_0x11211c(0x179)](a220_0x134e45[_0x11211c(0x195)](_0x3ad583));}catch{throw CliErrors[_0x11211c(0x1be)](_0x11211c(0x1a0)+a220_0x134e45[_0x11211c(0x195)](_0x3ad583),_0x11211c(0x156));}const _0x2e9146=await a220_0x29be86[_0x11211c(0x168)](_0x23ae3d);if(!_0x2e9146[_0x11211c(0x152)]())throw CliErrors[_0x11211c(0x1be)]('Local\x20template\x20source\x20is\x20not\x20a\x20directory:\x20'+_0x23ae3d);const _0x13beb8=a220_0x134e45[_0x11211c(0x195)](_0x19e336),_0x103e61=await a220_0x29be86[_0x11211c(0x179)](a220_0x134e45[_0x11211c(0x157)](_0x13beb8)),_0x19707c=a220_0x134e45[_0x11211c(0x1bb)](_0x103e61,a220_0x134e45[_0x11211c(0x1a3)](_0x13beb8));if(containsPath(_0x23ae3d,_0x19707c)||containsPath(_0x19707c,_0x23ae3d))throw CliErrors[_0x11211c(0x1be)](_0x11211c(0x1a5),_0x11211c(0x187));try{await a220_0x29be86[_0x11211c(0x168)](_0x19707c);throw CliErrors[_0x11211c(0x1be)]('Project\x20directory\x20already\x20exists:\x20'+_0x19707c,_0x11211c(0x197));}catch(_0x3b72dc){if(_0x3b72dc[_0x11211c(0x188)]!==_0x11211c(0x18c))throw _0x3b72dc;}const _0x5a2f07=a220_0x134e45[_0x11211c(0x157)](_0x19707c);await a220_0x29be86['access'](_0x5a2f07);const _0xe9bfad=await a220_0x29be86[_0x11211c(0x17d)](a220_0x134e45[_0x11211c(0x1bb)](_0x5a2f07,_0x11211c(0x193))),_0x38c26a=a220_0x134e45[_0x11211c(0x1bb)](_0xe9bfad,'project');try{_0x3d0a07?.(_0x11211c(0x180)),await copyLocalTemplateDirectory(_0x23ae3d,_0x38c26a),await assertTemplateRoot(_0x38c26a);const _0x171826=await readTemplateVersion(_0x38c26a);return await commitStagedProject(_0x38c26a,_0x19707c),{'source':_0x11211c(0x14e),'version':_0x171826};}catch(_0x5b83e7){const _0x286dec=_0x5b83e7 instanceof Error?_0x5b83e7[_0x11211c(0x173)]:String(_0x5b83e7);throw CliErrors[_0x11211c(0x1be)]('Invalid\x20local\x20template\x20source:\x20'+_0x286dec,'Check\x20the\x20source\x20directory\x20and\x20retry.');}finally{await a220_0x29be86['rm'](_0xe9bfad,{'recursive':!![],'force':!![]});}}
|
|
1
|
+
import{createHash}from"node:crypto";import fs from"node:fs/promises";import path from"node:path";import semver from"semver";import{getProjectTemplateRelativeUrl}from"../../../constant/cdn.js";import{extractProjectTemplateArchive}from"../../../commands/project/create/project-template-archive.js";import{fetchProjectTemplateCdnConfig,isBetaCliVersion,resolveProjectTemplateDescriptor}from"../../../utils/cli-version-policy.js";import{getCliVersion}from"../../../utils/version.js";import{CliErrors}from"../../../errors.js";const TEMPLATE_ID="sub-app-react-demo";const ARCHIVE_TIMEOUT_MS=15e3;const MAX_ARCHIVE_SIZE=20*1024*1024;function nonEmptyString(value){return typeof value==="string"&&value.trim()?value.trim():null}function parseDescriptor(raw){if(!raw||typeof raw!=="object"){throw new Error(`CDN config does not define template "${TEMPLATE_ID}".`)}const source=raw;const version=nonEmptyString(source.version);const name=nonEmptyString(source.name)
|
|
2
|
+
;const url=source.url===undefined?undefined:nonEmptyString(source.url)||undefined;const sha256=nonEmptyString(source.sha256)?.toLowerCase();const size=source.size;if(!version||!semver.valid(version)||!name||name!==path.posix.basename(name)||name.includes("\\")||source.url!==undefined&&!url||!sha256||!/^sha256:[a-f0-9]{64}$/.test(sha256)||typeof size!=="number"||!Number.isSafeInteger(size)||size<=0||size>MAX_ARCHIVE_SIZE){throw new Error(`CDN config contains an invalid descriptor for "${TEMPLATE_ID}".`)}return{version:version,name:name,url:url,sha256:sha256,size:size}}async function fetchWithTimeout(url,timeoutMs,accept,consume){const controller=new AbortController;const timeoutId=setTimeout(()=>controller.abort(),timeoutMs);try{const response=await fetch(url,{headers:{Accept:accept},redirect:"error",signal:controller.signal});return await consume(response)}finally{clearTimeout(timeoutId)}}async function fetchTemplateDescriptor(){const cliVersion=getCliVersion()
|
|
3
|
+
;const channel=isBetaCliVersion(cliVersion)?"beta":"release";const resolution=await fetchProjectTemplateCdnConfig();if(!resolution)throw new Error("Rabetbase CDN config is unavailable.");const descriptor=parseDescriptor(resolveProjectTemplateDescriptor(resolution.config,cliVersion));return{descriptor:descriptor,channel:channel,assetBaseUrl:resolution.assetBaseUrl,legacyAssetBaseUrl:resolution.legacyAssetBaseUrl}}function resolveArchiveUrl(descriptor,channel,baseUrl,legacyBaseUrl){const assetBaseUrl=new URL(`${baseUrl}/`);const expectedRelativeUrls=[getProjectTemplateRelativeUrl(channel),getProjectTemplateRelativeUrl(channel,descriptor.version)];if(descriptor.url&&!expectedRelativeUrls.includes(descriptor.url)){throw new Error(`CDN project template relative URL must match its release channel or version.`)}const legacyAssetBase=new URL(`${legacyBaseUrl}/`);const url=descriptor.url?new URL(descriptor.url,assetBaseUrl.origin):new URL(descriptor.name,legacyAssetBase)
|
|
4
|
+
;const trustedOrigin=descriptor.url?assetBaseUrl.origin:legacyAssetBase.origin;if(url.protocol!=="https:"||url.origin!==trustedOrigin||path.posix.basename(decodeURIComponent(url.pathname))!==descriptor.name||!descriptor.url&&!url.pathname.startsWith(legacyAssetBase.pathname)){throw new Error("CDN project template URL must use the trusted HTTPS origin.")}return url.href}async function readResponseBytes(response,maximumSize){if(!response.body){const bytes=Buffer.from(await response.arrayBuffer());if(bytes.length>maximumSize){throw new Error("CDN project template exceeds its declared download size.")}return bytes}const reader=response.body.getReader();const chunks=[];let receivedSize=0;try{while(true){const{done:done,value:value}=await reader.read();if(done)break;receivedSize+=value.byteLength;if(receivedSize>maximumSize){await reader.cancel();throw new Error("CDN project template exceeds its declared download size.")}chunks.push(Buffer.from(value))}}finally{reader.releaseLock()}
|
|
5
|
+
return Buffer.concat(chunks,receivedSize)}async function downloadArchive(descriptor,channel,assetBaseUrl,legacyAssetBaseUrl,targetPath,onProgress){const bytes=await fetchWithTimeout(resolveArchiveUrl(descriptor,channel,assetBaseUrl,legacyAssetBaseUrl),ARCHIVE_TIMEOUT_MS,"application/zip",async response=>{if(!response.ok){throw new Error(`CDN project template request failed with HTTP ${response.status}.`)}const contentLength=Number(response.headers.get("content-length"));if(Number.isFinite(contentLength)&&contentLength>MAX_ARCHIVE_SIZE){throw new Error("CDN project template exceeds the 20 MB download limit.")}return readResponseBytes(response,descriptor.size)});if(bytes.length!==descriptor.size){throw new Error(`CDN project template size mismatch: expected ${descriptor.size}, received ${bytes.length}.`)}onProgress?.("verifying");const actualHash=`sha256:${createHash("sha256").update(bytes).digest("hex")}`;if(actualHash!==descriptor.sha256){
|
|
6
|
+
throw new Error("CDN project template checksum verification failed.")}await fs.writeFile(targetPath,bytes,{flag:"wx"})}async function assertTemplateRoot(templateDir){const packageJsonPath=path.join(templateDir,"package.json");const packageJson=JSON.parse(await fs.readFile(packageJsonPath,"utf8"));if(!packageJson||typeof packageJson!=="object"){throw new Error("Project template package.json is invalid.")}}const LOCAL_FORBIDDEN_NAMES=new Set([".DS_Store",".codegraph",".git",".idea",".lovrabet.json",".lovrabet.log",".rabetbase",".rabetbase.json","dist","node_modules"]);function isForbiddenTemplateEntry(name){if(LOCAL_FORBIDDEN_NAMES.has(name))return true;return name===".env"||name.startsWith(".env.")&&name!==".env.example"}function containsPath(parent,child){const relativePath=path.relative(parent,child);return relativePath===""||!relativePath.startsWith(`..${path.sep}`)&&relativePath!==".."&&!path.isAbsolute(relativePath)}async function copyLocalTemplateDirectory(sourceDir,targetDir){
|
|
7
|
+
await fs.mkdir(targetDir,{recursive:true});for(const entry of await fs.readdir(sourceDir,{withFileTypes:true})){const sourcePath=path.join(sourceDir,entry.name);const targetPath=path.join(targetDir,entry.name);if(isForbiddenTemplateEntry(entry.name)){throw new Error(`Local project template contains a local-only entry: ${sourcePath}`)}const stats=await fs.lstat(sourcePath);if(stats.isSymbolicLink()){throw new Error(`Local project template must not contain symlinks: ${sourcePath}`)}if(stats.isDirectory()){await copyLocalTemplateDirectory(sourcePath,targetPath);continue}if(!stats.isFile())continue;await fs.copyFile(sourcePath,targetPath);await fs.chmod(targetPath,stats.mode&511)}}async function readTemplateVersion(templateDir){const packageJson=JSON.parse(await fs.readFile(path.join(templateDir,"package.json"),"utf8"));return nonEmptyString(packageJson.version)||"local"}async function readDirectoryIdentity(directory){try{const stats=await fs.lstat(directory)
|
|
8
|
+
;if(!stats.isDirectory())return null;return{dev:stats.dev,ino:stats.ino}}catch{return null}}async function commitStagedProject(stagingDir,projectDir){await fs.mkdir(projectDir);const identity=await readDirectoryIdentity(projectDir);if(!identity)throw new Error("Unable to claim the project directory.");try{for(const entry of await fs.readdir(stagingDir)){await fs.rename(path.join(stagingDir,entry),path.join(projectDir,entry))}}catch(error){const currentIdentity=await readDirectoryIdentity(projectDir);if(currentIdentity?.dev===identity.dev&¤tIdentity.ino===identity.ino){await fs.rm(projectDir,{recursive:true,force:true})}throw error}}export async function materializeProjectTemplate(projectDir,onProgress){const resolvedProjectDir=path.resolve(projectDir);const parentDir=path.dirname(resolvedProjectDir);try{await fs.lstat(resolvedProjectDir);throw new Error(`Project directory already exists: ${resolvedProjectDir}`)}catch(error){if(error.code!=="ENOENT")throw error}
|
|
9
|
+
const workDir=await fs.mkdtemp(path.join(parentDir,".rabetbase-create-"));const stagingDir=path.join(workDir,"project");const archivePath=path.join(workDir,"template.zip");try{try{onProgress?.("resolving");const{descriptor:descriptor,channel:channel,assetBaseUrl:assetBaseUrl,legacyAssetBaseUrl:legacyAssetBaseUrl}=await fetchTemplateDescriptor();onProgress?.("downloading");await downloadArchive(descriptor,channel,assetBaseUrl,legacyAssetBaseUrl,archivePath,onProgress);onProgress?.("extracting");await extractProjectTemplateArchive(archivePath,stagingDir);await assertTemplateRoot(stagingDir);await commitStagedProject(stagingDir,resolvedProjectDir);return{source:"cdn",version:descriptor.version}}catch(error){if(error.code==="EEXIST"){throw CliErrors.validation(`Project directory already exists: ${resolvedProjectDir}`,"Use a different project name.")}const reason=error instanceof Error?error.message:String(error)
|
|
10
|
+
;throw CliErrors.validation("Unable to download a valid project template from CDN.",`Check your network and retry. Details: ${reason}`)}}finally{await fs.rm(workDir,{recursive:true,force:true})}}export async function materializeLocalProjectTemplate(sourceDir,projectDir,onProgress){let resolvedSourceDir;try{resolvedSourceDir=await fs.realpath(path.resolve(sourceDir))}catch{throw CliErrors.validation(`Local template source does not exist: ${path.resolve(sourceDir)}`,"Pass a directory containing the template source package.json.")}const sourceStats=await fs.lstat(resolvedSourceDir);if(!sourceStats.isDirectory()){throw CliErrors.validation(`Local template source is not a directory: ${resolvedSourceDir}`)}const requestedProjectDir=path.resolve(projectDir);const resolvedProjectParent=await fs.realpath(path.dirname(requestedProjectDir));const resolvedProjectDir=path.join(resolvedProjectParent,path.basename(requestedProjectDir))
|
|
11
|
+
;if(containsPath(resolvedSourceDir,resolvedProjectDir)||containsPath(resolvedProjectDir,resolvedSourceDir)){throw CliErrors.validation("Local template source and project output must not overlap.","Choose an output directory outside the template source.")}try{await fs.lstat(resolvedProjectDir);throw CliErrors.validation(`Project directory already exists: ${resolvedProjectDir}`,"Choose a different project name or remove the directory first.")}catch(error){if(error.code!=="ENOENT")throw error}const parentDir=path.dirname(resolvedProjectDir);await fs.access(parentDir);const workDir=await fs.mkdtemp(path.join(parentDir,".rabetbase-create-"));const stagingDir=path.join(workDir,"project");try{onProgress?.("copying");await copyLocalTemplateDirectory(resolvedSourceDir,stagingDir);await assertTemplateRoot(stagingDir);const version=await readTemplateVersion(stagingDir);await commitStagedProject(stagingDir,resolvedProjectDir);return{source:"local",version:version}}catch(error){
|
|
12
|
+
const reason=error instanceof Error?error.message:String(error);throw CliErrors.validation(`Invalid local template source: ${reason}`,"Check the source directory and retry.")}finally{await fs.rm(workDir,{recursive:true,force:true})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{CliErrors}from"../../../errors.js";const PROJECT_NAME_PATTERN=/^[A-Za-z0-9][A-Za-z0-9_-]*$/;const WINDOWS_RESERVED_NAME=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;const MAX_PROJECT_NAME_LENGTH=100;export function getProjectNameValidationError(value){const projectName=value.trim();if(!projectName)return"Project name cannot be empty";if(projectName.length>MAX_PROJECT_NAME_LENGTH){return`Project name cannot exceed ${MAX_PROJECT_NAME_LENGTH} characters`}if(!PROJECT_NAME_PATTERN.test(projectName)){return"Must start with a letter/number and only contain letters, numbers, - and _"}if(WINDOWS_RESERVED_NAME.test(projectName)){return`Project name "${projectName}" is reserved on Windows`}return null}export function validateProjectName(value){const projectName=value.trim();const error=getProjectNameValidationError(projectName);if(error){throw CliErrors.validation(error,"Use a portable directory name without path separators.")}return projectName}
|