zentao-api 0.3.1 → 0.3.3
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 +38 -2
- package/dist/browser/zentao-api.global.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/misc/errors.d.ts +2 -0
- package/dist/misc/errors.js +2 -0
- package/dist/modules/define.d.ts +67 -0
- package/dist/modules/define.js +123 -0
- package/dist/modules/generated.d.ts +0 -38
- package/dist/modules/generated.js +0 -38
- package/dist/modules/override.d.ts +60 -0
- package/dist/modules/override.js +113 -0
- package/dist/modules/query.d.ts +44 -0
- package/dist/modules/query.js +68 -0
- package/dist/modules/registry-store.d.ts +39 -0
- package/dist/modules/registry-store.js +181 -0
- package/dist/modules/registry.d.ts +4 -120
- package/dist/modules/registry.js +16 -221
- package/dist/modules/resolve.d.ts +2 -2
- package/dist/modules/resolve.js +8 -8
- package/dist/request/index.d.ts +3 -0
- package/dist/request/index.js +58 -4
- package/dist/types/client.d.ts +38 -0
- package/dist/types/client.js +1 -0
- package/dist/types/data.d.ts +42 -0
- package/dist/types/data.js +1 -0
- package/dist/types/index.d.ts +17 -359
- package/dist/types/index.js +17 -1
- package/dist/types/module.d.ts +143 -0
- package/dist/types/module.js +1 -0
- package/dist/types/options.d.ts +51 -0
- package/dist/types/options.js +1 -0
- package/dist/types/profile.d.ts +54 -0
- package/dist/types/profile.js +1 -0
- package/dist/types/response.d.ts +70 -0
- package/dist/types/response.js +1 -0
- package/dist/version.js +2 -2
- package/package.json +1 -1
|
@@ -174,7 +174,6 @@ export const BUILTIN_MODULES = [
|
|
|
174
174
|
pathParams: {
|
|
175
175
|
userID: '用户ID',
|
|
176
176
|
},
|
|
177
|
-
render: 'action',
|
|
178
177
|
}
|
|
179
178
|
],
|
|
180
179
|
},
|
|
@@ -344,7 +343,6 @@ export const BUILTIN_MODULES = [
|
|
|
344
343
|
pathParams: {
|
|
345
344
|
programID: '项目集ID',
|
|
346
345
|
},
|
|
347
|
-
render: 'action',
|
|
348
346
|
}
|
|
349
347
|
],
|
|
350
348
|
},
|
|
@@ -562,7 +560,6 @@ export const BUILTIN_MODULES = [
|
|
|
562
560
|
pathParams: {
|
|
563
561
|
productID: '产品ID',
|
|
564
562
|
},
|
|
565
|
-
render: 'action',
|
|
566
563
|
}
|
|
567
564
|
],
|
|
568
565
|
},
|
|
@@ -757,7 +754,6 @@ export const BUILTIN_MODULES = [
|
|
|
757
754
|
pathParams: {
|
|
758
755
|
projectID: '项目ID',
|
|
759
756
|
},
|
|
760
|
-
render: 'action',
|
|
761
757
|
}
|
|
762
758
|
],
|
|
763
759
|
},
|
|
@@ -1006,7 +1002,6 @@ export const BUILTIN_MODULES = [
|
|
|
1006
1002
|
pathParams: {
|
|
1007
1003
|
executionID: '执行ID',
|
|
1008
1004
|
},
|
|
1009
|
-
render: 'action',
|
|
1010
1005
|
}
|
|
1011
1006
|
],
|
|
1012
1007
|
},
|
|
@@ -1193,7 +1188,6 @@ export const BUILTIN_MODULES = [
|
|
|
1193
1188
|
pathParams: {
|
|
1194
1189
|
productplanID: '产品计划ID',
|
|
1195
1190
|
},
|
|
1196
|
-
render: 'action',
|
|
1197
1191
|
}
|
|
1198
1192
|
],
|
|
1199
1193
|
},
|
|
@@ -1423,7 +1417,6 @@ export const BUILTIN_MODULES = [
|
|
|
1423
1417
|
pathParams: {
|
|
1424
1418
|
storyID: '需求ID',
|
|
1425
1419
|
},
|
|
1426
|
-
render: 'action',
|
|
1427
1420
|
}, {
|
|
1428
1421
|
name: 'activate',
|
|
1429
1422
|
display: '激活需求',
|
|
@@ -1451,7 +1444,6 @@ export const BUILTIN_MODULES = [
|
|
|
1451
1444
|
}
|
|
1452
1445
|
},
|
|
1453
1446
|
},
|
|
1454
|
-
render: 'action',
|
|
1455
1447
|
}, {
|
|
1456
1448
|
name: 'change',
|
|
1457
1449
|
display: '变更需求',
|
|
@@ -1493,7 +1485,6 @@ export const BUILTIN_MODULES = [
|
|
|
1493
1485
|
]
|
|
1494
1486
|
},
|
|
1495
1487
|
},
|
|
1496
|
-
render: 'action',
|
|
1497
1488
|
}, {
|
|
1498
1489
|
name: 'close',
|
|
1499
1490
|
display: '关闭需求',
|
|
@@ -1524,7 +1515,6 @@ export const BUILTIN_MODULES = [
|
|
|
1524
1515
|
]
|
|
1525
1516
|
},
|
|
1526
1517
|
},
|
|
1527
|
-
render: 'action',
|
|
1528
1518
|
}
|
|
1529
1519
|
],
|
|
1530
1520
|
},
|
|
@@ -1745,7 +1735,6 @@ export const BUILTIN_MODULES = [
|
|
|
1745
1735
|
pathParams: {
|
|
1746
1736
|
epicID: '业务需求ID',
|
|
1747
1737
|
},
|
|
1748
|
-
render: 'action',
|
|
1749
1738
|
}, {
|
|
1750
1739
|
name: 'activate',
|
|
1751
1740
|
display: '激活业务需求',
|
|
@@ -1773,7 +1762,6 @@ export const BUILTIN_MODULES = [
|
|
|
1773
1762
|
}
|
|
1774
1763
|
},
|
|
1775
1764
|
},
|
|
1776
|
-
render: 'action',
|
|
1777
1765
|
}, {
|
|
1778
1766
|
name: 'change',
|
|
1779
1767
|
display: '变更业务需求',
|
|
@@ -1815,7 +1803,6 @@ export const BUILTIN_MODULES = [
|
|
|
1815
1803
|
]
|
|
1816
1804
|
},
|
|
1817
1805
|
},
|
|
1818
|
-
render: 'action',
|
|
1819
1806
|
}, {
|
|
1820
1807
|
name: 'close',
|
|
1821
1808
|
display: '关闭业务需求',
|
|
@@ -1846,7 +1833,6 @@ export const BUILTIN_MODULES = [
|
|
|
1846
1833
|
]
|
|
1847
1834
|
},
|
|
1848
1835
|
},
|
|
1849
|
-
render: 'action',
|
|
1850
1836
|
}
|
|
1851
1837
|
],
|
|
1852
1838
|
},
|
|
@@ -2066,7 +2052,6 @@ export const BUILTIN_MODULES = [
|
|
|
2066
2052
|
pathParams: {
|
|
2067
2053
|
requirementID: '用户需求ID',
|
|
2068
2054
|
},
|
|
2069
|
-
render: 'action',
|
|
2070
2055
|
}, {
|
|
2071
2056
|
name: 'activate',
|
|
2072
2057
|
display: '激活用户需求',
|
|
@@ -2094,7 +2079,6 @@ export const BUILTIN_MODULES = [
|
|
|
2094
2079
|
}
|
|
2095
2080
|
},
|
|
2096
2081
|
},
|
|
2097
|
-
render: 'action',
|
|
2098
2082
|
}, {
|
|
2099
2083
|
name: 'change',
|
|
2100
2084
|
display: '变更用户需求',
|
|
@@ -2126,7 +2110,6 @@ export const BUILTIN_MODULES = [
|
|
|
2126
2110
|
}
|
|
2127
2111
|
},
|
|
2128
2112
|
},
|
|
2129
|
-
render: 'action',
|
|
2130
2113
|
}, {
|
|
2131
2114
|
name: 'close',
|
|
2132
2115
|
display: '关闭用户需求',
|
|
@@ -2157,7 +2140,6 @@ export const BUILTIN_MODULES = [
|
|
|
2157
2140
|
]
|
|
2158
2141
|
},
|
|
2159
2142
|
},
|
|
2160
|
-
render: 'action',
|
|
2161
2143
|
}
|
|
2162
2144
|
],
|
|
2163
2145
|
},
|
|
@@ -2376,7 +2358,6 @@ export const BUILTIN_MODULES = [
|
|
|
2376
2358
|
pathParams: {
|
|
2377
2359
|
bugID: 'Bug ID',
|
|
2378
2360
|
},
|
|
2379
|
-
render: 'action',
|
|
2380
2361
|
}, {
|
|
2381
2362
|
name: 'activate',
|
|
2382
2363
|
display: '激活Bug',
|
|
@@ -2411,7 +2392,6 @@ export const BUILTIN_MODULES = [
|
|
|
2411
2392
|
}
|
|
2412
2393
|
},
|
|
2413
2394
|
},
|
|
2414
|
-
render: 'action',
|
|
2415
2395
|
}, {
|
|
2416
2396
|
name: 'close',
|
|
2417
2397
|
display: '关闭Bug',
|
|
@@ -2435,7 +2415,6 @@ export const BUILTIN_MODULES = [
|
|
|
2435
2415
|
}
|
|
2436
2416
|
},
|
|
2437
2417
|
},
|
|
2438
|
-
render: 'action',
|
|
2439
2418
|
}, {
|
|
2440
2419
|
name: 'resolve',
|
|
2441
2420
|
display: '解决Bug',
|
|
@@ -2478,7 +2457,6 @@ export const BUILTIN_MODULES = [
|
|
|
2478
2457
|
]
|
|
2479
2458
|
},
|
|
2480
2459
|
},
|
|
2481
|
-
render: 'action',
|
|
2482
2460
|
}
|
|
2483
2461
|
],
|
|
2484
2462
|
},
|
|
@@ -2715,7 +2693,6 @@ export const BUILTIN_MODULES = [
|
|
|
2715
2693
|
pathParams: {
|
|
2716
2694
|
testcasID: '测试用例ID',
|
|
2717
2695
|
},
|
|
2718
|
-
render: 'action',
|
|
2719
2696
|
}
|
|
2720
2697
|
],
|
|
2721
2698
|
},
|
|
@@ -2933,7 +2910,6 @@ export const BUILTIN_MODULES = [
|
|
|
2933
2910
|
pathParams: {
|
|
2934
2911
|
taskID: '任务ID',
|
|
2935
2912
|
},
|
|
2936
|
-
render: 'action',
|
|
2937
2913
|
}, {
|
|
2938
2914
|
name: 'activate',
|
|
2939
2915
|
display: '激活任务',
|
|
@@ -2966,7 +2942,6 @@ export const BUILTIN_MODULES = [
|
|
|
2966
2942
|
}
|
|
2967
2943
|
},
|
|
2968
2944
|
},
|
|
2969
|
-
render: 'action',
|
|
2970
2945
|
}, {
|
|
2971
2946
|
name: 'close',
|
|
2972
2947
|
display: '关闭任务',
|
|
@@ -2990,7 +2965,6 @@ export const BUILTIN_MODULES = [
|
|
|
2990
2965
|
}
|
|
2991
2966
|
},
|
|
2992
2967
|
},
|
|
2993
|
-
render: 'action',
|
|
2994
2968
|
}, {
|
|
2995
2969
|
name: 'finish',
|
|
2996
2970
|
display: '完成任务',
|
|
@@ -3041,7 +3015,6 @@ export const BUILTIN_MODULES = [
|
|
|
3041
3015
|
]
|
|
3042
3016
|
},
|
|
3043
3017
|
},
|
|
3044
|
-
render: 'action',
|
|
3045
3018
|
}, {
|
|
3046
3019
|
name: 'start',
|
|
3047
3020
|
display: '启动任务',
|
|
@@ -3086,7 +3059,6 @@ export const BUILTIN_MODULES = [
|
|
|
3086
3059
|
]
|
|
3087
3060
|
},
|
|
3088
3061
|
},
|
|
3089
|
-
render: 'action',
|
|
3090
3062
|
}
|
|
3091
3063
|
],
|
|
3092
3064
|
},
|
|
@@ -3277,7 +3249,6 @@ export const BUILTIN_MODULES = [
|
|
|
3277
3249
|
pathParams: {
|
|
3278
3250
|
feedbackID: '反馈ID',
|
|
3279
3251
|
},
|
|
3280
|
-
render: 'action',
|
|
3281
3252
|
}, {
|
|
3282
3253
|
name: 'activate',
|
|
3283
3254
|
display: '激活反馈',
|
|
@@ -3305,7 +3276,6 @@ export const BUILTIN_MODULES = [
|
|
|
3305
3276
|
}
|
|
3306
3277
|
},
|
|
3307
3278
|
},
|
|
3308
|
-
render: 'action',
|
|
3309
3279
|
}, {
|
|
3310
3280
|
name: 'close',
|
|
3311
3281
|
display: '关闭反馈',
|
|
@@ -3336,7 +3306,6 @@ export const BUILTIN_MODULES = [
|
|
|
3336
3306
|
]
|
|
3337
3307
|
},
|
|
3338
3308
|
},
|
|
3339
|
-
render: 'action',
|
|
3340
3309
|
}
|
|
3341
3310
|
],
|
|
3342
3311
|
},
|
|
@@ -3538,7 +3507,6 @@ export const BUILTIN_MODULES = [
|
|
|
3538
3507
|
pathParams: {
|
|
3539
3508
|
ticketID: '工单ID',
|
|
3540
3509
|
},
|
|
3541
|
-
render: 'action',
|
|
3542
3510
|
}, {
|
|
3543
3511
|
name: 'activate',
|
|
3544
3512
|
display: '激活工单',
|
|
@@ -3566,7 +3534,6 @@ export const BUILTIN_MODULES = [
|
|
|
3566
3534
|
}
|
|
3567
3535
|
},
|
|
3568
3536
|
},
|
|
3569
|
-
render: 'action',
|
|
3570
3537
|
}, {
|
|
3571
3538
|
name: 'close',
|
|
3572
3539
|
display: '关闭工单',
|
|
@@ -3598,7 +3565,6 @@ export const BUILTIN_MODULES = [
|
|
|
3598
3565
|
]
|
|
3599
3566
|
},
|
|
3600
3567
|
},
|
|
3601
|
-
render: 'action',
|
|
3602
3568
|
}
|
|
3603
3569
|
],
|
|
3604
3570
|
},
|
|
@@ -3866,7 +3832,6 @@ export const BUILTIN_MODULES = [
|
|
|
3866
3832
|
pathParams: {
|
|
3867
3833
|
buildID: '版本ID',
|
|
3868
3834
|
},
|
|
3869
|
-
render: 'action',
|
|
3870
3835
|
}
|
|
3871
3836
|
],
|
|
3872
3837
|
},
|
|
@@ -4034,7 +3999,6 @@ export const BUILTIN_MODULES = [
|
|
|
4034
3999
|
pathParams: {
|
|
4035
4000
|
testtaskID: '测试单ID',
|
|
4036
4001
|
},
|
|
4037
|
-
render: 'action',
|
|
4038
4002
|
}
|
|
4039
4003
|
],
|
|
4040
4004
|
},
|
|
@@ -4176,7 +4140,6 @@ export const BUILTIN_MODULES = [
|
|
|
4176
4140
|
pathParams: {
|
|
4177
4141
|
releasID: '发布ID',
|
|
4178
4142
|
},
|
|
4179
|
-
render: 'action',
|
|
4180
4143
|
}
|
|
4181
4144
|
],
|
|
4182
4145
|
},
|
|
@@ -4219,7 +4182,6 @@ export const BUILTIN_MODULES = [
|
|
|
4219
4182
|
pathParams: {
|
|
4220
4183
|
fileID: '附件ID',
|
|
4221
4184
|
},
|
|
4222
|
-
render: 'action',
|
|
4223
4185
|
}
|
|
4224
4186
|
],
|
|
4225
4187
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置覆盖 / 扩展定义。
|
|
3
|
+
*
|
|
4
|
+
* 这里集中存放对自动生成注册表(`./generated.ts`)的手工扩展:补充缺失的模块动作、
|
|
5
|
+
* 修正个别动作的元数据,或登记 OpenAPI 尚未覆盖的自定义模块。
|
|
6
|
+
*
|
|
7
|
+
* 与「用户运行时调用 {@link defineModules}」不同,这里的定义会在模块加载时自动应用,
|
|
8
|
+
* 并在 {@link resetModuleDefinitions} 重置后重新应用,因此它们等同于**内置定义**,
|
|
9
|
+
* 会随 SDK 一起发布。
|
|
10
|
+
*
|
|
11
|
+
* 维护约定:
|
|
12
|
+
* - 不要修改 `./generated.ts`(它由 `scripts/update-registry.ts` 自动生成)。
|
|
13
|
+
* 能通过更新 OpenAPI 数据解决的,优先走生成流程;只有生成器无法表达的扩展才写在这里。
|
|
14
|
+
* - 复用 {@link defineModules} / {@link defineModuleActions} 的语义:
|
|
15
|
+
* - {@link defineModuleActions}:为**已存在**的模块追加动作(同名替换、未知追加)。
|
|
16
|
+
* - {@link defineModules}:登记**新模块**,或对已存在模块做合并 / 整体替换(`replace`)。
|
|
17
|
+
* - 写入会自动深克隆 + 深冻结,无需自己处理不可变性。
|
|
18
|
+
*
|
|
19
|
+
* @example 为已存在的 `bug` 模块补充一个自定义动作:
|
|
20
|
+
* ```ts
|
|
21
|
+
* defineModuleActions('bug', {
|
|
22
|
+
* name: 'assignTo',
|
|
23
|
+
* display: '指派 Bug',
|
|
24
|
+
* type: 'action',
|
|
25
|
+
* method: 'put',
|
|
26
|
+
* path: '/bugs/{bugID}/assignto',
|
|
27
|
+
* resultType: 'text',
|
|
28
|
+
* pathParams: { bugID: 'Bug ID' },
|
|
29
|
+
* requestBody: {
|
|
30
|
+
* required: true,
|
|
31
|
+
* schema: {
|
|
32
|
+
* assignedTo: { type: 'string', description: '指派给' },
|
|
33
|
+
* comment: { type: 'string', description: '备注' },
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example 登记一个 OpenAPI 未覆盖的新模块:
|
|
40
|
+
* ```ts
|
|
41
|
+
* defineModules({
|
|
42
|
+
* name: 'custom',
|
|
43
|
+
* display: '自定义模块',
|
|
44
|
+
* actions: [
|
|
45
|
+
* {
|
|
46
|
+
* name: 'list',
|
|
47
|
+
* type: 'list',
|
|
48
|
+
* method: 'get',
|
|
49
|
+
* path: '/customs',
|
|
50
|
+
* resultType: 'list',
|
|
51
|
+
* pagerGetter: 'pager',
|
|
52
|
+
* resultGetter: 'customs',
|
|
53
|
+
* },
|
|
54
|
+
* ],
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export declare function applyBuiltinOverrides(): void;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { extendModuleAction } from './define.js';
|
|
2
|
+
/**
|
|
3
|
+
* 内置覆盖 / 扩展定义。
|
|
4
|
+
*
|
|
5
|
+
* 这里集中存放对自动生成注册表(`./generated.ts`)的手工扩展:补充缺失的模块动作、
|
|
6
|
+
* 修正个别动作的元数据,或登记 OpenAPI 尚未覆盖的自定义模块。
|
|
7
|
+
*
|
|
8
|
+
* 与「用户运行时调用 {@link defineModules}」不同,这里的定义会在模块加载时自动应用,
|
|
9
|
+
* 并在 {@link resetModuleDefinitions} 重置后重新应用,因此它们等同于**内置定义**,
|
|
10
|
+
* 会随 SDK 一起发布。
|
|
11
|
+
*
|
|
12
|
+
* 维护约定:
|
|
13
|
+
* - 不要修改 `./generated.ts`(它由 `scripts/update-registry.ts` 自动生成)。
|
|
14
|
+
* 能通过更新 OpenAPI 数据解决的,优先走生成流程;只有生成器无法表达的扩展才写在这里。
|
|
15
|
+
* - 复用 {@link defineModules} / {@link defineModuleActions} 的语义:
|
|
16
|
+
* - {@link defineModuleActions}:为**已存在**的模块追加动作(同名替换、未知追加)。
|
|
17
|
+
* - {@link defineModules}:登记**新模块**,或对已存在模块做合并 / 整体替换(`replace`)。
|
|
18
|
+
* - 写入会自动深克隆 + 深冻结,无需自己处理不可变性。
|
|
19
|
+
*
|
|
20
|
+
* @example 为已存在的 `bug` 模块补充一个自定义动作:
|
|
21
|
+
* ```ts
|
|
22
|
+
* defineModuleActions('bug', {
|
|
23
|
+
* name: 'assignTo',
|
|
24
|
+
* display: '指派 Bug',
|
|
25
|
+
* type: 'action',
|
|
26
|
+
* method: 'put',
|
|
27
|
+
* path: '/bugs/{bugID}/assignto',
|
|
28
|
+
* resultType: 'text',
|
|
29
|
+
* pathParams: { bugID: 'Bug ID' },
|
|
30
|
+
* requestBody: {
|
|
31
|
+
* required: true,
|
|
32
|
+
* schema: {
|
|
33
|
+
* assignedTo: { type: 'string', description: '指派给' },
|
|
34
|
+
* comment: { type: 'string', description: '备注' },
|
|
35
|
+
* },
|
|
36
|
+
* },
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example 登记一个 OpenAPI 未覆盖的新模块:
|
|
41
|
+
* ```ts
|
|
42
|
+
* defineModules({
|
|
43
|
+
* name: 'custom',
|
|
44
|
+
* display: '自定义模块',
|
|
45
|
+
* actions: [
|
|
46
|
+
* {
|
|
47
|
+
* name: 'list',
|
|
48
|
+
* type: 'list',
|
|
49
|
+
* method: 'get',
|
|
50
|
+
* path: '/customs',
|
|
51
|
+
* resultType: 'list',
|
|
52
|
+
* pagerGetter: 'pager',
|
|
53
|
+
* resultGetter: 'customs',
|
|
54
|
+
* },
|
|
55
|
+
* ],
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export function applyBuiltinOverrides() {
|
|
62
|
+
// 创建执行时,需要添加产品字段
|
|
63
|
+
extendModuleAction('execution', 'create', (action) => {
|
|
64
|
+
const required = action.requestBody.schema?.required;
|
|
65
|
+
if (Array.isArray(required) && !required.includes('products')) {
|
|
66
|
+
required.push('products');
|
|
67
|
+
}
|
|
68
|
+
return action;
|
|
69
|
+
});
|
|
70
|
+
// 修改 story/update 字段定义
|
|
71
|
+
extendModuleAction('story', 'update', (action) => {
|
|
72
|
+
const properties = action.requestBody.schema?.properties;
|
|
73
|
+
// 为 story/update 增加 plan 字段
|
|
74
|
+
if (properties && !properties.plan) {
|
|
75
|
+
properties.plan = {
|
|
76
|
+
type: 'integer',
|
|
77
|
+
description: '所属计划',
|
|
78
|
+
format: 'int32',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// 修改 category 字段类型为 string
|
|
82
|
+
if (properties && properties.category) {
|
|
83
|
+
properties.category = {
|
|
84
|
+
type: 'string',
|
|
85
|
+
description: '类别',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return action;
|
|
89
|
+
});
|
|
90
|
+
// 修改 task/list URL 定义
|
|
91
|
+
extendModuleAction('task', 'list', (action) => {
|
|
92
|
+
action.path = '/executions/{executionID}/tasks';
|
|
93
|
+
action.pathParams = {
|
|
94
|
+
executionID: '执行ID',
|
|
95
|
+
};
|
|
96
|
+
return action;
|
|
97
|
+
});
|
|
98
|
+
// 修改 acl 字段默认值为 open
|
|
99
|
+
[
|
|
100
|
+
['product', 'create'],
|
|
101
|
+
['product', 'update'],
|
|
102
|
+
['execution', 'create'],
|
|
103
|
+
['execution', 'update'],
|
|
104
|
+
].forEach(([moduleName, actionName]) => {
|
|
105
|
+
extendModuleAction(moduleName, actionName, (action) => {
|
|
106
|
+
const properties = action.requestBody.schema?.properties;
|
|
107
|
+
if (properties.acl && properties.acl.defaultValue === undefined) {
|
|
108
|
+
properties.acl.defaultValue = 'open';
|
|
109
|
+
}
|
|
110
|
+
return action;
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ModuleAction, ModuleDefinition } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* 获取模块定义。
|
|
4
|
+
*
|
|
5
|
+
* 模块名匹配大小写不敏感。返回值是注册表内部的已深冻结引用(O(1) 查询、零拷贝),
|
|
6
|
+
* 任何写入尝试在严格模式下会抛 `TypeError`;如需修改请使用 {@link defineModules}。
|
|
7
|
+
*
|
|
8
|
+
* @param moduleName - 模块名。
|
|
9
|
+
* @returns 已注册的模块定义。
|
|
10
|
+
* @throws {ZentaoError} `E_INVALID_MODULE` —— 模块未注册。
|
|
11
|
+
*/
|
|
12
|
+
export declare function getModule(moduleName: string): ModuleDefinition;
|
|
13
|
+
/**
|
|
14
|
+
* 获取指定模块下的某个动作。
|
|
15
|
+
*
|
|
16
|
+
* 解析顺序:
|
|
17
|
+
* 1. `actionName === 'ls'` 时映射为 `list`(仅作为别名,不会修改注册表)。
|
|
18
|
+
* 2. 在该模块的动作中按名称大小写不敏感匹配。
|
|
19
|
+
* 3. 当请求的动作不是基础 CRUD(`list`/`get`/`create`/`update`/`delete`)时,
|
|
20
|
+
* 额外允许命中 `type === 'action'` 的自定义动作(即使名字不在基础 CRUD 中)。
|
|
21
|
+
*
|
|
22
|
+
* 返回值同样是已深冻结的引用,请勿尝试修改。
|
|
23
|
+
*
|
|
24
|
+
* @param moduleName - 模块名(大小写不敏感)。
|
|
25
|
+
* @param actionName - 动作名(大小写不敏感);支持 `ls` 作为 `list` 的别名。
|
|
26
|
+
* @returns 匹配到的动作定义。
|
|
27
|
+
* @throws {ZentaoError} `E_INVALID_MODULE`(模块未注册)或 `E_INVALID_ACTION`(动作不存在)。
|
|
28
|
+
*/
|
|
29
|
+
export declare function getModuleAction(moduleName: string, actionName: string): ModuleAction;
|
|
30
|
+
/**
|
|
31
|
+
* 返回当前运行时注册表中的所有模块名。
|
|
32
|
+
*
|
|
33
|
+
* 顺序与模块写入注册表的顺序一致;包括内置模块和通过 {@link defineModules} 追加的用户模块。
|
|
34
|
+
*
|
|
35
|
+
* @returns 模块名数组(保留原始大小写)。
|
|
36
|
+
*/
|
|
37
|
+
export declare function getModuleNames(): string[];
|
|
38
|
+
/**
|
|
39
|
+
* 判断模块名是否已注册。
|
|
40
|
+
*
|
|
41
|
+
* @param moduleName - 模块名;匹配大小写不敏感。
|
|
42
|
+
* @returns 已注册返回 `true`,否则 `false`。
|
|
43
|
+
*/
|
|
44
|
+
export declare function isModuleName(moduleName: string): boolean;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ZentaoError } from '../misc/errors.js';
|
|
2
|
+
import { getModuleMapState, getModulesState } from './registry-store.js';
|
|
3
|
+
/**
|
|
4
|
+
* 获取模块定义。
|
|
5
|
+
*
|
|
6
|
+
* 模块名匹配大小写不敏感。返回值是注册表内部的已深冻结引用(O(1) 查询、零拷贝),
|
|
7
|
+
* 任何写入尝试在严格模式下会抛 `TypeError`;如需修改请使用 {@link defineModules}。
|
|
8
|
+
*
|
|
9
|
+
* @param moduleName - 模块名。
|
|
10
|
+
* @returns 已注册的模块定义。
|
|
11
|
+
* @throws {ZentaoError} `E_INVALID_MODULE` —— 模块未注册。
|
|
12
|
+
*/
|
|
13
|
+
export function getModule(moduleName) {
|
|
14
|
+
const module = getModuleMapState().get(moduleName.toLowerCase());
|
|
15
|
+
if (!module) {
|
|
16
|
+
throw new ZentaoError('E_INVALID_MODULE', { module: moduleName });
|
|
17
|
+
}
|
|
18
|
+
return module;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 获取指定模块下的某个动作。
|
|
22
|
+
*
|
|
23
|
+
* 解析顺序:
|
|
24
|
+
* 1. `actionName === 'ls'` 时映射为 `list`(仅作为别名,不会修改注册表)。
|
|
25
|
+
* 2. 在该模块的动作中按名称大小写不敏感匹配。
|
|
26
|
+
* 3. 当请求的动作不是基础 CRUD(`list`/`get`/`create`/`update`/`delete`)时,
|
|
27
|
+
* 额外允许命中 `type === 'action'` 的自定义动作(即使名字不在基础 CRUD 中)。
|
|
28
|
+
*
|
|
29
|
+
* 返回值同样是已深冻结的引用,请勿尝试修改。
|
|
30
|
+
*
|
|
31
|
+
* @param moduleName - 模块名(大小写不敏感)。
|
|
32
|
+
* @param actionName - 动作名(大小写不敏感);支持 `ls` 作为 `list` 的别名。
|
|
33
|
+
* @returns 匹配到的动作定义。
|
|
34
|
+
* @throws {ZentaoError} `E_INVALID_MODULE`(模块未注册)或 `E_INVALID_ACTION`(动作不存在)。
|
|
35
|
+
*/
|
|
36
|
+
export function getModuleAction(moduleName, actionName) {
|
|
37
|
+
const module = getModule(moduleName);
|
|
38
|
+
const normalized = actionName === 'ls' ? 'list' : actionName;
|
|
39
|
+
const direct = module.actions.find((action) => String(action.name).toLowerCase() === normalized.toLowerCase());
|
|
40
|
+
if (direct)
|
|
41
|
+
return direct;
|
|
42
|
+
const crud = new Set(['list', 'get', 'create', 'update', 'delete']);
|
|
43
|
+
if (!crud.has(normalized)) {
|
|
44
|
+
const custom = module.actions.find((action) => action.type === 'action' && String(action.name).toLowerCase() === normalized.toLowerCase());
|
|
45
|
+
if (custom)
|
|
46
|
+
return custom;
|
|
47
|
+
}
|
|
48
|
+
throw new ZentaoError('E_INVALID_ACTION', { module: moduleName, action: actionName });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 返回当前运行时注册表中的所有模块名。
|
|
52
|
+
*
|
|
53
|
+
* 顺序与模块写入注册表的顺序一致;包括内置模块和通过 {@link defineModules} 追加的用户模块。
|
|
54
|
+
*
|
|
55
|
+
* @returns 模块名数组(保留原始大小写)。
|
|
56
|
+
*/
|
|
57
|
+
export function getModuleNames() {
|
|
58
|
+
return getModulesState().map((module) => module.name);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 判断模块名是否已注册。
|
|
62
|
+
*
|
|
63
|
+
* @param moduleName - 模块名;匹配大小写不敏感。
|
|
64
|
+
* @returns 已注册返回 `true`,否则 `false`。
|
|
65
|
+
*/
|
|
66
|
+
export function isModuleName(moduleName) {
|
|
67
|
+
return getModuleMapState().has(moduleName.toLowerCase());
|
|
68
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ModuleAction, ModuleDefinition } from '../types/index.js';
|
|
2
|
+
export declare function deepClone<T>(value: T): T;
|
|
3
|
+
/**
|
|
4
|
+
* 深度合并:以 `patch` 覆盖 `base`,返回新对象,不修改任何入参。
|
|
5
|
+
*
|
|
6
|
+
* - 仅当两侧同为普通对象时递归合并;其余情况(含数组)由 `patch` 整体替换。
|
|
7
|
+
* - `patch` 中值为 `undefined` 的键会被跳过,因此扩展方只需给出待修改的字段。
|
|
8
|
+
* - 未被 `patch` 触及的嵌套值沿用 `base` 的引用(外层会重新深冻结,引用本就不可变)。
|
|
9
|
+
*/
|
|
10
|
+
export declare function deepMerge<T>(base: T, patch: unknown): T;
|
|
11
|
+
export declare function cloneBuiltinModules(): ModuleDefinition[];
|
|
12
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
13
|
+
/**
|
|
14
|
+
* 按 {@link ModuleAction.type} 就地补齐省略的 `method` / `resultType`。
|
|
15
|
+
*
|
|
16
|
+
* 已显式声明的字段保持不变;当 `type` 无法推导出对应默认值时抛错,提示显式指定。
|
|
17
|
+
*
|
|
18
|
+
* @throws {ZentaoError} `E_INDETERMINATE_ACTION_METHOD` / `E_INDETERMINATE_ACTION_RESULT_TYPE`
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeAction(action: ModuleAction): ModuleAction;
|
|
21
|
+
export declare function freezeAction(action: ModuleAction): ModuleAction;
|
|
22
|
+
export declare function freezeModule(module: ModuleDefinition): ModuleDefinition;
|
|
23
|
+
export declare function freezeModules(source: ModuleDefinition[]): ModuleDefinition[];
|
|
24
|
+
export declare function findActionIndex(source: readonly ModuleAction[], actionName: string): number;
|
|
25
|
+
export declare function mergeActions(base: readonly ModuleAction[], extension: readonly ModuleAction[]): ModuleAction[];
|
|
26
|
+
export declare function mergeModule(base: ModuleDefinition, extension: ModuleDefinition): ModuleDefinition;
|
|
27
|
+
export declare function buildModuleMap(source: readonly ModuleDefinition[]): Map<string, ModuleDefinition>;
|
|
28
|
+
export declare function validateModule(module: ModuleDefinition): void;
|
|
29
|
+
export declare function validateAction(action: ModuleAction): void;
|
|
30
|
+
/** 当前运行时注册表中的模块数组(define 侧原地修改,query 侧只读)。 */
|
|
31
|
+
export declare function getModulesState(): ModuleDefinition[];
|
|
32
|
+
/** 当前模块名(小写)到模块定义的查找表(O(1) 查询)。 */
|
|
33
|
+
export declare function getModuleMapState(): Map<string, ModuleDefinition>;
|
|
34
|
+
/** 依据当前 modules 重建 moduleMap。所有写入完成后调用以保持二者一致。 */
|
|
35
|
+
export declare function rebuildModuleMap(): void;
|
|
36
|
+
/** 注册「重置后钩子」,在每次 {@link resetState} 还原内置基线后调用。 */
|
|
37
|
+
export declare function setPostResetHook(hook: (() => void) | undefined): void;
|
|
38
|
+
/** 将注册表重置为内置模块(深克隆 + 深冻结),重建查找表,并触发重置后钩子。 */
|
|
39
|
+
export declare function resetState(): void;
|