style: format generated code and new modules

Author: Aaron Steven White
Commit 67e8a479ce8908774abe4bfa74cc0c3d76fbc371
Parent: 4af490f94b
Structural diff unavailable

These commits were pushed via plain git push, so no pre-parsed schemas are available. Install git-remote-cospan and re-push via panproto:// to see scope-level changes, breaking change detection, and semantic diffs.

brew install panproto/tap/git-remote-cospan
6 files changed +170 -107
@@ -190,13 +190,10 @@ async fn dispatch_special_upsert(
190190             db::issue_state::upsert(&state.db, &row).await?;
191191 
192192             let (issue_did, issue_rkey) = parse_at_uri_did_rkey(&issue_uri);
193-            if let Some(issue) =
194-                db::issue::get_by_pk(&state.db, &issue_did, &issue_rkey).await?
195-            {
193+            if let Some(issue) = db::issue::get_by_pk(&state.db, &issue_did, &issue_rkey).await? {
196194                 let old_state = &issue.state;
197195                 if old_state != &new_state {
198-                    db::issue::update_state(&state.db, &issue_did, &issue_rkey, &new_state)
199-                        .await?;
196+                    db::issue::update_state(&state.db, &issue_did, &issue_rkey, &new_state).await?;
200197 
201198                     if old_state == "open" && new_state != "open" {
202199                         decrement_repo_open_issue_count(
@@ -289,23 +286,14 @@ async fn dispatch_special_upsert(
289286             if let Some(pull) = db::pull::get_by_pk(&state.db, &pull_did, &pull_rkey).await? {
290287                 let old_state = &pull.state;
291288                 if old_state != &new_state {
292-                    db::pull::update_state(&state.db, &pull_did, &pull_rkey, &new_state)
293-                        .await?;
289+                    db::pull::update_state(&state.db, &pull_did, &pull_rkey, &new_state).await?;
294290 
295291                     if old_state == "open" && new_state != "open" {
296-                        decrement_repo_open_mr_count(
297-                            &state.db,
298-                            &pull.repo_did,
299-                            &pull.repo_name,
300-                        )
301-                        .await?;
292+                        decrement_repo_open_mr_count(&state.db, &pull.repo_did, &pull.repo_name)
293+                            .await?;
302294                     } else if old_state != "open" && new_state == "open" {
303-                        increment_repo_open_mr_count(
304-                            &state.db,
305-                            &pull.repo_did,
306-                            &pull.repo_name,
307-                        )
308-                        .await?;
295+                        increment_repo_open_mr_count(&state.db, &pull.repo_did, &pull.repo_name)
296+                            .await?;
309297                     }
310298 
311299                     // SSE only for cospan-native events
@@ -448,7 +436,9 @@ async fn dispatch_special_upsert(
448436         }
449437 
450438         // ─── Tangled-only records (no Cospan equivalent) ────────────
451-        "sh.tangled.publicKey" | "sh.tangled.string" | "sh.tangled.repo.artifact"
439+        "sh.tangled.publicKey"
440+        | "sh.tangled.string"
441+        | "sh.tangled.repo.artifact"
452442         | "sh.tangled.label.op" => {
453443             tracing::debug!(
454444                 collection,
@@ -557,7 +547,9 @@ async fn dispatch_special_delete(
557547         }
558548 
559549         // ─── Tangled-only records ───────────────────────────────────
560-        "sh.tangled.publicKey" | "sh.tangled.string" | "sh.tangled.repo.artifact"
550+        "sh.tangled.publicKey"
551+        | "sh.tangled.string"
552+        | "sh.tangled.repo.artifact"
561553         | "sh.tangled.label.op" => {
562554             tracing::debug!(
563555                 collection,
@@ -103,23 +103,18 @@ pub fn emit_create_table(
103103         }
104104     }
105105 
106-    // Composite PRIMARY KEY
107-    if config.conflict_keys.len() > 1 {
108-        let pk_cols = config.conflict_keys.join(", ");
109-        let has_more = !config.foreign_keys.is_empty();
106+    // Table-level PRIMARY KEY for composite PKs
107+    if needs_table_pk {
108+        let pk_str = pk_columns.join(", ");
109+        let has_more = !composite_fks.is_empty();
110110         if has_more {
111-            let _ = writeln!(out, "    PRIMARY KEY ({pk_cols}),");
111+            let _ = writeln!(out, "    PRIMARY KEY ({pk_str}),");
112112         } else {
113-            let _ = writeln!(out, "    PRIMARY KEY ({pk_cols})");
113+            let _ = writeln!(out, "    PRIMARY KEY ({pk_str})");
114114         }
115115     }
116116 
117117     // FOREIGN KEY constraints (composite only; single-column FKs use REFERENCES inline)
118-    let composite_fks: Vec<_> = config
119-        .foreign_keys
120-        .iter()
121-        .filter(|fk| fk.columns.len() > 1)
122-        .collect();
123118     for (i, fk) in composite_fks.iter().enumerate() {
124119         let local = fk.columns.join(", ");
125120         let remote = fk.ref_columns.join(", ");
@@ -53,11 +53,7 @@ fn emit_struct(
5353     w.indent();
5454 
5555     for (edge, prop_vertex) in &props {
56-        let field_name = edge
57-            .name
58-            .as_ref()
59-            .map(|n| n.as_str())
60-            .unwrap_or("unknown");
56+        let field_name = edge.name.as_ref().map(|n| n.as_str()).unwrap_or("unknown");
6157         let snake = camel_to_snake(field_name);
6258         let is_required = is_field_required(schema, vertex_id, field_name);
6359         let rust_type = kind_to_rust_type(&prop_vertex.kind, field_name);
@@ -79,7 +79,8 @@ fn main() -> Result<()> {
7979     all_crud.push_str("// Do not edit manually.\n\n");
8080     all_crud.push_str("use chrono::{DateTime, Utc};\nuse sqlx::PgPool;\nuse super::types::*;\n\n");
8181 
82-    all_xrpc_types.push_str("// Generated by cospan-codegen from Lexicon query/procedure definitions.\n");
82+    all_xrpc_types
83+        .push_str("// Generated by cospan-codegen from Lexicon query/procedure definitions.\n");
8384     all_xrpc_types.push_str("// Do not edit manually.\n\n");
8485     all_xrpc_types.push_str("use serde::{Serialize, Deserialize};\n\n");
8586 
@@ -144,7 +145,10 @@ fn main() -> Result<()> {
144145         }
145146 
146147         // --- XRPC types from query/procedure Lexicons ---
147-        let def_type = json.pointer("/defs/main/type").and_then(|v| v.as_str()).unwrap_or("");
148+        let def_type = json
149+            .pointer("/defs/main/type")
150+            .and_then(|v| v.as_str())
151+            .unwrap_or("");
148152         if def_type == "query" || def_type == "procedure" {
149153             if let Ok(code) = emit_xrpc::emit_xrpc_types(&atproto_schema, nsid, def_type) {
150154                 if !code.is_empty() {
@@ -332,13 +332,34 @@ pub fn all_record_configs() -> Vec<RecordConfig> {
332332                 ref_columns: &["did"],
333333             }],
334334             column_defaults: &[
335-                ColumnDefault { column: "default_branch", expression: "'main'" },
336-                ColumnDefault { column: "visibility", expression: "'public'" },
337-                ColumnDefault { column: "star_count", expression: "0" },
338-                ColumnDefault { column: "fork_count", expression: "0" },
339-                ColumnDefault { column: "open_issue_count", expression: "0" },
340-                ColumnDefault { column: "open_mr_count", expression: "0" },
341-                ColumnDefault { column: "source", expression: "'cospan'" },
335+                ColumnDefault {
336+                    column: "default_branch",
337+                    expression: "'main'",
338+                },
339+                ColumnDefault {
340+                    column: "visibility",
341+                    expression: "'public'",
342+                },
343+                ColumnDefault {
344+                    column: "star_count",
345+                    expression: "0",
346+                },
347+                ColumnDefault {
348+                    column: "fork_count",
349+                    expression: "0",
350+                },
351+                ColumnDefault {
352+                    column: "open_issue_count",
353+                    expression: "0",
354+                },
355+                ColumnDefault {
356+                    column: "open_mr_count",
357+                    expression: "0",
358+                },
359+                ColumnDefault {
360+                    column: "source",
361+                    expression: "'cospan'",
362+                },
342363             ],
343364         },
344365         RecordConfig {
@@ -412,8 +433,14 @@ pub fn all_record_configs() -> Vec<RecordConfig> {
412433                 ref_columns: &["did", "name"],
413434             }],
414435             column_defaults: &[
415-                ColumnDefault { column: "breaking_change_count", expression: "0" },
416-                ColumnDefault { column: "commit_count", expression: "0" },
436+                ColumnDefault {
437+                    column: "breaking_change_count",
438+                    expression: "0",
439+                },
440+                ColumnDefault {
441+                    column: "commit_count",
442+                    expression: "0",
443+                },
417444             ],
418445         },
419446         RecordConfig {
@@ -485,8 +512,14 @@ pub fn all_record_configs() -> Vec<RecordConfig> {
485512                 ref_columns: &["did", "name"],
486513             }],
487514             column_defaults: &[
488-                ColumnDefault { column: "state", expression: "'open'" },
489-                ColumnDefault { column: "comment_count", expression: "0" },
515+                ColumnDefault {
516+                    column: "state",
517+                    expression: "'open'",
518+                },
519+                ColumnDefault {
520+                    column: "comment_count",
521+                    expression: "0",
522+                },
490523             ],
491524         },
492525         RecordConfig {
@@ -614,8 +647,14 @@ pub fn all_record_configs() -> Vec<RecordConfig> {
614647                 ref_columns: &["did", "name"],
615648             }],
616649             column_defaults: &[
617-                ColumnDefault { column: "state", expression: "'open'" },
618-                ColumnDefault { column: "comment_count", expression: "0" },
650+                ColumnDefault {
651+                    column: "state",
652+                    expression: "'open'",
653+                },
654+                ColumnDefault {
655+                    column: "comment_count",
656+                    expression: "0",
657+                },
619658             ],
620659         },
621660         RecordConfig {
cospan · schematic version control on atproto built on AT Protocol