Skip to main content

Crate modelith_plugin_protocol

Crate modelith_plugin_protocol 

Source
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

FeatureDefaultWhat it adds
codegenoffschemars::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
プラグインが追加する機能(拡張点)。
CountRange
数の範囲(両端を含む)。省いた側は制限しない。
Diagnostic
検査ルールなどが報告する診断。
ElementMatch
ルールを当てる要素の条件(すべてを満たす要素に当てる)。
Engines
プラグインが動く本体の版の範囲(本体の ADR-0023 §5)。
Exporter
Importer
ModelElement
ModelPort
ModelRelation
ModelSnapshot
didChange で送る解析結果。
PaletteItem
PluginId
逆ドメイン形式のプラグイン ID(例: jp.modelith.iso15288-rules)。
PluginIdError
PluginManifest
プラグインのマニフェスト。
Position
Publisher
Range
RegistryEntry
RegistryVersion
Requirement
当たった要素が満たすべき条件(書いたものすべて)。
Rule
1 つの検査ルール。match に当たる要素ごとに require を確かめ、満たさなければ診断を出す。
RuleId
ルール ID(例: req-has-satisfier)。
RuleIdError
RuleSet
検査ルールのファイル。
TextEdit
プラグインが返す変更案。ホストが検証してから適用する。
View

Enums§

DiagnosticSeverity
HostMessage
ホストからプラグインへのメッセージ。
NotifyLevel
OneOrMany
文字列 1 つか、文字列の並び。
Permission
プラグインが要求できる権限。
PluginMessage
プラグインからホストへのメッセージ。
PortDirection
Pricing
RelationKind
関係の種類。検査ルールの 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 の正規表現(英小文字・数字・-、英小文字か数字で始まる)。