@@ -84,159 +84,6 @@ func NewConnector(ctx context.Context, opts ...ConnectorOption) *Connector {
8484 return connector
8585}
8686
87- // NewDynamicConnectorWithSchema creates a dynamically configured Connector using the provided schema, bindings, and options.
88- func NewDynamicConnectorWithSchema (ctx context.Context , service protoreflect.ServiceDescriptor , bounds []Binding , opts ... ConnectorOption ) * Connector {
89- procedureName := "/" + string (service .FullName ()) + "/"
90- methods := make ([]* ConnectorMethod , 0 , service .Methods ().Len ())
91- for j := 0 ; j < service .Methods ().Len (); j ++ {
92- method := service .Methods ().Get (j )
93- // fmt.Printf(" Method Name: %s\n", method.Name())
94-
95- methodProcedureName := procedureName + string (method .Name ())
96- methods = append (methods , & ConnectorMethod {
97- ProcedureName : methodProcedureName ,
98- Input : method .Input (),
99- Output : method .Output (),
100- Schema : method ,
101- })
102- }
103-
104- mbp := make (map [string ]* ConnectorMethod )
105- for _ , method := range methods {
106- mbp [method .ProcedureName ] = method
107- }
108-
109- // c := Configuration{}
110- // c.ResolveConfiguration()
111-
112- bindings := RegisterBindings (ctx , bounds )
113-
114- options , err := newConnectorOptions (opts )
115- if err != nil {
116- fmt .Println (err )
117- }
118-
119- connector := & Connector {
120- Bindings : bindings ,
121- ProcedureName : procedureName ,
122- Name : string (service .FullName ()),
123- Err : nil ,
124- Schema : service ,
125- Methods : methods ,
126- MethodsByPath : mbp ,
127- Opts : opts ,
128-
129- options : options ,
130- }
131-
132- // TODO create a WithConnectOption option to allow to pass data directly to connect
133- // connector.Handler = NewDynamicConnectorHandler(connector)
134-
135- return connector
136- }
137-
138- //
139- //// NewDynamicConnector creates a new instance of Connector based on the given service path, bindings, and optional configurations.
140- //// It resolves the service schema dynamically and initializes the Connector with methods and bindings information.
141- //// Returns a Connector, which may include an error if schema resolution fails.
142- //func NewDynamicConnector(ctx context.Context, servicePath string, bounds []Binding, opts ...ConnectorOption) *Connector {
143- // serviceName := strings.TrimSuffix(strings.TrimPrefix(servicePath, "/"), "/")
144- // desc, err := protoregistry.GlobalFiles.FindDescriptorByName(protoreflect.FullName(serviceName))
145- // if err != nil {
146- // return &Connector{Err: fmt.Errorf("could not resolve schema for service at path %q: %w", servicePath, err)}
147- // }
148- // svcDesc, ok := desc.(protoreflect.ServiceDescriptor)
149- // if !ok {
150- // return &Connector{
151- // Err: fmt.Errorf("could not resolve schema for service at path %q: resolved descriptor is %s, not a service", servicePath, descKind(desc)),
152- // }
153- // }
154- // return NewDynamicConnectorWithSchema(ctx, svcDesc, bounds, opts...)
155- //}
156- //
157- //// func (ImplementedDynamicServiceHandler) DynamicUnary(context.Context, *connect.Request[dynamicpb.Message]) (*connect.Response[dynamicpb.Message], error) {
158- //
159- //// DynamicUnary processes a CreateConfigurationRequest and returns a CreateConfigurationResponse or an error.
160- //func (connector *Connector) DynamicUnary(_ context.Context, req *connect.Request[v2alpha.CreateConfigurationRequest]) (*connect.Response[v2alpha.CreateConfigurationResponse], error) {
161- // // fmt.Println(req.HTTPMethod())
162- // // fmt.Println(req.Spec().Schema)
163- // // fmt.Println(req.Spec().StreamType)
164- // fmt.Println(req.Spec().Procedure)
165- // // fmt.Println(req.Spec().IdempotencyLevel)
166- // // fmt.Println(req.Spec().IsClient)
167- //
168- // fmt.Println(req.Msg)
169- //
170- // return connect.NewResponse(&v2alpha.CreateConfigurationResponse{
171- // SpecContext: &specv2pb.SpecResponseContext{
172- // ResponseValidation: &typev2pb.ResponseValidation{
173- // ValidateOnly: true,
174- // },
175- // OrganizationSlug: "hello",
176- // WorkspaceSlug: "world",
177- // WorkspaceJan: 1,
178- // RoutineId: "123",
179- // },
180- // Configuration: &v2alpha.Configuration{
181- // Id: "123",
182- // OrganizationSlug: "hello",
183- // WorkspaceSlug: "world",
184- // },
185- // }), nil
186- // //
187- // //tracer := *opentelemetryv1.Bound.Tracer
188- // //log := *zaploggerv1.Bound.Logger
189- // //
190- // //// Get it from the GlobalSystem Registry
191- // //_, err := GlobalSystems.GetSystemByName(req.Spec().Procedure)
192- // //if err != nil {
193- // // return nil, err
194- // //}
195- // //
196- // //// Executes top level validation, no business domain validation
197- // //validationCtx, validationSpan := tracer.Start(ctx, "request-validation", trace.WithSpanKind(trace.SpanKindInternal))
198- // //v := *protovalidatev0.Bound.Validator
199- // //if err := v.Validate(req.Msg); err != nil {
200- // // return nil, ErrServerPreconditionFailed.WithInternalErrorDetail(err)
201- // //}
202- // //validationSpan.End()
203- // //
204- // //// Spec Propagation
205- // //specCtx, specSpan := tracer.Start(validationCtx, "spec-propagation", trace.WithSpanKind(trace.SpanKindInternal))
206- // //spec, ok := ctx.Value("spec").(*specv2pb.Spec)
207- // //if !ok {
208- // // return nil, ErrServerInternal.WithInternalErrorDetail(errors.New("cannot propagate spec to context"))
209- // //}
210- // //specSpan.End()
211- // //
212- // //// Distributed Domain Handler
213- // //handlerCtx, handlerSpan := tracer.Start(specCtx, "event-generation", trace.WithSpanKind(trace.SpanKindInternal))
214- // //
215- // //entity := DynamicSpecEntity{}
216- // //reply, err2 := natsnodev1.Bound.MultiplexCommandSync(handlerCtx, spec, &natsnodev1.SpecCommand{
217- // // Request: req.Msg,
218- // // Stream: natsnodev1.NewInboundStream(),
219- // // CommandName: "",
220- // // CommandTopic: EventDataDynamicTopic,
221- // // EntityTypeName: entity.TypeName(),
222- // //})
223- // //if err2 != nil {
224- // // log.SpecError(err2.SpecError())
225- // // return nil, connect.NewError(connect.CodeInternal, errors.New("internal error"))
226- // //}
227- // //
228- // //var dd v2alpha.CreateConfigurationResponse
229- // //err3 := proto.Unmarshal(reply.Data, &dd)
230- // //if err3 != nil {
231- // // log.SpecError(err3.SpecError())
232- // // return nil, connect.NewError(connect.CodeInternal, errors.New("internal error"))
233- // //}
234- // //
235- // //handlerSpan.End()
236- // //
237- // //return connect.NewResponse(&dd), nil
238- //}
239-
24087// ListenAndProcess initializes the connector's context, manages its lifecycle, and delegates processing tasks with context.
24188func (connector * Connector ) ListenAndProcess () {
24289 ctx := context .Background ()
0 commit comments