zentao-api 0.5.1 → 0.5.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/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { ZentaoClient } from './client/index.js';
2
2
  export { ERRORS, ZentaoError, type ErrorCode } from './misc/errors.js';
3
3
  export { getGlobalOptions, setGlobalOptions } from './misc/global-options.js';
4
4
  export { ZENTAO_PROFILES_STORAGE_KEY, addProfile, deleteProfile, getAllProfiles, getProfile, getProfileKey, switchProfile, } from './profiles/index.js';
5
- export { defineModuleActions, defineModules, type DefineModulesOptions, extendModuleAction, getModuleNames, getModule, getModuleAction, getModuleActionParams, getObjectProps, } from './modules/registry.js';
5
+ export { defineModuleActions, defineModules, type DefineModulesOptions, type ExportRegistryOptions, type ExportedModuleAction, type ExportedModuleDefinition, exportRegistry, extendModuleAction, getModuleNames, getModule, getModuleAction, getModuleActionParams, getObjectProps, } from './modules/registry.js';
6
6
  export { request, type BuiltinRequestName, type RequestParamsFor, type RequestResultFor, } from './request/index.js';
7
7
  export { pickFields, pickFieldsSingle, filterData, searchData, sortData, processData, } from './utils/index.js';
8
8
  export { BUILD, VERSION } from './version.js';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export { ZentaoClient } from './client/index.js';
2
2
  export { ERRORS, ZentaoError } from './misc/errors.js';
3
3
  export { getGlobalOptions, setGlobalOptions } from './misc/global-options.js';
4
4
  export { ZENTAO_PROFILES_STORAGE_KEY, addProfile, deleteProfile, getAllProfiles, getProfile, getProfileKey, switchProfile, } from './profiles/index.js';
5
- export { defineModuleActions, defineModules, extendModuleAction, getModuleNames, getModule, getModuleAction, getModuleActionParams, getObjectProps, } from './modules/registry.js';
5
+ export { defineModuleActions, defineModules, exportRegistry, extendModuleAction, getModuleNames, getModule, getModuleAction, getModuleActionParams, getObjectProps, } from './modules/registry.js';
6
6
  export { request, } from './request/index.js';
7
7
  export { pickFields, pickFieldsSingle, filterData, searchData, sortData, processData, } from './utils/index.js';
8
8
  export { BUILD, VERSION } from './version.js';
@@ -0,0 +1,33 @@
1
+ import type { ModuleAction, ModuleActionParam, ModuleDefinition } from '../types/index.js';
2
+ /** 导出的模块动作定义。 */
3
+ export type ExportedModuleAction = Omit<ModuleAction, 'requestBody'> & {
4
+ bodyParams: ModuleActionParam[];
5
+ };
6
+ /** 导出的模块定义。 */
7
+ export type ExportedModuleDefinition = Omit<ModuleDefinition, 'actions'> & {
8
+ actions: ExportedModuleAction[];
9
+ };
10
+ /** {@link exportRegistry} 的选项。 */
11
+ export interface ExportRegistryOptions {
12
+ /** 是否保留注册表中的原始模块定义。 */
13
+ raw?: boolean;
14
+ /** 是否递归移除值为函数的属性;默认为 `true`。 */
15
+ jsonSafe?: boolean;
16
+ }
17
+ /**
18
+ * 导出注册表。
19
+ *
20
+ * 默认会把动作的 `requestBody` 转换成扁平的 `bodyParams`;传入 `raw: true`
21
+ * 时则保留原始模块结构。默认还会递归移除函数属性,以便安全地序列化为 JSON;
22
+ * 如需保留函数,可传入 `jsonSafe: false`。
23
+ *
24
+ * @param options - 导出选项。
25
+ * @returns 以模块名为键的模块定义。
26
+ */
27
+ export declare function exportRegistry(options: ExportRegistryOptions & {
28
+ raw: true;
29
+ }): Record<string, ModuleDefinition>;
30
+ export declare function exportRegistry(options?: ExportRegistryOptions & {
31
+ raw?: false;
32
+ }): Record<string, ExportedModuleDefinition>;
33
+ export declare function exportRegistry(options: ExportRegistryOptions): Record<string, ModuleDefinition | ExportedModuleDefinition>;
@@ -0,0 +1,42 @@
1
+ import { getModuleActionParams } from './query.js';
2
+ import { getModuleMapState } from './registry-store.js';
3
+ function removeFunctions(value) {
4
+ if (Array.isArray(value)) {
5
+ return value
6
+ .filter((item) => typeof item !== 'function')
7
+ .map((item) => removeFunctions(item));
8
+ }
9
+ if (value && typeof value === 'object') {
10
+ const result = {};
11
+ for (const [key, item] of Object.entries(value)) {
12
+ if (typeof item !== 'function') {
13
+ result[key] = removeFunctions(item);
14
+ }
15
+ }
16
+ return result;
17
+ }
18
+ return value;
19
+ }
20
+ export function exportRegistry(options = {}) {
21
+ const raw = options.raw ?? false;
22
+ const jsonSafe = options.jsonSafe ?? true;
23
+ const registry = {};
24
+ getModuleMapState().forEach((module) => {
25
+ const definition = raw
26
+ ? module
27
+ : {
28
+ ...module,
29
+ actions: module.actions.map((action) => {
30
+ const { requestBody, ...exportedAction } = action;
31
+ return {
32
+ ...exportedAction,
33
+ bodyParams: requestBody
34
+ ? getModuleActionParams(module.name, action.name, { roles: ['body'] })
35
+ : [],
36
+ };
37
+ }),
38
+ };
39
+ registry[module.name] = jsonSafe ? removeFunctions(definition) : definition;
40
+ });
41
+ return registry;
42
+ }
@@ -4239,3 +4239,4 @@ export declare const MODULES: readonly [{
4239
4239
  export { type DefineModulesOptions, defineModules, defineModuleActions, extendModuleAction, resetModuleDefinitions, } from './define.js';
4240
4240
  export { applyBuiltinOverrides };
4241
4241
  export { getModule, getModuleAction, getModuleActionParams, getModuleNames, isModuleName, getObjectProps, } from './query.js';
4242
+ export { type ExportRegistryOptions, type ExportedModuleAction, type ExportedModuleDefinition, exportRegistry, } from './export.js';
@@ -17,3 +17,4 @@ export { applyBuiltinOverrides };
17
17
  setPostResetHook(applyBuiltinOverrides);
18
18
  applyBuiltinOverrides();
19
19
  export { getModule, getModuleAction, getModuleActionParams, getModuleNames, isModuleName, getObjectProps, } from './query.js';
20
+ export { exportRegistry, } from './export.js';
@@ -113,7 +113,7 @@ function hasListProcessing(options) {
113
113
  *
114
114
  * - 对象列表:交由 {@link processData} 完整处理。
115
115
  * - 基本类型数组:仅 `limit` 生效(按数量截断),避免破坏原始元素。
116
- * - 单条对象:只有 `pick` 生效。
116
+ * - 单条对象:应用 `convertSingle`,再应用 `pick`。
117
117
  * - 其他形态原样返回。
118
118
  */
119
119
  function applyProcessing(data, options) {
@@ -135,8 +135,8 @@ function applyProcessing(data, options) {
135
135
  const limit = Number(options.limit);
136
136
  return Number.isFinite(limit) && limit >= 0 ? data.slice(0, Math.floor(limit)) : data;
137
137
  }
138
- if (isRecord(data) && options.pick && options.pick.length > 0) {
139
- return processData(data, { pick: options.pick });
138
+ if (isRecord(data) && (options.convertSingle || (options.pick && options.pick.length > 0))) {
139
+ return processData(data, { convert: options.convertSingle, pick: options.pick });
140
140
  }
141
141
  return data;
142
142
  }
@@ -16,21 +16,21 @@ export interface DataRecordFilterGroup {
16
16
  /** 组内条件列表。 */
17
17
  conditions: DataRecordFilter[];
18
18
  }
19
- /** 排序表达式,格式为 `字段:asc|desc`。 */
20
- export type SortExpr = `${string}:${'asc' | 'desc'}`;
19
+ /** 排序表达式;推荐 `字段:asc|desc`,兼容 `字段_asc|desc`。 */
20
+ export type SortExpr = `${string}:${'asc' | 'desc'}` | `${string}_${'asc' | 'desc'}`;
21
21
  /** 自定义排序比较函数。 */
22
22
  export type SortFn = (a: DataRecord, b: DataRecord) => number;
23
23
  /** {@link processData} 处理列表时的选项;执行顺序为 转换 → 过滤 → 搜索 → 排序 → 限制数量 → 摘取。 */
24
24
  export interface ProcessListOptions {
25
- /** 转换函数,用于对列表中的每条记录进行转换。 */
25
+ /** 列表转换函数,在过滤前对记录数组整体执行。 */
26
26
  convert?: (records: DataRecord[]) => DataRecord[];
27
- /** 过滤表达式列表,例如 `["status=active", "pri>=2"]`,多条之间按 AND 组合。 */
27
+ /** 过滤表达式组,如 `["status=active,pri>=2", "assignedTo.id=5"]`;组内 AND、组间 OR,`=` 与 `:` 均表示相等。 */
28
28
  filter?: string[];
29
- /** 模糊搜索关键词组,组内空格分隔为 OR,多组之间按 AND 组合。 */
29
+ /** 模糊搜索关键词组,如 `["登录,超时", "注册,失败"]`;组内 AND、组间 OR。 */
30
30
  search?: string[];
31
31
  /** 限定搜索字段,缺省时搜索全部字段。 */
32
32
  searchFields?: string[];
33
- /** 排序表达式,多个字段以英文逗号分隔,例如 `pri:desc,id:asc`。 */
33
+ /** 排序表达式,多个字段以英文逗号分隔;推荐 `pri:desc,id:asc`,兼容 `pri_desc,id_asc`。 */
34
34
  sort?: string;
35
35
  /** 限制返回列表数量,在排序后、摘取前截断;不改变服务端页大小。 */
36
36
  limit?: string;
@@ -1,5 +1,5 @@
1
1
  import type { ZentaoClient } from '../client/index.js';
2
- import type { ProcessListOptions } from './data.js';
2
+ import type { ProcessListOptions, ProcessSingleOptions } from './data.js';
3
3
  /** SDK 进程级全局默认选项,供高阶 {@link request} 调用复用。 */
4
4
  export interface GlobalOptions {
5
5
  /** 默认客户端;通常由 `ZentaoClient.init()` 设置。 */
@@ -33,6 +33,8 @@ export interface RequestOptions extends ProcessListOptions {
33
33
  timeout?: number;
34
34
  /** 本次调用 TLS 跳过证书验证选项;仅 Node.js 运行时支持。 */
35
35
  insecure?: boolean;
36
+ /** 单条对象转换函数,在字段摘取前执行;列表转换请使用 `convert`。 */
37
+ convertSingle?: ProcessSingleOptions['convert'];
36
38
  /**
37
39
  * 当禅道服务端返回 `{ status: "fail" }` 时是否抛出 `E_API_FAILED`。
38
40
  * 不传时回落到全局 `throwOnFail`,默认 false(保留原始失败响应)。
@@ -8,13 +8,14 @@ export declare function filterData(data: DataRecord[], filterGroups: DataRecordF
8
8
  /**
9
9
  * 对列表做大小写不敏感的模糊匹配。
10
10
  *
11
- * 每个 `keywordGroups` 元素是一个关键词串,组内以空白分隔为 OR;多组之间按 AND 组合。
11
+ * 每个 `keywordGroups` 元素是一个关键词组,组内以逗号分隔为 AND;多个组之间按 OR 组合。
12
+ * 引号内的逗号视为关键词内容,不作为分隔符。
12
13
  */
13
14
  export declare function searchData(data: DataRecord[], keywordGroups: string[], searchFields?: string[]): DataRecord[];
14
15
  /**
15
16
  * 对列表排序,返回新数组(不修改入参)。
16
17
  *
17
- * `sortFields` 的每个元素可以是 `字段:asc|desc` 表达式或自定义比较函数,按先后顺序生效;
18
+ * `sortFields` 的每个元素可以是 `字段:asc|desc`(兼容 `字段_asc|desc`)或自定义比较函数,按先后顺序生效;
18
19
  * 数值字段按数字比较,否则按字符串 `localeCompare`。
19
20
  */
20
21
  export declare function sortData(data: DataRecord[], sortFields: (SortExpr | SortFn)[]): DataRecord[];
Binary file
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
- const fallbackBuild = "2026-08-11T13:56:37.064Z";
2
- const fallbackVersion = "0.5.1";
1
+ const fallbackBuild = "2026-08-12T03:04:33.420Z";
2
+ const fallbackVersion = "0.5.3";
3
3
  /**
4
4
  * 构建标识,由构建脚本通过 `__ZENTAO_API_BUILD__` 注入。
5
5
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zentao-api",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "description": "Browser and Node.js SDK for ZenTao API",
6
6
  "license": "MIT",