@oj-module/runtime 0.1.5
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/LICENSE +21 -0
- package/README.md +119 -0
- package/dist/api/notifications/index.d.ts +2 -0
- package/dist/api/system/menu/index.d.ts +6 -0
- package/dist/api/system/menu/types.d.ts +19 -0
- package/dist/api/system/role/api/client.d.ts +19 -0
- package/dist/api/system/role/api/client.schemas.d.ts +94 -0
- package/dist/api/system/role/index.d.ts +9 -0
- package/dist/api/system/role/types.d.ts +9 -0
- package/dist/api/user/index.d.ts +12 -0
- package/dist/api/user/types.d.ts +26 -0
- package/dist/components/access-control/index.d.ts +15 -0
- package/dist/components/basic-button/index.d.ts +7 -0
- package/dist/components/basic-content/index.d.ts +7 -0
- package/dist/components/basic-form/form-items/form-avatar-item.d.ts +6 -0
- package/dist/components/basic-form/form-items/form-tree-item.d.ts +13 -0
- package/dist/components/basic-form/form-items/index.d.ts +2 -0
- package/dist/components/basic-form/index.d.ts +1 -0
- package/dist/components/basic-table/constants.d.ts +1 -0
- package/dist/components/basic-table/index.d.ts +12 -0
- package/dist/components/basic-table/styles.d.ts +6 -0
- package/dist/components/exception-page/index.d.ts +3 -0
- package/dist/components/fullscreen-button/index.d.ts +17 -0
- package/dist/components/global-spin/index.d.ts +6 -0
- package/dist/components/iframe/index.d.ts +1 -0
- package/dist/components/jss-theme-provider/index.d.ts +26 -0
- package/dist/components/not-found/index.d.ts +6 -0
- package/dist/components/page-error/index.d.ts +2 -0
- package/dist/components/scrollbar/index.d.ts +7 -0
- package/dist/components/unknown-component/index.d.ts +6 -0
- package/dist/constants/options.d.ts +9 -0
- package/dist/contract/define-api.d.ts +43 -0
- package/dist/contract/define-api.js +44 -0
- package/dist/contract/errors.d.ts +16 -0
- package/dist/contract/errors.js +20 -0
- package/dist/contract/index.d.ts +15 -0
- package/dist/contract/index.js +13 -0
- package/dist/contract/scoped-request-like.d.ts +25 -0
- package/dist/contract/scoped-request-like.js +6 -0
- package/dist/hooks/use-access/constants.d.ts +24 -0
- package/dist/hooks/use-access/index.d.ts +9 -0
- package/dist/hooks/use-css-var/index.d.ts +17 -0
- package/dist/hooks/use-current-route/index.d.ts +6 -0
- package/dist/hooks/use-device-type/index.d.ts +9 -0
- package/dist/hooks/use-language/index.d.ts +5 -0
- package/dist/hooks/use-layout-menu/index.d.ts +6 -0
- package/dist/hooks/use-layout-style/index.d.ts +19 -0
- package/dist/hooks/use-preferences/index.d.ts +61 -0
- package/dist/icons/index.d.ts +3 -0
- package/dist/icons/local-icons.d.ts +17 -0
- package/dist/icons/menu-icons.d.ts +4 -0
- package/dist/icons/ri.d.ts +14 -0
- package/dist/icons/types.d.ts +9 -0
- package/dist/index.d.ts +44 -0
- package/dist/layout/constants.d.ts +50 -0
- package/dist/layout/container-layout/index.d.ts +11 -0
- package/dist/layout/fullscreen-layout/index.d.ts +9 -0
- package/dist/layout/hooks/index.d.ts +1 -0
- package/dist/layout/hooks/use-layout.d.ts +20 -0
- package/dist/layout/keep-alive-layer/index.d.ts +15 -0
- package/dist/layout/layout-content/index.d.ts +3 -0
- package/dist/layout/layout-effects/index.d.ts +9 -0
- package/dist/layout/layout-footer/index.d.ts +5 -0
- package/dist/layout/layout-header/components/fullscreen-button.d.ts +2 -0
- package/dist/layout/layout-header/components/language-button.d.ts +2 -0
- package/dist/layout/layout-header/components/theme-button.d.ts +9 -0
- package/dist/layout/layout-header/components/user-menu.d.ts +2 -0
- package/dist/layout/layout-header/index.d.ts +5 -0
- package/dist/layout/layout-menu/index.d.ts +17 -0
- package/dist/layout/layout-menu/style.d.ts +6 -0
- package/dist/layout/layout-menu/types.d.ts +26 -0
- package/dist/layout/layout-menu/use-menu.d.ts +7 -0
- package/dist/layout/layout-menu/utils.d.ts +49 -0
- package/dist/layout/layout-mixed-sidebar/first-column-menu.d.ts +9 -0
- package/dist/layout/layout-mixed-sidebar/index.d.ts +14 -0
- package/dist/layout/layout-mobile-menu/index.d.ts +1 -0
- package/dist/layout/layout-root/index.d.ts +5 -0
- package/dist/layout/layout-sidebar/index.d.ts +5 -0
- package/dist/layout/layout-tabbar/components/draggable-tab-bar.d.ts +16 -0
- package/dist/layout/layout-tabbar/components/tab-maximize.d.ts +10 -0
- package/dist/layout/layout-tabbar/components/tab-options.d.ts +17 -0
- package/dist/layout/layout-tabbar/hooks/use-dropdown-menu.d.ts +26 -0
- package/dist/layout/layout-tabbar/index.d.ts +5 -0
- package/dist/layout/layout-tabbar/style.d.ts +6 -0
- package/dist/layout/parent-layout/index.d.ts +1 -0
- package/dist/layout/widgets/breadcrumb-views/index.d.ts +1 -0
- package/dist/layout/widgets/global-search/components/search-footer.d.ts +5 -0
- package/dist/layout/widgets/global-search/components/search-panel.d.ts +11 -0
- package/dist/layout/widgets/global-search/index.d.ts +1 -0
- package/dist/layout/widgets/logo/index.d.ts +9 -0
- package/dist/layout/widgets/notification/index.d.ts +19 -0
- package/dist/layout/widgets/notification/notification-container.d.ts +2 -0
- package/dist/layout/widgets/notification/types.d.ts +7 -0
- package/dist/layout/widgets/preferences/blocks/animation/index.d.ts +1 -0
- package/dist/layout/widgets/preferences/blocks/footer/index.d.ts +1 -0
- package/dist/layout/widgets/preferences/blocks/general/index.d.ts +1 -0
- package/dist/layout/widgets/preferences/blocks/general/utils.d.ts +1 -0
- package/dist/layout/widgets/preferences/blocks/index.d.ts +7 -0
- package/dist/layout/widgets/preferences/blocks/layout/constants.d.ts +4 -0
- package/dist/layout/widgets/preferences/blocks/layout/index.d.ts +1 -0
- package/dist/layout/widgets/preferences/blocks/sidebar/index.d.ts +1 -0
- package/dist/layout/widgets/preferences/blocks/tabbar/index.d.ts +1 -0
- package/dist/layout/widgets/preferences/blocks/theme/builtin.d.ts +1 -0
- package/dist/layout/widgets/preferences/blocks/theme/index.d.ts +2 -0
- package/dist/layout/widgets/preferences/blocks/theme/theme.d.ts +1 -0
- package/dist/layout/widgets/preferences/index.d.ts +2 -0
- package/dist/layout/widgets/preferences/number-input-spinner.d.ts +10 -0
- package/dist/layout/widgets/preferences/select-item.d.ts +9 -0
- package/dist/layout/widgets/preferences/switch-item.d.ts +8 -0
- package/dist/layout/widgets/preferences/text-input.d.ts +8 -0
- package/dist/layout/widgets/sider-trigger/index.d.ts +5 -0
- package/dist/locales/helper.d.ts +15 -0
- package/dist/locales/index.d.ts +18 -0
- package/dist/locales/t.d.ts +10 -0
- package/dist/module-loader/define-module.d.ts +11 -0
- package/dist/module-loader/index.d.ts +20 -0
- package/dist/module-loader/keep-alive.d.ts +18 -0
- package/dist/module-loader/semver.d.ts +8 -0
- package/dist/module-loader/slots.d.ts +9 -0
- package/dist/module-loader/types.d.ts +91 -0
- package/dist/pages/login/index.d.ts +1 -0
- package/dist/plugins/hide-loading.d.ts +1 -0
- package/dist/plugins/loading.d.ts +7 -0
- package/dist/router/constants.d.ts +1 -0
- package/dist/router/extra-info/index.d.ts +1 -0
- package/dist/router/extra-info/route-path.d.ts +22 -0
- package/dist/router/guard/auth-guard.d.ts +21 -0
- package/dist/router/guard/index.d.ts +1 -0
- package/dist/router/guard/utils.d.ts +2 -0
- package/dist/router/index.d.ts +12 -0
- package/dist/router/routes/config.d.ts +7 -0
- package/dist/router/routes/core/auth.d.ts +13 -0
- package/dist/router/routes/core/exception.d.ts +12 -0
- package/dist/router/routes/core/fallback.d.ts +3 -0
- package/dist/router/routes/core/index.d.ts +2 -0
- package/dist/router/routes/index.d.ts +118 -0
- package/dist/router/types.d.ts +90 -0
- package/dist/router/utils/add-route-id-by-path.d.ts +81 -0
- package/dist/router/utils/ascending.d.ts +99 -0
- package/dist/router/utils/flatten-routes.d.ts +5 -0
- package/dist/router/utils/generate-menu-items-from-routes.d.ts +10 -0
- package/dist/router/utils/generate-routes-from-backend.d.ts +79 -0
- package/dist/router/utils/generate-routes-from-frontend.d.ts +5 -0
- package/dist/router/utils/merge-route-modules.d.ts +2 -0
- package/dist/router/utils/remove-trailing-slash.d.ts +10 -0
- package/dist/router/utils/resolve-layout.d.ts +17 -0
- package/dist/router/utils/resolve-login-route.d.ts +31 -0
- package/dist/runtime.js +27121 -0
- package/dist/store/access.d.ts +14 -0
- package/dist/store/api-provider.d.ts +47 -0
- package/dist/store/auth-provider.d.ts +19 -0
- package/dist/store/auth.d.ts +20 -0
- package/dist/store/global.d.ts +12 -0
- package/dist/store/preferences/index.d.ts +80 -0
- package/dist/store/preferences/types.d.ts +254 -0
- package/dist/store/tabs.d.ts +343 -0
- package/dist/store/user.d.ts +7 -0
- package/dist/types/app-info.d.ts +18 -0
- package/dist/utils/cn/index.d.ts +2 -0
- package/dist/utils/dom/index.d.ts +14 -0
- package/dist/utils/get-all-expanded-keys/index.d.ts +1 -0
- package/dist/utils/get-app-info/index.d.ts +13 -0
- package/dist/utils/get-app-namespace/index.d.ts +1 -0
- package/dist/utils/get-redirect-path.d.ts +8 -0
- package/dist/utils/iframe-guard.d.ts +18 -0
- package/dist/utils/is/index.d.ts +56 -0
- package/dist/utils/is-dark-theme/index.d.ts +7 -0
- package/dist/utils/is-light-theme/index.d.ts +7 -0
- package/dist/utils/is-windows-os/index.d.ts +6 -0
- package/dist/utils/progress/index.d.ts +3 -0
- package/dist/utils/remember-route/index.d.ts +1 -0
- package/dist/utils/request/constants.d.ts +5 -0
- package/dist/utils/request/envelope.d.ts +5 -0
- package/dist/utils/request/error-response.d.ts +12 -0
- package/dist/utils/request/global-progress.d.ts +21 -0
- package/dist/utils/request/go-login.d.ts +6 -0
- package/dist/utils/request/header-safe.d.ts +1 -0
- package/dist/utils/request/index.d.ts +1 -0
- package/dist/utils/request/refresh.d.ts +11 -0
- package/dist/utils/request/scoped.d.ts +17 -0
- package/dist/utils/request/whitelist.d.ts +1 -0
- package/dist/utils/static-antd/index.d.ts +12 -0
- package/dist/utils/toggle-html-class/index.d.ts +9 -0
- package/dist/utils/tree/index.d.ts +35 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 CondorHero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# @oj-module/runtime
|
|
2
|
+
|
|
3
|
+
框架运行时。模块工程**唯一**应该 import 的框架入口。
|
|
4
|
+
|
|
5
|
+
## 定位
|
|
6
|
+
|
|
7
|
+
| | |
|
|
8
|
+
|---|---|
|
|
9
|
+
| 消费者 | 模块工程(`entry.ts` 与页面代码)、宿主(`@oj-module/cli` 内置 `shell-dist`) |
|
|
10
|
+
| 产物 | `dist/runtime.js`(单文件 ESM)。`dist/runtime.d.ts` 尚未产出,类型出口在 P3 随出口冻结一起收敛 |
|
|
11
|
+
| 加载方式 | 由宿主 importmap 映射为 `/assets/runtime.js`,全站唯一实例(单例,见设计文档 D5) |
|
|
12
|
+
|
|
13
|
+
产物只保留**相对路径**代码;所有裸说明符(`react` / `antd` / `react-router` …)都被 external,交给宿主 importmap 解析。这是单例的实现前提——模块与宿主 import 到的是同一个 URL,因而是同一份实例。
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
模块工程把它放在 `devDependencies`(仅用于类型检查与 IDE 跳转),运行期由宿主提供:
|
|
18
|
+
|
|
19
|
+
```jsonc
|
|
20
|
+
{
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@oj-module/runtime": "^x.y.z"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 对外出口
|
|
28
|
+
|
|
29
|
+
出口在 `src/index.ts` 收敛,当前为最小集合(P3 阶段依据实际用量冻结):
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// 模块契约
|
|
33
|
+
import type {
|
|
34
|
+
AppRouteRecordRaw,
|
|
35
|
+
ModuleDefinition,
|
|
36
|
+
RouteMeta,
|
|
37
|
+
} from "@oj-module/runtime";
|
|
38
|
+
import {
|
|
39
|
+
BasicContent,
|
|
40
|
+
defineModule,
|
|
41
|
+
} from "@oj-module/runtime";
|
|
42
|
+
|
|
43
|
+
// 宿主侧模块加载(模块工程一般不需要)
|
|
44
|
+
import {
|
|
45
|
+
getModule,
|
|
46
|
+
getModules,
|
|
47
|
+
getRegisteredApiPrefix,
|
|
48
|
+
getRegisteredStore,
|
|
49
|
+
getRoutes,
|
|
50
|
+
loadAll,
|
|
51
|
+
} from "@oj-module/runtime";
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
> `antd`、`react`、`react-router`、`@tanstack/react-query` 等共享依赖**不从 runtime 转出**。模块请直接 import 这些包,由 importmap 命中宿主提供的同一份实例。
|
|
55
|
+
|
|
56
|
+
## 模块定义示例
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import type { AppRouteRecordRaw, ModuleDefinition } from "@oj-module/runtime";
|
|
60
|
+
import { defineModule } from "@oj-module/runtime";
|
|
61
|
+
import { lazy } from "react";
|
|
62
|
+
|
|
63
|
+
const routes: AppRouteRecordRaw[] = [
|
|
64
|
+
{
|
|
65
|
+
path: "/demo",
|
|
66
|
+
Component: lazy(() => import("./pages/demo")),
|
|
67
|
+
handle: {
|
|
68
|
+
title: "demo:menu.demo",
|
|
69
|
+
// 布局语义:container(默认)| parent | none
|
|
70
|
+
layout: "container",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
export default defineModule({
|
|
76
|
+
name: "demo",
|
|
77
|
+
description: "示例模块",
|
|
78
|
+
version: "1.0.0",
|
|
79
|
+
routes,
|
|
80
|
+
i18n: {
|
|
81
|
+
"zh-CN": () => import("./locales/zh-CN.json"),
|
|
82
|
+
"en-US": () => import("./locales/en-US.json"),
|
|
83
|
+
},
|
|
84
|
+
} satisfies ModuleDefinition);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 内置能力(非出口,但影响模块行为)
|
|
88
|
+
|
|
89
|
+
- **路由级缓存**:KeepAlive 位于宿主固定层,缓存开关由各模块路由的 `handle.keepAlive` 汇总得出,不依赖任何具体布局组件是否存在。
|
|
90
|
+
- **布局语义**:`handle.layout` 决定该路由用哪层布局包裹(`container` / `parent` / `none`)。迁移期未声明时按 `container` 处理,保持既有行为。
|
|
91
|
+
- **兜底页**:`NotFound`(404)与 `UnknownComponent`(后端下发路由找不到前端组件)由框架内置,模块无需提供;需要自定义时用自己的路由覆盖。
|
|
92
|
+
|
|
93
|
+
## 构建
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# 只出 JS(shell 构建链路走这条,当前唯一可用的构建)
|
|
97
|
+
pnpm --filter @oj-module/runtime exec vite build
|
|
98
|
+
|
|
99
|
+
# vite build + tsc 出 d.ts + 重写 d.ts 里的 #src/* 说明符
|
|
100
|
+
# ⚠️ 目前 tsc 声明阶段仍有 3 处 declaration-emit 报错,属 P3 待办
|
|
101
|
+
pnpm --filter @oj-module/runtime build
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`dist/` 是**随仓库分发的预置产物**(`.gitignore` 中已显式放行),改动 runtime 源码后需要重新构建并提交。
|
|
105
|
+
|
|
106
|
+
## 目录约定
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
packages/runtime/src/
|
|
110
|
+
├── index.ts # 唯一对外出口
|
|
111
|
+
├── components/ # 框架组件(含 not-found / unknown-component 兜底页)
|
|
112
|
+
├── layout/ # 布局与 keep-alive-layer(宿主固定层)
|
|
113
|
+
├── module-loader/ # 模块加载、拓扑排序、生命周期、i18n 合并
|
|
114
|
+
├── router/ # 路由类型、工具、核心路由表
|
|
115
|
+
├── locales/ # 框架文案(模块文案由模块自带)
|
|
116
|
+
└── store/ # 框架状态
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
内部引用统一走 `#src/*` 子路径 imports;**禁止**出现 `#modules/*`(框架不得反向依赖业务模块,CI 有卡口)。
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MenuItemType } from "./types";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export declare function fetchMenuList(data: any): Promise<ListData<MenuItemType>>;
|
|
4
|
+
export declare function fetchAddMenuItem(data: MenuItemType): Promise<string>;
|
|
5
|
+
export declare function fetchUpdateMenuItem(data: MenuItemType): Promise<string>;
|
|
6
|
+
export declare function fetchDeleteMenuItem(id: number): Promise<string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface MenuItemType {
|
|
2
|
+
parentId: string;
|
|
3
|
+
id: number;
|
|
4
|
+
menuType: 0 | 1 | 2 | 3;
|
|
5
|
+
name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
component: string;
|
|
8
|
+
order: number;
|
|
9
|
+
icon: string;
|
|
10
|
+
currentActiveMenu: string;
|
|
11
|
+
iframeLink: string;
|
|
12
|
+
keepAlive: number;
|
|
13
|
+
externalLink: string;
|
|
14
|
+
hideInMenu: number;
|
|
15
|
+
ignoreAccess: number;
|
|
16
|
+
status: 1;
|
|
17
|
+
createTime: number;
|
|
18
|
+
updateTime: number;
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { schemas } from "./client.schemas";
|
|
3
|
+
export type FetchAddRoleItemBody = z.input<(typeof schemas)["fetchAddRoleItem"]["body"]>;
|
|
4
|
+
export type FetchAddRoleItemData = z.infer<(typeof schemas)["fetchAddRoleItem"]["data"]>;
|
|
5
|
+
export declare function fetchAddRoleItem(body: FetchAddRoleItemBody): Promise<FetchAddRoleItemData>;
|
|
6
|
+
export type FetchDeleteRoleItemBody = z.input<(typeof schemas)["fetchDeleteRoleItem"]["body"]>;
|
|
7
|
+
export type FetchDeleteRoleItemData = z.infer<(typeof schemas)["fetchDeleteRoleItem"]["data"]>;
|
|
8
|
+
export declare function fetchDeleteRoleItem(body: FetchDeleteRoleItemBody): Promise<FetchDeleteRoleItemData>;
|
|
9
|
+
export type FetchMenuByRoleIdQuery = z.input<(typeof schemas)["fetchMenuByRoleId"]["query"]>;
|
|
10
|
+
export type FetchMenuByRoleIdData = z.infer<(typeof schemas)["fetchMenuByRoleId"]["data"]>;
|
|
11
|
+
export declare function fetchMenuByRoleId(query: FetchMenuByRoleIdQuery): Promise<FetchMenuByRoleIdData>;
|
|
12
|
+
export type FetchRoleListQuery = z.input<(typeof schemas)["fetchRoleList"]["query"]>;
|
|
13
|
+
export type FetchRoleListData = z.infer<(typeof schemas)["fetchRoleList"]["data"]>;
|
|
14
|
+
export declare function fetchRoleList(query: FetchRoleListQuery): Promise<FetchRoleListData>;
|
|
15
|
+
export type FetchRoleMenuData = z.infer<(typeof schemas)["fetchRoleMenu"]["data"]>;
|
|
16
|
+
export declare function fetchRoleMenu(): Promise<FetchRoleMenuData>;
|
|
17
|
+
export type FetchUpdateRoleItemBody = z.input<(typeof schemas)["fetchUpdateRoleItem"]["body"]>;
|
|
18
|
+
export type FetchUpdateRoleItemData = z.infer<(typeof schemas)["fetchUpdateRoleItem"]["data"]>;
|
|
19
|
+
export declare function fetchUpdateRoleItem(body: FetchUpdateRoleItemBody): Promise<FetchUpdateRoleItemData>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const schemas: {
|
|
3
|
+
fetchAddRoleItem: {
|
|
4
|
+
body: z.ZodObject<{
|
|
5
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
code: z.ZodString;
|
|
8
|
+
status: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<0>]>;
|
|
9
|
+
remark: z.ZodOptional<z.ZodString>;
|
|
10
|
+
menus: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
data: z.ZodObject<{
|
|
13
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
name: z.ZodString;
|
|
15
|
+
code: z.ZodString;
|
|
16
|
+
status: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<0>]>;
|
|
17
|
+
remark: z.ZodOptional<z.ZodString>;
|
|
18
|
+
menus: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
};
|
|
21
|
+
fetchDeleteRoleItem: {
|
|
22
|
+
body: z.ZodNumber;
|
|
23
|
+
data: z.ZodNumber;
|
|
24
|
+
};
|
|
25
|
+
fetchMenuByRoleId: {
|
|
26
|
+
query: z.ZodObject<{
|
|
27
|
+
id: z.ZodNumber;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
data: z.ZodArray<z.ZodNumber>;
|
|
30
|
+
};
|
|
31
|
+
fetchRoleList: {
|
|
32
|
+
query: z.ZodObject<{
|
|
33
|
+
name: z.ZodOptional<z.ZodString>;
|
|
34
|
+
code: z.ZodOptional<z.ZodString>;
|
|
35
|
+
status: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<0>]>>;
|
|
36
|
+
current: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
data: z.ZodObject<{
|
|
40
|
+
list: z.ZodArray<z.ZodObject<{
|
|
41
|
+
id: z.ZodNumber;
|
|
42
|
+
createTime: z.ZodNumber;
|
|
43
|
+
updateTime: z.ZodNumber;
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
code: z.ZodString;
|
|
46
|
+
status: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<0>]>;
|
|
47
|
+
remark: z.ZodString;
|
|
48
|
+
}, z.core.$strip>>;
|
|
49
|
+
total: z.ZodNumber;
|
|
50
|
+
pageSize: z.ZodNumber;
|
|
51
|
+
current: z.ZodNumber;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
};
|
|
54
|
+
fetchRoleMenu: {
|
|
55
|
+
data: z.ZodArray<z.ZodObject<{
|
|
56
|
+
parentId: z.ZodString;
|
|
57
|
+
id: z.ZodNumber;
|
|
58
|
+
menuType: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<3>]>;
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
path: z.ZodString;
|
|
61
|
+
component: z.ZodString;
|
|
62
|
+
order: z.ZodNumber;
|
|
63
|
+
icon: z.ZodString;
|
|
64
|
+
currentActiveMenu: z.ZodString;
|
|
65
|
+
iframeLink: z.ZodString;
|
|
66
|
+
keepAlive: z.ZodNumber;
|
|
67
|
+
externalLink: z.ZodString;
|
|
68
|
+
hideInMenu: z.ZodNumber;
|
|
69
|
+
ignoreAccess: z.ZodNumber;
|
|
70
|
+
permission: z.ZodString;
|
|
71
|
+
status: z.ZodNumber;
|
|
72
|
+
createTime: z.ZodNumber;
|
|
73
|
+
updateTime: z.ZodNumber;
|
|
74
|
+
}, z.core.$strip>>;
|
|
75
|
+
};
|
|
76
|
+
fetchUpdateRoleItem: {
|
|
77
|
+
body: z.ZodObject<{
|
|
78
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
code: z.ZodString;
|
|
81
|
+
status: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<0>]>;
|
|
82
|
+
remark: z.ZodOptional<z.ZodString>;
|
|
83
|
+
menus: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
data: z.ZodObject<{
|
|
86
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
name: z.ZodString;
|
|
88
|
+
code: z.ZodString;
|
|
89
|
+
status: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<0>]>;
|
|
90
|
+
remark: z.ZodOptional<z.ZodString>;
|
|
91
|
+
menus: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FetchAddRoleItemBody, FetchAddRoleItemData, FetchDeleteRoleItemBody, FetchDeleteRoleItemData, FetchMenuByRoleIdData, FetchMenuByRoleIdQuery, FetchRoleListData, FetchRoleListQuery, FetchRoleMenuData, FetchUpdateRoleItemBody, FetchUpdateRoleItemData } from "./api/client";
|
|
2
|
+
export declare function fetchRoleList(query: FetchRoleListQuery): Promise<FetchRoleListData>;
|
|
3
|
+
export declare function fetchAddRoleItem(body: FetchAddRoleItemBody): Promise<FetchAddRoleItemData>;
|
|
4
|
+
export declare function fetchUpdateRoleItem(body: FetchUpdateRoleItemBody): Promise<FetchUpdateRoleItemData>;
|
|
5
|
+
export declare function fetchDeleteRoleItem(body: FetchDeleteRoleItemBody): Promise<FetchDeleteRoleItemData>;
|
|
6
|
+
export declare function fetchRoleMenu(): Promise<FetchRoleMenuData>;
|
|
7
|
+
export declare function fetchMenuByRoleId(query: FetchMenuByRoleIdQuery): Promise<FetchMenuByRoleIdData>;
|
|
8
|
+
export { fetchAddMenuItem, fetchDeleteMenuItem, fetchMenuList, fetchUpdateMenuItem, } from "../menu";
|
|
9
|
+
export * from "./types";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AppRouteRecordRaw } from "../../router/types";
|
|
2
|
+
import type { AuthType, LoginInfo, UserInfoType } from "./types";
|
|
3
|
+
export * from "./types";
|
|
4
|
+
export declare function fetchLogin(data: LoginInfo): Promise<AuthType>;
|
|
5
|
+
export declare function fetchLogout(data?: {
|
|
6
|
+
readonly refreshToken?: string;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
export declare function fetchAsyncRoutes(): Promise<AppRouteRecordRaw[]>;
|
|
9
|
+
export declare function fetchUserInfo(): Promise<UserInfoType>;
|
|
10
|
+
export declare function fetchRefreshToken(data: {
|
|
11
|
+
readonly refreshToken: string;
|
|
12
|
+
}): Promise<AuthType>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AppRouteRecordRaw } from "../../router/types";
|
|
2
|
+
export interface AuthType {
|
|
3
|
+
token: string;
|
|
4
|
+
refreshToken: string;
|
|
5
|
+
}
|
|
6
|
+
export interface LoginInfo {
|
|
7
|
+
username: string;
|
|
8
|
+
password: string;
|
|
9
|
+
}
|
|
10
|
+
export interface UserInfoType {
|
|
11
|
+
id: string;
|
|
12
|
+
avatar: string;
|
|
13
|
+
username: string;
|
|
14
|
+
email: string;
|
|
15
|
+
phoneNumber: string;
|
|
16
|
+
description: string;
|
|
17
|
+
roles: Array<string>;
|
|
18
|
+
/** 权限码列表(后端下发;模块级 requiredPermissions 门禁消费,P7.12) */
|
|
19
|
+
permissions?: Array<string>;
|
|
20
|
+
menus?: AppRouteRecordRaw[];
|
|
21
|
+
}
|
|
22
|
+
export interface AuthListProps {
|
|
23
|
+
label: string;
|
|
24
|
+
name: string;
|
|
25
|
+
auth: string[];
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
interface AccessControlProps {
|
|
3
|
+
type?: "code" | "role";
|
|
4
|
+
codes?: string | string[];
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
fallback?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 权限验证组件
|
|
10
|
+
*
|
|
11
|
+
* @param AccessControlProps 权限验证组件的属性
|
|
12
|
+
* @returns 若子组件存在,并且传入的权限值有效,则返回子组件;否则返回 null
|
|
13
|
+
*/
|
|
14
|
+
export declare function AccessControl({ type, codes, children, fallback }: AccessControlProps): ReactNode;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ButtonProps } from "antd";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
interface BasicButtonProps extends ButtonProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare function BasicButton(props: BasicButtonProps): import("#node_modules/@types/react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BasicDataNode } from "antd/lib/tree";
|
|
2
|
+
export interface TreeDataNodeWithId extends BasicDataNode {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
children: TreeDataNodeWithId[];
|
|
6
|
+
}
|
|
7
|
+
interface FormTreeItemProps {
|
|
8
|
+
treeData: TreeDataNodeWithId[];
|
|
9
|
+
value?: React.Key[];
|
|
10
|
+
onChange?: (value: React.Key[]) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function FormTreeItem({ treeData, value, onChange }: FormTreeItemProps): import("#node_modules/@types/react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./form-items";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BASIC_TABLE_ROOT_CLASS_NAME = "basic-table";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ParamsType, ProTableProps } from "@ant-design/pro-components";
|
|
2
|
+
export interface BasicTableProps<D, U, V> extends ProTableProps<D, U, V> {
|
|
3
|
+
/**
|
|
4
|
+
* @description 自适应内容区高度,如果设置了 scroll.y,则不进行自适应
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
adaptive?: boolean | {
|
|
8
|
+
/** 表格距离页面底部的偏移量,默认值为 `16` */
|
|
9
|
+
offsetBottom?: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function BasicTable<DataType extends Record<string, any>, Params extends ParamsType = ParamsType, ValueType = "text">(props: BasicTableProps<DataType, Params, ValueType>): import("#node_modules/@types/react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ButtonProps } from "antd";
|
|
2
|
+
import type { RefObject } from "react";
|
|
3
|
+
export interface FullscreenButtonProps extends Omit<ButtonProps, "target"> {
|
|
4
|
+
target: HTMLElement | (() => Element) | RefObject<Element>;
|
|
5
|
+
fullscreenIcon?: React.ReactNode;
|
|
6
|
+
fullscreenExitIcon?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 全屏按钮组件
|
|
10
|
+
*
|
|
11
|
+
* @param target 全屏目标元素
|
|
12
|
+
* @param fullscreenIcon 全屏时图标
|
|
13
|
+
* @param fullscreenExitIcon 退出全屏时图标
|
|
14
|
+
* @param restProps 其他属性
|
|
15
|
+
* @returns 返回全屏按钮组件
|
|
16
|
+
*/
|
|
17
|
+
export declare const FullscreenButton: React.FC<FullscreenButtonProps>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface GlobalSpinProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare function GlobalSpin({ children, className }: GlobalSpinProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("#node_modules/@types/react").ReactPortal | import("#node_modules/@types/react").ReactElement<unknown, string | import("#node_modules/@types/react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("#node_modules/@types/react").JSX.Element | null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Iframe(): import("#node_modules/@types/react").JSX.Element | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* 自定义的JSS主题提供者组件
|
|
4
|
+
*
|
|
5
|
+
* @zh 自定义的 JSS 主题提供者组件,用于在 React 应用中提供 JSS 主题
|
|
6
|
+
* @en Custom JSS theme provider component, used to provide JSS themes in React applications
|
|
7
|
+
*/
|
|
8
|
+
export interface JSSThemeProviderProps {
|
|
9
|
+
/**
|
|
10
|
+
* 子组件
|
|
11
|
+
*
|
|
12
|
+
* @zh 子组件,该组件将接收JSS主题
|
|
13
|
+
* @en Children components, which will receive the JSS theme
|
|
14
|
+
*/
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* JSSThemeProvider 组件
|
|
19
|
+
*
|
|
20
|
+
* @zh JSSThemeProvider 组件,用于将 Ant Design 的 token 和全局主题状态传递给子组件
|
|
21
|
+
* @en JSSThemeProvider component, used to pass Ant Design tokens and global theme state to child components
|
|
22
|
+
*
|
|
23
|
+
* @param {JSSThemeProviderProps} props 组件属性
|
|
24
|
+
* @returns {JSX.Element} 返回的JSX元素
|
|
25
|
+
*/
|
|
26
|
+
export declare function JSSThemeProvider({ children }: JSSThemeProviderProps): import("#node_modules/@types/react").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Props as SimplebarProps } from "simplebar-react";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://github.com/Grsmto/simplebar/tree/master/packages/simplebar-react
|
|
4
|
+
*/
|
|
5
|
+
export declare function Scrollbar({ ref, children, ...other }: SimplebarProps & {
|
|
6
|
+
ref?: React.RefObject<HTMLElement | null>;
|
|
7
|
+
}): import("#node_modules/@types/react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zh 框架内置「路由无对应组件」兜底页,用于后端下发路由找不到前端组件时。
|
|
3
|
+
* @en Framework built-in fallback for backend routes whose frontend component is missing.
|
|
4
|
+
*/
|
|
5
|
+
export declare function UnknownComponent(): import("#node_modules/@types/react").JSX.Element;
|
|
6
|
+
export default UnknownComponent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TFunction } from "i18next";
|
|
2
|
+
export declare function getYesNoOptions(t: TFunction<"translation", undefined>): {
|
|
3
|
+
label: string;
|
|
4
|
+
value: number;
|
|
5
|
+
}[];
|
|
6
|
+
export declare function getBooleanOptions(t: TFunction<"translation", undefined>): {
|
|
7
|
+
label: string;
|
|
8
|
+
value: boolean;
|
|
9
|
+
}[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* AC-D11/AC-D4:契约端点定义。
|
|
4
|
+
*
|
|
5
|
+
* route 一律相对 apiPrefix(无 oj 根绝对写法——前端受模块手册 D11 前缀收敛,
|
|
6
|
+
* 根绝对逃逸语义不放行);参数段支持 oj matchit 同款 `{id}` 单段与
|
|
7
|
+
* `{*path}` catch-all,参数段内不得混字面(`{id}.json` 非法)。
|
|
8
|
+
*/
|
|
9
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
|
10
|
+
export interface ApiDefinitionInput {
|
|
11
|
+
/** 模块 API 前缀("/" 开头);uni-dev 形态字面等于 oj 模块段名(AC-D9) */
|
|
12
|
+
apiPrefix: string;
|
|
13
|
+
/** 相对 apiPrefix 的路由("/" 开头),支持 `{id}` / `{*path}` 参数段 */
|
|
14
|
+
route: string;
|
|
15
|
+
/** HTTP 方法,缺省 "GET"(IR 层归一) */
|
|
16
|
+
method?: HttpMethod;
|
|
17
|
+
/** 查询参数 schema(声明语义类型,URL 序列化由生成物负责) */
|
|
18
|
+
query?: z.ZodType;
|
|
19
|
+
/** 路径参数 schema(与 route 参数段一一对应) */
|
|
20
|
+
params?: z.ZodType;
|
|
21
|
+
/** 请求体 schema */
|
|
22
|
+
body?: z.ZodType;
|
|
23
|
+
/** 响应信封 data 部分的 schema;与 response:"raw" 互斥 */
|
|
24
|
+
data?: z.ZodType;
|
|
25
|
+
/** "raw" = 二进制/非信封逃生口:不解包、不校验、不进 mock 生成 */
|
|
26
|
+
response?: "raw";
|
|
27
|
+
/** true = 该端点不触发全局加载条(客户端表现层开关,非线协议,不进 OpenAPI) */
|
|
28
|
+
ignoreLoading?: boolean;
|
|
29
|
+
/** 接口描述(进 OpenAPI 文档) */
|
|
30
|
+
description?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* defineApi 产物的品牌标记(Symbol.for 跨模块实例稳定)。
|
|
34
|
+
* 非枚举属性——不影响 .route 等的可枚举性;codegen 据此可靠识别端点,
|
|
35
|
+
* 不与契约文件里导出的普通 schema/常量混淆。
|
|
36
|
+
*
|
|
37
|
+
* 注:旧标记 `Symbol.for("ram.api.def")` 不在本包公开——只有 cli 的 IR 识别
|
|
38
|
+
* 存量产物时才需要它,故由 `packages/cli/src/contract/ir.ts` 自行声明(避免把
|
|
39
|
+
* 兼容专用符号扩进公共出口,设计 §7 R3)。
|
|
40
|
+
*/
|
|
41
|
+
export declare const API_DEF: unique symbol;
|
|
42
|
+
/** 定义一个契约端点:定义期校验后原样返回(描述符 .route 等可枚举,供 codegen/mock 遍历) */
|
|
43
|
+
export declare function defineApi<D extends ApiDefinitionInput>(def: D): D;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** oj matchit 同款参数段:整段必须是 {name} 或 {*name},不得混字面 */
|
|
2
|
+
const PARAM_SEGMENT = /^\{\*?[a-z_]\w*\}$/i;
|
|
3
|
+
function fail(route, reason) {
|
|
4
|
+
throw new Error(`[契约] 端点定义非法(route: ${route}):${reason}`);
|
|
5
|
+
}
|
|
6
|
+
function validateDefinition(def) {
|
|
7
|
+
const { apiPrefix, route } = def;
|
|
8
|
+
if (!apiPrefix?.startsWith("/")) {
|
|
9
|
+
throw new Error(`[契约] apiPrefix 必须以 "/" 开头(收到: ${apiPrefix})——如 "/order";uni-dev 形态请与 oj 模块段名保持一致(AC-D9)。`);
|
|
10
|
+
}
|
|
11
|
+
if (!route?.startsWith("/"))
|
|
12
|
+
fail(route, `route 必须以 "/" 开头(收到: ${route}),且一律相对 apiPrefix——不支持 oj 的根绝对写法(模块手册 D11 前缀收敛)。`);
|
|
13
|
+
if (route.split("/").some(seg => seg === ".." || seg === "." || seg === "\\"))
|
|
14
|
+
fail(route, "route 含路径穿越段(.././\\),请改为正常静态段。");
|
|
15
|
+
for (const seg of route.split("/")) {
|
|
16
|
+
if (seg.includes("{") && !PARAM_SEGMENT.test(seg))
|
|
17
|
+
fail(route, `参数段 "${seg}" 混入字面量——matchit 约束:参数段必须整段为 {name} 或 {*name},需要前缀/后缀字面时请拆成静态多段。`);
|
|
18
|
+
}
|
|
19
|
+
if (def.data && def.response === "raw")
|
|
20
|
+
fail(route, "data schema 与 response:\"raw\" 互斥——raw 端点不解包信封,不需要 data schema。");
|
|
21
|
+
if (def.response !== undefined && def.response !== "raw")
|
|
22
|
+
fail(route, `response 仅支持 "raw"(收到: ${String(def.response)})。`);
|
|
23
|
+
// 评审 F9:方法面在定义期封顶,而不是延迟到 codegen 才炸
|
|
24
|
+
if (def.method === "OPTIONS")
|
|
25
|
+
fail(route, "OPTIONS 不在支持范围(ky/oj 均无对应方法)——预检请求由 fetch/CORS 层处理,契约不表达。");
|
|
26
|
+
if (def.method === "HEAD" && def.data)
|
|
27
|
+
fail(route, "HEAD 端点无响应体,不能声明 data schema——需要响应体请改用 GET。");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* defineApi 产物的品牌标记(Symbol.for 跨模块实例稳定)。
|
|
31
|
+
* 非枚举属性——不影响 .route 等的可枚举性;codegen 据此可靠识别端点,
|
|
32
|
+
* 不与契约文件里导出的普通 schema/常量混淆。
|
|
33
|
+
*
|
|
34
|
+
* 注:旧标记 `Symbol.for("ram.api.def")` 不在本包公开——只有 cli 的 IR 识别
|
|
35
|
+
* 存量产物时才需要它,故由 `packages/cli/src/contract/ir.ts` 自行声明(避免把
|
|
36
|
+
* 兼容专用符号扩进公共出口,设计 §7 R3)。
|
|
37
|
+
*/
|
|
38
|
+
export const API_DEF = Symbol.for("ojm.api.def");
|
|
39
|
+
/** 定义一个契约端点:定义期校验后原样返回(描述符 .route 等可枚举,供 codegen/mock 遍历) */
|
|
40
|
+
export function defineApi(def) {
|
|
41
|
+
validateDefinition(def);
|
|
42
|
+
Object.defineProperty(def, API_DEF, { value: true, enumerable: false });
|
|
43
|
+
return def;
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 契约制 client 的统一错误类型(AC-D5/§6.2)。
|
|
3
|
+
*
|
|
4
|
+
* 业务错误(非 2xx,oj json.fail(code,msg))与契约违例(dev 校验失败,
|
|
5
|
+
* code=-1)都收敛为本类型,消费方可 `instanceof` 判别并取 code/msg。
|
|
6
|
+
*
|
|
7
|
+
* 本子路径出口(`@oj-module/runtime/contract/errors`)是**生成 client 在
|
|
8
|
+
* 浏览器侧的唯一入口**(评审 F3):刻意 zod-free——zod 只随 runtime dist
|
|
9
|
+
* 走(AC-D15),不进共享资产。
|
|
10
|
+
*/
|
|
11
|
+
export declare class ContractApiError extends Error {
|
|
12
|
+
readonly code: number;
|
|
13
|
+
readonly msg: string;
|
|
14
|
+
constructor(code: number, msg: string);
|
|
15
|
+
}
|
|
16
|
+
export type { ScopedRequestLike } from "./scoped-request-like.ts";
|