@codaco/protocol-utilities

中文文档
5.0.0发布于 2026/10/13MITTypeScriptES Module构建来源已验证近 30 天下载 3484

Synthetic network generation and interview-payload builder for Network Canvas protocols.

原始使用文档
文档目录4 节
  1. Exports
  2. Family pedigree generation
  3. Refused protocols
  4. Consumers

@codaco/protocol-utilities

Synthetic network generation and interview-payload builder for Network Canvas protocols.

Exports

  • generateNetwork(params) — pure function that produces an NcNetwork (plus stage metadata and step state) for a given protocol. Takes a single GenerateNetworkParams object: codebook and stages are required; externalData, seed, simulateDropOut, respectSkipLogicAndFiltering, inProgressStageIndex, config, and familyPedigree are optional. Returns a GenerateNetworkResult.
  • GenerateNetworkParams, GenerateNetworkResult — the parameter and result types.
  • GenerationConfig — tuning constants (node counts, edge probabilities, drop-out factor, and the date relative date bounds resolve against). params.config takes a Partial of it.
  • SyntheticDataConstraintError, ConstraintConflict — the refusal generateNetwork throws, and the shape it carries. See below.
  • SyntheticInterview — fluent builder that constructs codebooks, stages, prompts, forms, and full interview payloads.

Both share a ValueGenerator (@faker-js/faker wrapper) for deterministic value synthesis: pass a seed for reproducible output.

Family pedigree generation

FamilyPedigree stages use an isolated demographic generator rather than the generic node-and-edge stage handlers. The bundled US_FAMILY_PEDIGREE_POPULATION profile derives completed family sizes from the 2017–2019 National Survey of Family Growth, then uses size-biased draws for a focal person's siblings and parents' sibling groups. It includes source URLs so callers can audit the assumptions or replace the profile for another study population.

Pass familyPedigree to customize the population, cap optional branches, disable planted disease lineages, or force an adoption, donor-conception, or surrogacy scenario for testing. Population mode samples these scenarios at the profile's configured rates. Family topology and attributes use a stage-specific deterministic random stream, so changing a pedigree does not move the random stream used by other interview stages.

Refused protocols

Generated values satisfy the validation rules a protocol declares on its variables, so a synthetic network holds only data a participant could have entered. Where a protocol's rules cannot all be satisfied at once, generateNetwork throws SyntheticDataConstraintError rather than emitting data the interview would reject.

Most refusals are decided before anything is drawn, from the declared bounds alone, so they do not depend on the seed. The remainder are raised while drawing, when a variable runs out of values against the ones its rules tie it to.

The error's conflicts array carries one ConstraintConflict per problem, each naming the entity (entity, plus entityType and entityTypeName for nodes and edges), the variableIds and variableNames involved, the rules at issue, and a reason. A consumer can render these directly; the error's message is the same information as text.

Consumers

  • apps/architect — generateNetwork populates protocol previews.
  • apps/interviewer — generateNetwork backs synthetic interview generation.
  • @codaco/interview — SyntheticInterview builds Storybook and E2E fixtures. Dev-only consumer.
  • Fresco — external consumer of generateNetwork.

版本与发布记录

@codaco/protocol-utilities 共发布 17 个版本,首次发布于 2026/05/21;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.0.0latest2026/10/1327 天前
4.1.02026/09/291 个月前
4.0.02026/08/312 个月前
3.2.12026/08/112 个月前
3.2.02026/08/063 个月前
3.1.12026/08/053 个月前

其他发布通道:alpha → 1.0.0-alpha.0。

关于 @codaco/protocol-utilities 的常见问题

@codaco/protocol-utilities 是什么?

Synthetic network generation and interview-payload builder for Network Canvas protocols.

如何安装 @codaco/protocol-utilities?

在项目目录运行 npm install @codaco/protocol-utilities,或使用 pnpm add / yarn add / bun add。

@codaco/protocol-utilities 支持 TypeScript 吗?

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

@codaco/protocol-utilities 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@codaco/protocol-utilities 可以商用吗?

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

@codaco/protocol-utilities 的下载量有多少?

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

@codaco/protocol-utilities 还在维护吗?

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