@datocms/cma-client-analysis

中文文档
6.1.0发布于 2026/08/31MITTypeScriptCommonJS零依赖近 30 天下载 8.6万

TypeScript-based static analysis utilities for the @datocms/cma-client-node Client class. Extracts method signatures, referenced types, and endpoint mappings.

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. Caching

Node.js CI

DatoCMS CMA Client Analysis

Static-analysis utilities for @datocms/cma-client-node, built on the TypeScript Compiler API. Inspects the Client class to extract method signatures, resolve referenced types, and produce ready-to-render TypeScript snippets — useful for generating API reference docs, AI tooling, or any introspection of the CMA client surface.

Installation

npm install @datocms/cma-client-analysis @datocms/cma-client-node @datocms/rest-api-reference typescript

@datocms/cma-client-node, @datocms/rest-api-reference, and typescript are peer dependencies — the package introspects whichever versions of them are installed in your tree, so the output is always in sync with the client you actually run.

Usage

import {
  getCmaClientProgram,
  extractAllMethodNames,
  extractMethodSignature,
  extractResourcesEndpointMethods,
  extractTypeDependencies,
} from '@datocms/cma-client-analysis';

// Build a TypeScript program over @datocms/cma-client-node's .d.ts entry.
// Expensive (~hundreds of ms): build once, thread through every extract* call.
const { program, checker, clientClass } = getCmaClientProgram();

// All method names available on a resource.
extractAllMethodNames(checker, clientClass, 'items');
// → ['list', 'find', 'create', 'rawList', 'rawFind', 'rawCreate', ...]

// Full signature for one method, including referenced type symbols.
const signature = extractMethodSignature(checker, clientClass, 'items', 'create');
// → { methodName, parameters, returnType, referencedTypeSymbols, ... }

// All client methods that implement a given REST endpoint, matched by docUrl.
import { findResourcesEntityByNamespace, findResourcesEndpointByRel, parseResourcesSchema } from '@datocms/rest-api-reference';
import resourcesJson from '@datocms/cma-client/resources.json';

const resourcesSchema = parseResourcesSchema(resourcesJson);
const entity = findResourcesEntityByNamespace(resourcesSchema, 'menuItems');
const endpoint = findResourcesEndpointByRel(entity!, 'create');

const methods = extractResourcesEndpointMethods(checker, clientClass, endpoint!);
// → [
//     { name: 'create',    functionDefinition: 'create(body: MenuItemCreateSchema): Promise<MenuItem>',                  referencedTypes: Set { ... } },
//     { name: 'rawCreate', functionDefinition: 'rawCreate(body: MenuItemCreateSchema): Promise<MenuItemCreateTargetSchema>', referencedTypes: Set { ... } },
//   ]

// Inline TypeScript declarations for a set of referenced types, walking up to a depth.
const { expandedTypes, notExpandedTypes } = extractTypeDependencies(
  checker,
  program,
  Array.from(signature!.referencedTypeSymbols.keys()),
  signature!.referencedTypeSymbols,
  { maxDepth: 2 },
);

Caching

getCmaClientProgram() is not cached — every call rebuilds the program. The cost (parsing the full client .d.ts graph) is non-trivial, so:

  • One-shot processes (CLIs, scripts): call once at startup, thread the result through.
  • Long-running processes (servers, MCP): wrap the call in your own memoization.

This keeps the lifetime decision in the consumer's hands instead of pinning it to module-level state.

版本与发布记录

@datocms/cma-client-analysis 共发布 29 个版本,首次发布于 2026/04/27;过去 12 个月发布了 29 个版本。

版本发布日期距今
6.1.0latest2026/08/312 个月前
6.0.02026/08/312 个月前
5.8.02026/08/242 个月前
5.7.02026/08/152 个月前
5.6.22026/08/103 个月前
5.6.02026/07/233 个月前

其他发布通道:next → 5.5.0-alpha.2。

关于 @datocms/cma-client-analysis 的常见问题

@datocms/cma-client-analysis 是什么?

TypeScript-based static analysis utilities for the @datocms/cma-client-node Client class. Extracts method signatures, referenced types, and endpoint mappings.

如何安装 @datocms/cma-client-analysis?

在项目目录运行 npm install @datocms/cma-client-analysis,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@datocms/cma-client-node(^6.1.0)、@datocms/rest-api-reference(^6.1.0)、typescript(>=5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@datocms/cma-client-analysis 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@datocms/cma-client-analysis 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@datocms/cma-client-analysis 可以商用吗?

@datocms/cma-client-analysis 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@datocms/cma-client-analysis 的下载量有多少?

根据 npm 官方下载统计,@datocms/cma-client-analysis 在 2026/10/12 – 2026/11/10 这 30 天内被下载 86,364 次,日均约 2,879 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@datocms/cma-client-analysis 还在维护吗?

最新版本 6.1.0 发布于 2026/08/31(2 个月前);至今共发布 29 个版本,其中过去 12 个月发布了 29 个;首次发布于 2026/04/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。