@basketry/rules

中文文档
0.2.2发布于 2025/08/24MITTypeScriptCommonJS构建来源已验证近 30 天下载 2200

Common rules for building Basketry pipelines

原始使用文档
文档目录22 节
  1. Descriptions
  2. Options
  3. Array parameter length
  4. Options
  5. HTTP status codes
  6. Options
  7. Pagination
  8. Options
  9. String IDs
  10. Options
  11. Response envelopes
  12. Options
  13. Object Bodies
  14. Options
  15. No Disallowed HTTP Bodies
  16. Options
  17. Pluralization
  18. Options
  19. Casing
  20. Options
  21. JSON:API Error
  22. Options

main master

Basketry Rules

Common rules for building Basketry pipelines. These rules may be used with any Basketry parser and may be combined with any other Basketry rules.

Descriptions

Rule
@basketry/rules/lib/method-descriptionRequires all methods to have a description
@basketry/rules/lib/parameter-descriptionRequires all method parameters to have a description
@basketry/rules/lib/property-descriptionRequires all type properties to have a description
@basketry/rules/lib/type-descriptionRequires all types to have a description
@basketry/rules/lib/descriptionCombines all of the other description rules

Options

By default, violations of these rules will be displayed as errors. This may be overridden with the severity option:

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/description",
      "options": { "severity": "warning" }
    }
  ]
}

Array parameter length

Rule
@basketry/rules/lib/array-parameter-lengthRequires method array-typed parameters to specify max item lengths.

Options

By default, violations of this rule will be displayed as errors. This may be overridden with the severity option:

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/array-parameter-length",
      "options": { "severity": "warning" }
    }
  ]
}

HTTP status codes

Rule
@basketry/rules/lib/http-delete-statusRequires that HTTP DELETE status codes must be 200, 202, or 204
@basketry/rules/lib/http-get-statusRequires that HTTP GET status codes must be 200, 204, or 206
@basketry/rules/lib/http-patch-statusRequires that HTTP PATCH status codes must be 200, 202, or 204
@basketry/rules/lib/http-post-statusRequires that HTTP POST status codes must be 200, 201, 202, or 204
@basketry/rules/lib/http-put-statusRequires that HTTP PUT status codes must be 200, 201, 202, or 204
@basketry/rules/lib/http-no-content-statusRequires methods with no return type return status code of 204 AND that methods that do return data do not return 204
@basketry/rules/lib/http-statusCombines all of the other HTTP status code rules

Options

By default, violations of these rules will be displayed as errors. This may be overridden with the severity option:

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/http-status",
      "options": { "severity": "warning" }
    }
  ]
}

Pagination

Rule
@basketry/rules/lib/offset-paginationRequires methods that return arrays define offset and limit parameters
@basketry/rules/lib/relay-paginationRequires methods that return arrays define Relay-style pagination parameters and also return a "page info" object

Options

By default, violations of these rules will be displayed as errors. This may be overridden with the severity option. This rule allows for both bare array and envelope object return types. By default, the payload is expected to be in a property called value, values, or data. These expectations may be overridden with the payload option.

If there is HTTP protocol information defined for this method, then the rules are only applied to HTTP GET methods. This may be overridden with the verb or verbs option.

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/offset-pagination",
      "options": {
        "severity": "warning",
        "payload": ["result", "results"],
        "verbs": ["GET", "POST"]
      }
    }
  ]
}

To apply the rule selectively, use an allow/deny list with method names.

In the following example, the rule will only be enforced on myPaginatedMethod. The pagination rule will not be enforced on any method not in the allow list.

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/offset-pagination",
      "options": { "allow": ["myPaginatedMethod"] }
    }
  ]
}

In the following example, the rule will not be enforced on myUnpaginatedMethod. The pagination rule will be enforced on all methods not in the deny list.

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/offset-pagination",
      "options": { "deny": ["myUnpaginatedMethod"] }
    }
  ]
}

Simultaneous usage of both allow and deny lists may lead to unpredictable results.

String IDs

Rule
@basketry/rules/lib/string-idRequires that type properties named id must be of type string

Options

By default, violations of this rule will be displayed as errors. This may be overridden with the severity option:

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/string-id",
      "options": { "severity": "warning" }
    }
  ]
}

Response envelopes

Rule
@basketry/rules/lib/response-envelopeRequires that all methods return envelope objects that contain both an errors array and a payload property.

Options

By default, violations of these rules will be displayed as errors. This may be overridden with the severity option. This rule allows for both bare array and evelope object return types. By default, the payload is expected to be in a property called value, values, or data. These expectations may be overridded with the payload option. Note that other rules may enforce various pluralization requirements, so be sure to include both the plural and singular form of your payload name.

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/response-envelope",
      "options": {
        "severity": "warning",
        "payload": ["result", "results"]
      }
    }
  ]
}

Object Bodies

Rule
@basketry/rules/lib/object-request-bodyRequires that request bodies (if defined) be objects or unions of objects.
@basketry/rules/lib/object-response-bodyRequires that response bodies (if defined) be objects or unions of objects.
@basketry/rules/lib/object-bodyCombines all of the other object body rules.

Options

By default, violations of these rules will be displayed as errors. This may be overridden with the severity option.

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/object-body",
      "options": { "severity": "warning" }
    }
  ]
}

No Disallowed HTTP Bodies

The HTTP/1.1 specification (RFC 7231) either prohibits bodies or does not define body behavior for certain HTTP methods. In these cases, certain systems may ignore, reject, or fail if a body is provided. The following rules prohibit bodies from being defined for those HTTP methods.

Rule
@basketry/rules/lib/no-http-delete-bodyProhibits HTTP DELETE methods from defining a request body.
@basketry/rules/lib/no-http-get-bodyProhibits HTTP GET methods from defining a request body.
@basketry/rules/lib/no-http-head-bodyProhibits HTTP HEAD methods from defining a request body.
@basketry/rules/lib/no-http-options-bodyProhibits HTTP OPTIONS methods from defining a request body.
@basketry/rules/lib/no-http-trace-bodyProhibits HTTP TRACE methods from defining a request body.
@basketry/rules/lib/no-disallowed-http-bodyCombines all of the other disallowed HTTP body rules.

Options

By default, violations of these rules will be displayed as errors. This may be overridden with the severity option.

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/no-disallowed-http-body",
      "options": { "severity": "warning" }
    }
  ]
}

Pluralization

Rule
@basketry/rules/lib/enum-pluralizationRequires that enums have singular names.
@basketry/rules/lib/parameter-pluralizationRequires that array parameters have pluralized names and non-array parameters have singular names.
@basketry/rules/lib/property-pluralizationRequires that array properties have pluralized names and non-array properties have singular names.
@basketry/rules/lib/pluralizationCombines all of the other pluralization rules

Options

By default, violations of this rule will be displayed as errors. This may be overridden with the severity option:

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/string-id",
      "options": { "severity": "warning" }
    }
  ]
}

Casing

Rule
@basketry/rules/lib/casingDefines casing requirements for the various parts of a service

Options

Casing values must be one of the following:

  • snake - eg. some_item_name
  • pascal - eg. SomeItemName
  • camel - eg. someItemName
  • kebab - eg. some-item-name
  • header - eg. Some-Item-Name
  • constant' - eg. SOME_ITEM_NAME

Any other casing value will be silently ignored.

The following opitons may be used to enforcing casing rules within the service:

  • enum
  • enumValue
  • path
  • method
  • parameter
  • query
  • header
  • property
  • type

Note that if query or header are supplied when parameter is also supplied, then the more specific rules for headers and query parameters will override the setting for all other parameters. If query or header are not supplied, the the value for parameter will also be used for headers and query parameters.

By default, violations of this rule will be displayed as errors. This may be overridden with the severity option.

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/casing",
      "options": {
        "severity": "warning",
        "enum": "camel",
        "enumValue": "constant",
        "path": "kabab",
        "method": "camel",
        "parameter": "camel",
        "query": "kabab",
        "header": "header",
        "property": "camel",
        "type": "camel"
      }
    }
  ]
}

If a casing rule is not specified for a particular element, then any casing will be allowed. There are no default values.

Warning: changing the casing for enum values, paths, query parameters, and properties is a breaking change for HTTP (aka RESTful) services because those values are passed directly in the HTTP request or response. Query parameters are not technically case-sensitive. Enum, method, and type names are never included in HTTP traffic.

Also note that various Generators may emit code that is idiomatic to a particular language regardless of these casing rules; however, all generated code MUST send and receive values in the specified casing when communicating over service boundaries and/or respect the casing requirements of the protocol with which they do so.

JSON:API Error

Rule
@basketry/rules/lib/json-api-errorRequires that an "Error" type be defined that conforms to the JSON:API Error Object specification

Options

By default, violations of this rule will be displayed as errors. This may be overridden with the severity option.

By default, this requires strict conformity to the JSON:API Error Object spec. When in strict mode, status must be a string value if defined and code cannot be defined as an enum. When strict is explicitly set to false (true by default), then status can be a numeric type, and code can be a string enum type.

{
  "rules": [
    {
      "rule": "@basketry/rules/lib/json-api-error",
      "options": {
        "severity": "warning",
        "strict": false
      }
    }
  ]
}

Generated with generator-ts-console

版本与发布记录

@basketry/rules 共发布 24 个版本,首次发布于 2022/05/20;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.2latest2025/08/241.2 年前
0.2.12025/08/171.2 年前
0.2.02025/08/111.2 年前
0.2.0-rc.0rc2025/07/311.3 年前
0.2.0-alpha.2alpha2025/07/271.3 年前
0.2.0-alpha.12025/05/291.4 年前

关于 @basketry/rules 的常见问题

@basketry/rules 是什么?

Common rules for building Basketry pipelines

如何安装 @basketry/rules?

在项目目录运行 npm install @basketry/rules,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 basketry-rules,可以用 npx basketry-rules 直接运行。

@basketry/rules 支持 TypeScript 吗?

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

@basketry/rules 支持 ESM 还是 CommonJS?

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

@basketry/rules 可以商用吗?

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

@basketry/rules 的下载量有多少?

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

@basketry/rules 还在维护吗?

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