MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / compileFunction

Function compileFunction

db/functions/function.go:100–127  ·  view source on GitHub ↗

Creates a functionImpl from a UserFunctionConfig.

(ctx context.Context, name string, typeName string, fnConfig *FunctionConfig)

Source from the content-addressed store, hash-verified

98
99// Creates a functionImpl from a UserFunctionConfig.
100func compileFunction(ctx context.Context, name string, typeName string, fnConfig *FunctionConfig) (*functionImpl, error) {
101 userFn := &functionImpl{
102 FunctionConfig: fnConfig,
103 name: name,
104 typeName: typeName,
105 checkArgs: true,
106 }
107 var err error
108 switch fnConfig.Type {
109 case "javascript":
110 userFn.compiled, err = newFunctionJSServer(ctx, name, typeName, fnConfig.Code)
111 case "query":
112 err = validateN1QLQuery(fnConfig.Code)
113 if err != nil {
114 err = fmt.Errorf("%s %q invalid query: %v", typeName, name, err)
115 }
116 default:
117 err = fmt.Errorf("%s %q has unrecognized 'type' %q", typeName, name, fnConfig.Type)
118 }
119
120 if err == nil {
121 if err = fnConfig.validateAllow(); err != nil {
122 err = base.HTTPErrorf(http.StatusInternalServerError, "%s %q has an illegal 'allow' pattern: %v", typeName, name, err)
123
124 }
125 }
126 return userFn, err
127}
128
129func (fn *functionImpl) Name() string {
130 return fn.name

Callers 1

CompileFunctionsFunction · 0.85

Calls 5

HTTPErrorfFunction · 0.92
newFunctionJSServerFunction · 0.85
validateN1QLQueryFunction · 0.85
ErrorfMethod · 0.80
validateAllowMethod · 0.80

Tested by

no test coverage detected