Module version

Module version 

Source
Expand description

Version control types for SCIM resources.

This module provides types and functionality for handling resource versioning and conditional operations, enabling ETag-based concurrency control as specified in RFC 7644 (SCIM 2.0) and RFC 7232 (HTTP ETags).

§ETag Concurrency Control

The version system provides automatic optimistic concurrency control for SCIM resources, preventing lost updates when multiple clients modify the same resource simultaneously. All versions are computed deterministically from resource content using SHA-256 hashing.

§Type-Safe Format Management

This module uses phantom types to distinguish between HTTP ETag format and raw internal format at compile time, preventing format confusion:

§Basic Usage

use scim_server::resource::version::{RawVersion, HttpVersion};

// Create version from hash string (for provider-specific versioning)
let raw_version = RawVersion::from_hash("db-sequence-123");

// Create version from content hash (automatic versioning)
let resource_json = br#"{"id":"123","userName":"john.doe","active":true}"#;
let content_version = RawVersion::from_content(resource_json);

// Parse from HTTP weak ETag header (client-provided versions)
let etag_version: HttpVersion = "W/\"abc123def\"".parse().unwrap();

// Convert to HTTP weak ETag header (for responses)
let etag_header = HttpVersion::from(raw_version.clone()).to_string(); // Returns: "W/\"abc123def\""

// Check version equality (works across formats)
let matches = raw_version == etag_version;

§Format Conversions

use scim_server::resource::version::{RawVersion, HttpVersion};

// Raw to HTTP format
let raw_version = RawVersion::from_hash("abc123");
let http_version = HttpVersion::from(raw_version);

// HTTP to Raw format
let http_version: HttpVersion = "W/\"xyz789\"".parse().unwrap();
let raw_version = RawVersion::from(http_version);

// Direct string parsing
let raw_from_str: RawVersion = "abc123".parse().unwrap();
let http_from_str: HttpVersion = "\"xyz789\"".parse().unwrap();

§Conditional Operations

use scim_server::resource::version::{ConditionalResult, RawVersion, HttpVersion};
use serde_json::json;

// Version types provide type-safe version handling for conditional operations
let expected_version = RawVersion::from_hash("current-version");
let http_version: HttpVersion = expected_version.clone().into();

// ConditionalResult enum provides type-safe results:
// - Success(resource) - Operation succeeded
// - VersionMismatch(conflict) - Resource was modified by another client
// - NotFound - Resource doesn't exist

let update_data = json!({"userName": "updated.name", "active": false});
// Used with ConditionalOperations trait for optimistic locking

Structs§

Http
Raw
ScimVersion
Opaque version identifier for SCIM resources with compile-time format safety.
VersionConflict
Details about a version conflict during a conditional operation.

Enums§

ConditionalResult
Result type for conditional SCIM operations.
VersionError
Errors that can occur during version operations.

Type Aliases§

HttpVersion
Type alias for HTTP ETag format versions (“W/"abc123"”)
RawVersion
Type alias for raw internal format versions (“abc123”)