Skip to main content

composio_sdk/models/
migration.rs

1//! Migration models for converting legacy UUIDs to NanoIds.
2
3use serde::{Deserialize, Serialize};
4
5/// Migration resource type for UUID-to-NanoId conversion.
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
8pub enum MigrationResourceType {
9    /// Connected account resources.
10    ConnectedAccount,
11    /// Auth config resources.
12    AuthConfig,
13    /// Trigger instance resources.
14    TriggerInstance,
15}
16
17/// Query parameters for retrieving a NanoId from a legacy UUID.
18#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
19pub struct MigrationGetNanoIdParams {
20    /// Resource type associated with the UUID.
21    #[serde(rename = "type")]
22    pub resource_type: MigrationResourceType,
23    /// Legacy UUID to convert.
24    pub uuid: String,
25}
26
27/// Response containing the converted NanoId.
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
29pub struct MigrationGetNanoIdResponse {
30    /// NanoId corresponding to the provided legacy UUID.
31    pub nanoid: String,
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn test_migration_get_nanoid_params_serialization() {
40        let params = MigrationGetNanoIdParams {
41            resource_type: MigrationResourceType::ConnectedAccount,
42            uuid: "550e8400-e29b-41d4-a716-446655440000".to_string(),
43        };
44
45        let value = serde_json::to_value(&params).unwrap();
46        assert_eq!(value["type"], "CONNECTED_ACCOUNT");
47        assert_eq!(value["uuid"], "550e8400-e29b-41d4-a716-446655440000");
48    }
49
50    #[test]
51    fn test_migration_get_nanoid_response_deserialization() {
52        let payload = r#"{"nanoid":"ca_abc123xyz"}"#;
53        let response: MigrationGetNanoIdResponse = serde_json::from_str(payload).unwrap();
54        assert_eq!(response.nanoid, "ca_abc123xyz");
55    }
56}