apimock-rs 5.1.2 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +55 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -134,6 +134,61 @@ For more details, **🧭 check out our [full documentation](https://apimokka.git
134
134
 
135
135
  ---
136
136
 
137
+ ## Workspace layout (5.0.0+)
138
+
139
+ Starting with 5.0.0, apimock is organised as a Cargo workspace:
140
+
141
+ | crate | responsibility |
142
+ | --- | --- |
143
+ | [`apimock-config`](crates/apimock-config) | TOML config model — load, validate, resolve relative paths. Defines the stage-1 edit / snapshot API types a GUI can depend on. |
144
+ | [`apimock-routing`](crates/apimock-routing) | Rule-set definitions, request matching, read-only view types for GUI tooling. |
145
+ | [`apimock-server`](crates/apimock-server) | HTTP(S) listener, request dispatch, Rhai middleware compilation, response building. |
146
+ | `apimock` (workspace root) | CLI binary + thin façade library. Re-exports the three member crates under `apimock::config`, `apimock::routing`, `apimock::server`. |
147
+
148
+ End users installing via `cargo install apimock` or `npx apimock` see no difference from 4.8.0. Library consumers migrating from 4.x paths can find the mapping in [CHANGELOG.md](CHANGELOG.md).
149
+
150
+ ### GUI-facing Workspace API (5.1.0+)
151
+
152
+ 5.1.0 adds `apimock_config::Workspace` for tooling that wants to edit a configuration through structured commands instead of TOML text. A GUI typically holds a single `Workspace` value for one editing session, calls `snapshot()` to produce a render-ready view, and `apply(EditCommand)` to mutate. Every editable node carries a stable `NodeId` (a v4 UUID) that survives reorderings, so a selection set anchored on NodeIds remains valid across edits.
153
+
154
+ ```rust
155
+ use apimock_config::{
156
+ Workspace, EditCommand, RespondPayload, RulePayload,
157
+ NodeId, ConfigFileKind, NodeKind,
158
+ };
159
+
160
+ let mut ws = Workspace::load("apimock.toml".into())?;
161
+
162
+ // Find the rule-set node from the snapshot.
163
+ let snap = ws.snapshot();
164
+ let rule_set_id: NodeId = snap.files.iter()
165
+ .find(|f| matches!(f.kind, ConfigFileKind::RuleSet))
166
+ .and_then(|f| f.nodes.iter().find(|n| matches!(n.kind, NodeKind::RuleSet)))
167
+ .map(|n| n.id)
168
+ .expect("rule set");
169
+
170
+ // Add a new rule.
171
+ let result = ws.apply(EditCommand::AddRule {
172
+ parent: rule_set_id,
173
+ rule: RulePayload {
174
+ url_path: Some("/api/new".into()),
175
+ method: Some("GET".into()),
176
+ respond: RespondPayload {
177
+ text: Some("hello".into()),
178
+ ..Default::default()
179
+ },
180
+ },
181
+ })?;
182
+
183
+ if !result.diagnostics.is_empty() {
184
+ // surface each per-node diagnostic in the GUI
185
+ }
186
+ ```
187
+
188
+ Saving back to disk (`Workspace::save`) is reserved for 5.2.0; 5.1.0 covers Steps 1–3 of the GUI extension plan (snapshot + apply + validate).
189
+
190
+ ---
191
+
137
192
  ## Open-source, with care
138
193
 
139
194
  This project is lovingly built and maintained by volunteers.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apimock-rs",
3
- "version": "5.1.2",
3
+ "version": "5.2.0",
4
4
  "description": "HTTP(S) mock server. Drop JSON files into a folder and your API immediately exists.",
5
5
  "author": "nabbisen",
6
6
  "license": "Apache-2.0",