@origen-ui/admin-cli 2.0.2 → 3.0.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 +20 -9
- package/bin/contract-sync.mjs +112 -0
- package/bin/lib/errors.mjs +8 -0
- package/bin/lib/fs-json.mjs +18 -0
- package/bin/lib/hash.mjs +9 -0
- package/bin/og-admin.mjs +165 -35
- package/bin/sync-project.mjs +717 -0
- package/package.json +20 -17
- package/templates/current/clean/.agents/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/clean/.agents/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/clean/.agents/skills/build-admin-feature/SKILL.md +20 -0
- package/templates/current/clean/.agents/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/{examples/.codex → clean/.agents}/skills/use-og-form/SKILL.md +1 -1
- package/templates/current/{examples/.codex → clean/.agents}/skills/use-og-form-table/SKILL.md +4 -3
- package/templates/current/clean/{.codex → .agents}/skills/use-og-search/SKILL.md +3 -3
- package/templates/current/clean/.agents/skills/use-og-table/SKILL.md +22 -0
- package/templates/current/{examples/.codex → clean/.agents}/skills/use-og-upload/SKILL.md +6 -5
- package/templates/current/clean/.api-client-e2e.config.ts +13 -0
- package/templates/current/clean/.claude/rules/01-feature-architecture.md +10 -0
- package/templates/current/clean/.claude/rules/02-vue-typescript.md +10 -0
- package/templates/current/clean/.claude/rules/03-component-policy.md +31 -0
- package/templates/current/clean/.claude/rules/04-api-auth-router.md +10 -0
- package/templates/current/clean/.claude/rules/05-style.md +10 -0
- package/templates/current/clean/.claude/rules/06-quality.md +10 -0
- package/templates/current/clean/.claude/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/clean/.claude/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/clean/.claude/skills/build-admin-feature/SKILL.md +20 -0
- package/templates/current/clean/.claude/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/clean/{.codex → .claude}/skills/use-og-form/SKILL.md +1 -1
- package/templates/current/clean/{.codex → .claude}/skills/use-og-form-table/SKILL.md +4 -3
- package/templates/current/{examples/.codex → clean/.claude}/skills/use-og-search/SKILL.md +3 -3
- package/templates/current/clean/.claude/skills/use-og-table/SKILL.md +22 -0
- package/templates/current/clean/{.codex → .claude}/skills/use-og-upload/SKILL.md +6 -5
- package/templates/current/clean/.codebuddy/rules/01-feature-architecture.md +2 -2
- package/templates/current/clean/.codebuddy/rules/03-component-policy.md +4 -1
- package/templates/current/clean/.codebuddy/skills/admin-component-usage/SKILL.md +31 -0
- package/templates/current/clean/.codebuddy/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/clean/.codebuddy/skills/build-admin-feature/SKILL.md +11 -5
- package/templates/current/clean/.codebuddy/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/clean/.codebuddy/skills/use-og-form/SKILL.md +1 -1
- package/templates/current/clean/.codebuddy/skills/use-og-form-table/SKILL.md +4 -3
- package/templates/current/clean/.codebuddy/skills/use-og-search/SKILL.md +3 -3
- package/templates/current/clean/.codebuddy/skills/use-og-table/SKILL.md +16 -10
- package/templates/current/clean/.codebuddy/skills/use-og-upload/SKILL.md +6 -5
- package/templates/current/clean/.codex/AGENTS.md +55 -8
- package/templates/current/clean/.codex/rules/01-feature-architecture.md +2 -2
- package/templates/current/clean/.codex/rules/03-component-policy.md +4 -1
- package/templates/current/clean/.cursor/rules/.generated +5 -0
- package/templates/current/clean/.cursor/rules/01-feature-architecture.mdc +2 -2
- package/templates/current/clean/.cursor/rules/03-component-policy.mdc +4 -1
- package/templates/current/clean/.cursor/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/clean/.cursor/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/clean/.cursor/skills/build-admin-feature/SKILL.md +11 -5
- package/templates/current/clean/.cursor/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/clean/.cursor/skills/use-og-form/SKILL.md +1 -1
- package/templates/current/clean/.cursor/skills/use-og-form-table/SKILL.md +4 -3
- package/templates/current/clean/.cursor/skills/use-og-search/SKILL.md +3 -3
- package/templates/current/clean/.cursor/skills/use-og-table/SKILL.md +16 -10
- package/templates/current/clean/.cursor/skills/use-og-upload/SKILL.md +6 -5
- package/templates/current/clean/{.env.example → .env.dev} +3 -2
- package/templates/current/clean/.env.mock +4 -0
- package/templates/current/clean/.env.production +5 -0
- package/templates/current/clean/.env.test +4 -0
- package/templates/current/clean/.prettierignore +17 -0
- package/templates/current/clean/.prettierrc +8 -0
- package/templates/current/clean/.qoder/rules/01-feature-architecture.md +3 -4
- package/templates/current/clean/.qoder/rules/02-vue-typescript.md +1 -2
- package/templates/current/clean/.qoder/rules/03-component-policy.md +5 -3
- package/templates/current/clean/.qoder/rules/04-api-auth-router.md +1 -2
- package/templates/current/clean/.qoder/rules/05-style.md +1 -2
- package/templates/current/clean/.qoder/rules/06-quality.md +1 -2
- package/templates/current/clean/.qoder/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/clean/.qoder/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/clean/.qoder/skills/build-admin-feature/SKILL.md +11 -5
- package/templates/current/clean/.qoder/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/clean/.qoder/skills/use-og-form/SKILL.md +1 -1
- package/templates/current/clean/.qoder/skills/use-og-form-table/SKILL.md +4 -3
- package/templates/current/clean/.qoder/skills/use-og-search/SKILL.md +3 -3
- package/templates/current/clean/.qoder/skills/use-og-table/SKILL.md +16 -10
- package/templates/current/clean/.qoder/skills/use-og-upload/SKILL.md +6 -5
- package/templates/current/clean/.zcode/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/clean/.zcode/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/clean/.zcode/skills/build-admin-feature/SKILL.md +20 -0
- package/templates/current/clean/.zcode/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/clean/.zcode/skills/style-og-origen-ui/SKILL.md +11 -0
- package/templates/current/clean/.zcode/skills/use-og-dialog/SKILL.md +12 -0
- package/templates/current/clean/.zcode/skills/use-og-editor/SKILL.md +25 -0
- package/templates/current/clean/.zcode/skills/use-og-form/SKILL.md +12 -0
- package/templates/current/clean/.zcode/skills/use-og-form-table/SKILL.md +26 -0
- package/templates/current/clean/.zcode/skills/use-og-http/SKILL.md +13 -0
- package/templates/current/clean/.zcode/skills/use-og-router-tabs/SKILL.md +11 -0
- package/templates/current/clean/.zcode/skills/use-og-search/SKILL.md +14 -0
- package/templates/current/clean/.zcode/skills/use-og-table/SKILL.md +22 -0
- package/templates/current/clean/.zcode/skills/use-og-upload/SKILL.md +26 -0
- package/templates/current/clean/AGENTS.md +55 -9
- package/templates/current/clean/CHANGELOG.md +107 -0
- package/templates/current/clean/CLAUDE.md +3 -0
- package/templates/current/clean/README.md +58 -88
- package/templates/current/clean/component-catalog.json +766 -348
- package/templates/current/clean/component-catalog.v2.json +2040 -0
- package/templates/current/clean/docs/components/dialog.md +405 -0
- package/templates/current/clean/docs/components/editor-viewer.md +87 -0
- package/templates/current/clean/docs/components/editor.md +275 -0
- package/templates/current/clean/docs/components/form-table.md +222 -0
- package/templates/current/clean/docs/components/form.md +750 -0
- package/templates/current/clean/docs/components/index.md +44 -0
- package/templates/current/clean/docs/components/router.md +452 -0
- package/templates/current/clean/docs/components/search.md +1205 -0
- package/templates/current/clean/docs/components/svg-icon.md +124 -0
- package/templates/current/clean/docs/components/table-local.md +176 -0
- package/templates/current/clean/docs/components/table-with-search.md +207 -0
- package/templates/current/clean/docs/components/table.md +813 -0
- package/templates/current/clean/docs/components/tabs.md +440 -0
- package/templates/current/clean/docs/components/upload.md +349 -0
- package/templates/current/clean/eslint.config.js +89 -0
- package/templates/current/clean/index.html +1 -1
- package/templates/current/clean/openapi.json +10048 -999
- package/templates/current/clean/package.json +45 -33
- package/templates/current/clean/playwright.config.ts +20 -6
- package/templates/current/clean/playwright.mock.config.ts +42 -0
- package/templates/current/clean/pnpm-workspace.yaml +19 -3
- package/templates/current/clean/recipes/remote-crud-dialog-form.vue +15 -13
- package/templates/current/clean/scaffold.lock.json +164 -4
- package/templates/current/clean/scripts/api-codegen.config.ts +35 -0
- package/templates/current/clean/scripts/api-codegen.ts +2015 -0
- package/templates/current/clean/scripts/api-templates/http-client.ejs +359 -0
- package/templates/current/clean/scripts/check-admin-scaffold.mjs +311 -17
- package/templates/current/clean/scripts/generate-api.ts +290 -85
- package/templates/current/clean/scripts/lib/admin-component-catalog.mjs +515 -0
- package/templates/current/clean/scripts/lib/repository-root.mjs +9 -0
- package/templates/current/clean/scripts/mock-api.ts +1356 -0
- package/templates/current/clean/scripts/remove-examples.mjs +9 -34
- package/templates/current/clean/src/App.vue +9 -18
- package/templates/current/clean/src/api/generated/data-contracts.ts +23 -265
- package/templates/current/clean/src/api/generated/http-client.ts +351 -180
- package/templates/current/clean/src/api/generated/index.ts +22 -0
- package/templates/current/clean/src/api/generated/services/auth.ts +123 -0
- package/templates/current/clean/src/api/generated/services/common/files.ts +111 -0
- package/templates/current/clean/src/api/generated/services/monitor/cache.ts +164 -0
- package/templates/current/clean/src/api/generated/services/monitor/job.ts +195 -0
- package/templates/current/clean/src/api/generated/services/monitor/jobLog.ts +126 -0
- package/templates/current/clean/src/api/generated/services/monitor/logininfor.ts +126 -0
- package/templates/current/clean/src/api/generated/services/monitor/online.ts +66 -0
- package/templates/current/clean/src/api/generated/services/monitor/operlog.ts +106 -0
- package/templates/current/clean/src/api/generated/services/monitor/server.ts +41 -0
- package/templates/current/clean/src/api/generated/services/system/configs.ts +190 -0
- package/templates/current/clean/src/api/generated/services/system/departments.ts +173 -0
- package/templates/current/clean/src/api/generated/services/system/dictionaries/data.ts +169 -0
- package/templates/current/clean/src/api/generated/services/system/dictionaries/types.ts +187 -0
- package/templates/current/clean/src/api/generated/services/system/index.ts +158 -0
- package/templates/current/clean/src/api/generated/services/system/menus.ts +193 -0
- package/templates/current/clean/src/api/generated/services/system/notices.ts +221 -0
- package/templates/current/clean/src/api/generated/services/system/posts.ts +168 -0
- package/templates/current/clean/src/api/generated/services/system/roles.ts +354 -0
- package/templates/current/clean/src/api/generated/services/system/users.ts +425 -0
- package/templates/current/clean/src/api/generated/services/tool/code-generator.ts +304 -0
- package/templates/current/clean/src/api/generated/types/auth.types.ts +132 -0
- package/templates/current/clean/src/api/generated/types/common/files.types.ts +57 -0
- package/templates/current/clean/src/api/generated/types/common.ts +174 -0
- package/templates/current/clean/src/api/generated/types/enum-dict.ts +94 -0
- package/templates/current/clean/src/api/generated/types/enums.ts +155 -0
- package/templates/current/clean/src/api/generated/types/monitor/cache.types.ts +149 -0
- package/templates/current/clean/src/api/generated/types/monitor/job.types.ts +207 -0
- package/templates/current/clean/src/api/generated/types/monitor/jobLog.types.ts +134 -0
- package/templates/current/clean/src/api/generated/types/monitor/logininfor.types.ts +135 -0
- package/templates/current/clean/src/api/generated/types/monitor/online.types.ts +80 -0
- package/templates/current/clean/src/api/generated/types/monitor/operlog.types.ts +126 -0
- package/templates/current/clean/src/api/generated/types/monitor/server.types.ts +205 -0
- package/templates/current/clean/src/api/generated/types/system/configs.types.ts +200 -0
- package/templates/current/clean/src/api/generated/types/system/departments.types.ts +145 -0
- package/templates/current/clean/src/api/generated/types/system/dictionaries/data.types.ts +210 -0
- package/templates/current/clean/src/api/generated/types/system/dictionaries/types.types.ts +221 -0
- package/templates/current/clean/src/api/generated/types/system/index.types.ts +19 -0
- package/templates/current/clean/src/api/generated/types/system/menus.types.ts +234 -0
- package/templates/current/clean/src/api/generated/types/system/notices.types.ts +270 -0
- package/templates/current/clean/src/api/generated/types/system/posts.types.ts +198 -0
- package/templates/current/clean/src/api/generated/types/system/roles.types.ts +410 -0
- package/templates/current/clean/src/api/generated/types/system/users.types.ts +413 -0
- package/templates/current/clean/src/api/generated/types/tool/code-generator.types.ts +388 -0
- package/templates/current/clean/src/api/index.ts +44 -39
- package/templates/current/clean/src/app/__tests__/api-generated.types.ts +24 -0
- package/templates/current/clean/src/app/api.ts +6 -0
- package/templates/current/clean/src/app/authorization/permission.ts +9 -0
- package/templates/current/{examples/src/app → clean/src/app/config}/runtimeConfig.ts +44 -12
- package/templates/current/clean/src/app/errors/errorMessage.ts +80 -0
- package/templates/current/clean/src/app/http/client.ts +141 -0
- package/templates/current/clean/src/app/http/http-adapter.ts +71 -0
- package/templates/current/{examples/src/app → clean/src/app/i18n}/adminLocale.ts +25 -19
- package/templates/current/clean/src/app/{localeFormat.ts → i18n/localeFormat.ts} +29 -6
- package/templates/current/clean/src/app/i18n/origenUiLocale.ts +15 -0
- package/templates/current/clean/src/app/menu/menu.ts +175 -0
- package/templates/current/clean/src/app/menu/menuTypes.ts +20 -0
- package/templates/current/clean/src/{features → app}/security/devtoolsProtection.ts +8 -7
- package/templates/current/clean/src/app/ui/createAdminUi.ts +31 -0
- package/templates/current/clean/src/app/ui/iconCatalog.ts +71 -0
- package/templates/current/clean/src/assets/icons/appearance.svg +1 -0
- package/templates/current/clean/src/assets/icons/arrow-right.svg +1 -0
- package/templates/current/clean/src/assets/icons/check.svg +1 -0
- package/templates/current/clean/src/assets/icons/circle-check.svg +1 -0
- package/templates/current/clean/src/assets/icons/default.svg +4 -0
- package/templates/current/clean/src/assets/icons/directory/setting.svg +1 -0
- package/templates/current/clean/src/assets/icons/expand.svg +1 -0
- package/templates/current/clean/src/assets/icons/fold.svg +1 -0
- package/templates/current/clean/src/assets/icons/key.svg +1 -0
- package/templates/current/clean/src/assets/icons/lock.svg +1 -0
- package/templates/current/clean/src/assets/icons/monitor.svg +1 -0
- package/templates/current/clean/src/assets/icons/moon.svg +11 -0
- package/templates/current/clean/src/assets/icons/page/department.svg +1 -0
- package/templates/current/clean/src/assets/icons/page/dictionary.svg +1 -0
- package/templates/current/clean/src/assets/icons/page/menus.svg +1 -0
- package/templates/current/clean/src/assets/icons/page/user.svg +1 -0
- package/templates/current/clean/src/assets/icons/page/users.svg +1 -0
- package/templates/current/clean/src/assets/icons/plus.svg +1 -0
- package/templates/current/clean/src/assets/icons/profile.svg +1 -0
- package/templates/current/clean/src/assets/icons/refresh.svg +1 -0
- package/templates/current/clean/src/assets/icons/roles.svg +1 -0
- package/templates/current/clean/src/assets/icons/search.svg +1 -0
- package/templates/current/clean/src/assets/icons/sunny.svg +1 -0
- package/templates/current/clean/src/assets/icons/system.svg +1 -0
- package/templates/current/clean/src/assets/icons/theme-auto.svg +14 -0
- package/templates/current/clean/src/assets/icons/tune.svg +13 -0
- package/templates/current/clean/src/{features/shell/components → components}/RouteProgress.vue +2 -2
- package/templates/current/{examples/src/features/system/access → clean/src}/composables/useAuthorizationRefresh.ts +6 -1
- package/templates/current/clean/src/composables/useSystemTableSearchVisibility.ts +33 -0
- package/templates/current/clean/src/{features/appearance/composables → composables}/useTheme.ts +1 -1
- package/templates/current/clean/src/env.d.ts +6 -19
- package/templates/current/clean/src/layouts/AdminLayout.vue +7 -9
- package/templates/current/clean/src/{features/shell/components → layouts}/AdminWatermark.vue +2 -2
- package/templates/current/clean/src/layouts/BreadcrumbBar.vue +9 -1
- package/templates/current/clean/src/layouts/SideMenu.vue +7 -15
- package/templates/current/clean/src/{features/appearance/components → layouts}/ThemePanel.vue +39 -11
- package/templates/current/clean/src/layouts/TopBar.vue +60 -28
- package/templates/current/clean/src/layouts/WorkspaceTabs.vue +10 -1
- package/templates/current/clean/src/layouts/topBarMenuSearch.ts +25 -4
- package/templates/current/clean/src/locales/en-US.json +227 -219
- package/templates/current/clean/src/locales/index.ts +72 -32
- package/templates/current/clean/src/locales/messages-types.ts +15 -10
- package/templates/current/clean/src/locales/vue-i18n.d.ts +1 -1
- package/templates/current/clean/src/locales/zh-CN.json +226 -218
- package/templates/current/clean/src/locales/zh-TW.json +222 -214
- package/templates/current/clean/src/main.ts +59 -30
- package/templates/current/clean/src/router/bootstrap.ts +69 -24
- package/templates/current/clean/src/router/dynamic/componentLoader.ts +150 -0
- package/templates/current/clean/src/router/{dynamicMenuRefresh.ts → dynamic/dynamicMenuRefresh.ts} +6 -2
- package/templates/current/clean/src/router/dynamic/dynamicRoutes.ts +247 -0
- package/templates/current/clean/src/router/navigation/guards.ts +12 -0
- package/templates/current/clean/src/router/navigation/paths.ts +28 -0
- package/templates/current/clean/src/router/navigation/staticRoutes.ts +109 -0
- package/templates/current/clean/src/router/{queryEncryption.ts → query/queryEncryption.ts} +29 -12
- package/templates/current/clean/src/router/query/routeQuery.ts +29 -0
- package/templates/current/clean/src/router/{useRouteQueryDefaults.ts → query/useRouteQueryDefaults.ts} +9 -8
- package/templates/current/clean/src/router/query/useRouteQueryDefaults.types.ts +28 -0
- package/templates/current/clean/src/router/{runtimeErrorRecovery.ts → recovery/runtimeErrorRecovery.ts} +21 -3
- package/templates/current/clean/src/{features/auth/store → store}/auth.ts +96 -61
- package/templates/current/clean/src/store/dictionaries.ts +86 -0
- package/templates/current/clean/src/{features/shell/store → store}/sidebar.ts +9 -2
- package/templates/current/{examples/src/features/appearance → clean/src}/store/theme.ts +8 -4
- package/templates/current/clean/src/styles/layout.css +51 -0
- package/templates/current/clean/src/templates/og-form.ts +7 -2
- package/templates/current/clean/src/templates/og-table.ts +88 -20
- package/templates/current/clean/src/templates/router.ts +11 -2
- package/templates/current/clean/src/utils/color-mix.ts +6 -2
- package/templates/current/clean/src/utils/download.ts +11 -0
- package/templates/current/clean/src/utils/permissions.ts +1 -1
- package/templates/current/clean/src/utils/retryableDialog.ts +46 -0
- package/templates/current/clean/src/{features → views}/errors/pages/Forbidden.vue +6 -2
- package/templates/current/clean/src/views/errors/pages/MethodNotAllowed.vue +34 -0
- package/templates/current/clean/src/{features → views}/errors/pages/NotFound.vue +6 -2
- package/templates/current/clean/src/{features → views}/errors/pages/ServerError.vue +6 -2
- package/templates/current/clean/src/{features/auth/pages/Login.vue → views/login/pages/index.vue} +99 -10
- package/templates/current/clean/src/views/system/access/services/admin-repository.ts +489 -0
- package/templates/current/clean/src/views/system/access/services/rbac.ts +317 -0
- package/templates/current/clean/src/views/system/dept/components/DepartmentEditorForm.vue +87 -0
- package/templates/current/clean/src/views/system/dept/composables/useDepartmentManagement.ts +314 -0
- package/templates/current/clean/src/views/system/dept/pages/index.vue +44 -0
- package/templates/current/clean/src/views/system/dept/services/departments.ts +168 -0
- package/templates/current/clean/src/views/system/dict/components/DictionaryDataEditorForm.vue +98 -0
- package/templates/current/clean/src/views/system/dict/components/DictionaryDataPreview.vue +233 -0
- package/templates/current/clean/src/views/system/dict/components/DictionaryTypeEditorForm.vue +66 -0
- package/templates/current/clean/src/views/system/dict/composables/useDictionaryDataManagement.ts +406 -0
- package/templates/current/clean/src/views/system/dict/composables/useDictionaryTypeManagement.ts +329 -0
- package/templates/current/clean/src/views/system/dict/data/pages/index.vue +134 -0
- package/templates/current/clean/src/views/system/dict/pages/index.vue +113 -0
- package/templates/current/clean/src/views/system/dict/services/dictionaries.ts +239 -0
- package/templates/current/clean/src/views/system/menu/components/MenuEditorForm.vue +252 -0
- package/templates/current/clean/src/views/system/menu/composables/useMenuManagement.ts +357 -0
- package/templates/current/clean/src/views/system/menu/menuDraft.ts +45 -0
- package/templates/current/clean/src/views/system/menu/pages/ExternalLink.vue +37 -0
- package/templates/current/clean/src/views/system/menu/pages/index.vue +75 -0
- package/templates/current/clean/src/views/system/post/components/PostEditorForm.vue +69 -0
- package/templates/current/clean/src/views/system/post/composables/usePostManagement.ts +245 -0
- package/templates/current/clean/src/views/system/post/pages/index.vue +92 -0
- package/templates/current/clean/src/views/system/post/services/posts.ts +100 -0
- package/templates/current/clean/src/views/system/role/auth-users/pages/index.vue +100 -0
- package/templates/current/clean/src/views/system/role/components/RoleDataScopeForm.vue +167 -0
- package/templates/current/clean/src/views/system/role/components/RoleEditorForm.vue +165 -0
- package/templates/current/clean/src/views/system/role/components/RoleUserSelectForm.vue +129 -0
- package/templates/current/clean/src/views/system/role/composables/useRoleManagement.ts +422 -0
- package/templates/current/clean/src/views/system/role/composables/useRoleUserManagement.ts +233 -0
- package/templates/current/clean/src/views/system/role/pages/index.vue +110 -0
- package/templates/current/clean/src/views/system/role/services/roleAccess.ts +162 -0
- package/templates/current/clean/src/views/system/user/auth-roles/pages/index.vue +209 -0
- package/templates/current/clean/src/views/system/user/components/UserDetailsForm.vue +108 -0
- package/templates/current/clean/src/views/system/user/components/UserEditorForm.vue +207 -0
- package/templates/current/clean/src/views/system/user/components/UserImportDialog.vue +80 -0
- package/templates/current/clean/src/views/system/user/components/UserResetPasswordForm.vue +56 -0
- package/templates/current/clean/src/views/system/user/composables/useUserManagement.ts +502 -0
- package/templates/current/clean/src/views/system/user/pages/index.vue +459 -0
- package/templates/current/clean/tests/e2e/admin-access-business.spec.ts +33 -0
- package/templates/current/clean/tests/e2e/admin-shell.spec.ts +50 -0
- package/templates/current/clean/tests/e2e/fixtures/adminMockBackend.ts +95 -0
- package/templates/current/clean/tests/e2e/fixtures/labelGeometry.ts +52 -0
- package/templates/current/clean/tests/e2e/mock-api-generation.spec.ts +27 -0
- package/templates/current/clean/tests/e2e/mock-business.spec.ts +555 -0
- package/templates/current/clean/tests/e2e/mock-menu-retry-form-label.spec.ts +100 -0
- package/templates/current/clean/tests/e2e/mock-shell.spec.ts +25 -0
- package/templates/current/clean/tests/e2e/mock-tree-selection-layout.spec.ts +113 -0
- package/templates/current/clean/tests/unit/api/api-codegen.spec.ts +893 -0
- package/templates/current/clean/tests/unit/api/client.spec.ts +145 -0
- package/templates/current/clean/tests/unit/api/generated-http-client.spec.ts +290 -0
- package/templates/current/{examples/src → clean/tests/unit}/api/http-adapter.spec.ts +3 -3
- package/templates/current/clean/tests/unit/api/system-apis.spec.ts +118 -0
- package/templates/current/clean/tests/unit/app/createAdminUi.spec.ts +79 -0
- package/templates/current/clean/{src → tests/unit}/app/errorMessage.spec.ts +1 -1
- package/templates/current/clean/tests/unit/app/iconCatalog.spec.ts +12 -0
- package/templates/current/clean/tests/unit/app/menu.spec.ts +215 -0
- package/templates/current/{examples/src → clean/tests/unit}/app/origenUiLocale.spec.ts +1 -1
- package/templates/current/{examples/src → clean/tests/unit}/app/permission.spec.ts +4 -5
- package/templates/current/clean/tests/unit/app/runtimeConfig.spec.ts +36 -0
- package/templates/current/{examples/src/features → clean/tests/unit/app}/security/devtoolsProtection.spec.ts +17 -7
- package/templates/current/{examples/src/features/shell → clean/tests/unit}/composables/useRouteProgress.spec.ts +1 -1
- package/templates/current/{examples/src/features/shell/components → clean/tests/unit/layouts}/AdminWatermark.spec.ts +5 -7
- package/templates/current/{examples/src → clean/tests/unit}/layouts/topBarMenuSearch.spec.ts +25 -8
- package/templates/current/clean/{src → tests/unit}/locales/messages.spec.ts +43 -17
- package/templates/current/clean/tests/unit/router/dynamicMenuRefresh.spec.ts +151 -0
- package/templates/current/clean/tests/unit/router/dynamicRoutes.spec.ts +374 -0
- package/templates/current/clean/tests/unit/router/paths.spec.ts +103 -0
- package/templates/current/clean/{src → tests/unit}/router/queryEncryption.spec.ts +49 -12
- package/templates/current/{examples/src → clean/tests/unit}/router/routeQuery.spec.ts +8 -1
- package/templates/current/clean/{src → tests/unit}/router/runtimeErrorRecovery.spec.ts +11 -6
- package/templates/current/{examples/src → clean/tests/unit}/router/useRouteQueryDefaults.spec.ts +46 -12
- package/templates/current/clean/tests/unit/scripts/mock-api.spec.ts +440 -0
- package/templates/current/clean/{scripts → tests/unit/scripts}/vite-build-policy.spec.ts +35 -6
- package/templates/current/clean/{src/features/auth → tests/unit}/store/auth.spec.ts +68 -15
- package/templates/current/clean/tests/unit/store/dictionaries.spec.ts +106 -0
- package/templates/current/{examples/src → clean/tests/unit}/templates/templates.spec.ts +60 -16
- package/templates/current/clean/{src/utils/__tests__ → tests/unit/utils}/color-mix.spec.ts +1 -1
- package/templates/current/clean/tests/unit/utils/retryableDialog.spec.ts +61 -0
- package/templates/current/{examples/src/features/errors/pages → clean/tests/unit/views/errors}/error-pages.spec.ts +11 -7
- package/templates/current/clean/tests/unit/views/feature-composables.spec.ts +233 -0
- package/templates/current/clean/tests/unit/views/system/access/admin-repository.spec.ts +353 -0
- package/templates/current/clean/tests/unit/views/system/access/rbac.spec.ts +329 -0
- package/templates/current/clean/tests/unit/views/system/dept/departments.spec.ts +104 -0
- package/templates/current/clean/tests/unit/views/system/dict/dictionaries.spec.ts +234 -0
- package/templates/current/clean/tests/unit/views/system/menu/menuDraft.spec.ts +77 -0
- package/templates/current/clean/tests/unit/views/system/menu/useMenuManagement.spec.ts +339 -0
- package/templates/current/clean/tests/unit/views/system/user/searchControl.spec.ts +128 -0
- package/templates/current/clean/tsconfig.json +4 -19
- package/templates/current/clean/vite.build-policy.ts +97 -22
- package/templates/current/clean/vite.config.ts +50 -7
- package/templates/current/examples/.agents/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/examples/.agents/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/examples/.agents/skills/build-admin-feature/SKILL.md +20 -0
- package/templates/current/examples/.agents/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/examples/.agents/skills/style-og-origen-ui/SKILL.md +11 -0
- package/templates/current/examples/.agents/skills/use-og-dialog/SKILL.md +12 -0
- package/templates/current/examples/.agents/skills/use-og-editor/SKILL.md +25 -0
- package/templates/current/examples/.agents/skills/use-og-form/SKILL.md +12 -0
- package/templates/current/examples/.agents/skills/use-og-form-table/SKILL.md +26 -0
- package/templates/current/examples/.agents/skills/use-og-http/SKILL.md +13 -0
- package/templates/current/examples/.agents/skills/use-og-router-tabs/SKILL.md +11 -0
- package/templates/current/examples/.agents/skills/use-og-search/SKILL.md +14 -0
- package/templates/current/examples/.agents/skills/use-og-table/SKILL.md +22 -0
- package/templates/current/examples/.agents/skills/use-og-upload/SKILL.md +26 -0
- package/templates/current/examples/.api-client-e2e.config.ts +13 -0
- package/templates/current/examples/.claude/rules/01-feature-architecture.md +10 -0
- package/templates/current/examples/.claude/rules/02-vue-typescript.md +10 -0
- package/templates/current/examples/.claude/rules/03-component-policy.md +31 -0
- package/templates/current/examples/.claude/rules/04-api-auth-router.md +10 -0
- package/templates/current/examples/.claude/rules/05-style.md +10 -0
- package/templates/current/examples/.claude/rules/06-quality.md +10 -0
- package/templates/current/examples/.claude/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/examples/.claude/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/examples/.claude/skills/build-admin-feature/SKILL.md +20 -0
- package/templates/current/examples/.claude/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/examples/.claude/skills/style-og-origen-ui/SKILL.md +11 -0
- package/templates/current/examples/.claude/skills/use-og-dialog/SKILL.md +12 -0
- package/templates/current/examples/.claude/skills/use-og-editor/SKILL.md +25 -0
- package/templates/current/examples/.claude/skills/use-og-form/SKILL.md +12 -0
- package/templates/current/examples/.claude/skills/use-og-form-table/SKILL.md +26 -0
- package/templates/current/examples/.claude/skills/use-og-http/SKILL.md +13 -0
- package/templates/current/examples/.claude/skills/use-og-router-tabs/SKILL.md +11 -0
- package/templates/current/examples/.claude/skills/use-og-search/SKILL.md +14 -0
- package/templates/current/examples/.claude/skills/use-og-table/SKILL.md +22 -0
- package/templates/current/examples/.claude/skills/use-og-upload/SKILL.md +26 -0
- package/templates/current/examples/.codebuddy/rules/01-feature-architecture.md +2 -2
- package/templates/current/examples/.codebuddy/rules/03-component-policy.md +4 -1
- package/templates/current/examples/.codebuddy/skills/admin-component-usage/SKILL.md +31 -0
- package/templates/current/examples/.codebuddy/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/examples/.codebuddy/skills/build-admin-feature/SKILL.md +11 -5
- package/templates/current/examples/.codebuddy/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/examples/.codebuddy/skills/use-og-form/SKILL.md +1 -1
- package/templates/current/examples/.codebuddy/skills/use-og-form-table/SKILL.md +4 -3
- package/templates/current/examples/.codebuddy/skills/use-og-search/SKILL.md +3 -3
- package/templates/current/examples/.codebuddy/skills/use-og-table/SKILL.md +16 -10
- package/templates/current/examples/.codebuddy/skills/use-og-upload/SKILL.md +6 -5
- package/templates/current/examples/.codex/AGENTS.md +55 -8
- package/templates/current/examples/.codex/rules/01-feature-architecture.md +2 -2
- package/templates/current/examples/.codex/rules/03-component-policy.md +4 -1
- package/templates/current/examples/.cursor/rules/.generated +5 -0
- package/templates/current/examples/.cursor/rules/01-feature-architecture.mdc +2 -2
- package/templates/current/examples/.cursor/rules/03-component-policy.mdc +4 -1
- package/templates/current/examples/.cursor/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/examples/.cursor/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/examples/.cursor/skills/build-admin-feature/SKILL.md +11 -5
- package/templates/current/examples/.cursor/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/examples/.cursor/skills/use-og-form/SKILL.md +1 -1
- package/templates/current/examples/.cursor/skills/use-og-form-table/SKILL.md +4 -3
- package/templates/current/examples/.cursor/skills/use-og-search/SKILL.md +3 -3
- package/templates/current/examples/.cursor/skills/use-og-table/SKILL.md +16 -10
- package/templates/current/examples/.cursor/skills/use-og-upload/SKILL.md +6 -5
- package/templates/current/examples/{.env.example → .env.dev} +3 -2
- package/templates/current/examples/.env.mock +4 -0
- package/templates/current/examples/.env.production +5 -0
- package/templates/current/examples/.env.test +4 -0
- package/templates/current/examples/.prettierignore +17 -0
- package/templates/current/examples/.prettierrc +8 -0
- package/templates/current/examples/.qoder/rules/01-feature-architecture.md +3 -4
- package/templates/current/examples/.qoder/rules/02-vue-typescript.md +1 -2
- package/templates/current/examples/.qoder/rules/03-component-policy.md +5 -3
- package/templates/current/examples/.qoder/rules/04-api-auth-router.md +1 -2
- package/templates/current/examples/.qoder/rules/05-style.md +1 -2
- package/templates/current/examples/.qoder/rules/06-quality.md +1 -2
- package/templates/current/examples/.qoder/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/examples/.qoder/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/examples/.qoder/skills/build-admin-feature/SKILL.md +11 -5
- package/templates/current/examples/.qoder/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/examples/.qoder/skills/use-og-form/SKILL.md +1 -1
- package/templates/current/examples/.qoder/skills/use-og-form-table/SKILL.md +4 -3
- package/templates/current/examples/.qoder/skills/use-og-search/SKILL.md +3 -3
- package/templates/current/examples/.qoder/skills/use-og-table/SKILL.md +16 -10
- package/templates/current/examples/.qoder/skills/use-og-upload/SKILL.md +6 -5
- package/templates/current/examples/.zcode/skills/admin-component-usage/SKILL.md +28 -0
- package/templates/current/examples/.zcode/skills/admin-component-usage/references/component-directory.md +270 -0
- package/templates/current/examples/.zcode/skills/build-admin-feature/SKILL.md +20 -0
- package/templates/current/examples/.zcode/skills/build-admin-feature/references/component-selection.md +38 -0
- package/templates/current/examples/.zcode/skills/style-og-origen-ui/SKILL.md +11 -0
- package/templates/current/examples/.zcode/skills/use-og-dialog/SKILL.md +12 -0
- package/templates/current/examples/.zcode/skills/use-og-editor/SKILL.md +25 -0
- package/templates/current/examples/.zcode/skills/use-og-form/SKILL.md +12 -0
- package/templates/current/examples/.zcode/skills/use-og-form-table/SKILL.md +26 -0
- package/templates/current/examples/.zcode/skills/use-og-http/SKILL.md +13 -0
- package/templates/current/examples/.zcode/skills/use-og-router-tabs/SKILL.md +11 -0
- package/templates/current/examples/.zcode/skills/use-og-search/SKILL.md +14 -0
- package/templates/current/examples/.zcode/skills/use-og-table/SKILL.md +22 -0
- package/templates/current/examples/.zcode/skills/use-og-upload/SKILL.md +26 -0
- package/templates/current/examples/AGENTS.md +55 -9
- package/templates/current/examples/CHANGELOG.md +107 -0
- package/templates/current/examples/CLAUDE.md +3 -0
- package/templates/current/examples/README.md +58 -88
- package/templates/current/examples/component-catalog.json +766 -348
- package/templates/current/examples/component-catalog.v2.json +2040 -0
- package/templates/current/examples/docs/components/dialog.md +405 -0
- package/templates/current/examples/docs/components/editor-viewer.md +87 -0
- package/templates/current/examples/docs/components/editor.md +275 -0
- package/templates/current/examples/docs/components/form-table.md +222 -0
- package/templates/current/examples/docs/components/form.md +750 -0
- package/templates/current/examples/docs/components/index.md +44 -0
- package/templates/current/examples/docs/components/router.md +452 -0
- package/templates/current/examples/docs/components/search.md +1205 -0
- package/templates/current/examples/docs/components/svg-icon.md +124 -0
- package/templates/current/examples/docs/components/table-local.md +176 -0
- package/templates/current/examples/docs/components/table-with-search.md +207 -0
- package/templates/current/examples/docs/components/table.md +813 -0
- package/templates/current/examples/docs/components/tabs.md +440 -0
- package/templates/current/examples/docs/components/upload.md +349 -0
- package/templates/current/examples/eslint.config.js +89 -0
- package/templates/current/examples/index.html +1 -1
- package/templates/current/examples/openapi.json +10048 -999
- package/templates/current/examples/package.json +45 -33
- package/templates/current/examples/playwright.config.ts +20 -6
- package/templates/current/examples/playwright.mock.config.ts +42 -0
- package/templates/current/examples/pnpm-workspace.yaml +19 -3
- package/templates/current/examples/recipes/remote-crud-dialog-form.vue +15 -13
- package/templates/current/examples/scaffold.lock.json +164 -4
- package/templates/current/examples/scripts/api-codegen.config.ts +35 -0
- package/templates/current/examples/scripts/api-codegen.ts +2015 -0
- package/templates/current/examples/scripts/api-templates/http-client.ejs +359 -0
- package/templates/current/examples/scripts/check-admin-scaffold.mjs +311 -17
- package/templates/current/examples/scripts/generate-api.ts +290 -85
- package/templates/current/examples/scripts/lib/admin-component-catalog.mjs +515 -0
- package/templates/current/examples/scripts/lib/repository-root.mjs +9 -0
- package/templates/current/examples/scripts/mock-api.ts +1356 -0
- package/templates/current/examples/scripts/remove-examples.mjs +9 -34
- package/templates/current/examples/src/App.vue +9 -18
- package/templates/current/examples/src/api/generated/data-contracts.ts +23 -265
- package/templates/current/examples/src/api/generated/http-client.ts +351 -180
- package/templates/current/examples/src/api/generated/index.ts +22 -0
- package/templates/current/examples/src/api/generated/services/auth.ts +123 -0
- package/templates/current/examples/src/api/generated/services/common/files.ts +111 -0
- package/templates/current/examples/src/api/generated/services/monitor/cache.ts +164 -0
- package/templates/current/examples/src/api/generated/services/monitor/job.ts +195 -0
- package/templates/current/examples/src/api/generated/services/monitor/jobLog.ts +126 -0
- package/templates/current/examples/src/api/generated/services/monitor/logininfor.ts +126 -0
- package/templates/current/examples/src/api/generated/services/monitor/online.ts +66 -0
- package/templates/current/examples/src/api/generated/services/monitor/operlog.ts +106 -0
- package/templates/current/examples/src/api/generated/services/monitor/server.ts +41 -0
- package/templates/current/examples/src/api/generated/services/system/configs.ts +190 -0
- package/templates/current/examples/src/api/generated/services/system/departments.ts +173 -0
- package/templates/current/examples/src/api/generated/services/system/dictionaries/data.ts +169 -0
- package/templates/current/examples/src/api/generated/services/system/dictionaries/types.ts +187 -0
- package/templates/current/examples/src/api/generated/services/system/index.ts +158 -0
- package/templates/current/examples/src/api/generated/services/system/menus.ts +193 -0
- package/templates/current/examples/src/api/generated/services/system/notices.ts +221 -0
- package/templates/current/examples/src/api/generated/services/system/posts.ts +168 -0
- package/templates/current/examples/src/api/generated/services/system/roles.ts +354 -0
- package/templates/current/examples/src/api/generated/services/system/users.ts +425 -0
- package/templates/current/examples/src/api/generated/services/tool/code-generator.ts +304 -0
- package/templates/current/examples/src/api/generated/types/auth.types.ts +132 -0
- package/templates/current/examples/src/api/generated/types/common/files.types.ts +57 -0
- package/templates/current/examples/src/api/generated/types/common.ts +174 -0
- package/templates/current/examples/src/api/generated/types/enum-dict.ts +94 -0
- package/templates/current/examples/src/api/generated/types/enums.ts +155 -0
- package/templates/current/examples/src/api/generated/types/monitor/cache.types.ts +149 -0
- package/templates/current/examples/src/api/generated/types/monitor/job.types.ts +207 -0
- package/templates/current/examples/src/api/generated/types/monitor/jobLog.types.ts +134 -0
- package/templates/current/examples/src/api/generated/types/monitor/logininfor.types.ts +135 -0
- package/templates/current/examples/src/api/generated/types/monitor/online.types.ts +80 -0
- package/templates/current/examples/src/api/generated/types/monitor/operlog.types.ts +126 -0
- package/templates/current/examples/src/api/generated/types/monitor/server.types.ts +205 -0
- package/templates/current/examples/src/api/generated/types/system/configs.types.ts +200 -0
- package/templates/current/examples/src/api/generated/types/system/departments.types.ts +145 -0
- package/templates/current/examples/src/api/generated/types/system/dictionaries/data.types.ts +210 -0
- package/templates/current/examples/src/api/generated/types/system/dictionaries/types.types.ts +221 -0
- package/templates/current/examples/src/api/generated/types/system/index.types.ts +19 -0
- package/templates/current/examples/src/api/generated/types/system/menus.types.ts +234 -0
- package/templates/current/examples/src/api/generated/types/system/notices.types.ts +270 -0
- package/templates/current/examples/src/api/generated/types/system/posts.types.ts +198 -0
- package/templates/current/examples/src/api/generated/types/system/roles.types.ts +410 -0
- package/templates/current/examples/src/api/generated/types/system/users.types.ts +413 -0
- package/templates/current/examples/src/api/generated/types/tool/code-generator.types.ts +388 -0
- package/templates/current/examples/src/api/index.ts +44 -39
- package/templates/current/examples/src/app/__tests__/api-generated.types.ts +24 -0
- package/templates/current/examples/src/app/api.ts +6 -0
- package/templates/current/examples/src/app/authorization/permission.ts +9 -0
- package/templates/current/{clean/src/app → examples/src/app/config}/runtimeConfig.ts +44 -12
- package/templates/current/examples/src/app/errors/errorMessage.ts +80 -0
- package/templates/current/examples/src/app/http/client.ts +141 -0
- package/templates/current/examples/src/app/http/http-adapter.ts +71 -0
- package/templates/current/{clean/src/app → examples/src/app/i18n}/adminLocale.ts +25 -19
- package/templates/current/examples/src/app/{localeFormat.ts → i18n/localeFormat.ts} +29 -6
- package/templates/current/examples/src/app/i18n/origenUiLocale.ts +15 -0
- package/templates/current/examples/src/app/menu/menu.ts +175 -0
- package/templates/current/examples/src/app/menu/menuTypes.ts +20 -0
- package/templates/current/examples/src/{features → app}/security/devtoolsProtection.ts +8 -7
- package/templates/current/examples/src/app/ui/createAdminUi.ts +31 -0
- package/templates/current/examples/src/app/ui/iconCatalog.ts +71 -0
- package/templates/current/examples/src/assets/icons/appearance.svg +1 -0
- package/templates/current/examples/src/assets/icons/arrow-right.svg +1 -0
- package/templates/current/examples/src/assets/icons/check.svg +1 -0
- package/templates/current/examples/src/assets/icons/circle-check.svg +1 -0
- package/templates/current/examples/src/assets/icons/default.svg +4 -0
- package/templates/current/examples/src/assets/icons/directory/setting.svg +1 -0
- package/templates/current/examples/src/assets/icons/expand.svg +1 -0
- package/templates/current/examples/src/assets/icons/fold.svg +1 -0
- package/templates/current/examples/src/assets/icons/key.svg +1 -0
- package/templates/current/examples/src/assets/icons/lock.svg +1 -0
- package/templates/current/examples/src/assets/icons/monitor.svg +1 -0
- package/templates/current/examples/src/assets/icons/moon.svg +11 -0
- package/templates/current/examples/src/assets/icons/page/department.svg +1 -0
- package/templates/current/examples/src/assets/icons/page/dictionary.svg +1 -0
- package/templates/current/examples/src/assets/icons/page/menus.svg +1 -0
- package/templates/current/examples/src/assets/icons/page/user.svg +1 -0
- package/templates/current/examples/src/assets/icons/page/users.svg +1 -0
- package/templates/current/examples/src/assets/icons/plus.svg +1 -0
- package/templates/current/examples/src/assets/icons/profile.svg +1 -0
- package/templates/current/examples/src/assets/icons/refresh.svg +1 -0
- package/templates/current/examples/src/assets/icons/roles.svg +1 -0
- package/templates/current/examples/src/assets/icons/search.svg +1 -0
- package/templates/current/examples/src/assets/icons/sunny.svg +1 -0
- package/templates/current/examples/src/assets/icons/system.svg +1 -0
- package/templates/current/examples/src/assets/icons/theme-auto.svg +14 -0
- package/templates/current/examples/src/assets/icons/tune.svg +13 -0
- package/templates/current/examples/src/{features/shell/components → components}/RouteProgress.vue +2 -2
- package/templates/current/{clean/src/features/system/access → examples/src}/composables/useAuthorizationRefresh.ts +6 -1
- package/templates/current/examples/src/composables/useSystemTableSearchVisibility.ts +33 -0
- package/templates/current/examples/src/{features/appearance/composables → composables}/useTheme.ts +1 -1
- package/templates/current/examples/src/env.d.ts +6 -19
- package/templates/current/examples/src/layouts/AdminLayout.vue +7 -9
- package/templates/current/examples/src/{features/shell/components → layouts}/AdminWatermark.vue +2 -2
- package/templates/current/examples/src/layouts/BreadcrumbBar.vue +9 -1
- package/templates/current/examples/src/layouts/SideMenu.vue +7 -15
- package/templates/current/examples/src/{features/appearance/components → layouts}/ThemePanel.vue +39 -11
- package/templates/current/examples/src/layouts/TopBar.vue +60 -28
- package/templates/current/examples/src/layouts/WorkspaceTabs.vue +10 -1
- package/templates/current/examples/src/layouts/topBarMenuSearch.ts +25 -4
- package/templates/current/examples/src/locales/en-US.json +227 -219
- package/templates/current/examples/src/locales/index.ts +72 -32
- package/templates/current/examples/src/locales/messages-types.ts +15 -10
- package/templates/current/examples/src/locales/vue-i18n.d.ts +1 -1
- package/templates/current/examples/src/locales/zh-CN.json +226 -218
- package/templates/current/examples/src/locales/zh-TW.json +222 -214
- package/templates/current/examples/src/main.ts +50 -40
- package/templates/current/examples/src/router/bootstrap.ts +69 -24
- package/templates/current/examples/src/router/dynamic/componentLoader.ts +150 -0
- package/templates/current/examples/src/router/{dynamicMenuRefresh.ts → dynamic/dynamicMenuRefresh.ts} +6 -2
- package/templates/current/examples/src/router/dynamic/dynamicRoutes.ts +247 -0
- package/templates/current/examples/src/router/navigation/guards.ts +12 -0
- package/templates/current/examples/src/router/navigation/paths.ts +28 -0
- package/templates/current/examples/src/router/navigation/staticRoutes.ts +109 -0
- package/templates/current/examples/src/router/{queryEncryption.ts → query/queryEncryption.ts} +29 -12
- package/templates/current/examples/src/router/query/routeQuery.ts +29 -0
- package/templates/current/examples/src/router/{useRouteQueryDefaults.ts → query/useRouteQueryDefaults.ts} +9 -8
- package/templates/current/examples/src/router/query/useRouteQueryDefaults.types.ts +28 -0
- package/templates/current/examples/src/router/{runtimeErrorRecovery.ts → recovery/runtimeErrorRecovery.ts} +21 -3
- package/templates/current/examples/src/{features/auth/store → store}/auth.ts +96 -61
- package/templates/current/examples/src/store/dictionaries.ts +86 -0
- package/templates/current/examples/src/{features/shell/store → store}/sidebar.ts +9 -2
- package/templates/current/{clean/src/features/appearance → examples/src}/store/theme.ts +8 -4
- package/templates/current/examples/src/styles/layout.css +51 -0
- package/templates/current/examples/src/templates/og-form.ts +7 -2
- package/templates/current/examples/src/templates/og-table.ts +88 -20
- package/templates/current/examples/src/templates/router.ts +11 -2
- package/templates/current/examples/src/utils/color-mix.ts +6 -2
- package/templates/current/examples/src/utils/download.ts +11 -0
- package/templates/current/examples/src/utils/permissions.ts +1 -1
- package/templates/current/examples/src/utils/retryableDialog.ts +46 -0
- package/templates/current/{clean/scripts/clean-overlay/src/features → examples/src/views}/errors/pages/Forbidden.vue +6 -2
- package/templates/current/examples/src/views/errors/pages/MethodNotAllowed.vue +34 -0
- package/templates/current/examples/{scripts/clean-overlay/src/features → src/views}/errors/pages/NotFound.vue +6 -2
- package/templates/current/examples/{scripts/clean-overlay/src/features → src/views}/errors/pages/ServerError.vue +6 -2
- package/templates/current/examples/src/{features/auth/pages/Login.vue → views/login/pages/index.vue} +99 -10
- package/templates/current/examples/src/views/system/access/services/admin-repository.ts +489 -0
- package/templates/current/examples/src/views/system/access/services/rbac.ts +317 -0
- package/templates/current/examples/src/views/system/dept/components/DepartmentEditorForm.vue +87 -0
- package/templates/current/examples/src/views/system/dept/composables/useDepartmentManagement.ts +314 -0
- package/templates/current/examples/src/views/system/dept/pages/index.vue +44 -0
- package/templates/current/examples/src/views/system/dept/services/departments.ts +168 -0
- package/templates/current/examples/src/views/system/dict/components/DictionaryDataEditorForm.vue +98 -0
- package/templates/current/examples/src/views/system/dict/components/DictionaryDataPreview.vue +233 -0
- package/templates/current/examples/src/views/system/dict/components/DictionaryTypeEditorForm.vue +66 -0
- package/templates/current/examples/src/views/system/dict/composables/useDictionaryDataManagement.ts +406 -0
- package/templates/current/examples/src/views/system/dict/composables/useDictionaryTypeManagement.ts +329 -0
- package/templates/current/examples/src/views/system/dict/data/pages/index.vue +134 -0
- package/templates/current/examples/src/views/system/dict/pages/index.vue +113 -0
- package/templates/current/examples/src/views/system/dict/services/dictionaries.ts +239 -0
- package/templates/current/examples/src/views/system/menu/components/MenuEditorForm.vue +252 -0
- package/templates/current/examples/src/views/system/menu/composables/useMenuManagement.ts +357 -0
- package/templates/current/examples/src/views/system/menu/menuDraft.ts +45 -0
- package/templates/current/examples/src/views/system/menu/pages/ExternalLink.vue +37 -0
- package/templates/current/examples/src/views/system/menu/pages/index.vue +75 -0
- package/templates/current/examples/src/views/system/post/components/PostEditorForm.vue +69 -0
- package/templates/current/examples/src/views/system/post/composables/usePostManagement.ts +245 -0
- package/templates/current/examples/src/views/system/post/pages/index.vue +92 -0
- package/templates/current/examples/src/views/system/post/services/posts.ts +100 -0
- package/templates/current/examples/src/views/system/role/auth-users/pages/index.vue +100 -0
- package/templates/current/examples/src/views/system/role/components/RoleDataScopeForm.vue +167 -0
- package/templates/current/examples/src/views/system/role/components/RoleEditorForm.vue +165 -0
- package/templates/current/examples/src/views/system/role/components/RoleUserSelectForm.vue +129 -0
- package/templates/current/examples/src/views/system/role/composables/useRoleManagement.ts +422 -0
- package/templates/current/examples/src/views/system/role/composables/useRoleUserManagement.ts +233 -0
- package/templates/current/examples/src/views/system/role/pages/index.vue +110 -0
- package/templates/current/examples/src/views/system/role/services/roleAccess.ts +162 -0
- package/templates/current/examples/src/views/system/user/auth-roles/pages/index.vue +209 -0
- package/templates/current/examples/src/views/system/user/components/UserDetailsForm.vue +108 -0
- package/templates/current/examples/src/views/system/user/components/UserEditorForm.vue +207 -0
- package/templates/current/examples/src/views/system/user/components/UserImportDialog.vue +80 -0
- package/templates/current/examples/src/views/system/user/components/UserResetPasswordForm.vue +56 -0
- package/templates/current/examples/src/views/system/user/composables/useUserManagement.ts +502 -0
- package/templates/current/examples/src/views/system/user/pages/index.vue +459 -0
- package/templates/current/examples/tests/e2e/admin-access-business.spec.ts +33 -0
- package/templates/current/examples/tests/e2e/admin-shell.spec.ts +50 -0
- package/templates/current/examples/tests/e2e/fixtures/adminMockBackend.ts +95 -0
- package/templates/current/examples/tests/e2e/fixtures/labelGeometry.ts +52 -0
- package/templates/current/examples/tests/e2e/mock-api-generation.spec.ts +27 -0
- package/templates/current/examples/tests/e2e/mock-business.spec.ts +555 -0
- package/templates/current/examples/tests/e2e/mock-menu-retry-form-label.spec.ts +100 -0
- package/templates/current/examples/tests/e2e/mock-shell.spec.ts +25 -0
- package/templates/current/examples/tests/e2e/mock-tree-selection-layout.spec.ts +113 -0
- package/templates/current/examples/tests/unit/api/api-codegen.spec.ts +893 -0
- package/templates/current/examples/tests/unit/api/client.spec.ts +145 -0
- package/templates/current/examples/tests/unit/api/generated-http-client.spec.ts +290 -0
- package/templates/current/{clean/src → examples/tests/unit}/api/http-adapter.spec.ts +3 -3
- package/templates/current/examples/tests/unit/api/system-apis.spec.ts +118 -0
- package/templates/current/examples/tests/unit/app/createAdminUi.spec.ts +79 -0
- package/templates/current/examples/{src → tests/unit}/app/errorMessage.spec.ts +1 -1
- package/templates/current/examples/tests/unit/app/iconCatalog.spec.ts +12 -0
- package/templates/current/examples/tests/unit/app/menu.spec.ts +215 -0
- package/templates/current/{clean/src → examples/tests/unit}/app/origenUiLocale.spec.ts +1 -1
- package/templates/current/{clean/src → examples/tests/unit}/app/permission.spec.ts +4 -5
- package/templates/current/examples/tests/unit/app/runtimeConfig.spec.ts +36 -0
- package/templates/current/{clean/src/features → examples/tests/unit/app}/security/devtoolsProtection.spec.ts +17 -7
- package/templates/current/{clean/src/features/shell → examples/tests/unit}/composables/useRouteProgress.spec.ts +1 -1
- package/templates/current/{clean/src/features/shell/components → examples/tests/unit/layouts}/AdminWatermark.spec.ts +5 -7
- package/templates/current/{clean/src → examples/tests/unit}/layouts/topBarMenuSearch.spec.ts +25 -8
- package/templates/current/examples/{src → tests/unit}/locales/messages.spec.ts +43 -17
- package/templates/current/examples/tests/unit/router/dynamicMenuRefresh.spec.ts +151 -0
- package/templates/current/examples/tests/unit/router/dynamicRoutes.spec.ts +374 -0
- package/templates/current/examples/tests/unit/router/paths.spec.ts +103 -0
- package/templates/current/examples/{src → tests/unit}/router/queryEncryption.spec.ts +49 -12
- package/templates/current/{clean/src → examples/tests/unit}/router/routeQuery.spec.ts +8 -1
- package/templates/current/examples/{src → tests/unit}/router/runtimeErrorRecovery.spec.ts +11 -6
- package/templates/current/{clean/src → examples/tests/unit}/router/useRouteQueryDefaults.spec.ts +46 -12
- package/templates/current/examples/tests/unit/scripts/mock-api.spec.ts +440 -0
- package/templates/current/examples/{scripts → tests/unit/scripts}/vite-build-policy.spec.ts +35 -6
- package/templates/current/examples/{src/features/auth → tests/unit}/store/auth.spec.ts +68 -15
- package/templates/current/examples/tests/unit/store/dictionaries.spec.ts +106 -0
- package/templates/current/{clean/src → examples/tests/unit}/templates/templates.spec.ts +60 -16
- package/templates/current/examples/{src/utils/__tests__ → tests/unit/utils}/color-mix.spec.ts +1 -1
- package/templates/current/examples/tests/unit/utils/retryableDialog.spec.ts +61 -0
- package/templates/current/examples/{scripts/clean-overlay/src/features/errors/pages → tests/unit/views/errors}/error-pages.spec.ts +12 -9
- package/templates/current/examples/tests/unit/views/feature-composables.spec.ts +233 -0
- package/templates/current/examples/tests/unit/views/system/access/admin-repository.spec.ts +353 -0
- package/templates/current/examples/tests/unit/views/system/access/rbac.spec.ts +329 -0
- package/templates/current/examples/tests/unit/views/system/dept/departments.spec.ts +104 -0
- package/templates/current/examples/tests/unit/views/system/dict/dictionaries.spec.ts +234 -0
- package/templates/current/examples/tests/unit/views/system/menu/menuDraft.spec.ts +77 -0
- package/templates/current/examples/tests/unit/views/system/menu/useMenuManagement.spec.ts +339 -0
- package/templates/current/examples/tests/unit/views/system/user/searchControl.spec.ts +128 -0
- package/templates/current/examples/tsconfig.json +4 -19
- package/templates/current/examples/vite.build-policy.ts +97 -22
- package/templates/current/examples/vite.config.ts +50 -7
- package/templates/current/clean/.codebuddy/AGENTS.md +0 -18
- package/templates/current/clean/.codex/skills/build-admin-feature/SKILL.md +0 -14
- package/templates/current/clean/.codex/skills/build-admin-feature/references/component-selection.md +0 -25
- package/templates/current/clean/.codex/skills/use-og-table/SKILL.md +0 -16
- package/templates/current/clean/.cursor/AGENTS.md +0 -18
- package/templates/current/clean/.env.production.example +0 -31
- package/templates/current/clean/.qoder/AGENTS.md +0 -15
- package/templates/current/clean/e2e/admin-shell.spec.ts +0 -156
- package/templates/current/clean/e2e/demo-shell.spec.ts +0 -372
- package/templates/current/clean/playwright.demo.config.ts +0 -25
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +0 -31
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +0 -31
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +0 -41
- package/templates/current/clean/scripts/clean-overlay/src/main.ts +0 -100
- package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +0 -12
- package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +0 -14
- package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +0 -77
- package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +0 -21
- package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +0 -63
- package/templates/current/clean/scripts/demo-api.ts +0 -873
- package/templates/current/clean/src/api/client.spec.ts +0 -66
- package/templates/current/clean/src/api/client.ts +0 -152
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +0 -144
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +0 -50
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +0 -63
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +0 -169
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +0 -180
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +0 -167
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +0 -168
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +0 -95
- package/templates/current/clean/src/api/http-adapter.ts +0 -83
- package/templates/current/clean/src/app/createAdminUi.spec.ts +0 -166
- package/templates/current/clean/src/app/createAdminUi.ts +0 -63
- package/templates/current/clean/src/app/embedded-token.spec.ts +0 -40
- package/templates/current/clean/src/app/embedded.spec.ts +0 -135
- package/templates/current/clean/src/app/embedded.ts +0 -255
- package/templates/current/clean/src/app/errorMessage.ts +0 -53
- package/templates/current/clean/src/app/menu-host.spec.ts +0 -77
- package/templates/current/clean/src/app/menu.spec.ts +0 -320
- package/templates/current/clean/src/app/menu.ts +0 -308
- package/templates/current/clean/src/app/menuTypes.ts +0 -18
- package/templates/current/clean/src/app/origenUiLocale.ts +0 -10
- package/templates/current/clean/src/app/permission.ts +0 -9
- package/templates/current/clean/src/demo-api.spec.ts +0 -478
- package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +0 -41
- package/templates/current/clean/src/features/system/access/api/admin-repository.spec.ts +0 -14
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +0 -298
- package/templates/current/clean/src/features/system/access/api/rbac.spec.ts +0 -72
- package/templates/current/clean/src/features/system/access/api/rbac.ts +0 -292
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +0 -134
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +0 -96
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +0 -185
- package/templates/current/clean/src/router/componentCache.ts +0 -12
- package/templates/current/clean/src/router/componentRegistry.ts +0 -14
- package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +0 -101
- package/templates/current/clean/src/router/dynamicRoutes.spec.ts +0 -77
- package/templates/current/clean/src/router/dynamicRoutes.ts +0 -177
- package/templates/current/clean/src/router/guards.ts +0 -5
- package/templates/current/clean/src/router/paths.spec.ts +0 -50
- package/templates/current/clean/src/router/paths.ts +0 -21
- package/templates/current/clean/src/router/routeQuery.ts +0 -6
- package/templates/current/clean/src/router/staticRoutes.ts +0 -63
- package/templates/current/clean/src/router/useRouteQueryDefaults.types.ts +0 -20
- package/templates/current/examples/.codebuddy/AGENTS.md +0 -18
- package/templates/current/examples/.codex/skills/build-admin-feature/SKILL.md +0 -14
- package/templates/current/examples/.codex/skills/build-admin-feature/references/component-selection.md +0 -25
- package/templates/current/examples/.codex/skills/use-og-table/SKILL.md +0 -16
- package/templates/current/examples/.cursor/AGENTS.md +0 -18
- package/templates/current/examples/.env.production.example +0 -31
- package/templates/current/examples/.qoder/AGENTS.md +0 -15
- package/templates/current/examples/e2e/admin-shell.spec.ts +0 -156
- package/templates/current/examples/e2e/demo-shell.spec.ts +0 -372
- package/templates/current/examples/playwright.demo.config.ts +0 -25
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +0 -31
- package/templates/current/examples/scripts/clean-overlay/src/main.ts +0 -100
- package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +0 -12
- package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +0 -14
- package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +0 -77
- package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +0 -21
- package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +0 -63
- package/templates/current/examples/scripts/demo-api.ts +0 -873
- package/templates/current/examples/src/api/client.spec.ts +0 -66
- package/templates/current/examples/src/api/client.ts +0 -152
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +0 -144
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +0 -50
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +0 -63
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +0 -169
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +0 -180
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +0 -167
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +0 -168
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +0 -95
- package/templates/current/examples/src/api/http-adapter.ts +0 -83
- package/templates/current/examples/src/app/createAdminUi.spec.ts +0 -166
- package/templates/current/examples/src/app/createAdminUi.ts +0 -63
- package/templates/current/examples/src/app/embedded-token.spec.ts +0 -40
- package/templates/current/examples/src/app/embedded.spec.ts +0 -135
- package/templates/current/examples/src/app/embedded.ts +0 -255
- package/templates/current/examples/src/app/errorMessage.ts +0 -53
- package/templates/current/examples/src/app/menu-host.spec.ts +0 -77
- package/templates/current/examples/src/app/menu.spec.ts +0 -320
- package/templates/current/examples/src/app/menu.ts +0 -308
- package/templates/current/examples/src/app/menuTypes.ts +0 -18
- package/templates/current/examples/src/app/origenUiLocale.ts +0 -10
- package/templates/current/examples/src/app/permission.ts +0 -9
- package/templates/current/examples/src/demo-api.spec.ts +0 -478
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +0 -31
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +0 -31
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +0 -31
- package/templates/current/examples/src/features/feature-composables.spec.ts +0 -245
- package/templates/current/examples/src/features/system/access/api/admin-repository.spec.ts +0 -14
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +0 -298
- package/templates/current/examples/src/features/system/access/api/rbac.spec.ts +0 -72
- package/templates/current/examples/src/features/system/access/api/rbac.ts +0 -292
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +0 -134
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +0 -96
- package/templates/current/examples/src/features/system/audit/composables/useAuditManagement.ts +0 -122
- package/templates/current/examples/src/features/system/audit/pages/AuditList.vue +0 -20
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +0 -279
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +0 -435
- package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +0 -204
- package/templates/current/examples/src/features/system/menus/menuDraft.ts +0 -116
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +0 -268
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +0 -317
- package/templates/current/examples/src/features/system/menus/pages/MenuList.vue +0 -51
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +0 -116
- package/templates/current/examples/src/features/system/roles/composables/useRoleManagement.ts +0 -194
- package/templates/current/examples/src/features/system/roles/pages/RoleList.vue +0 -47
- package/templates/current/examples/src/features/system/users/components/UserEditorForm.vue +0 -104
- package/templates/current/examples/src/features/system/users/composables/useUserManagement.ts +0 -228
- package/templates/current/examples/src/features/system/users/pages/UserList.vue +0 -51
- package/templates/current/examples/src/features/workspace/pages/Dashboard.spec.ts +0 -41
- package/templates/current/examples/src/features/workspace/pages/Dashboard.vue +0 -325
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +0 -185
- package/templates/current/examples/src/router/componentCache.ts +0 -18
- package/templates/current/examples/src/router/componentRegistry.ts +0 -66
- package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +0 -101
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +0 -144
- package/templates/current/examples/src/router/dynamicRoutes.ts +0 -177
- package/templates/current/examples/src/router/guards.ts +0 -5
- package/templates/current/examples/src/router/paths.spec.ts +0 -50
- package/templates/current/examples/src/router/paths.ts +0 -21
- package/templates/current/examples/src/router/routeQuery.ts +0 -6
- package/templates/current/examples/src/router/staticRoutes.ts +0 -63
- package/templates/current/examples/src/router/useRouteQueryDefaults.types.ts +0 -20
- /package/templates/current/clean/{.codex → .agents}/skills/style-og-origen-ui/SKILL.md +0 -0
- /package/templates/current/clean/{.codex → .agents}/skills/style-og-origen-ui/agents/openai.yaml +0 -0
- /package/templates/current/clean/{.codex → .agents}/skills/use-og-dialog/SKILL.md +0 -0
- /package/templates/current/clean/{.codex → .agents}/skills/use-og-dialog/agents/openai.yaml +0 -0
- /package/templates/current/clean/{.codex → .agents}/skills/use-og-editor/SKILL.md +0 -0
- /package/templates/current/clean/{.codex → .agents}/skills/use-og-http/SKILL.md +0 -0
- /package/templates/current/clean/{.codex → .agents}/skills/use-og-http/agents/openai.yaml +0 -0
- /package/templates/current/clean/{.codex → .agents}/skills/use-og-router-tabs/SKILL.md +0 -0
- /package/templates/current/{examples/.codex → clean/.claude}/skills/style-og-origen-ui/SKILL.md +0 -0
- /package/templates/current/{examples/.codex → clean/.claude}/skills/use-og-dialog/SKILL.md +0 -0
- /package/templates/current/{examples/.codex → clean/.claude}/skills/use-og-editor/SKILL.md +0 -0
- /package/templates/current/{examples/.codex → clean/.claude}/skills/use-og-http/SKILL.md +0 -0
- /package/templates/current/{examples/.codex → clean/.claude}/skills/use-og-router-tabs/SKILL.md +0 -0
- /package/templates/current/clean/src/{features/security/components → components}/DevtoolsProtectionOverlay.vue +0 -0
- /package/templates/current/clean/src/{features/shell/composables → composables}/useRouteProgress.ts +0 -0
- /package/templates/current/clean/src/{features/workspace → views/fallback}/pages/Empty.vue +0 -0
- /package/templates/current/examples/{.codex → .agents}/skills/style-og-origen-ui/agents/openai.yaml +0 -0
- /package/templates/current/examples/{.codex → .agents}/skills/use-og-dialog/agents/openai.yaml +0 -0
- /package/templates/current/examples/{.codex → .agents}/skills/use-og-http/agents/openai.yaml +0 -0
- /package/templates/current/examples/src/{features/security/components → components}/DevtoolsProtectionOverlay.vue +0 -0
- /package/templates/current/examples/src/{features/shell/composables → composables}/useRouteProgress.ts +0 -0
- /package/templates/current/examples/src/{features/workspace → views/fallback}/pages/Empty.vue +0 -0
|
@@ -0,0 +1,2015 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import { copyFile, mkdir, readdir, rename, rm, rmdir } from 'node:fs/promises'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import * as ts from 'typescript'
|
|
5
|
+
|
|
6
|
+
export type ApiSplitMode = 'tag' | 'dto-vo-enum'
|
|
7
|
+
export type ApiModelKind = 'dto' | 'vo' | 'enum'
|
|
8
|
+
|
|
9
|
+
export interface ApiNameMapping {
|
|
10
|
+
suffix: string
|
|
11
|
+
type: ApiModelKind
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ApiSharedEnumMapping {
|
|
15
|
+
name: string
|
|
16
|
+
properties: string[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type OpenApiEnumValue = string | number | boolean | null
|
|
20
|
+
|
|
21
|
+
export interface OpenApiEnumMember {
|
|
22
|
+
name: string
|
|
23
|
+
label: string
|
|
24
|
+
value: OpenApiEnumValue
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface OpenApiEnumDefinition {
|
|
28
|
+
name: string
|
|
29
|
+
members: OpenApiEnumMember[]
|
|
30
|
+
locations: string[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ApiCodegenOptions {
|
|
34
|
+
splitMode: ApiSplitMode
|
|
35
|
+
commonTypeNames: string[]
|
|
36
|
+
nameMapping: ApiNameMapping[]
|
|
37
|
+
strictNames: boolean
|
|
38
|
+
generateEnumDict: boolean
|
|
39
|
+
sharedEnumMappings?: ApiSharedEnumMapping[]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface GeneratedServiceSource {
|
|
43
|
+
fileName: string
|
|
44
|
+
source: string
|
|
45
|
+
outputPath?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface GeneratedServiceFile extends GeneratedServiceSource {
|
|
49
|
+
outputPath: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SplitContractResult {
|
|
53
|
+
files: Map<string, string>
|
|
54
|
+
services: GeneratedServiceFile[]
|
|
55
|
+
warnings: string[]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ApiServiceGroup {
|
|
59
|
+
tag: string
|
|
60
|
+
operationTags: readonly string[]
|
|
61
|
+
generatedFileName: string
|
|
62
|
+
outputPath: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const API_SERVICE_GROUPS: readonly ApiServiceGroup[] = [
|
|
66
|
+
{
|
|
67
|
+
tag: 'Auth',
|
|
68
|
+
operationTags: ['Login', 'Register', 'Captcha'],
|
|
69
|
+
generatedFileName: 'Auth.ts',
|
|
70
|
+
outputPath: 'services/auth.ts',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
tag: 'SystemUsers',
|
|
74
|
+
operationTags: ['User'],
|
|
75
|
+
generatedFileName: 'SystemUsers.ts',
|
|
76
|
+
outputPath: 'services/system/users.ts',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
tag: 'SystemRoles',
|
|
80
|
+
operationTags: ['Role'],
|
|
81
|
+
generatedFileName: 'SystemRoles.ts',
|
|
82
|
+
outputPath: 'services/system/roles.ts',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
tag: 'SystemDepartments',
|
|
86
|
+
operationTags: ['Dept'],
|
|
87
|
+
generatedFileName: 'SystemDepartments.ts',
|
|
88
|
+
outputPath: 'services/system/departments.ts',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
tag: 'SystemPosts',
|
|
92
|
+
operationTags: ['Post'],
|
|
93
|
+
generatedFileName: 'SystemPosts.ts',
|
|
94
|
+
outputPath: 'services/system/posts.ts',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
tag: 'SystemMenus',
|
|
98
|
+
operationTags: ['Menu'],
|
|
99
|
+
generatedFileName: 'SystemMenus.ts',
|
|
100
|
+
outputPath: 'services/system/menus.ts',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
tag: 'SystemNotices',
|
|
104
|
+
operationTags: ['Notice'],
|
|
105
|
+
generatedFileName: 'SystemNotices.ts',
|
|
106
|
+
outputPath: 'services/system/notices.ts',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
tag: 'SystemConfigs',
|
|
110
|
+
operationTags: ['Config'],
|
|
111
|
+
generatedFileName: 'SystemConfigs.ts',
|
|
112
|
+
outputPath: 'services/system/configs.ts',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
tag: 'SystemDictionaryTypes',
|
|
116
|
+
operationTags: ['DictType'],
|
|
117
|
+
generatedFileName: 'SystemDictionaryTypes.ts',
|
|
118
|
+
outputPath: 'services/system/dictionaries/types.ts',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
tag: 'SystemDictionaryData',
|
|
122
|
+
operationTags: ['DictData'],
|
|
123
|
+
generatedFileName: 'SystemDictionaryData.ts',
|
|
124
|
+
outputPath: 'services/system/dictionaries/data.ts',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
tag: 'MonitorServer',
|
|
128
|
+
operationTags: ['Server'],
|
|
129
|
+
generatedFileName: 'MonitorServer.ts',
|
|
130
|
+
outputPath: 'services/monitor/server.ts',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
tag: 'MonitorOperationLogs',
|
|
134
|
+
operationTags: ['OperLog'],
|
|
135
|
+
generatedFileName: 'MonitorOperationLogs.ts',
|
|
136
|
+
outputPath: 'services/monitor/operlog.ts',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
tag: 'MonitorLoginInformation',
|
|
140
|
+
operationTags: ['LoginLog'],
|
|
141
|
+
generatedFileName: 'MonitorLoginInformation.ts',
|
|
142
|
+
outputPath: 'services/monitor/logininfor.ts',
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
tag: 'MonitorOnlineUsers',
|
|
146
|
+
operationTags: ['OnlineUser'],
|
|
147
|
+
generatedFileName: 'MonitorOnlineUsers.ts',
|
|
148
|
+
outputPath: 'services/monitor/online.ts',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
tag: 'MonitorJobs',
|
|
152
|
+
operationTags: ['Job'],
|
|
153
|
+
generatedFileName: 'MonitorJobs.ts',
|
|
154
|
+
outputPath: 'services/monitor/job.ts',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
tag: 'MonitorJobLogs',
|
|
158
|
+
operationTags: ['JobLog'],
|
|
159
|
+
generatedFileName: 'MonitorJobLogs.ts',
|
|
160
|
+
outputPath: 'services/monitor/jobLog.ts',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
tag: 'MonitorCache',
|
|
164
|
+
operationTags: ['Cache'],
|
|
165
|
+
generatedFileName: 'MonitorCache.ts',
|
|
166
|
+
outputPath: 'services/monitor/cache.ts',
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
tag: 'CommonFiles',
|
|
170
|
+
operationTags: ['Common'],
|
|
171
|
+
generatedFileName: 'CommonFiles.ts',
|
|
172
|
+
outputPath: 'services/common/files.ts',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
tag: 'CodeGenerator',
|
|
176
|
+
operationTags: ['Gen'],
|
|
177
|
+
generatedFileName: 'CodeGenerator.ts',
|
|
178
|
+
outputPath: 'services/tool/code-generator.ts',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
tag: 'SystemIndex',
|
|
182
|
+
operationTags: ['Index'],
|
|
183
|
+
generatedFileName: 'SystemIndex.ts',
|
|
184
|
+
outputPath: 'services/system/index.ts',
|
|
185
|
+
},
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
const HTTP_METHODS = new Set([
|
|
189
|
+
'get',
|
|
190
|
+
'put',
|
|
191
|
+
'post',
|
|
192
|
+
'delete',
|
|
193
|
+
'options',
|
|
194
|
+
'head',
|
|
195
|
+
'patch',
|
|
196
|
+
'trace',
|
|
197
|
+
])
|
|
198
|
+
|
|
199
|
+
export interface NormalizedOpenApiDocument {
|
|
200
|
+
document: Record<string, unknown>
|
|
201
|
+
operationCount: number
|
|
202
|
+
assignments: Map<string, ApiServiceGroup>
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface PreparedOpenApiEnums {
|
|
206
|
+
document: Record<string, unknown>
|
|
207
|
+
definitions: OpenApiEnumDefinition[]
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
211
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function validateApiServiceGroups(groups: readonly ApiServiceGroup[]): void {
|
|
215
|
+
const tags = new Set<string>()
|
|
216
|
+
const operationTags = new Set<string>()
|
|
217
|
+
const fileNames = new Set<string>()
|
|
218
|
+
const outputPaths = new Set<string>()
|
|
219
|
+
for (const group of groups) {
|
|
220
|
+
if (tags.has(group.tag))
|
|
221
|
+
throw new Error(`API service tag is configured more than once: ${group.tag}`)
|
|
222
|
+
if (group.operationTags.length === 0) {
|
|
223
|
+
throw new Error(`API service group must map at least one operation tag: ${group.tag}`)
|
|
224
|
+
}
|
|
225
|
+
for (const operationTag of group.operationTags) {
|
|
226
|
+
if (operationTags.has(operationTag)) {
|
|
227
|
+
throw new Error(`OpenAPI operation tag is mapped more than once: ${operationTag}`)
|
|
228
|
+
}
|
|
229
|
+
operationTags.add(operationTag)
|
|
230
|
+
}
|
|
231
|
+
if (fileNames.has(group.generatedFileName)) {
|
|
232
|
+
throw new Error(
|
|
233
|
+
`Generated API service filename is configured more than once: ${group.generatedFileName}`,
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
if (outputPaths.has(group.outputPath)) {
|
|
237
|
+
throw new Error(`API service output path is configured more than once: ${group.outputPath}`)
|
|
238
|
+
}
|
|
239
|
+
if (
|
|
240
|
+
!group.outputPath.endsWith('.ts') ||
|
|
241
|
+
path.posix.isAbsolute(group.outputPath) ||
|
|
242
|
+
path.posix.normalize(group.outputPath).startsWith('../')
|
|
243
|
+
) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`API service output path must be a safe relative TypeScript path: ${group.outputPath}`,
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
tags.add(group.tag)
|
|
249
|
+
fileNames.add(group.generatedFileName)
|
|
250
|
+
outputPaths.add(group.outputPath)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function resolveApiServiceGroup(
|
|
255
|
+
operationTags: readonly string[],
|
|
256
|
+
groups: readonly ApiServiceGroup[] = API_SERVICE_GROUPS,
|
|
257
|
+
): ApiServiceGroup | undefined {
|
|
258
|
+
if (operationTags.length === 0) return undefined
|
|
259
|
+
const matches = operationTags.map((operationTag) =>
|
|
260
|
+
groups.find((group) => group.operationTags.includes(operationTag)),
|
|
261
|
+
)
|
|
262
|
+
if (matches.includes(undefined)) return undefined
|
|
263
|
+
const uniqueMatches = [
|
|
264
|
+
...new Set(matches),
|
|
265
|
+
]
|
|
266
|
+
if (uniqueMatches.length > 1) {
|
|
267
|
+
throw new Error(
|
|
268
|
+
`OpenAPI operation tags map to multiple API service groups: ${operationTags.join(', ')}.`,
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
return uniqueMatches[0]
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function normalizeOpenApiDocument(
|
|
275
|
+
openApi: unknown,
|
|
276
|
+
groups: readonly ApiServiceGroup[] = API_SERVICE_GROUPS,
|
|
277
|
+
): NormalizedOpenApiDocument {
|
|
278
|
+
validateApiServiceGroups(groups)
|
|
279
|
+
if (!isRecord(openApi)) throw new Error('OpenAPI input must be a JSON object.')
|
|
280
|
+
const document = JSON.parse(JSON.stringify(openApi)) as Record<string, unknown>
|
|
281
|
+
if (!isRecord(document.paths)) throw new Error('OpenAPI input must contain a paths object.')
|
|
282
|
+
delete document.tags
|
|
283
|
+
|
|
284
|
+
const assignments = new Map<string, ApiServiceGroup>()
|
|
285
|
+
const operationNames = new Map<string, string>()
|
|
286
|
+
for (const [pathname, pathItemValue] of Object.entries(document.paths)) {
|
|
287
|
+
if (!isRecord(pathItemValue)) throw new Error(`OpenAPI path item is invalid: ${pathname}`)
|
|
288
|
+
for (const [method, operationValue] of Object.entries(pathItemValue)) {
|
|
289
|
+
if (!HTTP_METHODS.has(method)) continue
|
|
290
|
+
if (!isRecord(operationValue)) {
|
|
291
|
+
throw new Error(`OpenAPI operation is invalid: ${method.toUpperCase()} ${pathname}`)
|
|
292
|
+
}
|
|
293
|
+
const operationKey = `${method.toUpperCase()} ${pathname}`
|
|
294
|
+
if (assignments.has(operationKey)) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
`OpenAPI operation is assigned to more than one API service: ${operationKey}`,
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
const operationTags = Array.isArray(operationValue.tags)
|
|
300
|
+
? operationValue.tags.filter((tag): tag is string => typeof tag === 'string')
|
|
301
|
+
: []
|
|
302
|
+
if (operationTags.length === 0) {
|
|
303
|
+
throw new Error(`OpenAPI operation has no operation-level tags: ${operationKey}`)
|
|
304
|
+
}
|
|
305
|
+
const group = resolveApiServiceGroup(operationTags, groups)
|
|
306
|
+
if (group === undefined) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
`OpenAPI operation tags have no API service mapping: ${operationKey} (tags: ${operationTags.join(', ')}).`,
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
const operationId = operationValue.operationId
|
|
312
|
+
if (typeof operationId !== 'string' || operationId.trim() === '') {
|
|
313
|
+
throw new Error(`OpenAPI operation has no operationId: ${operationKey}`)
|
|
314
|
+
}
|
|
315
|
+
const operationNameKey = `${group.tag}:${operationId}`
|
|
316
|
+
const previousOperation = operationNames.get(operationNameKey)
|
|
317
|
+
if (previousOperation !== undefined) {
|
|
318
|
+
throw new Error(
|
|
319
|
+
`OpenAPI operations in ${group.tag} have duplicate operationId ${operationId}: ${previousOperation} and ${operationKey}.`,
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
operationNames.set(operationNameKey, operationKey)
|
|
323
|
+
operationValue.tags = [group.tag]
|
|
324
|
+
assignments.set(operationKey, group)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (assignments.size === 0) throw new Error('OpenAPI input does not contain any operations.')
|
|
328
|
+
return { document, operationCount: assignments.size, assignments }
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const ENUM_METADATA_KEYS = new Set([
|
|
332
|
+
'enum',
|
|
333
|
+
'type',
|
|
334
|
+
'x-enum-values',
|
|
335
|
+
'x-enum-varnames',
|
|
336
|
+
'x-enumDescriptions',
|
|
337
|
+
'x-enumNames',
|
|
338
|
+
'x-enum-descriptions',
|
|
339
|
+
])
|
|
340
|
+
|
|
341
|
+
function pascalCase(value: string): string {
|
|
342
|
+
const words = value.replace(/([a-z\d])([A-Z])/gu, '$1 $2').match(/[\w$]+/gu) ?? []
|
|
343
|
+
return words
|
|
344
|
+
.map((word) => `${word.charAt(0).toUpperCase()}${word.slice(1)}`)
|
|
345
|
+
.join('')
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function generatedEnumName(schemaName: string, propertyName: string): string {
|
|
349
|
+
const schemaPrefix = pascalCase(schemaName)
|
|
350
|
+
const propertySuffix = pascalCase(propertyName)
|
|
351
|
+
const name = `${schemaPrefix}${propertySuffix}Enum`
|
|
352
|
+
if (!/^[$A-Z_a-z][$\w]*$/u.test(name)) {
|
|
353
|
+
throw new Error(`Could not derive an enum name for ${schemaName}.${propertyName}.`)
|
|
354
|
+
}
|
|
355
|
+
return name
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function enumMemberName(name: string | undefined, value: OpenApiEnumValue): string {
|
|
359
|
+
const explicitName = name?.trim()
|
|
360
|
+
const source = explicitName === undefined || explicitName === ''
|
|
361
|
+
? String(value).replace(/^-/, 'Minus').replace(/\./gu, 'Point')
|
|
362
|
+
: explicitName
|
|
363
|
+
const normalized = pascalCase(source)
|
|
364
|
+
const identifier = /^[A-Za-z_$]/u.test(normalized)
|
|
365
|
+
? normalized
|
|
366
|
+
: `Value${normalized}`
|
|
367
|
+
return identifier || 'Value'
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function enumDefinitionFromSchema(
|
|
371
|
+
name: string,
|
|
372
|
+
schema: Record<string, unknown>,
|
|
373
|
+
location: string,
|
|
374
|
+
): { definition: OpenApiEnumDefinition, signature: string } {
|
|
375
|
+
if (!/^[$A-Z_a-z][$\w]*$/u.test(name)) {
|
|
376
|
+
throw new Error(`OpenAPI enum component name is not a valid TypeScript identifier: ${name}.`)
|
|
377
|
+
}
|
|
378
|
+
if (!Array.isArray(schema.enum) || schema.enum.length === 0) {
|
|
379
|
+
throw new Error(`OpenAPI enum has no values: ${location}.`)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const enumValues = schema.enum.map((value) => {
|
|
383
|
+
if (
|
|
384
|
+
value !== null &&
|
|
385
|
+
typeof value !== 'string' &&
|
|
386
|
+
typeof value !== 'number' &&
|
|
387
|
+
typeof value !== 'boolean'
|
|
388
|
+
) {
|
|
389
|
+
throw new Error(`OpenAPI enum value is not a scalar: ${location}.`)
|
|
390
|
+
}
|
|
391
|
+
return value as OpenApiEnumValue
|
|
392
|
+
})
|
|
393
|
+
const enumValueKeys = new Set(enumValues.map((value) => JSON.stringify(value)))
|
|
394
|
+
const metadataByValue = new Map<string, Record<string, unknown>>()
|
|
395
|
+
const metadata = schema['x-enum-values']
|
|
396
|
+
if (metadata !== undefined && !Array.isArray(metadata)) {
|
|
397
|
+
throw new Error(`OpenAPI x-enum-values must be an array: ${location}.`)
|
|
398
|
+
}
|
|
399
|
+
for (const item of (metadata ?? []) as unknown[]) {
|
|
400
|
+
if (!isRecord(item) || !('value' in item)) {
|
|
401
|
+
throw new Error(`OpenAPI x-enum-values entry is invalid: ${location}.`)
|
|
402
|
+
}
|
|
403
|
+
const valueKey = JSON.stringify(item.value)
|
|
404
|
+
if (!enumValueKeys.has(valueKey) || metadataByValue.has(valueKey)) {
|
|
405
|
+
throw new Error(`OpenAPI x-enum-values does not match enum values: ${location}.`)
|
|
406
|
+
}
|
|
407
|
+
metadataByValue.set(valueKey, item)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const members = enumValues.map((value) => {
|
|
411
|
+
const item = metadataByValue.get(JSON.stringify(value))
|
|
412
|
+
const explicitName = typeof item?.name === 'string'
|
|
413
|
+
? item.name
|
|
414
|
+
: undefined
|
|
415
|
+
const memberName = enumMemberName(explicitName, value)
|
|
416
|
+
const label = typeof item?.label === 'string'
|
|
417
|
+
? item.label
|
|
418
|
+
: String(value)
|
|
419
|
+
return { name: memberName, label, value }
|
|
420
|
+
})
|
|
421
|
+
const memberNames = new Set<string>()
|
|
422
|
+
for (const member of members) {
|
|
423
|
+
if (memberNames.has(member.name)) {
|
|
424
|
+
throw new Error(`OpenAPI enum member names collide after normalization: ${location}.`)
|
|
425
|
+
}
|
|
426
|
+
memberNames.add(member.name)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const signature = JSON.stringify({
|
|
430
|
+
type: schema.type ?? typeof enumValues[0],
|
|
431
|
+
members,
|
|
432
|
+
})
|
|
433
|
+
return {
|
|
434
|
+
definition: {
|
|
435
|
+
name,
|
|
436
|
+
members,
|
|
437
|
+
locations: [location],
|
|
438
|
+
},
|
|
439
|
+
signature,
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function normalizeEnumSchemaForGenerator(
|
|
444
|
+
schema: Record<string, unknown>,
|
|
445
|
+
definition: OpenApiEnumDefinition,
|
|
446
|
+
): Record<string, unknown> {
|
|
447
|
+
return {
|
|
448
|
+
...schema,
|
|
449
|
+
'x-enum-varnames': definition.members.map((member) => member.name),
|
|
450
|
+
'x-enumDescriptions': definition.members.map((member) => member.label),
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function enumComponentNameFromRef(reference: string): string | undefined {
|
|
455
|
+
const prefix = '#/components/schemas/'
|
|
456
|
+
if (!reference.startsWith(prefix)) return undefined
|
|
457
|
+
const encodedName = reference.slice(prefix.length)
|
|
458
|
+
if (encodedName.includes('/')) return undefined
|
|
459
|
+
return encodedName.replace(/~1/gu, '/').replace(/~0/gu, '~')
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function referenceToEnumComponent(name: string): string {
|
|
463
|
+
const encodedName = name.replace(/~/gu, '~0').replace(/\//gu, '~1')
|
|
464
|
+
return `#/components/schemas/${encodedName}`
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function schemaEnumSource(
|
|
468
|
+
propertySchema: Record<string, unknown>,
|
|
469
|
+
schemas: Record<string, unknown>,
|
|
470
|
+
): { schema: Record<string, unknown>, arrayItem: boolean, referenced: boolean } | undefined {
|
|
471
|
+
const arrayItem = propertySchema.type === 'array'
|
|
472
|
+
const candidate = arrayItem && isRecord(propertySchema.items)
|
|
473
|
+
? propertySchema.items
|
|
474
|
+
: propertySchema
|
|
475
|
+
if (Array.isArray(candidate.enum)) return { schema: candidate, arrayItem, referenced: false }
|
|
476
|
+
|
|
477
|
+
if (typeof candidate.$ref === 'string') {
|
|
478
|
+
const componentName = enumComponentNameFromRef(candidate.$ref)
|
|
479
|
+
const componentSchema = componentName === undefined
|
|
480
|
+
? undefined
|
|
481
|
+
: schemas[componentName]
|
|
482
|
+
if (isRecord(componentSchema) && Array.isArray(componentSchema.enum)) {
|
|
483
|
+
return { schema: componentSchema, arrayItem, referenced: true }
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return undefined
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function referenceSchema(
|
|
490
|
+
schema: Record<string, unknown>,
|
|
491
|
+
componentName: string,
|
|
492
|
+
): Record<string, unknown> {
|
|
493
|
+
const retained = Object.fromEntries(
|
|
494
|
+
Object.entries(schema).filter(([key]) => !ENUM_METADATA_KEYS.has(key) && key !== '$ref'),
|
|
495
|
+
)
|
|
496
|
+
return {
|
|
497
|
+
...retained,
|
|
498
|
+
$ref: referenceToEnumComponent(componentName),
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function replacePropertyEnumReference(
|
|
503
|
+
schemas: Record<string, unknown>,
|
|
504
|
+
location: string,
|
|
505
|
+
componentName: string,
|
|
506
|
+
): void {
|
|
507
|
+
const separator = location.indexOf('.')
|
|
508
|
+
const schemaName = location.slice(0, separator)
|
|
509
|
+
const propertyName = location.slice(separator + 1)
|
|
510
|
+
const modelSchema = schemas[schemaName]
|
|
511
|
+
if (!isRecord(modelSchema) || !isRecord(modelSchema.properties)) {
|
|
512
|
+
throw new Error(`OpenAPI enum mapping points to a missing model property: ${location}.`)
|
|
513
|
+
}
|
|
514
|
+
const propertySchema = modelSchema.properties[propertyName]
|
|
515
|
+
if (!isRecord(propertySchema)) {
|
|
516
|
+
throw new Error(`OpenAPI enum mapping points to a missing model property: ${location}.`)
|
|
517
|
+
}
|
|
518
|
+
if (propertySchema.type === 'array') {
|
|
519
|
+
if (!isRecord(propertySchema.items)) {
|
|
520
|
+
throw new Error(`OpenAPI enum array has no item schema: ${location}.`)
|
|
521
|
+
}
|
|
522
|
+
propertySchema.items = referenceSchema(propertySchema.items, componentName)
|
|
523
|
+
return
|
|
524
|
+
}
|
|
525
|
+
modelSchema.properties[propertyName] = referenceSchema(propertySchema, componentName)
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** Hoist model-field enums into named components so shared fields have one generated identity. */
|
|
529
|
+
export function prepareOpenApiEnums(
|
|
530
|
+
openApi: unknown,
|
|
531
|
+
sharedMappings: readonly ApiSharedEnumMapping[] = [],
|
|
532
|
+
): PreparedOpenApiEnums {
|
|
533
|
+
if (!isRecord(openApi)) throw new Error('OpenAPI input must be a JSON object.')
|
|
534
|
+
const document = JSON.parse(JSON.stringify(openApi)) as Record<string, unknown>
|
|
535
|
+
const components = isRecord(document.components)
|
|
536
|
+
? document.components
|
|
537
|
+
: {}
|
|
538
|
+
const schemas = isRecord(components.schemas)
|
|
539
|
+
? components.schemas
|
|
540
|
+
: {}
|
|
541
|
+
components.schemas = schemas
|
|
542
|
+
document.components = components
|
|
543
|
+
|
|
544
|
+
const entriesByName = new Map<string, { definition: OpenApiEnumDefinition, signature: string }>()
|
|
545
|
+
const register = (
|
|
546
|
+
name: string,
|
|
547
|
+
schema: Record<string, unknown>,
|
|
548
|
+
location: string,
|
|
549
|
+
): OpenApiEnumDefinition => {
|
|
550
|
+
const next = enumDefinitionFromSchema(name, schema, location)
|
|
551
|
+
const existing = entriesByName.get(name)
|
|
552
|
+
if (existing !== undefined) {
|
|
553
|
+
if (existing.signature !== next.signature) {
|
|
554
|
+
throw new Error(`OpenAPI enum name ${name} has conflicting definitions at ${location}.`)
|
|
555
|
+
}
|
|
556
|
+
if (!existing.definition.locations.includes(location)) {
|
|
557
|
+
existing.definition.locations.push(location)
|
|
558
|
+
}
|
|
559
|
+
return existing.definition
|
|
560
|
+
}
|
|
561
|
+
entriesByName.set(name, next)
|
|
562
|
+
return next.definition
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const originalSchemaEntries = Object.entries(schemas)
|
|
566
|
+
for (const [schemaName, schema] of originalSchemaEntries) {
|
|
567
|
+
if (!isRecord(schema) || !Array.isArray(schema.enum)) continue
|
|
568
|
+
const definition = register(schemaName, schema, `components.schemas.${schemaName}`)
|
|
569
|
+
schemas[schemaName] = normalizeEnumSchemaForGenerator(schema, definition)
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const mappedLocations = new Set<string>()
|
|
573
|
+
const mappedNames = new Set<string>()
|
|
574
|
+
for (const mapping of sharedMappings) {
|
|
575
|
+
if (!mapping.name || mappedNames.has(mapping.name)) {
|
|
576
|
+
throw new Error(`OpenAPI shared enum name is empty or repeated: ${mapping.name}.`)
|
|
577
|
+
}
|
|
578
|
+
if (!Array.isArray(mapping.properties) || mapping.properties.length === 0) {
|
|
579
|
+
throw new Error(`OpenAPI shared enum mapping has no properties: ${mapping.name}.`)
|
|
580
|
+
}
|
|
581
|
+
mappedNames.add(mapping.name)
|
|
582
|
+
|
|
583
|
+
const sources = mapping.properties.map((location) => {
|
|
584
|
+
if (mappedLocations.has(location)) {
|
|
585
|
+
throw new Error(`OpenAPI model property is mapped to more than one shared enum: ${location}.`)
|
|
586
|
+
}
|
|
587
|
+
const separator = location.indexOf('.')
|
|
588
|
+
if (separator <= 0 || separator === location.length - 1) {
|
|
589
|
+
throw new Error(`OpenAPI shared enum location must be Schema.property: ${location}.`)
|
|
590
|
+
}
|
|
591
|
+
const modelSchema = schemas[location.slice(0, separator)]
|
|
592
|
+
const propertySchema = isRecord(modelSchema) && isRecord(modelSchema.properties)
|
|
593
|
+
? modelSchema.properties[location.slice(separator + 1)]
|
|
594
|
+
: undefined
|
|
595
|
+
if (!isRecord(propertySchema)) {
|
|
596
|
+
throw new Error(`OpenAPI enum mapping points to a missing model property: ${location}.`)
|
|
597
|
+
}
|
|
598
|
+
const source = schemaEnumSource(propertySchema, schemas)
|
|
599
|
+
if (source === undefined) {
|
|
600
|
+
throw new Error(`OpenAPI shared enum mapping points to a non-enum property: ${location}.`)
|
|
601
|
+
}
|
|
602
|
+
return { location, ...source }
|
|
603
|
+
})
|
|
604
|
+
const firstSource = sources[0]
|
|
605
|
+
if (firstSource === undefined) continue
|
|
606
|
+
const first = enumDefinitionFromSchema(mapping.name, firstSource.schema, firstSource.location)
|
|
607
|
+
for (const source of sources.slice(1)) {
|
|
608
|
+
const candidate = enumDefinitionFromSchema(mapping.name, source.schema, source.location)
|
|
609
|
+
if (candidate.signature !== first.signature) {
|
|
610
|
+
throw new Error(
|
|
611
|
+
`OpenAPI shared enum ${mapping.name} has inconsistent values, names, or labels at ${source.location}.`,
|
|
612
|
+
)
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const existingSchema = schemas[mapping.name]
|
|
617
|
+
if (existingSchema !== undefined) {
|
|
618
|
+
if (!isRecord(existingSchema) || !Array.isArray(existingSchema.enum)) {
|
|
619
|
+
throw new Error(`OpenAPI shared enum component already exists and is not an enum: ${mapping.name}.`)
|
|
620
|
+
}
|
|
621
|
+
const existing = enumDefinitionFromSchema(
|
|
622
|
+
mapping.name,
|
|
623
|
+
existingSchema,
|
|
624
|
+
`components.schemas.${mapping.name}`,
|
|
625
|
+
)
|
|
626
|
+
if (existing.signature !== first.signature) {
|
|
627
|
+
throw new Error(`OpenAPI shared enum component conflicts with its mapping: ${mapping.name}.`)
|
|
628
|
+
}
|
|
629
|
+
} else {
|
|
630
|
+
schemas[mapping.name] = normalizeEnumSchemaForGenerator(firstSource.schema, first.definition)
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const definition = register(mapping.name, firstSource.schema, firstSource.location)
|
|
634
|
+
for (const source of sources) {
|
|
635
|
+
mappedLocations.add(source.location)
|
|
636
|
+
replacePropertyEnumReference(schemas, source.location, mapping.name)
|
|
637
|
+
if (!definition.locations.includes(source.location)) definition.locations.push(source.location)
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const generatedInlineLocations = new Map<string, string>()
|
|
642
|
+
for (const [schemaName, schema] of originalSchemaEntries) {
|
|
643
|
+
if (!isRecord(schema) || !isRecord(schema.properties) || Array.isArray(schema.enum)) continue
|
|
644
|
+
for (const [propertyName, propertySchema] of Object.entries(schema.properties)) {
|
|
645
|
+
const location = `${schemaName}.${propertyName}`
|
|
646
|
+
if (mappedLocations.has(location) || !isRecord(propertySchema)) continue
|
|
647
|
+
const source = schemaEnumSource(propertySchema, schemas)
|
|
648
|
+
if (source === undefined || source.referenced) continue
|
|
649
|
+
const componentName = generatedEnumName(schemaName, propertyName)
|
|
650
|
+
const previousLocation = generatedInlineLocations.get(componentName)
|
|
651
|
+
if (previousLocation !== undefined) {
|
|
652
|
+
throw new Error(
|
|
653
|
+
`OpenAPI inline enum fields ${previousLocation} and ${location} resolve to the same generated name: ${componentName}.`,
|
|
654
|
+
)
|
|
655
|
+
}
|
|
656
|
+
generatedInlineLocations.set(componentName, location)
|
|
657
|
+
if (schemas[componentName] !== undefined) {
|
|
658
|
+
throw new Error(
|
|
659
|
+
`Generated OpenAPI enum name collides with an existing schema: ${componentName} (${location}).`,
|
|
660
|
+
)
|
|
661
|
+
}
|
|
662
|
+
const definition = register(componentName, source.schema, location)
|
|
663
|
+
schemas[componentName] = normalizeEnumSchemaForGenerator(source.schema, definition)
|
|
664
|
+
replacePropertyEnumReference(schemas, location, componentName)
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return {
|
|
669
|
+
document,
|
|
670
|
+
definitions: Array.from(entriesByName.values(), ({ definition }) => definition)
|
|
671
|
+
.sort((left, right) => left.name.localeCompare(right.name)),
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export function assignGeneratedServiceOutputPaths(
|
|
676
|
+
services: GeneratedServiceSource[],
|
|
677
|
+
expectedTags?: ReadonlySet<string>,
|
|
678
|
+
groups: readonly ApiServiceGroup[] = API_SERVICE_GROUPS,
|
|
679
|
+
): GeneratedServiceSource[] {
|
|
680
|
+
validateApiServiceGroups(groups)
|
|
681
|
+
const groupByFileName = new Map(groups.map((group) => [group.generatedFileName, group]))
|
|
682
|
+
const seenFileNames = new Set<string>()
|
|
683
|
+
const seenOutputPaths = new Set<string>()
|
|
684
|
+
const assignedTags = new Set<string>()
|
|
685
|
+
const result = services.map((service) => {
|
|
686
|
+
if (seenFileNames.has(service.fileName)) {
|
|
687
|
+
throw new Error(
|
|
688
|
+
`swagger-typescript-api emitted a duplicate service file: ${service.fileName}`,
|
|
689
|
+
)
|
|
690
|
+
}
|
|
691
|
+
seenFileNames.add(service.fileName)
|
|
692
|
+
const group = groupByFileName.get(service.fileName)
|
|
693
|
+
if (group === undefined || (expectedTags !== undefined && !expectedTags.has(group.tag))) {
|
|
694
|
+
throw new Error(`Generated API service has no matching path group: ${service.fileName}`)
|
|
695
|
+
}
|
|
696
|
+
if (seenOutputPaths.has(group.outputPath)) {
|
|
697
|
+
throw new Error(`Generated API services collide at output path: ${group.outputPath}`)
|
|
698
|
+
}
|
|
699
|
+
seenOutputPaths.add(group.outputPath)
|
|
700
|
+
assignedTags.add(group.tag)
|
|
701
|
+
return { ...service, outputPath: group.outputPath }
|
|
702
|
+
})
|
|
703
|
+
|
|
704
|
+
if (expectedTags !== undefined) {
|
|
705
|
+
const missingTags = Array.from(expectedTags).filter((tag) => !assignedTags.has(tag))
|
|
706
|
+
if (missingTags.length > 0) {
|
|
707
|
+
throw new Error(
|
|
708
|
+
`OpenAPI path groups produced no generated service: ${missingTags.join(', ')}`,
|
|
709
|
+
)
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return result
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function hasErrorCode(error: unknown, code: string): boolean {
|
|
716
|
+
return typeof error === 'object' && error !== null && 'code' in error && error.code === code
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function isDirectoryRenameUnavailable(error: unknown): boolean {
|
|
720
|
+
return ['EBUSY', 'EACCES', 'EPERM'].some((code) => hasErrorCode(error, code))
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
async function listFiles(directory: string): Promise<string[]> {
|
|
724
|
+
const entries = await readdir(directory, { withFileTypes: true })
|
|
725
|
+
const files: string[] = []
|
|
726
|
+
for (const entry of entries) {
|
|
727
|
+
const entryPath = path.join(directory, entry.name)
|
|
728
|
+
if (entry.isDirectory()) files.push(...(await listFiles(entryPath)))
|
|
729
|
+
else if (entry.isFile()) files.push(entryPath)
|
|
730
|
+
}
|
|
731
|
+
return files
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
async function copyDirectoryContents(source: string, destination: string): Promise<void> {
|
|
735
|
+
await mkdir(destination, { recursive: true })
|
|
736
|
+
const entries = await readdir(source, { withFileTypes: true })
|
|
737
|
+
for (const entry of entries) {
|
|
738
|
+
const sourcePath = path.join(source, entry.name)
|
|
739
|
+
const destinationPath = path.join(destination, entry.name)
|
|
740
|
+
if (entry.isDirectory()) {
|
|
741
|
+
await copyDirectoryContents(sourcePath, destinationPath)
|
|
742
|
+
} else if (entry.isFile()) {
|
|
743
|
+
await mkdir(path.dirname(destinationPath), { recursive: true })
|
|
744
|
+
await copyFile(sourcePath, destinationPath)
|
|
745
|
+
} else {
|
|
746
|
+
throw new Error(`Generated API directory contains an unsupported entry: ${sourcePath}`)
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
async function clearDirectoryContents(directory: string): Promise<void> {
|
|
752
|
+
const entries = await readdir(directory, { withFileTypes: true })
|
|
753
|
+
for (const entry of entries) {
|
|
754
|
+
await rm(path.join(directory, entry.name), { force: true, recursive: true })
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
async function removeEmptyDirectories(directory: string): Promise<void> {
|
|
759
|
+
const entries = await readdir(directory, { withFileTypes: true })
|
|
760
|
+
for (const entry of entries) {
|
|
761
|
+
if (!entry.isDirectory()) continue
|
|
762
|
+
const childPath = path.join(directory, entry.name)
|
|
763
|
+
await removeEmptyDirectories(childPath)
|
|
764
|
+
if ((await readdir(childPath)).length === 0) await rmdir(childPath)
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
async function replaceDirectoryContents(
|
|
769
|
+
stagedDirectory: string,
|
|
770
|
+
generatedDirectory: string,
|
|
771
|
+
backupDirectory: string,
|
|
772
|
+
copyDirectory: typeof copyDirectoryContents,
|
|
773
|
+
): Promise<string | undefined> {
|
|
774
|
+
try {
|
|
775
|
+
await copyDirectory(generatedDirectory, backupDirectory)
|
|
776
|
+
} catch (backupError) {
|
|
777
|
+
try {
|
|
778
|
+
await rm(backupDirectory, { force: true, recursive: true })
|
|
779
|
+
} catch (cleanupError) {
|
|
780
|
+
throw new AggregateError(
|
|
781
|
+
[backupError, cleanupError],
|
|
782
|
+
`Could not back up the previous generated API files. A partial backup may remain at ${backupDirectory}.`,
|
|
783
|
+
)
|
|
784
|
+
}
|
|
785
|
+
throw backupError
|
|
786
|
+
}
|
|
787
|
+
const stagedFiles = await listFiles(stagedDirectory)
|
|
788
|
+
const stagedPaths = new Set(
|
|
789
|
+
stagedFiles.map((filePath) => path.relative(stagedDirectory, filePath)),
|
|
790
|
+
)
|
|
791
|
+
|
|
792
|
+
try {
|
|
793
|
+
await copyDirectory(stagedDirectory, generatedDirectory)
|
|
794
|
+
const generatedFiles = await listFiles(generatedDirectory)
|
|
795
|
+
for (const filePath of generatedFiles) {
|
|
796
|
+
if (!stagedPaths.has(path.relative(generatedDirectory, filePath))) {
|
|
797
|
+
await rm(filePath, { force: true })
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
await removeEmptyDirectories(generatedDirectory)
|
|
801
|
+
} catch (error) {
|
|
802
|
+
try {
|
|
803
|
+
await clearDirectoryContents(generatedDirectory)
|
|
804
|
+
await copyDirectory(backupDirectory, generatedDirectory)
|
|
805
|
+
} catch (restoreError) {
|
|
806
|
+
throw new AggregateError(
|
|
807
|
+
[error, restoreError],
|
|
808
|
+
`Could not install generated API files or restore the previous output. Previous files remain at ${backupDirectory}.`,
|
|
809
|
+
)
|
|
810
|
+
}
|
|
811
|
+
await rm(backupDirectory, { force: true, recursive: true })
|
|
812
|
+
throw error
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
try {
|
|
816
|
+
await rm(backupDirectory, { force: true, recursive: true })
|
|
817
|
+
return undefined
|
|
818
|
+
} catch {
|
|
819
|
+
return `Generated API files were installed, but the previous output remains at ${backupDirectory}.`
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/** Replace only the generated API directory, restoring it if the staged rename fails. */
|
|
824
|
+
export async function replaceGeneratedDirectory(
|
|
825
|
+
stagedDirectory: string,
|
|
826
|
+
generatedDirectory: string,
|
|
827
|
+
renameDirectory: typeof rename = rename,
|
|
828
|
+
copyDirectory: typeof copyDirectoryContents = copyDirectoryContents,
|
|
829
|
+
): Promise<string | undefined> {
|
|
830
|
+
const parentDirectory = path.dirname(generatedDirectory)
|
|
831
|
+
const backupDirectory = path.join(parentDirectory, `.generated-backup-${randomUUID()}`)
|
|
832
|
+
let hasBackup = false
|
|
833
|
+
|
|
834
|
+
try {
|
|
835
|
+
await renameDirectory(generatedDirectory, backupDirectory)
|
|
836
|
+
hasBackup = true
|
|
837
|
+
} catch (error) {
|
|
838
|
+
if (hasErrorCode(error, 'ENOENT')) {
|
|
839
|
+
await renameDirectory(stagedDirectory, generatedDirectory)
|
|
840
|
+
return undefined
|
|
841
|
+
}
|
|
842
|
+
if (!isDirectoryRenameUnavailable(error)) throw error
|
|
843
|
+
return await replaceDirectoryContents(
|
|
844
|
+
stagedDirectory,
|
|
845
|
+
generatedDirectory,
|
|
846
|
+
backupDirectory,
|
|
847
|
+
copyDirectory,
|
|
848
|
+
)
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
try {
|
|
852
|
+
await renameDirectory(stagedDirectory, generatedDirectory)
|
|
853
|
+
} catch (error) {
|
|
854
|
+
if (hasBackup) {
|
|
855
|
+
try {
|
|
856
|
+
await renameDirectory(backupDirectory, generatedDirectory)
|
|
857
|
+
hasBackup = false
|
|
858
|
+
} catch (restoreError) {
|
|
859
|
+
throw new AggregateError(
|
|
860
|
+
[error, restoreError],
|
|
861
|
+
`Could not install generated API files or restore the previous output. Previous files remain at ${backupDirectory}.`,
|
|
862
|
+
)
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
throw error
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
if (!hasBackup) return undefined
|
|
869
|
+
try {
|
|
870
|
+
await rm(backupDirectory, { force: true, recursive: true })
|
|
871
|
+
return undefined
|
|
872
|
+
} catch {
|
|
873
|
+
return `Generated API files were installed, but the previous output remains at ${backupDirectory}.`
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
type ContractDeclaration = ts.EnumDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration
|
|
878
|
+
|
|
879
|
+
interface DeclarationRecord {
|
|
880
|
+
declaration: ContractDeclaration
|
|
881
|
+
name: string
|
|
882
|
+
source: string
|
|
883
|
+
references: Set<string>
|
|
884
|
+
kind: ApiModelKind | 'common'
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
interface InlineTypeDeclaration {
|
|
888
|
+
name: string
|
|
889
|
+
source: string
|
|
890
|
+
references: Set<string>
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
function isDeclarationRecord(
|
|
894
|
+
record: DeclarationRecord | InlineTypeDeclaration,
|
|
895
|
+
): record is DeclarationRecord {
|
|
896
|
+
return 'declaration' in record
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
interface EnumDictionaryEntry {
|
|
900
|
+
label: string
|
|
901
|
+
value: OpenApiEnumValue
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function parseTypeScript(source: string, fileName: string): ts.SourceFile {
|
|
905
|
+
const sourceFile = ts.createSourceFile(
|
|
906
|
+
fileName,
|
|
907
|
+
source,
|
|
908
|
+
ts.ScriptTarget.Latest,
|
|
909
|
+
true,
|
|
910
|
+
ts.ScriptKind.TS,
|
|
911
|
+
)
|
|
912
|
+
if (sourceFile.parseDiagnostics.length > 0) {
|
|
913
|
+
const diagnostic = sourceFile.parseDiagnostics[0]
|
|
914
|
+
const message =
|
|
915
|
+
diagnostic === undefined
|
|
916
|
+
? 'Unknown TypeScript parse error'
|
|
917
|
+
: ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')
|
|
918
|
+
throw new Error(`Cannot parse ${fileName}: ${message}`)
|
|
919
|
+
}
|
|
920
|
+
return sourceFile
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function isContractDeclaration(statement: ts.Statement): statement is ContractDeclaration {
|
|
924
|
+
return (
|
|
925
|
+
ts.isEnumDeclaration(statement) ||
|
|
926
|
+
ts.isInterfaceDeclaration(statement) ||
|
|
927
|
+
ts.isTypeAliasDeclaration(statement)
|
|
928
|
+
)
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
function getEntityName(name: ts.EntityName): string {
|
|
932
|
+
return ts.isIdentifier(name)
|
|
933
|
+
? name.text
|
|
934
|
+
: name.right.text
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function collectTypeReferences(node: ts.Node, knownNames: ReadonlySet<string>): Set<string> {
|
|
938
|
+
const references = new Set<string>()
|
|
939
|
+
const visit = (current: ts.Node) => {
|
|
940
|
+
if (ts.isTypeReferenceNode(current)) {
|
|
941
|
+
const name = getEntityName(current.typeName)
|
|
942
|
+
if (knownNames.has(name)) references.add(name)
|
|
943
|
+
}
|
|
944
|
+
if (ts.isExpressionWithTypeArguments(current) && ts.isIdentifier(current.expression)) {
|
|
945
|
+
if (knownNames.has(current.expression.text)) references.add(current.expression.text)
|
|
946
|
+
}
|
|
947
|
+
if (ts.isImportTypeNode(current) && current.qualifier !== undefined) {
|
|
948
|
+
const name = current.qualifier.getText()
|
|
949
|
+
if (knownNames.has(name)) references.add(name)
|
|
950
|
+
}
|
|
951
|
+
ts.forEachChild(current, visit)
|
|
952
|
+
}
|
|
953
|
+
visit(node)
|
|
954
|
+
return references
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function importedContractNames(source: string, fileName: string): Set<string> {
|
|
958
|
+
const sourceFile = parseTypeScript(source, fileName)
|
|
959
|
+
const names = new Set<string>()
|
|
960
|
+
for (const statement of sourceFile.statements) {
|
|
961
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
962
|
+
continue
|
|
963
|
+
if (!statement.moduleSpecifier.text.endsWith('data-contracts')) continue
|
|
964
|
+
const bindings = statement.importClause?.namedBindings
|
|
965
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) continue
|
|
966
|
+
for (const element of bindings.elements) {
|
|
967
|
+
names.add((element.propertyName ?? element.name).text)
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return names
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function collectClosure(
|
|
974
|
+
roots: Iterable<string>,
|
|
975
|
+
declarations: ReadonlyMap<string, DeclarationRecord>,
|
|
976
|
+
): Set<string> {
|
|
977
|
+
const result = new Set<string>()
|
|
978
|
+
const visit = (name: string) => {
|
|
979
|
+
if (result.has(name)) return
|
|
980
|
+
const record = declarations.get(name)
|
|
981
|
+
if (record === undefined) return
|
|
982
|
+
result.add(name)
|
|
983
|
+
for (const reference of record.references) visit(reference)
|
|
984
|
+
}
|
|
985
|
+
for (const root of roots) visit(root)
|
|
986
|
+
return result
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
function determineModelKind(
|
|
990
|
+
name: string,
|
|
991
|
+
declaration: ContractDeclaration,
|
|
992
|
+
options: ApiCodegenOptions,
|
|
993
|
+
warnings: string[],
|
|
994
|
+
): ApiModelKind | 'common' {
|
|
995
|
+
if (options.commonTypeNames.includes(name)) return 'common'
|
|
996
|
+
|
|
997
|
+
const matching = options.nameMapping.filter((item) => name.endsWith(item.suffix))
|
|
998
|
+
if (matching.length > 1) {
|
|
999
|
+
const message = `Schema ${name} matches multiple DTO/VO/Enum suffix rules.`
|
|
1000
|
+
if (options.strictNames) throw new Error(message)
|
|
1001
|
+
warnings.push(message)
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
if (ts.isEnumDeclaration(declaration)) {
|
|
1005
|
+
if (!matching.some((item) => item.type === 'enum')) {
|
|
1006
|
+
const message = `Enum ${name} has no configured Enum suffix; it remains an enum.`
|
|
1007
|
+
if (options.strictNames) throw new Error(message)
|
|
1008
|
+
warnings.push(message)
|
|
1009
|
+
}
|
|
1010
|
+
return 'enum'
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
const kind = matching[0]?.type
|
|
1014
|
+
if (kind !== undefined) return kind
|
|
1015
|
+
|
|
1016
|
+
const message = `Schema ${name} has no DTO/VO/Enum suffix; it is placed in common.`
|
|
1017
|
+
if (options.strictNames) throw new Error(message)
|
|
1018
|
+
warnings.push(message)
|
|
1019
|
+
return 'common'
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
function collectEnumDictionaryEntries(
|
|
1023
|
+
declaration: ContractDeclaration,
|
|
1024
|
+
sourceFile: ts.SourceFile,
|
|
1025
|
+
source: string,
|
|
1026
|
+
): EnumDictionaryEntry[] {
|
|
1027
|
+
if (ts.isEnumDeclaration(declaration)) {
|
|
1028
|
+
const entries: EnumDictionaryEntry[] = []
|
|
1029
|
+
let nextNumericValue = 0
|
|
1030
|
+
for (const member of declaration.members) {
|
|
1031
|
+
const key =
|
|
1032
|
+
ts.isIdentifier(member.name) || ts.isStringLiteral(member.name)
|
|
1033
|
+
? member.name.text
|
|
1034
|
+
: member.name.getText(sourceFile)
|
|
1035
|
+
const initializer = member.initializer
|
|
1036
|
+
let value: string | number
|
|
1037
|
+
if (initializer === undefined) {
|
|
1038
|
+
value = nextNumericValue
|
|
1039
|
+
nextNumericValue += 1
|
|
1040
|
+
} else if (ts.isStringLiteral(initializer)) {
|
|
1041
|
+
value = initializer.text
|
|
1042
|
+
} else if (ts.isNumericLiteral(initializer)) {
|
|
1043
|
+
value = Number(initializer.text)
|
|
1044
|
+
nextNumericValue = Number(initializer.text) + 1
|
|
1045
|
+
} else {
|
|
1046
|
+
return []
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
const ranges = ts.getLeadingCommentRanges(source, member.getFullStart()) ?? []
|
|
1050
|
+
const lastRange = ranges[ranges.length - 1]
|
|
1051
|
+
const comment =
|
|
1052
|
+
lastRange === undefined
|
|
1053
|
+
? ''
|
|
1054
|
+
: source
|
|
1055
|
+
.slice(lastRange.pos, lastRange.end)
|
|
1056
|
+
.replace(/^\/\*+|\*\/$|^\/\/\s?/gu, '')
|
|
1057
|
+
.trim()
|
|
1058
|
+
entries.push({ label: comment || key, value })
|
|
1059
|
+
}
|
|
1060
|
+
return entries
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
if (!ts.isTypeAliasDeclaration(declaration) || !ts.isUnionTypeNode(declaration.type)) return []
|
|
1064
|
+
const entries: EnumDictionaryEntry[] = []
|
|
1065
|
+
for (const member of declaration.type.types) {
|
|
1066
|
+
if (!ts.isLiteralTypeNode(member)) return []
|
|
1067
|
+
if (ts.isStringLiteral(member.literal)) {
|
|
1068
|
+
entries.push({ label: member.literal.text, value: member.literal.text })
|
|
1069
|
+
} else if (ts.isNumericLiteral(member.literal)) {
|
|
1070
|
+
entries.push({
|
|
1071
|
+
label: member.literal.text,
|
|
1072
|
+
value: Number(member.literal.text),
|
|
1073
|
+
})
|
|
1074
|
+
} else {
|
|
1075
|
+
return []
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
return entries
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function relativeModuleSpecifier(fromFile: string, targetFile: string): string {
|
|
1082
|
+
const targetWithoutExtension = targetFile.replace(/\.ts$/u, '')
|
|
1083
|
+
let specifier = path.posix.relative(path.posix.dirname(fromFile), targetWithoutExtension)
|
|
1084
|
+
if (!specifier.startsWith('.')) specifier = `./${specifier}`
|
|
1085
|
+
return specifier
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
function normalizeEnumDocumentationText(value: string): string {
|
|
1089
|
+
let normalized = ''
|
|
1090
|
+
let previousWasSeparator = false
|
|
1091
|
+
for (const character of value) {
|
|
1092
|
+
const codePoint = character.codePointAt(0)
|
|
1093
|
+
const isSeparator = codePoint !== undefined && (
|
|
1094
|
+
codePoint <= 0x1F ||
|
|
1095
|
+
(codePoint >= 0x7F && codePoint <= 0x9F) ||
|
|
1096
|
+
codePoint === 0x2028 ||
|
|
1097
|
+
codePoint === 0x2029
|
|
1098
|
+
)
|
|
1099
|
+
if (isSeparator) {
|
|
1100
|
+
if (!previousWasSeparator) normalized += ' '
|
|
1101
|
+
} else {
|
|
1102
|
+
normalized += character
|
|
1103
|
+
}
|
|
1104
|
+
previousWasSeparator = isSeparator
|
|
1105
|
+
}
|
|
1106
|
+
return normalized.replace(/\*\//gu, '*\\/')
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
function readJSDocContents(
|
|
1110
|
+
comments: readonly ts.JSDoc[] | undefined,
|
|
1111
|
+
sourceFile: ts.SourceFile,
|
|
1112
|
+
): string[] {
|
|
1113
|
+
return (comments ?? [])
|
|
1114
|
+
.map((comment) => comment.getText(sourceFile)
|
|
1115
|
+
.replace(/^\/\*\*/u, '')
|
|
1116
|
+
.replace(/\*\/$/u, '')
|
|
1117
|
+
.split(/\r\n?|[\n\u2028\u2029]/gu)
|
|
1118
|
+
.map((line) => line.replace(/^\s*\* ?/u, ''))
|
|
1119
|
+
.join('\n')
|
|
1120
|
+
.trim())
|
|
1121
|
+
.filter(Boolean)
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
function removeJSDocComments(
|
|
1125
|
+
source: string,
|
|
1126
|
+
comments: readonly ts.JSDoc[] | undefined,
|
|
1127
|
+
sourceFile: ts.SourceFile,
|
|
1128
|
+
): string {
|
|
1129
|
+
const ranges = (comments ?? [])
|
|
1130
|
+
.map((comment) => ({
|
|
1131
|
+
start: comment.getStart(sourceFile),
|
|
1132
|
+
end: comment.end,
|
|
1133
|
+
}))
|
|
1134
|
+
.sort((left, right) => right.start - left.start)
|
|
1135
|
+
return ranges.reduce(
|
|
1136
|
+
(result, { start, end }) => `${result.slice(0, start)}${result.slice(end)}`,
|
|
1137
|
+
source,
|
|
1138
|
+
)
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
function renderEnumLabelDocumentation(
|
|
1142
|
+
members: readonly OpenApiEnumMember[],
|
|
1143
|
+
existingDocContents: readonly string[] = [],
|
|
1144
|
+
): string {
|
|
1145
|
+
const entries = members.map((member) => {
|
|
1146
|
+
const label = normalizeEnumDocumentationText(member.label)
|
|
1147
|
+
const value = normalizeEnumDocumentationText(JSON.stringify(member.value) ?? String(member.value))
|
|
1148
|
+
return `- ${label}: ${value}`
|
|
1149
|
+
})
|
|
1150
|
+
const existingLines = existingDocContents.flatMap((content) => [
|
|
1151
|
+
'',
|
|
1152
|
+
...content.split('\n').map(normalizeEnumDocumentationText),
|
|
1153
|
+
])
|
|
1154
|
+
const bodyLines = [
|
|
1155
|
+
...entries,
|
|
1156
|
+
...existingLines,
|
|
1157
|
+
]
|
|
1158
|
+
return `/**\n${bodyLines.map((line) => line === ''
|
|
1159
|
+
? ' *'
|
|
1160
|
+
: ` * ${line}`).join('\n')}\n */`
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
function renderEnumUnionMembers(members: readonly OpenApiEnumMember[]): string {
|
|
1164
|
+
return members.map((member) => ` | ${JSON.stringify(member.value)}`).join('\n')
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
function renderEnumTypeAlias(
|
|
1168
|
+
definition: OpenApiEnumDefinition,
|
|
1169
|
+
existingDocContents: readonly string[] = [],
|
|
1170
|
+
): string {
|
|
1171
|
+
if (definition.members.length === 0) {
|
|
1172
|
+
throw new Error(`Generated OpenAPI enum has no values: ${definition.name}.`)
|
|
1173
|
+
}
|
|
1174
|
+
return `${renderEnumLabelDocumentation(definition.members, existingDocContents)}\nexport type ${definition.name} =\n${renderEnumUnionMembers(definition.members)};`
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
function renderDeclarations(
|
|
1178
|
+
outputPath: string,
|
|
1179
|
+
records: DeclarationRecord[],
|
|
1180
|
+
outputPathByName: ReadonlyMap<string, string>,
|
|
1181
|
+
inlineDeclarations: InlineTypeDeclaration[] = [],
|
|
1182
|
+
enumDefinitions: readonly OpenApiEnumDefinition[] = [],
|
|
1183
|
+
): string {
|
|
1184
|
+
const imports = new Map<string, Set<string>>()
|
|
1185
|
+
for (const declaration of [
|
|
1186
|
+
...records,
|
|
1187
|
+
...inlineDeclarations,
|
|
1188
|
+
]) {
|
|
1189
|
+
for (const reference of declaration.references) {
|
|
1190
|
+
const targetPath = outputPathByName.get(reference)
|
|
1191
|
+
if (targetPath === undefined || targetPath === outputPath) continue
|
|
1192
|
+
const specifier = relativeModuleSpecifier(outputPath, targetPath)
|
|
1193
|
+
const names = imports.get(specifier) ?? new Set<string>()
|
|
1194
|
+
names.add(reference)
|
|
1195
|
+
imports.set(specifier, names)
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
const importLines = Array.from(imports.entries())
|
|
1200
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
1201
|
+
.map(([specifier, names]) => {
|
|
1202
|
+
const sortedNames = Array.from(names).sort((left, right) => left.localeCompare(right))
|
|
1203
|
+
return `import type { ${sortedNames.join(', ')} } from ${JSON.stringify(specifier)};`
|
|
1204
|
+
})
|
|
1205
|
+
const enumDefinitionsByName = new Map(enumDefinitions.map((definition) => [definition.name, definition]))
|
|
1206
|
+
const declarations = [
|
|
1207
|
+
...records,
|
|
1208
|
+
...inlineDeclarations,
|
|
1209
|
+
]
|
|
1210
|
+
.map((record) => {
|
|
1211
|
+
const definition = enumDefinitionsByName.get(record.name)
|
|
1212
|
+
if (definition === undefined || !isDeclarationRecord(record)) return record.source.trim()
|
|
1213
|
+
if (definition.members.length === 0) {
|
|
1214
|
+
throw new Error(`Generated OpenAPI enum has no values: ${definition.name}.`)
|
|
1215
|
+
}
|
|
1216
|
+
if (!ts.isTypeAliasDeclaration(record.declaration)) {
|
|
1217
|
+
return renderEnumTypeAlias(
|
|
1218
|
+
definition,
|
|
1219
|
+
readJSDocContents(record.declaration.jsDoc, record.declaration.getSourceFile()),
|
|
1220
|
+
)
|
|
1221
|
+
}
|
|
1222
|
+
const sourceFile = parseTypeScript(record.source, `${record.name}.ts`)
|
|
1223
|
+
const typeAlias = sourceFile.statements.find(ts.isTypeAliasDeclaration)
|
|
1224
|
+
if (typeAlias === undefined) {
|
|
1225
|
+
throw new Error(`Generated OpenAPI enum has no type alias: ${record.name}.`)
|
|
1226
|
+
}
|
|
1227
|
+
const declarationPrefix = removeJSDocComments(
|
|
1228
|
+
record.source.slice(0, typeAlias.getStart(sourceFile)),
|
|
1229
|
+
typeAlias.jsDoc,
|
|
1230
|
+
sourceFile,
|
|
1231
|
+
).trim()
|
|
1232
|
+
const declarationHead = record.source
|
|
1233
|
+
.slice(typeAlias.getStart(sourceFile), typeAlias.type.getStart(sourceFile))
|
|
1234
|
+
.trimEnd()
|
|
1235
|
+
const declarationSuffix = record.source.slice(typeAlias.type.end)
|
|
1236
|
+
const existingDocContents = readJSDocContents(typeAlias.jsDoc, sourceFile)
|
|
1237
|
+
const preservedPrefix = declarationPrefix
|
|
1238
|
+
? `${declarationPrefix}\n`
|
|
1239
|
+
: ''
|
|
1240
|
+
return `${preservedPrefix}${renderEnumLabelDocumentation(definition.members, existingDocContents)}\n${declarationHead}\n${renderEnumUnionMembers(definition.members)}${declarationSuffix}`.trim()
|
|
1241
|
+
})
|
|
1242
|
+
.filter(Boolean)
|
|
1243
|
+
return `${[
|
|
1244
|
+
...importLines,
|
|
1245
|
+
...declarations,
|
|
1246
|
+
].join('\n\n')}\n`
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
function renderEnumDictionary(
|
|
1250
|
+
records: DeclarationRecord[],
|
|
1251
|
+
source: string,
|
|
1252
|
+
enumDefinitions?: readonly OpenApiEnumDefinition[],
|
|
1253
|
+
): string {
|
|
1254
|
+
if (enumDefinitions !== undefined) {
|
|
1255
|
+
const definitionNames = new Set(enumDefinitions.map((definition) => definition.name))
|
|
1256
|
+
const definitions = enumDefinitions.map((definition) => ({
|
|
1257
|
+
name: definition.name,
|
|
1258
|
+
entries: definition.members,
|
|
1259
|
+
}))
|
|
1260
|
+
const sourceFile = parseTypeScript(source, 'data-contracts.ts')
|
|
1261
|
+
const legacyDefinitions = records
|
|
1262
|
+
.filter((record) => !definitionNames.has(record.name))
|
|
1263
|
+
.map((record) => ({
|
|
1264
|
+
name: record.name,
|
|
1265
|
+
entries: collectEnumDictionaryEntries(record.declaration, sourceFile, source),
|
|
1266
|
+
}))
|
|
1267
|
+
const lines = [
|
|
1268
|
+
...definitions,
|
|
1269
|
+
...legacyDefinitions,
|
|
1270
|
+
].flatMap(({ name, entries }) => {
|
|
1271
|
+
if (entries.length === 0) return []
|
|
1272
|
+
const values = entries.map((entry) => {
|
|
1273
|
+
return ` { label: ${JSON.stringify(entry.label)}, value: ${JSON.stringify(entry.value)} },`
|
|
1274
|
+
})
|
|
1275
|
+
return [`export const ${name}Dict = [\n${values.join('\n')}\n] as const;`]
|
|
1276
|
+
})
|
|
1277
|
+
return lines.length > 0
|
|
1278
|
+
? `${lines.join('\n\n')}\n`
|
|
1279
|
+
: 'export {}\n'
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
const sourceFile = parseTypeScript(source, 'data-contracts.ts')
|
|
1283
|
+
const dictionaryLines: string[] = []
|
|
1284
|
+
for (const record of records) {
|
|
1285
|
+
const entries = collectEnumDictionaryEntries(record.declaration, sourceFile, source)
|
|
1286
|
+
if (entries.length === 0) continue
|
|
1287
|
+
const values = entries.map((entry) => {
|
|
1288
|
+
return ` { label: ${JSON.stringify(entry.label)}, value: ${JSON.stringify(entry.value)} },`
|
|
1289
|
+
})
|
|
1290
|
+
dictionaryLines.push(`export const ${record.name}Dict = [\n${values.join('\n')}\n] as const;`)
|
|
1291
|
+
}
|
|
1292
|
+
return dictionaryLines.length > 0
|
|
1293
|
+
? `${dictionaryLines.join('\n\n')}\n`
|
|
1294
|
+
: 'export {}\n'
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function resolveContractModulePath(
|
|
1298
|
+
fromFile: string,
|
|
1299
|
+
moduleSpecifier: string,
|
|
1300
|
+
files: ReadonlyMap<string, string>,
|
|
1301
|
+
): string | undefined {
|
|
1302
|
+
if (!moduleSpecifier.startsWith('.')) return undefined
|
|
1303
|
+
const basePath = path.posix.normalize(
|
|
1304
|
+
path.posix.join(path.posix.dirname(fromFile), moduleSpecifier),
|
|
1305
|
+
)
|
|
1306
|
+
return [
|
|
1307
|
+
basePath,
|
|
1308
|
+
`${basePath}.ts`,
|
|
1309
|
+
path.posix.join(basePath, 'index.ts'),
|
|
1310
|
+
].find((candidate) =>
|
|
1311
|
+
files.has(candidate),
|
|
1312
|
+
)
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
function exportedNamesFromContractFile(
|
|
1316
|
+
fileName: string,
|
|
1317
|
+
files: ReadonlyMap<string, string>,
|
|
1318
|
+
visited = new Set<string>(),
|
|
1319
|
+
): Set<string> {
|
|
1320
|
+
if (visited.has(fileName)) return new Set()
|
|
1321
|
+
visited.add(fileName)
|
|
1322
|
+
const source = files.get(fileName)
|
|
1323
|
+
if (source === undefined) throw new Error(`Generated contract file ${fileName} does not exist.`)
|
|
1324
|
+
const sourceFile = parseTypeScript(source, fileName)
|
|
1325
|
+
const names = new Set<string>()
|
|
1326
|
+
|
|
1327
|
+
for (const statement of sourceFile.statements) {
|
|
1328
|
+
if (ts.isExportDeclaration(statement)) {
|
|
1329
|
+
const moduleSpecifier = statement.moduleSpecifier
|
|
1330
|
+
if (moduleSpecifier === undefined || !ts.isStringLiteral(moduleSpecifier)) {
|
|
1331
|
+
if (statement.exportClause !== undefined && ts.isNamedExports(statement.exportClause)) {
|
|
1332
|
+
for (const element of statement.exportClause.elements) names.add(element.name.text)
|
|
1333
|
+
}
|
|
1334
|
+
continue
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
const targetFile = resolveContractModulePath(fileName, moduleSpecifier.text, files)
|
|
1338
|
+
if (targetFile === undefined) continue
|
|
1339
|
+
const targetNames = exportedNamesFromContractFile(targetFile, files, visited)
|
|
1340
|
+
if (statement.exportClause === undefined) {
|
|
1341
|
+
for (const name of targetNames) {
|
|
1342
|
+
if (name !== 'default') names.add(name)
|
|
1343
|
+
}
|
|
1344
|
+
} else if (ts.isNamedExports(statement.exportClause)) {
|
|
1345
|
+
for (const element of statement.exportClause.elements) {
|
|
1346
|
+
const sourceName = element.propertyName?.text ?? element.name.text
|
|
1347
|
+
if (!targetNames.has(sourceName)) {
|
|
1348
|
+
throw new Error(
|
|
1349
|
+
`Generated contract file ${fileName} re-exports missing type ${sourceName} from ${moduleSpecifier.text}.`,
|
|
1350
|
+
)
|
|
1351
|
+
}
|
|
1352
|
+
names.add(element.name.text)
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
continue
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
if (!ts.isStatement(statement) || !ts.canHaveModifiers(statement)) continue
|
|
1359
|
+
const modifiers = ts.getModifiers(statement)
|
|
1360
|
+
if (!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) continue
|
|
1361
|
+
if ('name' in statement && statement.name !== undefined && ts.isIdentifier(statement.name)) {
|
|
1362
|
+
names.add(statement.name.text)
|
|
1363
|
+
} else if (ts.isVariableStatement(statement)) {
|
|
1364
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1365
|
+
if (ts.isIdentifier(declaration.name)) names.add(declaration.name.text)
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
return names
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
function validateGeneratedContractExports(
|
|
1374
|
+
files: ReadonlyMap<string, string>,
|
|
1375
|
+
services: GeneratedServiceFile[],
|
|
1376
|
+
): void {
|
|
1377
|
+
const allFiles = new Map(files)
|
|
1378
|
+
for (const service of services) allFiles.set(service.outputPath, service.source)
|
|
1379
|
+
for (const service of services) {
|
|
1380
|
+
const sourceFile = parseTypeScript(service.source, service.outputPath)
|
|
1381
|
+
for (const statement of sourceFile.statements) {
|
|
1382
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
1383
|
+
continue
|
|
1384
|
+
const targetPath = resolveContractModulePath(
|
|
1385
|
+
service.outputPath,
|
|
1386
|
+
statement.moduleSpecifier.text,
|
|
1387
|
+
allFiles,
|
|
1388
|
+
)
|
|
1389
|
+
if (targetPath === undefined) continue
|
|
1390
|
+
const targetExports = exportedNamesFromContractFile(targetPath, allFiles)
|
|
1391
|
+
const bindings = statement.importClause?.namedBindings
|
|
1392
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) continue
|
|
1393
|
+
for (const element of bindings.elements) {
|
|
1394
|
+
const importedName = (element.propertyName ?? element.name).text
|
|
1395
|
+
if (!targetExports.has(importedName)) {
|
|
1396
|
+
throw new Error(
|
|
1397
|
+
`Generated API service ${service.outputPath} imports missing type ${importedName} from ${statement.moduleSpecifier.text}.`,
|
|
1398
|
+
)
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
function getOutputPathForTag(
|
|
1406
|
+
record: DeclarationRecord,
|
|
1407
|
+
serviceNamesByType: ReadonlyMap<string, Set<string>>,
|
|
1408
|
+
commonTypeNames: ReadonlySet<string>,
|
|
1409
|
+
): string {
|
|
1410
|
+
if (record.kind === 'enum' || ts.isEnumDeclaration(record.declaration)) return 'types/enums.ts'
|
|
1411
|
+
const serviceNames = serviceNamesByType.get(record.name)
|
|
1412
|
+
if (commonTypeNames.has(record.name) || serviceNames === undefined || serviceNames.size !== 1) {
|
|
1413
|
+
return 'types/common.ts'
|
|
1414
|
+
}
|
|
1415
|
+
return Array.from(serviceNames)[0] ?? 'types/common.ts'
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function serviceTypeOutputPath(service: GeneratedServiceSource): string {
|
|
1419
|
+
const outputPath = service.outputPath ?? `services/${service.fileName}`
|
|
1420
|
+
const servicePath = outputPath.startsWith('services/')
|
|
1421
|
+
? outputPath.slice('services/'.length)
|
|
1422
|
+
: path.posix.basename(outputPath)
|
|
1423
|
+
return `types/${servicePath.replace(/\.ts$/u, '.types.ts')}`
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
function getPropertyName(name: ts.PropertyName): string | undefined {
|
|
1427
|
+
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name))
|
|
1428
|
+
return name.text
|
|
1429
|
+
return undefined
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
function containsInlineObjectType(node: ts.TypeNode): boolean {
|
|
1433
|
+
if (ts.isTypeLiteralNode(node)) return true
|
|
1434
|
+
if (ts.isArrayTypeNode(node)) return containsInlineObjectType(node.elementType)
|
|
1435
|
+
if (ts.isUnionTypeNode(node) || ts.isIntersectionTypeNode(node)) {
|
|
1436
|
+
return node.types.some(containsInlineObjectType)
|
|
1437
|
+
}
|
|
1438
|
+
if (ts.isParenthesizedTypeNode(node)) return containsInlineObjectType(node.type)
|
|
1439
|
+
return false
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
function toTypeName(methodName: string, suffix: string): string {
|
|
1443
|
+
const pascalMethodName = `${methodName.charAt(0).toUpperCase()}${methodName.slice(1)}`
|
|
1444
|
+
return `${pascalMethodName}${suffix}`
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
interface TextReplacement {
|
|
1448
|
+
start: number
|
|
1449
|
+
end: number
|
|
1450
|
+
text: string
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
function replaceSourceRanges(source: string, replacements: TextReplacement[]): string {
|
|
1454
|
+
return [...replacements]
|
|
1455
|
+
.sort((left, right) => right.start - left.start)
|
|
1456
|
+
.reduce(
|
|
1457
|
+
(result, replacement) =>
|
|
1458
|
+
`${result.slice(0, replacement.start)}${replacement.text}${result.slice(replacement.end)}`,
|
|
1459
|
+
source,
|
|
1460
|
+
)
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
function generatedResponseDescription(
|
|
1464
|
+
typeNode: ts.TypeNode | undefined,
|
|
1465
|
+
sourceFile: ts.SourceFile,
|
|
1466
|
+
): string {
|
|
1467
|
+
if (typeNode === undefined || typeNode.kind === ts.SyntaxKind.UnknownKeyword) {
|
|
1468
|
+
return 'Response shape is not specified by the OpenAPI contract.'
|
|
1469
|
+
}
|
|
1470
|
+
if (typeNode.kind === ts.SyntaxKind.VoidKeyword) return 'The endpoint has no response body.'
|
|
1471
|
+
|
|
1472
|
+
const responseType = ts.isArrayTypeNode(typeNode)
|
|
1473
|
+
? typeNode.elementType
|
|
1474
|
+
: typeNode
|
|
1475
|
+
const arraySuffix = ts.isArrayTypeNode(typeNode)
|
|
1476
|
+
? '[]'
|
|
1477
|
+
: ''
|
|
1478
|
+
if (ts.isTypeReferenceNode(responseType)) {
|
|
1479
|
+
const name = getEntityName(responseType.typeName)
|
|
1480
|
+
if (name !== 'Record' && name !== 'Promise' && name !== 'Array') {
|
|
1481
|
+
return `Response data is defined by {@link ${name}}${arraySuffix}.`
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
const typeText = typeNode.getText(sourceFile).replace(/\s+/gu, ' ')
|
|
1486
|
+
if (typeText === 'any') return 'Response shape is not specified by the OpenAPI contract.'
|
|
1487
|
+
return `Response data has type \`${typeText}\`.`
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
function generatedParameterDescription(name: string, typeText: string | undefined): string {
|
|
1491
|
+
if (name === 'params' || typeText === 'RequestParams') return 'Request options.'
|
|
1492
|
+
if (name === 'query' || typeText?.endsWith('Query')) return 'Query parameters.'
|
|
1493
|
+
if (name === 'data' || name === 'body' || typeText?.endsWith('Body')) return 'Request body.'
|
|
1494
|
+
return 'Path parameter.'
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
function findGeneratedRequestCall(node: ts.Node): ts.CallExpression | undefined {
|
|
1498
|
+
if (
|
|
1499
|
+
ts.isCallExpression(node) &&
|
|
1500
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
1501
|
+
node.expression.name.text === 'request'
|
|
1502
|
+
) {
|
|
1503
|
+
return node
|
|
1504
|
+
}
|
|
1505
|
+
for (const child of node.getChildren()) {
|
|
1506
|
+
const requestCall = findGeneratedRequestCall(child)
|
|
1507
|
+
if (requestCall !== undefined) return requestCall
|
|
1508
|
+
}
|
|
1509
|
+
return undefined
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
/** Add readable JSDoc tags that point to the final extracted parameter and response types. */
|
|
1513
|
+
export function addStandardApiMethodJsDoc(source: string, fileName: string): string {
|
|
1514
|
+
const sourceFile = parseTypeScript(source, fileName)
|
|
1515
|
+
const replacements: TextReplacement[] = []
|
|
1516
|
+
const lineEnding = source.includes('\r\n')
|
|
1517
|
+
? '\r\n'
|
|
1518
|
+
: '\n'
|
|
1519
|
+
|
|
1520
|
+
for (const statement of sourceFile.statements) {
|
|
1521
|
+
if (!ts.isClassDeclaration(statement)) continue
|
|
1522
|
+
for (const member of statement.members) {
|
|
1523
|
+
if (
|
|
1524
|
+
!ts.isPropertyDeclaration(member) ||
|
|
1525
|
+
member.initializer === undefined ||
|
|
1526
|
+
!ts.isArrowFunction(member.initializer)
|
|
1527
|
+
) {
|
|
1528
|
+
continue
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
const leadingText = source.slice(member.getFullStart(), member.getStart(sourceFile))
|
|
1532
|
+
const commentMatches = Array.from(leadingText.matchAll(/\/\*\*[\s\S]*?\*\//gu))
|
|
1533
|
+
const commentMatch = commentMatches.at(-1)
|
|
1534
|
+
if (commentMatch?.index === undefined || leadingText.slice(commentMatch.index + commentMatch[0].length).trim()) {
|
|
1535
|
+
continue
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
const memberName = getPropertyName(member.name)
|
|
1539
|
+
if (memberName === undefined) continue
|
|
1540
|
+
const parameterDocs = member.initializer.parameters.flatMap((parameter) => {
|
|
1541
|
+
if (!ts.isIdentifier(parameter.name)) return []
|
|
1542
|
+
const typeText = parameter.type?.getText(sourceFile).replace(/\s+/gu, ' ')
|
|
1543
|
+
const safeType = typeText !== undefined && !/[{}\r\n]/u.test(typeText)
|
|
1544
|
+
? typeText
|
|
1545
|
+
: undefined
|
|
1546
|
+
const parameterName = parameter.questionToken !== undefined || parameter.initializer !== undefined
|
|
1547
|
+
? `[${parameter.name.text}]`
|
|
1548
|
+
: parameter.name.text
|
|
1549
|
+
const typeTag = safeType === undefined
|
|
1550
|
+
? ''
|
|
1551
|
+
: `{${safeType}} `
|
|
1552
|
+
return [
|
|
1553
|
+
`@param ${typeTag}${parameterName} - ${generatedParameterDescription(parameter.name.text, safeType)}`,
|
|
1554
|
+
]
|
|
1555
|
+
})
|
|
1556
|
+
const requestCall = findGeneratedRequestCall(member.initializer)
|
|
1557
|
+
const responseDocs = [
|
|
1558
|
+
`@returns ${generatedResponseDescription(requestCall?.typeArguments?.[0], sourceFile)}`,
|
|
1559
|
+
]
|
|
1560
|
+
const docTags = [
|
|
1561
|
+
...parameterDocs,
|
|
1562
|
+
...responseDocs,
|
|
1563
|
+
]
|
|
1564
|
+
const commentLines = commentMatch[0]
|
|
1565
|
+
.replace(/^[\t ]*\* No description\r?$/gmu, '')
|
|
1566
|
+
.split(/\r?\n/u)
|
|
1567
|
+
while (
|
|
1568
|
+
commentLines.length > 1 &&
|
|
1569
|
+
/^[\t ]*(?:\*[\t ]*)?$/u.test(commentLines[1] ?? '')
|
|
1570
|
+
) {
|
|
1571
|
+
commentLines.splice(1, 1)
|
|
1572
|
+
}
|
|
1573
|
+
const comment = commentLines.join(lineEnding)
|
|
1574
|
+
const closePattern = /\r?\n([\t ]*)\*\/$/u
|
|
1575
|
+
const closeMatch = closePattern.exec(comment)
|
|
1576
|
+
if (closeMatch === null || closeMatch.index === undefined) {
|
|
1577
|
+
throw new Error(`Generated API JSDoc is not closed correctly: ${memberName}`)
|
|
1578
|
+
}
|
|
1579
|
+
const indent = closeMatch[1] ?? ' '
|
|
1580
|
+
const tags = docTags.map((tag) => `${indent}* ${tag}`).join(lineEnding)
|
|
1581
|
+
const replacement = comment.replace(
|
|
1582
|
+
closePattern,
|
|
1583
|
+
`${lineEnding}${indent}*${lineEnding}${tags}${lineEnding}${indent}*/`,
|
|
1584
|
+
)
|
|
1585
|
+
const commentStart = member.getFullStart() + commentMatch.index
|
|
1586
|
+
replacements.push({
|
|
1587
|
+
start: commentStart,
|
|
1588
|
+
end: commentStart + commentMatch[0].length,
|
|
1589
|
+
text: replacement,
|
|
1590
|
+
})
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
return replaceSourceRanges(source, replacements)
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
function extractInlineServiceTypes(
|
|
1598
|
+
service: GeneratedServiceSource,
|
|
1599
|
+
knownContractNames: ReadonlySet<string>,
|
|
1600
|
+
): { source: string, declarations: InlineTypeDeclaration[] } {
|
|
1601
|
+
const sourceFile = parseTypeScript(service.source, service.fileName)
|
|
1602
|
+
const replacements: TextReplacement[] = []
|
|
1603
|
+
const declarations: InlineTypeDeclaration[] = []
|
|
1604
|
+
const usedNames = new Set(knownContractNames)
|
|
1605
|
+
|
|
1606
|
+
const addInlineType = (methodName: string, suffix: string, typeNode: ts.TypeNode): void => {
|
|
1607
|
+
const name = toTypeName(methodName, suffix)
|
|
1608
|
+
if (usedNames.has(name)) {
|
|
1609
|
+
throw new Error(`Generated inline API type name is assigned more than once: ${name}`)
|
|
1610
|
+
}
|
|
1611
|
+
usedNames.add(name)
|
|
1612
|
+
declarations.push({
|
|
1613
|
+
name,
|
|
1614
|
+
source: `export type ${name} = ${typeNode.getText(sourceFile)};`,
|
|
1615
|
+
references: collectTypeReferences(typeNode, knownContractNames),
|
|
1616
|
+
})
|
|
1617
|
+
replacements.push({
|
|
1618
|
+
start: typeNode.getStart(sourceFile),
|
|
1619
|
+
end: typeNode.end,
|
|
1620
|
+
text: name,
|
|
1621
|
+
})
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
const visitRequestCalls = (node: ts.Node, methodName: string): void => {
|
|
1625
|
+
if (
|
|
1626
|
+
ts.isCallExpression(node) &&
|
|
1627
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
1628
|
+
node.expression.name.text === 'request'
|
|
1629
|
+
) {
|
|
1630
|
+
if (node.typeArguments === undefined || node.typeArguments.length !== 2) {
|
|
1631
|
+
throw new Error(
|
|
1632
|
+
`Generated API service ${service.fileName} method ${methodName} must use exactly two HTTP request type arguments.`,
|
|
1633
|
+
)
|
|
1634
|
+
}
|
|
1635
|
+
const responseType = node.typeArguments[0]
|
|
1636
|
+
if (responseType !== undefined && containsInlineObjectType(responseType)) {
|
|
1637
|
+
addInlineType(methodName, 'Response', responseType)
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
ts.forEachChild(node, (child) => visitRequestCalls(child, methodName))
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
for (const statement of sourceFile.statements) {
|
|
1644
|
+
if (!ts.isClassDeclaration(statement)) continue
|
|
1645
|
+
for (const member of statement.members) {
|
|
1646
|
+
if (!ts.isPropertyDeclaration(member) || member.initializer === undefined) continue
|
|
1647
|
+
const methodName = getPropertyName(member.name)
|
|
1648
|
+
if (methodName === undefined || !ts.isArrowFunction(member.initializer)) continue
|
|
1649
|
+
|
|
1650
|
+
for (const parameter of member.initializer.parameters) {
|
|
1651
|
+
if (!ts.isIdentifier(parameter.name) || parameter.type === undefined) continue
|
|
1652
|
+
if (!ts.isTypeLiteralNode(parameter.type)) continue
|
|
1653
|
+
const suffix =
|
|
1654
|
+
parameter.name.text === 'query'
|
|
1655
|
+
? 'Query'
|
|
1656
|
+
: parameter.name.text === 'data' || parameter.name.text === 'body'
|
|
1657
|
+
? 'Body'
|
|
1658
|
+
: undefined
|
|
1659
|
+
if (suffix !== undefined) addInlineType(methodName, suffix, parameter.type)
|
|
1660
|
+
}
|
|
1661
|
+
visitRequestCalls(member.initializer, methodName)
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
return {
|
|
1666
|
+
source: replaceSourceRanges(service.source, replacements),
|
|
1667
|
+
declarations,
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
function rewriteTagServiceImports(
|
|
1672
|
+
service: GeneratedServiceSource,
|
|
1673
|
+
source: string,
|
|
1674
|
+
knownContractNames: ReadonlySet<string>,
|
|
1675
|
+
outputPathByName: ReadonlyMap<string, string>,
|
|
1676
|
+
inlineTypeNames: readonly string[],
|
|
1677
|
+
inlineTypePath: string,
|
|
1678
|
+
): GeneratedServiceFile {
|
|
1679
|
+
const serviceOutputPath = service.outputPath ?? `services/${service.fileName}`
|
|
1680
|
+
const sourceFile = parseTypeScript(source, serviceOutputPath)
|
|
1681
|
+
const usedContractNames = collectTypeReferences(sourceFile, knownContractNames)
|
|
1682
|
+
const importedTypeNames = new Map<string, string>()
|
|
1683
|
+
const importEdits: TextReplacement[] = []
|
|
1684
|
+
|
|
1685
|
+
for (const statement of sourceFile.statements) {
|
|
1686
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
1687
|
+
continue
|
|
1688
|
+
const moduleName = statement.moduleSpecifier.text
|
|
1689
|
+
if (moduleName.endsWith('data-contracts')) {
|
|
1690
|
+
const bindings = statement.importClause?.namedBindings
|
|
1691
|
+
if (bindings !== undefined && ts.isNamedImports(bindings)) {
|
|
1692
|
+
for (const element of bindings.elements) {
|
|
1693
|
+
const sourceName = (element.propertyName ?? element.name).text
|
|
1694
|
+
if (!knownContractNames.has(sourceName)) {
|
|
1695
|
+
throw new Error(
|
|
1696
|
+
`Generated API service ${serviceOutputPath} imports missing contract type ${sourceName}.`,
|
|
1697
|
+
)
|
|
1698
|
+
}
|
|
1699
|
+
importedTypeNames.set(element.name.text, sourceName)
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
importEdits.push({
|
|
1703
|
+
start: statement.getStart(sourceFile),
|
|
1704
|
+
end: statement.end,
|
|
1705
|
+
text: '',
|
|
1706
|
+
})
|
|
1707
|
+
} else if (moduleName.endsWith('http-client')) {
|
|
1708
|
+
const relativeHttpClientPath = relativeModuleSpecifier(serviceOutputPath, 'http-client.ts')
|
|
1709
|
+
importEdits.push({
|
|
1710
|
+
start: statement.moduleSpecifier.getStart(sourceFile),
|
|
1711
|
+
end: statement.moduleSpecifier.end,
|
|
1712
|
+
text: JSON.stringify(relativeHttpClientPath),
|
|
1713
|
+
})
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
const importsBySpecifier = new Map<string, Set<string>>()
|
|
1718
|
+
const addTypeImport = (name: string, exportedName: string, outputPath: string): void => {
|
|
1719
|
+
const specifier = relativeModuleSpecifier(serviceOutputPath, outputPath)
|
|
1720
|
+
const names = importsBySpecifier.get(specifier) ?? new Set<string>()
|
|
1721
|
+
names.add(exportedName === name
|
|
1722
|
+
? name
|
|
1723
|
+
: `${exportedName} as ${name}`)
|
|
1724
|
+
importsBySpecifier.set(specifier, names)
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
for (const localName of usedContractNames) {
|
|
1728
|
+
const exportedName = importedTypeNames.get(localName) ?? localName
|
|
1729
|
+
const outputPath = outputPathByName.get(exportedName)
|
|
1730
|
+
if (outputPath === undefined) {
|
|
1731
|
+
throw new Error(
|
|
1732
|
+
`Generated API service ${serviceOutputPath} references unknown contract type ${exportedName}.`,
|
|
1733
|
+
)
|
|
1734
|
+
}
|
|
1735
|
+
addTypeImport(localName, exportedName, outputPath)
|
|
1736
|
+
}
|
|
1737
|
+
for (const name of inlineTypeNames) addTypeImport(name, name, inlineTypePath)
|
|
1738
|
+
|
|
1739
|
+
const importLines = Array.from(importsBySpecifier.entries())
|
|
1740
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
1741
|
+
.map(([specifier, names]) => {
|
|
1742
|
+
const sortedNames = Array.from(names).sort((left, right) => left.localeCompare(right))
|
|
1743
|
+
return `import type { ${sortedNames.join(', ')} } from ${JSON.stringify(specifier)};`
|
|
1744
|
+
})
|
|
1745
|
+
let rewrittenSource = replaceSourceRanges(source, importEdits)
|
|
1746
|
+
if (importLines.length > 0) {
|
|
1747
|
+
const rewrittenSourceFile = parseTypeScript(rewrittenSource, serviceOutputPath)
|
|
1748
|
+
const lastImportEnd = rewrittenSourceFile.statements.reduce(
|
|
1749
|
+
(lastEnd, statement) =>
|
|
1750
|
+
ts.isImportDeclaration(statement)
|
|
1751
|
+
? Math.max(lastEnd, statement.end)
|
|
1752
|
+
: lastEnd,
|
|
1753
|
+
0,
|
|
1754
|
+
)
|
|
1755
|
+
rewrittenSource = `${rewrittenSource.slice(0, lastImportEnd)}\n${importLines.join('\n')}\n${rewrittenSource.slice(lastImportEnd)}`
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
return { ...service, outputPath: serviceOutputPath, source: rewrittenSource }
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
function buildTagContractFiles(
|
|
1762
|
+
records: DeclarationRecord[],
|
|
1763
|
+
serviceSources: GeneratedServiceSource[],
|
|
1764
|
+
options: ApiCodegenOptions,
|
|
1765
|
+
originalSource: string,
|
|
1766
|
+
enumDefinitions?: readonly OpenApiEnumDefinition[],
|
|
1767
|
+
): { files: Map<string, string>, services: GeneratedServiceFile[] } {
|
|
1768
|
+
const recordsByName = new Map(records.map((record) => [record.name, record]))
|
|
1769
|
+
const contractNames = new Set(recordsByName.keys())
|
|
1770
|
+
const extractedServices = serviceSources.map((service) => ({
|
|
1771
|
+
service,
|
|
1772
|
+
extracted: extractInlineServiceTypes(service, contractNames),
|
|
1773
|
+
typePath: serviceTypeOutputPath(service),
|
|
1774
|
+
}))
|
|
1775
|
+
const serviceNamesByType = new Map<string, Set<string>>()
|
|
1776
|
+
for (const { service, extracted, typePath } of extractedServices) {
|
|
1777
|
+
const directTypes = importedContractNames(service.source, service.fileName)
|
|
1778
|
+
for (const declaration of extracted.declarations) {
|
|
1779
|
+
for (const reference of declaration.references) directTypes.add(reference)
|
|
1780
|
+
}
|
|
1781
|
+
const closure = collectClosure(directTypes, recordsByName)
|
|
1782
|
+
for (const typeName of closure) {
|
|
1783
|
+
const serviceNames = serviceNamesByType.get(typeName) ?? new Set<string>()
|
|
1784
|
+
serviceNames.add(typePath)
|
|
1785
|
+
serviceNamesByType.set(typeName, serviceNames)
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
const outputPathByName = new Map<string, string>()
|
|
1790
|
+
for (const record of records) {
|
|
1791
|
+
outputPathByName.set(
|
|
1792
|
+
record.name,
|
|
1793
|
+
getOutputPathForTag(record, serviceNamesByType, new Set(options.commonTypeNames)),
|
|
1794
|
+
)
|
|
1795
|
+
}
|
|
1796
|
+
const grouped = new Map<string, DeclarationRecord[]>()
|
|
1797
|
+
for (const record of records) {
|
|
1798
|
+
const outputPath = outputPathByName.get(record.name)
|
|
1799
|
+
if (outputPath === undefined) continue
|
|
1800
|
+
const group = grouped.get(outputPath) ?? []
|
|
1801
|
+
group.push(record)
|
|
1802
|
+
grouped.set(outputPath, group)
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
const inlineByPath = new Map<string, InlineTypeDeclaration[]>()
|
|
1806
|
+
for (const { extracted, typePath } of extractedServices) {
|
|
1807
|
+
if (extracted.declarations.length === 0) continue
|
|
1808
|
+
const group = inlineByPath.get(typePath) ?? []
|
|
1809
|
+
group.push(...extracted.declarations)
|
|
1810
|
+
inlineByPath.set(typePath, group)
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
const files = new Map<string, string>()
|
|
1814
|
+
const typeOutputPaths = new Set([
|
|
1815
|
+
...grouped.keys(),
|
|
1816
|
+
...inlineByPath.keys(),
|
|
1817
|
+
])
|
|
1818
|
+
for (const outputPath of typeOutputPaths) {
|
|
1819
|
+
files.set(
|
|
1820
|
+
outputPath,
|
|
1821
|
+
renderDeclarations(
|
|
1822
|
+
outputPath,
|
|
1823
|
+
grouped.get(outputPath) ?? [],
|
|
1824
|
+
outputPathByName,
|
|
1825
|
+
inlineByPath.get(outputPath) ?? [],
|
|
1826
|
+
enumDefinitions ?? [],
|
|
1827
|
+
),
|
|
1828
|
+
)
|
|
1829
|
+
}
|
|
1830
|
+
if (options.generateEnumDict) {
|
|
1831
|
+
files.set(
|
|
1832
|
+
'types/enum-dict.ts',
|
|
1833
|
+
renderEnumDictionary(
|
|
1834
|
+
records.filter((record) => outputPathByName.get(record.name) === 'types/enums.ts'),
|
|
1835
|
+
originalSource,
|
|
1836
|
+
enumDefinitions,
|
|
1837
|
+
),
|
|
1838
|
+
)
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
const exports = Array.from(typeOutputPaths).sort((left, right) => left.localeCompare(right))
|
|
1842
|
+
if (files.has('types/enum-dict.ts')) exports.push('types/enum-dict.ts')
|
|
1843
|
+
files.set(
|
|
1844
|
+
'data-contracts.ts',
|
|
1845
|
+
`${exports.map((file) => `export * from ${JSON.stringify(`./${file.replace(/\.ts$/u, '')}`)};`).join('\n')}\n`,
|
|
1846
|
+
)
|
|
1847
|
+
|
|
1848
|
+
const services = extractedServices.map(({ service, extracted, typePath }) =>
|
|
1849
|
+
rewriteTagServiceImports(
|
|
1850
|
+
service,
|
|
1851
|
+
extracted.source,
|
|
1852
|
+
contractNames,
|
|
1853
|
+
outputPathByName,
|
|
1854
|
+
extracted.declarations.map((declaration) => declaration.name),
|
|
1855
|
+
typePath,
|
|
1856
|
+
),
|
|
1857
|
+
)
|
|
1858
|
+
return { files, services }
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
function buildDtoVoEnumContractFiles(
|
|
1862
|
+
records: DeclarationRecord[],
|
|
1863
|
+
options: ApiCodegenOptions,
|
|
1864
|
+
originalSource: string,
|
|
1865
|
+
enumDefinitions?: readonly OpenApiEnumDefinition[],
|
|
1866
|
+
): Map<string, string> {
|
|
1867
|
+
const files = new Map<string, string>()
|
|
1868
|
+
const outputPathByName = new Map<string, string>()
|
|
1869
|
+
const grouped = new Map<string, DeclarationRecord[]>()
|
|
1870
|
+
|
|
1871
|
+
for (const record of records) {
|
|
1872
|
+
let outputPath: string
|
|
1873
|
+
if (record.kind === 'dto') outputPath = `dtos/${record.name}.ts`
|
|
1874
|
+
else if (record.kind === 'vo') outputPath = `vos/${record.name}.ts`
|
|
1875
|
+
else if (record.kind === 'enum') outputPath = 'enums/enums.ts'
|
|
1876
|
+
else outputPath = 'common.ts'
|
|
1877
|
+
outputPathByName.set(record.name, outputPath)
|
|
1878
|
+
const group = grouped.get(outputPath) ?? []
|
|
1879
|
+
group.push(record)
|
|
1880
|
+
grouped.set(outputPath, group)
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
for (const [outputPath, group] of grouped) {
|
|
1884
|
+
files.set(
|
|
1885
|
+
outputPath,
|
|
1886
|
+
renderDeclarations(
|
|
1887
|
+
outputPath,
|
|
1888
|
+
group,
|
|
1889
|
+
outputPathByName,
|
|
1890
|
+
[],
|
|
1891
|
+
outputPath.includes('enums')
|
|
1892
|
+
? enumDefinitions ?? []
|
|
1893
|
+
: [],
|
|
1894
|
+
),
|
|
1895
|
+
)
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
const dtoNames = records.filter((record) => record.kind === 'dto').map((record) => record.name)
|
|
1899
|
+
const voNames = records.filter((record) => record.kind === 'vo').map((record) => record.name)
|
|
1900
|
+
if (dtoNames.length > 0) {
|
|
1901
|
+
files.set(
|
|
1902
|
+
'dtos/index.ts',
|
|
1903
|
+
`${dtoNames.map((name) => `export * from ${JSON.stringify(`./${name}`)};`).join('\n')}\n`,
|
|
1904
|
+
)
|
|
1905
|
+
}
|
|
1906
|
+
if (voNames.length > 0) {
|
|
1907
|
+
files.set(
|
|
1908
|
+
'vos/index.ts',
|
|
1909
|
+
`${voNames.map((name) => `export * from ${JSON.stringify(`./${name}`)};`).join('\n')}\n`,
|
|
1910
|
+
)
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
const enumRecords = records.filter((record) => record.kind === 'enum')
|
|
1914
|
+
if (enumRecords.length > 0) {
|
|
1915
|
+
if (options.generateEnumDict) {
|
|
1916
|
+
files.set(
|
|
1917
|
+
'enums/enum-dict.ts',
|
|
1918
|
+
renderEnumDictionary(enumRecords, originalSource, enumDefinitions),
|
|
1919
|
+
)
|
|
1920
|
+
}
|
|
1921
|
+
const enumExports = ['export * from "./enums";']
|
|
1922
|
+
if (options.generateEnumDict) enumExports.push('export * from "./enum-dict";')
|
|
1923
|
+
files.set('enums/index.ts', `${enumExports.join('\n')}\n`)
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
const contractExports: string[] = []
|
|
1927
|
+
if (files.has('common.ts')) contractExports.push('export * from "./common";')
|
|
1928
|
+
if (files.has('dtos/index.ts')) contractExports.push('export * from "./dtos";')
|
|
1929
|
+
if (files.has('vos/index.ts')) contractExports.push('export * from "./vos";')
|
|
1930
|
+
if (files.has('enums/index.ts')) contractExports.push('export * from "./enums";')
|
|
1931
|
+
files.set('data-contracts.ts', `${contractExports.join('\n')}\n`)
|
|
1932
|
+
return files
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
export function splitGeneratedContracts(
|
|
1936
|
+
contractSource: string,
|
|
1937
|
+
serviceSources: GeneratedServiceSource[],
|
|
1938
|
+
options: ApiCodegenOptions,
|
|
1939
|
+
enumDefinitions?: readonly OpenApiEnumDefinition[],
|
|
1940
|
+
): SplitContractResult {
|
|
1941
|
+
const sourceFile = parseTypeScript(contractSource, 'data-contracts.ts')
|
|
1942
|
+
const declarations = sourceFile.statements.filter(isContractDeclaration)
|
|
1943
|
+
const names = declarations.map((declaration) => declaration.name.text)
|
|
1944
|
+
if (new Set(names).size !== names.length) {
|
|
1945
|
+
throw new Error('Generated data-contracts.ts contains duplicate declaration names.')
|
|
1946
|
+
}
|
|
1947
|
+
const knownNames = new Set(names)
|
|
1948
|
+
const records: DeclarationRecord[] = declarations.map((declaration) => ({
|
|
1949
|
+
declaration,
|
|
1950
|
+
name: declaration.name.text,
|
|
1951
|
+
source: contractSource.slice(declaration.getFullStart(), declaration.end).trim(),
|
|
1952
|
+
references: collectTypeReferences(declaration, knownNames),
|
|
1953
|
+
kind: 'common',
|
|
1954
|
+
}))
|
|
1955
|
+
const warnings: string[] = []
|
|
1956
|
+
const enumDefinitionNames = new Set(enumDefinitions?.map((definition) => definition.name) ?? [])
|
|
1957
|
+
if (options.splitMode === 'dto-vo-enum') {
|
|
1958
|
+
for (const record of records) {
|
|
1959
|
+
record.kind = enumDefinitionNames.has(record.name)
|
|
1960
|
+
? 'enum'
|
|
1961
|
+
: determineModelKind(record.name, record.declaration, options, warnings)
|
|
1962
|
+
}
|
|
1963
|
+
} else {
|
|
1964
|
+
for (const record of records) {
|
|
1965
|
+
if (
|
|
1966
|
+
enumDefinitionNames.has(record.name) ||
|
|
1967
|
+
ts.isEnumDeclaration(record.declaration) ||
|
|
1968
|
+
options.nameMapping.some((mapping) => mapping.type === 'enum' && record.name.endsWith(mapping.suffix))
|
|
1969
|
+
) {
|
|
1970
|
+
record.kind = 'enum'
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
const tagSplit =
|
|
1975
|
+
options.splitMode === 'tag'
|
|
1976
|
+
? buildTagContractFiles(records, serviceSources, options, contractSource, enumDefinitions)
|
|
1977
|
+
: undefined
|
|
1978
|
+
const files = tagSplit?.files ?? buildDtoVoEnumContractFiles(records, options, contractSource, enumDefinitions)
|
|
1979
|
+
|
|
1980
|
+
const services =
|
|
1981
|
+
tagSplit?.services ??
|
|
1982
|
+
serviceSources.map((service) => {
|
|
1983
|
+
const content = service.source.replace(
|
|
1984
|
+
/from (["'])\.\/(data-contracts|http-client)\1/gu,
|
|
1985
|
+
(_match, quote: string, name: string) => `from ${quote}../${name}${quote}`,
|
|
1986
|
+
)
|
|
1987
|
+
return { ...service, outputPath: `services/${service.fileName}`, source: content }
|
|
1988
|
+
})
|
|
1989
|
+
validateGeneratedContractExports(files, services)
|
|
1990
|
+
return { files, services, warnings }
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
export function buildGeneratedApiIndex(services: GeneratedServiceFile[]): string {
|
|
1994
|
+
const serviceExports = services
|
|
1995
|
+
.map((service) => {
|
|
1996
|
+
const modulePath = `./${service.outputPath.replace(/\.ts$/u, '')}`
|
|
1997
|
+
return `export * from ${JSON.stringify(modulePath)};`
|
|
1998
|
+
})
|
|
1999
|
+
.sort((left, right) => left.localeCompare(right))
|
|
2000
|
+
serviceExports.push('export * from "./data-contracts";')
|
|
2001
|
+
serviceExports.push('export * from "./http-client";')
|
|
2002
|
+
return `${serviceExports.join('\n')}\n`
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
export function isGeneratedServiceFile(fileName: string, source: string): boolean {
|
|
2006
|
+
if (fileName === 'data-contracts.ts' || fileName === 'http-client.ts') return false
|
|
2007
|
+
const sourceFile = parseTypeScript(source, fileName)
|
|
2008
|
+
return sourceFile.statements.some((statement) => {
|
|
2009
|
+
if (!ts.isClassDeclaration(statement) || statement.name === undefined) return false
|
|
2010
|
+
return (
|
|
2011
|
+
statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ??
|
|
2012
|
+
false
|
|
2013
|
+
)
|
|
2014
|
+
})
|
|
2015
|
+
}
|