MCPcopy Index your code
hub / github.com/Permify/permify / RunWithShape

Method RunWithShape

pkg/development/development.go:141–521  ·  view source on GitHub ↗
(ctx context.Context, shape *file.Shape)

Source from the content-addressed store, hash-verified

139}
140
141func (c *Development) RunWithShape(ctx context.Context, shape *file.Shape) (errors []Error) {
142 // Parse the schema using the parser library
143 sch, err := parser.NewParser(shape.Schema).Parse()
144 if err != nil {
145 errors = append(errors, Error{
146 Type: "schema",
147 Key: "",
148 Message: err.Error(),
149 })
150 return errors
151 }
152
153 // Compile the parsed schema
154 _, _, err = compiler.NewCompiler(true, sch).Compile()
155 if err != nil {
156 errors = append(errors, Error{
157 Type: "schema",
158 Key: "",
159 Message: err.Error(),
160 })
161 return errors
162 }
163
164 // Generate a new unique ID for this version of the schema
165 version := xid.New().String()
166
167 // Create a slice of SchemaDefinitions, one for each statement in the schema
168 cnf := make([]storage.SchemaDefinition, 0, len(sch.Statements))
169 for _, st := range sch.Statements {
170 cnf = append(cnf, storage.SchemaDefinition{
171 TenantID: "t1",
172 Version: version,
173 Name: st.GetName(),
174 SerializedDefinition: []byte(st.String()),
175 })
176 }
177
178 // Write the schema definitions into the storage
179 err = c.Container.SW.WriteSchema(ctx, cnf)
180 if err != nil {
181 errors = append(errors, Error{
182 Type: "schema",
183 Key: "",
184 Message: err.Error(),
185 })
186 return errors
187 }
188
189 // Each item in the Relationships slice is processed individually
190 for _, t := range shape.Relationships {
191 tup, err := tuple.Tuple(t)
192 if err != nil {
193 errors = append(errors, Error{
194 Type: "relationships",
195 Key: t,
196 Message: err.Error(),
197 })
198 continue

Callers 1

RunMethod · 0.95

Calls 15

NewParserFunction · 0.92
NewCompilerFunction · 0.92
TupleFunction · 0.92
ValidateTupleFunction · 0.92
NewTupleCollectionFunction · 0.92
NewAttributeCollectionFunction · 0.92
AttributeFunction · 0.92
ValidateAttributeFunction · 0.92
EFunction · 0.92
EARFunction · 0.92
NewNoopTokenFunction · 0.92
SubjectToStringFunction · 0.92

Tested by

no test coverage detected