MCPcopy Index your code
hub / github.com/dagger/dagger / NewModFunction

Function NewModFunction

core/modfunc.go:46–84  ·  view source on GitHub ↗
(
	ctx context.Context,
	mod dagql.ObjectResult[*Module],
	objDef *ObjectTypeDef,
	metadata *Function,
)

Source from the content-addressed store, hash-verified

44}
45
46func NewModFunction(
47 ctx context.Context,
48 mod dagql.ObjectResult[*Module],
49 objDef *ObjectTypeDef,
50 metadata *Function,
51) (*ModuleFunction, error) {
52 modInst := NewUserMod(mod)
53 returnType, ok, err := modInst.ModTypeFor(ctx, metadata.ReturnType.Self(), true)
54 if err != nil {
55 return nil, fmt.Errorf("get mod type for function %q return type: %w", metadata.Name, err)
56 }
57 if !ok {
58 return nil, fmt.Errorf("find mod type for function %q return type: %q", metadata.Name, metadata.ReturnType.Self().ToType())
59 }
60
61 argTypes := make(map[string]*UserModFunctionArg, len(metadata.Args))
62 for _, argMetadataRes := range metadata.Args {
63 argMetadata := argMetadataRes.Self()
64 argModType, ok, err := modInst.ModTypeFor(ctx, argMetadata.TypeDef.Self(), true)
65 if err != nil {
66 return nil, fmt.Errorf("get mod type for function %q arg %q type: %w", metadata.Name, argMetadata.Name, err)
67 }
68 if !ok {
69 return nil, fmt.Errorf("find mod type for function %q arg %q type: %q", metadata.Name, argMetadata.Name, argMetadata.TypeDef.Self().ToType())
70 }
71 argTypes[argMetadata.Name] = &UserModFunctionArg{
72 metadata: argMetadata,
73 modType: argModType,
74 }
75 }
76
77 return &ModuleFunction{
78 mod: mod,
79 objDef: objDef,
80 metadata: metadata,
81 returnType: returnType,
82 args: argTypes,
83 }, nil
84}
85
86type CallOpts struct {
87 Inputs []CallInput

Callers 5

runModuleDefInSDKMethod · 0.92
GetCallableMethod · 0.85
installConstructorMethod · 0.85
objFunFunction · 0.85

Calls 4

NewUserModFunction · 0.85
SelfMethod · 0.80
ToTypeMethod · 0.80
ModTypeForMethod · 0.65

Tested by

no test coverage detected