MCPcopy Create free account
hub / github.com/bytebase/bytebase / injectJoinedSchemas

Function injectJoinedSchemas

backend/api/v1/document_masking.go:810–843  ·  view source on GitHub ↗

injectJoinedSchemas adds array-of-objects schemas for each $lookup/$graphLookup join into the source objectSchema so masking covers the joined field. The as field holds an array of joined documents, so the injected schema is ARRAY{item: joinedSchema}. If the source schema has no StructKind or the jo

(objectSchema *storepb.ObjectSchema, joins []joinedSchema)

Source from the content-addressed store, hash-verified

808// The as field holds an array of joined documents, so the injected schema is ARRAY{item: joinedSchema}.
809// If the source schema has no StructKind or the joined collection has no schema, the join is skipped silently.
810func injectJoinedSchemas(objectSchema *storepb.ObjectSchema, joins []joinedSchema) *storepb.ObjectSchema {
811 if objectSchema == nil || len(joins) == 0 {
812 return objectSchema
813 }
814 structKind := objectSchema.GetStructKind()
815 if structKind == nil {
816 return objectSchema
817 }
818
819 // Clone properties map so we don't mutate the cached schema.
820 props := make(map[string]*storepb.ObjectSchema, len(structKind.Properties)+len(joins))
821 maps.Copy(props, structKind.Properties)
822 for _, j := range joins {
823 if j.schema == nil {
824 continue
825 }
826 props[j.asField] = &storepb.ObjectSchema{
827 Type: storepb.ObjectSchema_ARRAY,
828 Kind: &storepb.ObjectSchema_ArrayKind_{
829 ArrayKind: &storepb.ObjectSchema_ArrayKind{
830 Kind: j.schema,
831 },
832 },
833 }
834 }
835 return &storepb.ObjectSchema{
836 Type: storepb.ObjectSchema_OBJECT,
837 Kind: &storepb.ObjectSchema_StructKind_{
838 StructKind: &storepb.ObjectSchema_StructKind{
839 Properties: props,
840 },
841 },
842 }
843}
844
845// joinedSchema pairs an as-field name with its resolved ObjectSchema.
846type joinedSchema struct {

Callers 1

maskResultsMethod · 0.85

Calls 1

GetStructKindMethod · 0.45

Tested by

no test coverage detected