zentao-api 0.5.2 → 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';
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
- const fallbackBuild = "2026-08-11T15:04:25.839Z";
2
- const fallbackVersion = "0.5.2";
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.2",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "description": "Browser and Node.js SDK for ZenTao API",
6
6
  "license": "MIT",