MCPcopy Create free account
hub / github.com/Easy-Editor/EasyEditor / buildOptions

Function buildOptions

packages/plugin-datasource/src/utils.ts:114–159  ·  view source on GitHub ↗
(ds: InterpretDataSourceConfig, context: IDataSourceRuntimeContext)

Source from the content-addressed store, hash-verified

112}
113
114export const buildOptions = (ds: InterpretDataSourceConfig, context: IDataSourceRuntimeContext) => {
115 const { options } = ds
116 if (!options) return undefined
117 // eslint-disable-next-line space-before-function-paren
118 return () => {
119 // 默认值
120 const fetchOptions: RuntimeOptionsConfig = {
121 uri: '',
122 params: {},
123 method: 'GET',
124 isCors: true,
125 timeout: 5000,
126 headers: undefined,
127 v: '1.0',
128 }
129 Object.keys(options).forEach((key: string) => {
130 switch (key) {
131 case 'uri':
132 fetchOptions.uri = getRuntimeValueFromConfig('string', options.uri, context)
133 break
134 case 'params':
135 fetchOptions.params = buildJsonObj(options.params!, context)
136 break
137 case 'method':
138 fetchOptions.method = getRuntimeValueFromConfig('string', options.method, context)
139 break
140 case 'isCors':
141 fetchOptions.isCors = getRuntimeValueFromConfig('boolean', options.isCors, context)
142 break
143 case 'timeout':
144 fetchOptions.timeout = getRuntimeValueFromConfig('number', options.timeout, context)
145 break
146 case 'headers':
147 fetchOptions.headers = buildJsonObj(options.headers!, context)
148 break
149 case 'v':
150 fetchOptions.v = getRuntimeValueFromConfig('string', options.v, context)
151 break
152 default:
153 // 其余的除了做表达式或者 function 的转换,直接透传
154 fetchOptions[key] = getRuntimeValueFromConfig('unknown', options[key], context)
155 }
156 })
157 return fetchOptions
158 }
159}

Callers 1

adapt2RuntimeFunction · 0.90

Calls 3

buildJsonObjFunction · 0.85
forEachMethod · 0.45

Tested by

no test coverage detected