@api-components/amf-helper-mixin

中文文档
4.5.38发布于 2026/08/20Apache-2.0TypeScriptESM + CJS近 30 天下载 6436

A mixin with common functions user by most AMF components to compute AMF values

原始使用文档
文档目录8 节
  1. Version compatibility
  2. Updating API's base URI
  3. Using AMF keys
  4. Installation
  5. Usage
  6. Development
  7. Running the tests
  8. Deployment

DEPRECATED

This component is being deprecated. The code base has been moved to amf-components module. This module will be archived when PR 1 is merged.


Common functions used by AMF components to compute AMF values. This mixin is safe to use in both Polymer and LitElement projects as well as pure web components.

Published on NPM

Tests and publishing

Version compatibility

This version only works with AMF model version 2 (AMF parser >= 4.0.0). For compatibility with previous model version use 3.x.x version of the component.

Updating API's base URI

(Only applies when using _computeUri() function)

By default the component render the documentation as it is defined in the AMF model. Sometimes, however, you may need to replace the base URI of the API with something else. It is useful when the API does not have base URI property defined (therefore this component render relative paths instead of URIs) or when you want to manage different environments.

To update base URI value update the baseUri property.

When the component constructs the final URI for the endpoint it does the following:

  • if the baseUri is set it uses this value as a base URI for the endpoint
  • else if amf is set then it computes base URI value from main model document Then it concatenates computed base URI with endpoint's path property.

Using AMF keys

The mixin has AMF's model namespace defined under ns property. Use this structure to request AMF key (for example when calling _getAmfKey()). AMF keys may change over time. This way it allows to manage the keys change easier as the components don't have to change, just this mixin.

don't do this

const key = this._getAmfKey(this.ns.aml.vocabularies.document + 'encodes');
const key = shape[this.ns.aml.vocabularies.document + 'encodes'];

do this

const key = this._getAmfKey(this.ns.aml.vocabularies.document.encodes);
const value = model[key];
// acceptable only if AMF model is not compact.
const value = model[this.ns.aml.vocabularies.document.encodes];

Installation

npm i @api-components/amf-helper-mixin

Usage

import { LitElement } from 'lit-element';
import { AmfHelperMixin } from '@api-components/amf-helper-mixin/amf-helper-mixin.js';

class AmfHelperImpl extends AmfHelperMixin(LitElement) {
  static get properties() {
    return {
      myProp: { type: String }
    };
  }
}

Development

git clone https://github.com/@advanced-rest-client/amf-helper-mixin
cd amf-helper-mixin
npm install

Running the tests

npm test

Deployment

Create a PR to the master branch. Once the master branch has a new commit the .github/workflows/deployment.yaml script runs which will publish the release to GitHub and to NPM. Note, you need to manually set a new version of the package.

版本与发布记录

@api-components/amf-helper-mixin 共发布 106 个版本,首次发布于 2018/05/19;过去 12 个月发布了 4 个版本。

版本发布日期距今
4.5.38latest2026/08/202 个月前
4.5.362026/01/299 个月前
4.5.352026/01/149 个月前
4.5.342025/11/2911 个月前
4.5.332025/09/101.2 年前
4.5.322025/09/101.2 年前

其他发布通道:next → 4.5.0-next。

关于 @api-components/amf-helper-mixin 的常见问题

@api-components/amf-helper-mixin 是什么?

A mixin with common functions user by most AMF components to compute AMF values

如何安装 @api-components/amf-helper-mixin?

在项目目录运行 npm install @api-components/amf-helper-mixin,或使用 pnpm add / yarn add / bun add。

@api-components/amf-helper-mixin 支持 TypeScript 吗?

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

@api-components/amf-helper-mixin 支持 ESM 还是 CommonJS?

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

@api-components/amf-helper-mixin 可以商用吗?

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

@api-components/amf-helper-mixin 的下载量有多少?

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

@api-components/amf-helper-mixin 还在维护吗?

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