this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more legacy codegen progress

+80 -12
+6 -7
cmd/lexgen/flatschema.go
··· 119 119 } 120 120 case lexicon.SchemaProcedure: 121 121 // v.Properties: same as above 122 - if v.Output != nil && v.Output.Schema != nil { 122 + if v.Input != nil && v.Input.Schema != nil { 123 123 tp := slices.Clone(tpath) 124 - tp = append(tp, "output") 125 - if err := fl.flattenType(fd, tp, v.Output.Schema); err != nil { 124 + tp = append(tp, "input") 125 + if err := fl.flattenType(fd, tp, v.Input.Schema); err != nil { 126 126 return err 127 127 } 128 128 } 129 - if v.Input != nil && v.Input.Schema != nil { 129 + if v.Output != nil && v.Output.Schema != nil { 130 130 tp := slices.Clone(tpath) 131 - tp = append(tp, "input") 132 - if err := fl.flattenType(fd, tp, v.Input.Schema); err != nil { 131 + tp = append(tp, "output") 132 + if err := fl.flattenType(fd, tp, v.Output.Schema); err != nil { 133 133 return err 134 134 } 135 135 } ··· 146 146 default: 147 147 return fmt.Errorf("subscription with non-union message schema: %T", v.Message.Schema.Inner) 148 148 } 149 - 150 149 } 151 150 case lexicon.SchemaObject: 152 151 if err := fl.flattenObject(fd, tpath, &v); err != nil {
+74 -4
cmd/lexgen/generate.go
··· 73 73 func (gen *FlatGenerator) deps() map[string]bool { 74 74 d := map[string]bool{ 75 75 "lexutil \"github.com/bluesky-social/indigo/lex/util\"": true, 76 + // TODO: this could be more conditional (the record check is not enough though) 77 + "cbg \"github.com/whyrusleeping/cbor-gen\"": true, 76 78 } 77 79 for _, t := range gen.Lex.Types { 78 80 switch t.Type { 79 81 case "query", "procedure": 80 82 d["\"context\""] = true 81 83 case "record": 82 - // TODO 83 - //d["cbg \"github.com/whyrusleeping/cbor-gen\""]: true 84 + d["cbg \"github.com/whyrusleeping/cbor-gen\""] = true 84 85 } 85 86 } 86 87 for ext, _ := range gen.Lex.ExternalRefs { ··· 89 90 } else if strings.HasPrefix(ext, "app.bsky.") { 90 91 d["appbsky \"github.com/bluesky-social/indigo/api/bsky\""] = true 91 92 } else if strings.HasPrefix(ext, "tools.ozone.") { 92 - d["toolsozone \"github.com/bluesky-social/indigo/api/toolsozone\""] = true 93 + d["toolsozone \"github.com/bluesky-social/indigo/api/ozone\""] = true 93 94 } else { 94 95 // XXX: handle more mappings; or log/error if missing 95 96 } ··· 429 430 } 430 431 } 431 432 fmt.Fprintf(gen.Out, "type %s struct {\n", name) 433 + for _, rname := range refNames { 434 + ref := unionRefs[rname] 435 + fmt.Fprintf(gen.Out, " %s *%s\n", ref.FieldName, ref.TypeName) 436 + } 437 + fmt.Fprintf(gen.Out, "}\n\n") 432 438 439 + // ... then MarshalJSON 440 + fmt.Fprintf(gen.Out, "func (t *%s) MarshalJSON() ([]byte, error) {\n", name) 433 441 for _, rname := range refNames { 434 442 ref := unionRefs[rname] 435 - fmt.Fprintf(gen.Out, " %s *%s\n", ref.FieldName, ref.TypeName) 443 + fmt.Fprintf(gen.Out, " if t.%s != nil {\n", ref.FieldName) 444 + fmt.Fprintf(gen.Out, " t.%s.LexiconTypeID = \"%s\"\n", ref.FieldName, ref.LexName) 445 + fmt.Fprintf(gen.Out, " return json.Marshal(t.%s)\n", ref.FieldName) 446 + fmt.Fprintf(gen.Out, " }\n") 447 + } 448 + // TODO: better error message here? 449 + fmt.Fprintf(gen.Out, " return nil, fmt.Errorf(\"cannot marshal empty enum\")") 450 + fmt.Fprintf(gen.Out, "}\n\n") 451 + 452 + // ... then UnmarshalJSON 453 + fmt.Fprintf(gen.Out, "func (t *%s) UnmarshalJSON(b []byte) error {\n", name) 454 + fmt.Fprintf(gen.Out, " typ, err := lexutil.TypeExtract(b)\n") 455 + fmt.Fprintf(gen.Out, " if err != nil {\n") 456 + fmt.Fprintf(gen.Out, " return err\n") 457 + fmt.Fprintf(gen.Out, " }\n\n") 458 + fmt.Fprintf(gen.Out, " switch typ {\n") 459 + for _, rname := range refNames { 460 + ref := unionRefs[rname] 461 + fmt.Fprintf(gen.Out, " case \"%s\":\n", ref.LexName) 462 + fmt.Fprintf(gen.Out, " t.%s = new(%s)\n", ref.FieldName, ref.TypeName) 463 + fmt.Fprintf(gen.Out, " return json.Unmarshal(b, t.%s)\n", ref.FieldName) 464 + } 465 + fmt.Fprintf(gen.Out, " default:\n") 466 + fmt.Fprintf(gen.Out, " return nil\n") 467 + fmt.Fprintf(gen.Out, " }\n") 468 + fmt.Fprintf(gen.Out, "}\n\n") 469 + 470 + // TODO: bailing out here for; need better logic around whether this is required for a record or not 471 + if true { 472 + return nil 473 + } 474 + 475 + // ... then MarshalCBOR 476 + fmt.Fprintf(gen.Out, "func (t *%s) MarshalCBOR(w io.Writer) error {\n", name) 477 + fmt.Fprintf(gen.Out, " if t == nil {\n") 478 + fmt.Fprintf(gen.Out, " _, err := w.Write(cbg.CborNull)\n") 479 + fmt.Fprintf(gen.Out, " return err") 480 + fmt.Fprintf(gen.Out, " }\n") 481 + for _, rname := range refNames { 482 + ref := unionRefs[rname] 483 + fmt.Fprintf(gen.Out, " if t.%s != nil {\n", ref.FieldName) 484 + fmt.Fprintf(gen.Out, " return t.%s.MarshalCBOR(w)\n", ref.FieldName) 485 + fmt.Fprintf(gen.Out, " }\n") 486 + } 487 + // TODO: better error message here? 488 + fmt.Fprintf(gen.Out, " return fmt.Errorf(\"cannot cbor marshal empty enum\")") 489 + fmt.Fprintf(gen.Out, "}\n\n") 490 + 491 + // ... then UnmarshalCBOR 492 + fmt.Fprintf(gen.Out, "func (t *%s) UnmarshalCBOR(b []byte) error {\n", name) 493 + fmt.Fprintf(gen.Out, " typ, err := lexutil.TypeExtract(b)\n") 494 + fmt.Fprintf(gen.Out, " if err != nil {\n") 495 + fmt.Fprintf(gen.Out, " return err\n") 496 + fmt.Fprintf(gen.Out, " }\n\n") 497 + fmt.Fprintf(gen.Out, " switch typ {\n") 498 + for _, rname := range refNames { 499 + ref := unionRefs[rname] 500 + fmt.Fprintf(gen.Out, " case \"%s\":\n", ref.LexName) 501 + fmt.Fprintf(gen.Out, " t.%s = new(%s)\n", ref.FieldName, ref.TypeName) 502 + fmt.Fprintf(gen.Out, " return t.%s.UnmarshalCBOR(bytes.NewReader(b))\n", ref.FieldName) 436 503 } 504 + fmt.Fprintf(gen.Out, " default:\n") 505 + fmt.Fprintf(gen.Out, " return nil\n") 506 + fmt.Fprintf(gen.Out, " }\n") 437 507 fmt.Fprintf(gen.Out, "}\n\n") 438 508 439 509 return nil
-1
cmd/lexgen/main.go
··· 162 162 TabIndent: false, 163 163 TabWidth: 4, 164 164 } 165 - //_ = fmtOpts 166 165 formatted, err := imports.Process(outPath, buf.Bytes(), &fmtOpts) 167 166 if err != nil { 168 167 return fmt.Errorf("failed to format codegen output (%s): %w", p, err)