MCPcopy Create free account
hub / github.com/Permify/permify / visualize

Function visualize

pkg/development/wasm/main.go:68–102  ·  view source on GitHub ↗

readSchemaGraph is a function that reads the Permify schema and converts it to a graph representation. It returns a JavaScript function that can be invoked from JavaScript code, enabling the interaction between JavaScript and Go code.

()

Source from the content-addressed store, hash-verified

66// It returns a JavaScript function that can be invoked from JavaScript code,
67// enabling the interaction between JavaScript and Go code.
68func visualize() js.Func {
69 return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
70 // Call the ReadSchema method to read the schema.
71 sch, err := dev.ReadSchema(context.Background())
72 // If there's an error in reading the schema, return the error.
73 if err != nil {
74 return js.ValueOf([]interface{}{nil, err.Error()})
75 }
76 // Convert the read schema to a graph representation.
77 r, err := graph.NewBuilder(sch).SchemaToGraph()
78 // If there's an error in converting, return the error.
79 if err != nil {
80 return js.ValueOf([]interface{}{nil, err.Error()})
81 }
82 // Marshal the nodes and edges of the graph into JSON format.
83 result, err := json.Marshal(struct {
84 Nodes []*graph.Node `json:"nodes"`
85 Edges []*graph.Edge `json:"edges"`
86 }{Nodes: r.Nodes(), Edges: r.Edges()})
87 // If there's an error in marshalling, return the error.
88 if err != nil {
89 return js.ValueOf([]interface{}{nil, err.Error()})
90 }
91
92 // Marshal the read schema into JSON format.
93 s, err := protojson.Marshal(sch)
94 // If there's an error in marshalling, return the error.
95 if err != nil {
96 return js.ValueOf([]interface{}{nil, err.Error()})
97 }
98
99 // Return the marshalled graph and no error.
100 return js.ValueOf([]interface{}{string(result), string(s), nil})
101 })
102}
103
104func main() {
105 ch := make(chan struct{}, 0)

Callers 1

mainFunction · 0.85

Calls 6

NewBuilderFunction · 0.92
SchemaToGraphMethod · 0.80
NodesMethod · 0.80
EdgesMethod · 0.80
ReadSchemaMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected