Expand description
§modelith-plugin-protocol
The contract between Modelith and its plugins, as Rust types:
the plugin manifest, rule files, the messages a browser plugin exchanges with the host,
text edits and diagnostics, and plugin registry entries.
These types are the single source of truth. The JSON Schemas and the TypeScript types in
@modelith/plugin-sdk are generated from them.
Modelith (the host) and the plugin registry’s CI depend on this crate.
Pre-1.0 (apiVersion "0"): the contract may still change between minor releases.
§Example
use modelith_plugin_protocol::{API_VERSION, Permission, PluginManifest, Runtime};
let manifest: PluginManifest = serde_json::from_str(r#"{
"id": "com.example.req-checks",
"name": "Requirement checks",
"version": "0.1.0",
"apiVersion": "0",
"runtime": "rules",
"license": "MIT",
"permissions": ["model:read"],
"contributes": { "rules": ["rules/requirements.yaml"] }
}"#)
.expect("a valid manifest");
assert_eq!(manifest.api_version, API_VERSION);
assert_eq!(manifest.runtime, Runtime::Rules);
assert!(manifest.permissions.contains(&Permission::ModelRead));Manifests and rule files reject unknown fields, so a typo is an error rather than silently ignored. Messages ignore unknown fields, so a host and a plugin of different versions keep working when either adds an optional field.
§Features
| Feature | Default | What it adds |
|---|---|---|
codegen | off | schemars::JsonSchema and ts_rs::TS for every type, and the generate module that writes the JSON Schemas and TypeScript types |
Without codegen the crate depends only on serde and serde_json.
§License
MIT
Re-exports§
pub use usage::USAGE_SCHEMA_VERSION;pub use usage::UsageReport;
Modules§
- usage
- 利用状況の送信(modelith の ADR-0026)。アプリ・サーバ・受け口が同じ一覧を使う(ADR-0026 の 4)。
Structs§
- Command
- Contributes
- プラグインが追加する機能(拡張点)。
- Count
Range - 数の範囲(両端を含む)。省いた側は制限しない。
- Diagnostic
- 検査ルールなどが報告する診断。
- Element
Match - ルールを当てる要素の条件(すべてを満たす要素に当てる)。
- Engines
- プラグインが動く本体の版の範囲(本体の ADR-0023 §5)。
- Exporter
- Importer
- Model
Element - Model
Port - Model
Relation - Model
Snapshot didChangeで送る解析結果。- Palette
Item - Plugin
Id - 逆ドメイン形式のプラグイン ID(例:
jp.modelith.iso15288-rules)。 - Plugin
IdError - Plugin
Manifest - プラグインのマニフェスト。
- Position
- Publisher
- Range
- Registry
Entry - Registry
Version - Requirement
- 当たった要素が満たすべき条件(書いたものすべて)。
- Rule
- 1 つの検査ルール。
matchに当たる要素ごとにrequireを確かめ、満たさなければ診断を出す。 - RuleId
- ルール ID(例:
req-has-satisfier)。 - Rule
IdError - RuleSet
- 検査ルールのファイル。
- Text
Edit - プラグインが返す変更案。ホストが検証してから適用する。
- View
Enums§
- Diagnostic
Severity - Host
Message - ホストからプラグインへのメッセージ。
- Notify
Level - OneOr
Many - 文字列 1 つか、文字列の並び。
- Permission
- プラグインが要求できる権限。
- Plugin
Message - プラグインからホストへのメッセージ。
- Port
Direction - Pricing
- Relation
Kind - 関係の種類。検査ルールの
incoming/outgoingと同じ言葉。 - Runtime
- プラグインの実行方式(ADR-0004 の段階に対応)。
Constants§
- API_
VERSION - このクレートが定義するプラグイン API のバージョン(SDK の MAJOR と同じ値)。
マニフェストの
apiVersionはこの値と一致しなければならない。 SDK が 1.0.0 未満の間は"0"で、互換性を約束しない(modelith の docs/reference/versioning.md)。 - PLUGIN_
ID_ PATTERN - プラグイン ID の正規表現(逆ドメイン形式、英小文字・数字・
-、2 区切り以上)。 - RULE_
ID_ PATTERN - ルール ID の正規表現(英小文字・数字・
-、英小文字か数字で始まる)。