One explicit PATCH input in Laravel Rust
Scope
Replace one flat package-backed input data object with an explicit app-owned PATCH boundary. Preserve omitted, null and supplied string values, authorization and public response fields. Exclude nested data, inferred validation, custom casts, lazy includes, polymorphic objects, collection wrapping and TypeScript generation. Keep callers using those features on their existing path. Preserve LICENSE.md when adapting upstream code.
At the time of writing, the Package Port catalog marked Rust as needing a direct port while listing a partial community alternative. Check get-recipe's current port catalog and offer a compatible implementation before extraction. This guidance has not been exercised in your app; verify it with the checks below.
Source behaviour
src/Concerns/BaseData.php builds a pipeline with authorization, name mapping, injection, validation, defaults and casting. src/DataPipes/ValidatePropertiesDataPipe.php consults the creation strategy; the inspected configuration defaults to validating requests, not every arbitrary array creation. A typed object alone is not evidence that validation or authorization ran.
src/DataPipes/DefaultValuesDataPipe.php distinguishes an existing key from a missing key: configured defaults take precedence, then eligible Optional values, then nullable defaults. src/Resolvers/TransformedDataResolver.php excludes Optional values but preserves null and can map output names. Creation and transformation are different contracts. The creation/transformation tests exercise optional values; removing the package must not turn an omitted PATCH field into a null assignment.
Implementation
- Inventory the chosen data class, constructor defaults, input/output names, rules, normalization middleware, authorization, custom creation methods, casts and every HTTP/job/CLI caller. Capture actual request/error/response fixtures. Select only one flat nullable string field; retain excluded features rather than silently dropping them.
- Decode a size-limited JSON object through the app's existing request boundary. Preserve key presence before typed extraction: ordinary nested
Optiondeserialization may collapse missing and null. Reject malformed/non-object input and apply the real decoder's duplicate-key/UTF-8 policy consistently. Preserve existing trimming and empty-to-null middleware deliberately; the classifier below does not normalize strings. - Represent omitted as no operation, null as explicit clearing and string as explicit assignment. The example deliberately rejects unknown keys and non-string scalars instead of reproducing every upstream casting/default configuration. Keep all endpoint rules, length limits and field-name mapping explicit. Match validation across HTTP, jobs and commands; do not assume deriving serialization runs domain validation.
- Authorize actor, tenant, resource and editable field independently of the DTO. Load the authorized row, apply only present allowed fields and preserve the app's existing concurrency policy. If multiple writes form one operation, use the existing transaction callback's
tx; propagate failures and preserve any expected-version check. A DTO does not prevent stale writes or provide idempotency. - Serialize an explicit response projection, not the input object or full model. Preserve omitted-versus-null output and existing envelope/error statuses; no lazy resolver may expose private fields. Dispatch required notifications after the established commit boundary and invalidate only scoped affected caches. Parsing needs no new database table, global registry or cache.
Complete pure field classifier for an already decoded serde_json::Value. It uses the app's existing serde_json dependency, performs object/key/type checks, and leaves domain validation, normalization, authorization and persistence to the caller:
use serde_json::Value;
#[derive(Debug, PartialEq, Eq)]
enum NamePatch { Unchanged, Set(Option<String>) }
fn name_patch(input: &Value) -> Result<NamePatch, &'static str> {
let fields = input.as_object().ok_or("object required")?;
if fields.keys().any(|key| key != "display_name") {
return Err("unknown field");
}
match fields.get("display_name") {
None => Ok(NamePatch::Unchanged),
Some(Value::Null) => Ok(NamePatch::Set(None)),
Some(Value::String(value)) => Ok(NamePatch::Set(Some(value.clone()))),
_ => Err("display_name must be string or null"),
}
}
Acceptance checklist
- From an existing
display_name: "Ada",{}leaves it unchanged, explicit null clears it, and"0"assigns the string. Empty string and" Åda "reach the declared normalization/rule boundary unchanged by this classifier. A number, boolean, array, object or unknownis_adminfield fails. - Reject malformed JSON, top-level arrays/null and oversized bodies. Exercise actual middleware, duplicate-key policy, renamed fields and error/resource shapes; do not infer framework extractor behavior from this pure function.
- A queued invocation enforces the same rules. Unauthorized and cross-tenant patches change nothing; client input cannot select actor, tenant, class or output projection.
- Omitted fields never overwrite stored values. Exercise the existing stale-write policy, rollback after a failed write and post-commit dispatch failure without repeating committed work. Private fields stay absent from output.
- Compare package-backed defaults, optional/null cases and transforms against captured fixtures. Search remaining data classes/helpers and retain the package until every used feature has a replacement.
Run formatting, strict Clippy and the app's request/resource/job/transaction tests on its actual framework and database. Record commands, versions, results and deliberate differences with the change.
Sources
- MIT reference source:
src/Concerns/BaseData.php,src/DataPipes/ValidatePropertiesDataPipe.php,src/DataPipes/DefaultValuesDataPipe.php,src/Resolvers/TransformedDataResolver.php,config/data.php,tests/CreationTest.php, andtests/TransformationTest.php. - Framework source checked:
crates/http/src/http/json.rsandcrates/database/src/db/neutral/transaction.rs. Reconcile metadata with the app's lockfile; extractor limits/error contracts still need app tests. - Port options: check
get-recipe's current port catalog (sourced from Package Port) at implementation time.