Skip to content

Commit

Permalink
updated redirect test case
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Oct 7, 2024
1 parent eec9aea commit d290deb
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 97 deletions.
2 changes: 1 addition & 1 deletion cmd/command/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/viant/datly/internal/plugin"
"github.com/viant/datly/internal/translator"
"github.com/viant/datly/repository"
"github.com/viant/datly/service/executor/handler"
"github.com/viant/datly/repository/handler"
"github.com/viant/datly/view/extension"
"github.com/viant/datly/view/state"
"github.com/viant/tagly/format/text"
Expand Down
2 changes: 1 addition & 1 deletion e2e/debug_gen/datly.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {

baseDir := filepath.Join(toolbox.CallerDirectory(3), "..")
fmt.Printf("base: %v\n", baseDir)
caseName := "029_generate_put_one_many"
caseName := "050_redirect"
caseFolder := filepath.Join(baseDir, "local/regression/cases/", caseName)
gen, err := loadGen(caseFolder, caseName)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions e2e/local/regression/cases/001_one_to_many/vendor_list.dql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@


#set( $_ = $VendorName<string>(form/name).Optional().WithPredicate(0, 'contains', 't', 'NAME'))
#set( $_ = $Fields<[]string>(query/xx).Optional().QuerySelector('vendor'))
#set( $_ = $Fields<[]string>(query/fields).Optional().QuerySelector('vendor'))
#set( $_ = $Page<int>(query/page).Optional().QuerySelector('vendor'))
#set( $_ = $Fields<[]string>(query/yy).Optional().QuerySelector('products'))


SELECT vendor.*,
Expand Down
32 changes: 0 additions & 32 deletions e2e/local/regression/cases/050_router_redirection/expect.json

This file was deleted.

5 changes: 0 additions & 5 deletions e2e/local/regression/cases/050_router_redirection/gen.json

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion e2e/local/regression/cases/050_router_redirection/skip.txt

This file was deleted.

12 changes: 0 additions & 12 deletions e2e/local/regression/cases/050_router_redirection/test.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion gateway/router/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (r *Handler) handleComponent(ctx context.Context, request *http.Request, aC
//TODO merge with Path settings
unmarshal := aComponent.UnmarshalFunc(request)
locatorOptions := append(aComponent.LocatorOptions(request, hstate.NewForm(), unmarshal))
aSession := session.New(aComponent.View, session.WithLocatorOptions(locatorOptions...))
aSession := session.New(aComponent.View, session.WithLocatorOptions(locatorOptions...), session.WithRegistry(r.registry))
err := aSession.InitKinds(state.KindComponent, state.KindHeader, state.KindRequestBody, state.KindForm, state.KindQuery)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1135,18 +1135,17 @@ github.com/viant/velty v0.2.1-0.20230927172116-ba56497b5c85 h1:zKk+6hqUipkJXCPCH
github.com/viant/velty v0.2.1-0.20230927172116-ba56497b5c85/go.mod h1:Q/UXviI2Nli8WROEpYd/BELMCSvnulQeyNrbPmMiS/Y=
github.com/viant/x v0.3.0 h1:/3A0z/uySGxMo6ixH90VAcdjI00w5e3REC1zg5hzhJA=
github.com/viant/x v0.3.0/go.mod h1:54jP3qV+nnQdNDaWxEwGTAAzCu9sx9er9htiwTW/Mcw=
github.com/viant/xdatly v0.5.4-0.20240923185204-11a0855c8bb5 h1:BK8UCvls5COU6y24/gLS/YUd8oWyjSVJ+9eOlx9iUsQ=
github.com/viant/xdatly v0.5.4-0.20240923185204-11a0855c8bb5/go.mod h1:YwNS31k5r1Ldw5s7wmQXUKaalN6BWcfX9qePO/b/ilc=
github.com/viant/xdatly v0.5.4-0.20241003184238-0d8a69ec651f h1:D3Uu0TCB5ZevIqioFGPXhAjHTyh5t23I4y2isuGT/KU=
github.com/viant/xdatly v0.5.4-0.20241003184238-0d8a69ec651f/go.mod h1:YwNS31k5r1Ldw5s7wmQXUKaalN6BWcfX9qePO/b/ilc=
github.com/viant/xdatly/extension v0.0.0-20231013204918-ecf3c2edf259 h1:9Yry3PUBDzc4rWacOYvAq/TKrTV0agvMF0gwm2gaoHI=
github.com/viant/xdatly/extension v0.0.0-20231013204918-ecf3c2edf259/go.mod h1:fb8YgbVadk8X5ZLz49LWGzWmQlZd7Y/I5wE0ru44bIo=
github.com/viant/xdatly/handler v0.0.0-20241003184238-0d8a69ec651f h1:HGc7Qe48ICl3ldP7aTvwQAhmVt8oxGo577teu/mIt7w=
github.com/viant/xdatly/handler v0.0.0-20241003184238-0d8a69ec651f/go.mod h1:bBa479sCB55VymMrXFccluUFkf6oRI77xhtnWIcL8K0=
github.com/viant/xdatly/types/core v0.0.0-20240109065401-9758ebacb4bb h1:X4emK6TIR6IXiFlQz9wEdCi5RJMG3dg3e8+VLQ2zhnM=
github.com/viant/xdatly/types/core v0.0.0-20240109065401-9758ebacb4bb/go.mod h1:LJN2m8xJjtYNCvyvNrVanJwvzj8+hYCuPswL8H4qRG0=
github.com/viant/xdatly/types/custom v0.0.0-20240801144911-4c2bfca4c23a h1:jecH7mH63gj1zJwD18SdvSHM9Ttr9FEOnhHkYfkCNkI=
github.com/viant/xdatly/types/custom v0.0.0-20240801144911-4c2bfca4c23a/go.mod h1:s0oJuKw3+AIT8RTyr+7+6nk+kBZhN/N4QWAQyYvvlqY=
github.com/viant/xlsy v0.3.0 h1:j/cADAd41XcxfAGSyPUZmEOHbVe2dcjdVI6JiTKA6ws=
github.com/viant/xlsy v0.3.0/go.mod h1:RajfF9HkL/PfIxRCvZSubpNlpdMUNDKYZp8C1o3vF4Q=
github.com/viant/xlsy v0.3.1 h1:KwA7PxOTVg+ns4CCPOdfNy5aEA9OUlIByUbuNC9ju0s=
github.com/viant/xlsy v0.3.1/go.mod h1:RajfF9HkL/PfIxRCvZSubpNlpdMUNDKYZp8C1o3vF4Q=
github.com/viant/xmlify v0.1.1-0.20231127181625-8a6b48ceea12 h1:j7I0D1M5lvmc5dxXzSyx99GSfYiilrSc1hnmFFL+jrg=
github.com/viant/xmlify v0.1.1-0.20231127181625-8a6b48ceea12/go.mod h1:w25+umH6nthlQ8ACT3K2/YJOLlbTXKLQXkdqFs6ky9s=
Expand Down
27 changes: 14 additions & 13 deletions internal/translator/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,20 @@ func (r *Resource) ExtractDeclared(dSQL *string) (err error) {
if err != nil {
return err
}
for _, item := range r.Declarations.Items {
r.RawSQL = strings.Replace(r.RawSQL, item.Raw, "", 1)
}

if index := strings.Index(r.RawSQL, "$Nop("); index != -1 {
offset := index + len("$Nop(")
if end := strings.Index(r.RawSQL[offset:], ")"); end != -1 {
noOp := r.RawSQL[offset : offset+end]
r.RawSQL = r.RawSQL[offset+end+1:]
r.Declarations.SQL = strings.Replace(r.Declarations.SQL, "$Nop("+noOp+")", "", 1)
}
}
r.RawSQL = strings.TrimSpace(r.RawSQL)
//for _, item := range r.Declarations.Items {
// r.RawSQL = strings.Replace(r.RawSQL, item.Raw, "", 1)
//}

//
//if index := strings.Index(r.RawSQL, "$Nop("); index != -1 {
// offset := index + len("$Nop(")
// if end := strings.Index(r.RawSQL[offset:], ")"); end != -1 {
// noOp := r.RawSQL[offset : offset+end]
// // r.RawSQL = r.RawSQL[offset+end+1:]
// r.Declarations.SQL = strings.Replace(r.Declarations.SQL, "$Nop("+noOp+")", "", 1)
// }
//}
//r.RawSQL = strings.TrimSpace(r.RawSQL)
r.State.Append(r.Declarations.State...)

r.appendPathVariableParams()
Expand Down
2 changes: 1 addition & 1 deletion internal/translator/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/viant/datly/repository/async"
"github.com/viant/datly/repository/content"
"github.com/viant/datly/repository/contract"
"github.com/viant/datly/repository/handler"
dpath "github.com/viant/datly/repository/path"
"github.com/viant/datly/service"
"github.com/viant/datly/service/executor/handler"
"github.com/viant/datly/shared"
"github.com/viant/datly/view"
"github.com/viant/datly/view/state"
Expand Down
2 changes: 1 addition & 1 deletion repository/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/viant/datly/repository/codegen"
"github.com/viant/datly/repository/content"
"github.com/viant/datly/repository/contract"
"github.com/viant/datly/repository/handler"
"github.com/viant/datly/repository/version"
"github.com/viant/datly/service"
"github.com/viant/datly/service/executor/handler"
"github.com/viant/datly/shared"
"github.com/viant/datly/utils/formatter"
"github.com/viant/datly/utils/types"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion repository/locator/component/dispatcher/disptacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (d *Dispatcher) Dispatch(ctx context.Context, path *contract.Path, opts ...
options = append(options, locator.WithHeaders(cOptions.Header))
}

aSession := session.New(aComponent.View, session.WithLocatorOptions(options...))
aSession := session.New(aComponent.View, session.WithLocatorOptions(options...), session.WithRegistry(d.registry))
ctx = aSession.Context(ctx, true)
value, err := d.service.Operate(ctx, aSession, aComponent)
return value, err
Expand Down
42 changes: 29 additions & 13 deletions service/executor/handler/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"context"
"database/sql"
"fmt"
"github.com/viant/datly/repository/contract"
executor "github.com/viant/datly/service/executor"
expand "github.com/viant/datly/service/executor/expand"
"github.com/viant/datly/service/executor/extension"
session "github.com/viant/datly/service/session"
"github.com/viant/datly/view"
"github.com/viant/datly/view/state"
"github.com/viant/xdatly/handler"
http2 "github.com/viant/xdatly/handler/http"
"github.com/viant/xdatly/handler/sqlx"
hstate "github.com/viant/xdatly/handler/state"
"github.com/viant/xdatly/handler/validator"
"net/http"
)
Expand Down Expand Up @@ -87,24 +90,27 @@ func (e *Executor) HandlerSession(ctx context.Context, opts ...Option) (*extensi
if e.handlerSession != nil {
return e.handlerSession, nil
}
sess := e.newSession(e.session, opts...)
e.handlerSession = sess
return sess, nil
}

func (e *Executor) newSession(aSession *session.Session, opts ...Option) *extension.Session {
var options = e.options.Clone(opts)
e.session.Apply(session.WithTypes(options.Types...))
e.session.Apply(session.WithEmbeddedFS(options.embedFS))

res := e.view.GetResource()
sess := extension.NewSession(
extension.WithTemplateFlush(func(ctx context.Context) error {
return e.Execute(ctx)
}),
extension.WithStater(e.session),
extension.WithStater(aSession),
extension.WithRedirect(e.redirect),
extension.WithSql(e.newSqlService),
extension.WithHttp(e.newHttp),
extension.WithMessageBus(res.MessageBuses),
)
e.handlerSession = sess
return sess, nil
return sess
}

func (e *Executor) newValidator() *validator.Service {
Expand Down Expand Up @@ -191,15 +197,25 @@ func (e *Executor) txStarted(tx *sql.Tx) {
}

func (e *Executor) redirect(ctx context.Context, route *http2.Route) (handler.Session, error) {
//TODO reimplement it
return nil, fmt.Errorf("not yey supported")
//match, err := e.route.match(ctx, route)
//if err != nil {
// return nil, err
//}
//
//newExecutor := NewExecutor(match, e.request, e.response)
//return newExecutor.HandlerSession(ctx)
registry := e.session.Registry()
if registry == nil {
return nil, fmt.Errorf("registry was empty")
}
aComponent, err := registry.Lookup(ctx, contract.NewPath(route.Method, route.URL))
if err != nil {
return nil, err
}
request, _ := http.NewRequest(route.Method, route.URL, nil)
unmarshal := aComponent.UnmarshalFunc(request)
locatorOptions := append(aComponent.LocatorOptions(request, hstate.NewForm(), unmarshal))
aSession := session.New(aComponent.View, session.WithLocatorOptions(locatorOptions...), session.WithRegistry(registry))
err = aSession.InitKinds(state.KindComponent, state.KindHeader, state.KindRequestBody, state.KindForm, state.KindQuery)
if err != nil {
return nil, err
}
ctx = aSession.Context(ctx, true)
anExecutor := NewExecutor(aComponent.View, aSession)
return anExecutor.NewHandlerSession(ctx)
}

func (e *Executor) newHttp() http2.Http {
Expand Down
8 changes: 4 additions & 4 deletions service/executor/handler/locator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package locator
import (
"context"
"fmt"
"github.com/viant/datly/service/executor/handler"
"github.com/viant/datly/repository/handler"
ehandler "github.com/viant/datly/service/executor/handler"
"github.com/viant/datly/service/session"
"github.com/viant/datly/view"
"github.com/viant/datly/view/extension"
Expand Down Expand Up @@ -45,10 +46,9 @@ func (v *Handler) Value(ctx context.Context, name string) (interface{}, bool, er
aView.Connector = resource.Connectors[0]
}
aSession := session.Context(ctx)
anExecutor := ehandler.NewExecutor(aView, aSession)

anExecutor := handler.NewExecutor(aView, aSession)

handlerSession, err := anExecutor.NewHandlerSession(ctx, handler.WithTypes(v.types...))
handlerSession, err := anExecutor.NewHandlerSession(ctx, ehandler.WithTypes(v.types...))
if err != nil {
return nil, false, fmt.Errorf("failed to create handler session: %w", err)
}
Expand Down
12 changes: 12 additions & 0 deletions service/session/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package session

import (
"embed"
"github.com/viant/datly/repository"
"github.com/viant/datly/view"
"github.com/viant/datly/view/state"
"github.com/viant/datly/view/state/kind/locator"
Expand All @@ -19,6 +20,7 @@ type (
locatorOpt *locator.Options
codecOptions []codec.Option
types []*state.Type
registry *repository.Registry
indirectState bool
reportNotAssignable *bool
scope string
Expand All @@ -27,6 +29,10 @@ type (
Option func(o *Options)
)

func (o *Options) Registry() *repository.Registry {
return o.registry
}

func (o *Options) HasInputParameters() bool {
if o.locatorOpt == nil {
return false
Expand Down Expand Up @@ -130,3 +136,9 @@ func WithEmbeddedFS(fs *embed.FS) Option {
s.embeddedFS = fs
}
}

func WithRegistry(registry *repository.Registry) Option {
return func(s *Options) {
s.registry = registry
}
}

0 comments on commit d290deb

Please sign in to comment.