@accordproject/concertino

中文文档
5.2.1发布于 2026/10/18Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 1.1万

Object-centric serialization of Concerto models

原始使用文档
文档目录8 节
  1. Benefits of the Concertino Format
  2. Features
  3. Installation
  4. Usage
  5. Using the ConcertinoConverter Class
  6. Checking a document against the Concertino schema
  7. Model Size
  8. Example Concertino JSON Format

Concertino - A Lightweight Concerto Format Converter

Concertino is a lightweight variant of the Concerto metamodel format, optimized for client applications that need to programmatically introspect declarations without taking a dependency on the full Concerto SDK.

Benefits of the Concertino Format

The Concertino format provides several advantages:

  • Flatter structure: By denormalizing the inheritance hierarchy, consumers don't need to traverse the hierarchy to understand a definition.

  • More explicit metadata: Additional metadata makes it clearer how properties should be interpreted.

  • Ready for consumption: The transformation prepares the data for easier consumption by tools and renderers, without requiring additional processing.

Features

  • Fully Resolved Type References: No ambiguous shortnames
  • Flattened Declarations: Declarations are not nested within models, enabling easier type lookup
  • Denormalized Properties: Inherited properties are fully denormalized with references to their source types
  • Extended Inheritance Chain: Concepts list their full inheritance chain, not just immediate parent
  • Scalar Type Denormalization: For convenience in client applications
  • Strict Mode By Default: Namespaces are always versioned.
  • Support for Partial Models Allowing client applications to filter models to tailor payloads for their use cases.
  • Lossless Conversion Concertino is designed for 100% lossless roundtrip conversion with Concerto models.

Concerto (Metamodel) → Concertino → Concerto (Metamodel)

Installation

npm install @accordproject/concertino

Usage

Using the ConcertinoConverter Class

Try it in Replit

const { ModelManager } = require('@accordproject/concerto-core');
const { ConcertinoConverter } = require('@accordproject/concertino');

// Prepare the Concerto model
const mm = new ModelManager();
mm.addModel(MODEL_FILE_CONTENTS);
const model = mm.getModelFile(MODEL_FILE_NAMESPACE).getAst();

// Initialize Concertino
const converter = new ConcertinoConverter();
const models = { models: [model] };

// Convert from Concerto metamodel to Concertino
const concertino = converter.fromConcertoMetamodel(models);
console.log('#### Concertino:')
console.log(JSON.stringify(concertino, null, 2));
console.log();

// Convert from Concertino back to Concerto metamodel
const metamodel = converter.toConcertoMetamodel(concertino);
console.log('#### Concerto AST (Full Metamodel Instance):')
console.log(JSON.stringify(metamodel, null, 2));

Checking a document against the Concertino schema

converter.isValid(concertino) checks a document against concertino.schema.json, and converter.getValidationErrors() returns the errors of the last check (ajv error objects), or null.

The schema checks are compiled at build time, so the package needs neither ajv nor new Function at run time (a strict Content-Security-Policy is fine). To check documents without the converter, import the ./schema subpath:

const { isValid, checkSchema } = require('@accordproject/concertino/schema');

isValid(concertino);     // true or false
checkSchema(concertino); // null, or the errors

convertToConcertino and convertToMetamodel imported on their own leave the schema checks out of a bundle.

Model Size

Despite the denormalization of metadata, the JSON serialization of Concertino models are often smaller in size than their Concerto AST equivalents due to a flatter, dictionary-like design and the removal of type-discriminators (i.e. $class properties).

It is expected that models that make heavy use of inheritance would be larger than their equivalent Concerto AST.

Note that when converting models, the namespaces in the source Concerto model should be fully resolved (including for local type references).

Example Concertino JSON Format

Below is an example of how a simple Concerto model is represented in the Concertino format:

{
  "declarations": {
    "[email protected]": {
      "properties": {
        "city": {
          "name": "city",
          "type": "String",
          "vocabulary": {
            "label": "City/Town",
          },
        },
        "country": {
          "name": "country",
          "type": "String",
        },
        "street": {
          "name": "street",
          "type": "String",
          "vocabulary": {
            "label": "Street Address",
          },
        },
        "zipCode": {
          "name": "zipCode",
          "type": "String",
        },
      },
      "type": "ConceptDeclaration",
      "vocabulary": {
        "label": "Physical Address",
      },
    },
    "[email protected]": {
      "regex": "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/",
      "type": "StringScalar",
    },
    "[email protected]": {
      "properties": {
        "address": {
          "isOptional": true,
          "name": "address",
          "type": "[email protected]",
          "vocabulary": {
            "label": "Mailing Address",
          },
        },
        "age": {
          "isOptional": true,
          "name": "age",
          "range": [
            0,
            null,
          ],
          "type": "Integer",
        },
        "email": {
          "isOptional": true,
          "metadata": {
            "sensitive": null,
          },
          "name": "email",
          "regex": "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/",
          "scalarType": "[email protected]",
          "type": "String",
        },
        "firstName": {
          "name": "firstName",
          "type": "String",
          "vocabulary": {
            "label": "Given Name",
          },
        },
        "lastName": {
          "name": "lastName",
          "type": "String",
          "vocabulary": {
            "label": "Family Name",
          },
        },
      },
      "type": "ConceptDeclaration",
      "vocabulary": {
        "additionalTerms": {
          "plural": "People",
        },
        "label": "Individual",
      },
    },
  },
  "metadata": {
    "concertinoVersion": "4.0.0-alpha.2",
    "models": {
      "[email protected]": {
        "concertoVersion": "1.0.0",
        "sourceUri": "org/example/models.cto",
        "decorators": [
          {
            "name": "license",
            "arguments": ["Apache-2.0"]
          }
        ]
      }
    }
  }
}

The equivalent Concerto CTO file would be:

@license("Apache-2.0")
namespace [email protected]

scalar Email extends String regex=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/

@Term("Individual")
@Term_plural("People")
concept Person {
  @Term("Given Name")
  o String firstName
  
  @Term("Family Name")
  o String lastName
  
  o Integer age optional range=[0, ]
  
  @sensitive
  o Email email optional 
  
  @Term("Mailing Address")
  o Address address optional
}

@Term("Physical Address")
concept Address {
  @Term("Street Address")
  o String street
  
  @Term("City/Town")
  o String city
  
  o String zipCode
  o String country
}

版本与发布记录

@accordproject/concertino 共发布 26 个版本,首次发布于 2025/08/02;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.2.1latest2026/10/1819 天前
5.2.02026/10/1620 天前
5.1.02026/10/0630 天前
5.0.02026/09/081 个月前
5.0.0-beta.3unstable2026/09/081 个月前
5.0.0-beta.22026/09/081 个月前

关于 @accordproject/concertino 的常见问题

@accordproject/concertino 是什么?

Object-centric serialization of Concerto models

如何安装 @accordproject/concertino?

在项目目录运行 npm install @accordproject/concertino,或使用 pnpm add / yarn add / bun add。

@accordproject/concertino 支持 TypeScript 吗?

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

@accordproject/concertino 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@accordproject/concertino 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@accordproject/concertino 可以商用吗?

@accordproject/concertino 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@accordproject/concertino 的下载量有多少?

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

@accordproject/concertino 还在维护吗?

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