this repo has no description
13
fork

Configure Feed

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

create lexicons from templates

+275 -7
+1 -7
cmd/glot/main.go
··· 27 27 Name: "glot", 28 28 Usage: "AT Lexicon Tool", 29 29 Version: versioninfo.Short(), 30 - Flags: []cli.Flag{ 31 - &cli.StringFlag{ 32 - Name: "log-level", 33 - Usage: "log verbosity level (eg: warn, info, debug)", 34 - Sources: cli.EnvVars("GLOT_LOG_LEVEL", "GO_LOG_LEVEL", "LOG_LEVEL"), 35 - }, 36 - }, 37 30 } 38 31 app.Commands = []*cli.Command{ 39 32 cmdLint, ··· 41 34 cmdStatus, 42 35 cmdDiff, 43 36 cmdCompat, 37 + cmdNew, 44 38 } 45 39 return app.Run(context.Background(), args) 46 40 }
+110
cmd/glot/new.go
··· 1 + package main 2 + 3 + import ( 4 + "context" 5 + _ "embed" 6 + "encoding/json" 7 + "fmt" 8 + "os" 9 + 10 + "github.com/bluesky-social/indigo/atproto/data" 11 + "github.com/bluesky-social/indigo/atproto/syntax" 12 + 13 + "github.com/urfave/cli/v3" 14 + ) 15 + 16 + //go:embed templates/record.json 17 + var tmplRecord string 18 + 19 + //go:embed templates/query-view.json 20 + var tmplQueryView string 21 + 22 + //go:embed templates/query-list.json 23 + var tmplQueryList string 24 + 25 + //go:embed templates/procedure.json 26 + var tmplProcedure string 27 + 28 + var cmdNew = &cli.Command{ 29 + Name: "new", 30 + Usage: "create new lexicon schema from template", 31 + //ArgsUsage: `<schema-type> <nsid>`, 32 + Arguments: []cli.Argument{ 33 + &cli.StringArg{ 34 + Name: "schema-type", 35 + }, 36 + &cli.StringArg{ 37 + Name: "nsid", 38 + }, 39 + }, 40 + Flags: []cli.Flag{ 41 + &cli.StringFlag{ 42 + Name: "lexicons-dir", 43 + Value: "./lexicons/", 44 + Usage: "base directory for project Lexicon files", 45 + Sources: cli.EnvVars("LEXICONS_DIR"), 46 + }, 47 + &cli.BoolFlag{ 48 + Name: "list-templates", 49 + Aliases: []string{"l"}, 50 + Usage: "list available templates (schema types)", 51 + }, 52 + }, 53 + Action: runNew, 54 + } 55 + 56 + func runNew(ctx context.Context, cmd *cli.Command) error { 57 + 58 + if cmd.Bool("list-templates") { 59 + fmt.Println("Available schema templates:") 60 + fmt.Println("") 61 + fmt.Println(" record") 62 + fmt.Println(" query-view") 63 + fmt.Println(" query-list") 64 + fmt.Println(" procedure") 65 + return nil 66 + } 67 + 68 + nsid, err := syntax.ParseNSID(cmd.StringArg("nsid")) 69 + if err != nil { 70 + return fmt.Errorf("invalid schema NSID syntax: %w", err) 71 + } 72 + 73 + schemaType := cmd.StringArg("schema-type") 74 + 75 + var orig json.RawMessage 76 + switch schemaType { 77 + case "record": 78 + orig = []byte(tmplRecord) 79 + case "query-view": 80 + orig = []byte(tmplQueryView) 81 + case "query-list": 82 + orig = []byte(tmplQueryList) 83 + case "procedure": 84 + orig = []byte(tmplProcedure) 85 + default: 86 + return fmt.Errorf("unknown schema template: %s", schemaType) 87 + } 88 + 89 + d, err := data.UnmarshalJSON(orig) 90 + if err != nil { 91 + fmt.Println(orig) 92 + fmt.Println(tmplRecord) 93 + return fmt.Errorf("XXX") 94 + //return err 95 + } 96 + d["id"] = nsid.String() 97 + 98 + b, err := json.Marshal(d) 99 + if err != nil { 100 + return err 101 + } 102 + 103 + fpath := pathForNSID(cmd, nsid) 104 + _, err = os.Stat(fpath) 105 + if err == nil { 106 + return fmt.Errorf("output file already exists: %s", fpath) 107 + } 108 + 109 + return writeLexiconFile(ctx, cmd, nsid, fpath, json.RawMessage(b)) 110 + }
+28
cmd/glot/templates/procedure.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "com.example.muteThing", 4 + "defs": { 5 + "main": { 6 + "type": "procedure", 7 + "description": "TODO: description of this API endpoint", 8 + "input": { 9 + "encoding": "application/json", 10 + "schema": { 11 + "type": "object", 12 + "required": ["subject"], 13 + "properties": { 14 + "subject": { "type": "string", "format": "at-identifier" } 15 + } 16 + } 17 + }, 18 + "output": { 19 + "encoding": "application/json", 20 + "schema": { 21 + "type": "object", 22 + "required": [], 23 + "properties": {} 24 + } 25 + } 26 + } 27 + } 28 + }
+50
cmd/glot/templates/query-list.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "com.example.listThings", 4 + "defs": { 5 + "main": { 6 + "type": "query", 7 + "description": "TODO: enumerates objects", 8 + "parameters": { 9 + "type": "params", 10 + "properties": { 11 + "limit": { 12 + "type": "integer", 13 + "minimum": 1, 14 + "maximum": 100, 15 + "default": 20 16 + }, 17 + "cursor": { "type": "string" } 18 + } 19 + }, 20 + "output": { 21 + "encoding": "application/json", 22 + "schema": { 23 + "type": "object", 24 + "required": ["values"], 25 + "properties": { 26 + "cursor": { "type": "string" }, 27 + "values": { 28 + "type": "array", 29 + "items": { "type": "ref", "ref": "#thing" } 30 + } 31 + } 32 + } 33 + } 34 + }, 35 + "thing": { 36 + "type": "object", 37 + "required": [ 38 + "uri", 39 + "cid", 40 + "title" 41 + ], 42 + "properties": { 43 + "uri": { "type": "string", "format": "at-uri" }, 44 + "cid": { "type": "string", "format": "cid" }, 45 + "title": { "type": "string" }, 46 + "extra": { "type": "unknown" } 47 + } 48 + } 49 + } 50 + }
+47
cmd/glot/templates/query-view.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "com.example.getThing", 4 + "defs": { 5 + "main": { 6 + "type": "query", 7 + "description": "TODO: retrieves a hydrated 'view' of a record.", 8 + "parameters": { 9 + "type": "params", 10 + "required": ["uri"], 11 + "properties": { 12 + "uri": { 13 + "type": "string", 14 + "format": "at-uri", 15 + "description": "Reference (AT-URI) of the record to hydrate." 16 + } 17 + } 18 + }, 19 + "output": { 20 + "encoding": "application/json", 21 + "schema": { 22 + "type": "ref", 23 + "ref": "#thingView" 24 + } 25 + } 26 + }, 27 + "thingView": { 28 + "type": "object", 29 + "required": ["record"], 30 + "properties": { 31 + "record": { "type": "ref", "ref": "com.example.record" }, 32 + "viewer": { "type": "ref", "ref": "#viewerState" }, 33 + "labels": { 34 + "type": "array", 35 + "items": { "type": "ref", "ref": "com.atproto.label.defs#label" } 36 + } 37 + } 38 + }, 39 + "viewerState": { 40 + "type": "object", 41 + "description": "Metadata about the requesting account's relationship with the subject. Only has meaningful content for authed requests.", 42 + "properties": { 43 + "muted": { "type": "boolean" } 44 + } 45 + } 46 + } 47 + }
+39
cmd/glot/templates/record.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "com.example.record", 4 + "defs": { 5 + "main": { 6 + "type": "record", 7 + "description": "TODO: describe purpose of this schema", 8 + "key": "any", 9 + "record": { 10 + "type": "object", 11 + "required": ["name", "createdAt"], 12 + "properties": { 13 + "name": { 14 + "type": "string", 15 + "maxGraphemes": 64, 16 + "maxLength": 640, 17 + "minLength": 1, 18 + "description": "TODO: title name of record; can not be empty" 19 + }, 20 + "description": { 21 + "type": "string", 22 + "maxGraphemes": 300, 23 + "maxLength": 3000 24 + }, 25 + "descriptionFacets": { 26 + "type": "array", 27 + "items": { "type": "ref", "ref": "app.bsky.richtext.facet" } 28 + }, 29 + "avatar": { 30 + "type": "blob", 31 + "accept": ["image/png", "image/jpeg"], 32 + "maxSize": 2000000 33 + }, 34 + "createdAt": { "type": "string", "format": "datetime" } 35 + } 36 + } 37 + } 38 + } 39 + }