From 158cf2f29a9e306ae3542d407abb8505ab3517bd Mon Sep 17 00:00:00 2001 From: lekko-jonathan <150070021+lekko-jonathan@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:35:21 -0700 Subject: [PATCH] Super basic argless calls (#463) * Super basic argless calls * merge * super simple e2e * comment out test --- cmd/lekko/sync_test.go | 23 +++++++++++++++++++++++ pkg/gen/ts.go | 15 +++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/cmd/lekko/sync_test.go b/cmd/lekko/sync_test.go index b564dad7..e12925ca 100644 --- a/cmd/lekko/sync_test.go +++ b/cmd/lekko/sync_test.go @@ -223,3 +223,26 @@ func Test_ProtoJsonToTs(t *testing.T) { }) } */ +/* +func Test_blobToTs(t *testing.T) { + repoContents, err := repo.DecodeRepositoryContents([]byte("Cp0CCgdkZWZhdWx0EnUKDWJhbm5lci1jb25maWcaYgovCi10eXBlLmdvb2dsZWFwaXMuY29tL2dvb2dsZS5wcm90b2J1Zi5Cb29sVmFsdWUaLwotdHlwZS5nb29nbGVhcGlzLmNvbS9nb29nbGUucHJvdG9idWYuQm9vbFZhbHVlIAESmgEKBXRoaW5nGo4BCkUKMnR5cGUuZ29vZ2xlYXBpcy5jb20vbGVra28ucnVsZXMudjFiZXRhMy5Db25maWdDYWxsEg8aDWJhbm5lci1jb25maWcaRQoydHlwZS5nb29nbGVhcGlzLmNvbS9sZWtrby5ydWxlcy52MWJldGEzLkNvbmZpZ0NhbGwSDxoNYmFubmVyLWNvbmZpZyABEuwLCvsBCh5nb29nbGUvcHJvdG9idWYvZHVyYXRpb24ucHJvdG8SD2dvb2dsZS5wcm90b2J1ZiI6CghEdXJhdGlvbhIYCgdzZWNvbmRzGAEgASgDUgdzZWNvbmRzEhQKBW5hbm9zGAIgASgFUgVuYW5vc0KDAQoTY29tLmdvb2dsZS5wcm90b2J1ZkINRHVyYXRpb25Qcm90b1ABWjFnb29nbGUuZ29sYW5nLm9yZy9wcm90b2J1Zi90eXBlcy9rbm93bi9kdXJhd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mdvb2dsZS9wcm90b2J1Zi93cmFwcGVycy5wcm90bxIPZ29vZ2xlLnByb3RvYnVmIiMKC0RvdWJsZVZhbHVlEhQKBXZhbHVlGAEgASgBUgV2YWx1ZSIiCgpGbG9hdFZhbHVlEhQKBXZhbHVlGAEgASgCUgV2YWx1ZSIiCgpJbnQ2NFZhbHVlEhQKBXZhbHVlGAEgASgDUgV2YWx1ZSIjCgtVSW50NjRWYWx1ZRIUCgV2YWx1ZRgBIAEoBFIFdmFsdWUiIgoKSW50MzJWYWx1ZRIUCgV2YWx1ZRgBIAEoBVIFdmFsdWUiIwoLVUludDMyVmFsdWUSFAoFdmFsdWUYASABKA1SBXZhbHVlIiEKCUJvb2xWYWx1ZRIUCgV2YWx1ZRgBIAEoCFIFdmFsdWUiIwoLU3RyaW5nVmFsdWUSFAoFdmFsdWUYASABKAlSBXZhbHVlIiIKCkJ5dGVzVmFsdWUSFAoFdmFsdWUYASABKAxSBXZhbHVlQoMBChNjb20uZ29vZ2xlLnByb3RvYnVmQg1XcmFwcGVyc1Byb3RvUAFaMWdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL3dyYXBwZXJzcGL4AQGiAgNHUEKqAh5Hb29nbGUuUHJvdG9idWYuV2VsbEtub3duVHlwZXNiBnByb3RvMw==")) + if err != nil { + panic(err) + } + + typeRegistry, err := protoutils.FileDescriptorSetToTypeRegistry(repoContents.FileDescriptorSet) + if err != nil { + panic(err) + } + + for _, namespace := range repoContents.Namespaces { + for _, f := range namespace.Features { + code, err := gen.GenTSForFeature(f, namespace.Name, "", typeRegistry) + if err != nil { + panic(err) + } + fmt.Println(code) + } + } +} +*/ diff --git a/pkg/gen/ts.go b/pkg/gen/ts.go index 5cda8498..145ffbbc 100644 --- a/pkg/gen/ts.go +++ b/pkg/gen/ts.go @@ -559,6 +559,21 @@ func FieldValueToTS(f protoreflect.FieldDescriptor, val protoreflect.Value, type } func translateRetValueTS(val *anypb.Any, t featurev1beta1.FeatureType, typeRegistry *protoregistry.Types) string { + // TODO - move to lekkoAny + if val.TypeUrl == "type.googleapis.com/lekko.rules.v1beta3.ConfigCall" { + call := &rulesv1beta3.ConfigCall{} + err := proto.Unmarshal(val.Value, call) + if err != nil { + panic(err) + } + var funcNameBuilder strings.Builder + funcNameBuilder.WriteString("get") + for _, word := range regexp.MustCompile("[_-]+").Split(call.Key, -1) { + funcNameBuilder.WriteString(strings.ToUpper(word[:1]) + word[1:]) + } + funcName := funcNameBuilder.String() + return fmt.Sprintf("%s()", funcName) + } //var dypb *dynamicpb.Message marshalOptions := protojson.MarshalOptions{ UseProtoNames: true,