MCPcopy Create free account
hub / github.com/dagger/dagger / loadValue

Function loadValue

sdk/typescript/src/module/entrypoint/load.ts:148–218  ·  view source on GitHub ↗
(
  executor: Executor,
  value: any,
  type: TypeDef<TypeDefKind>,
)

Source from the content-addressed store, hash-verified

146 * Note: The JSON.parse() is required to remove extra quotes
147 */
148export async function loadValue(
149 executor: Executor,
150 value: any,
151 type: TypeDef<TypeDefKind>,
152): Promise<any> {
153 // If value is undefinied, return it directly.
154 if (value === undefined) {
155 return value
156 }
157
158 switch (type.kind) {
159 case TypeDefKind.ListKind:
160 return Promise.all(
161 value.map(
162 async (v: any) =>
163 await loadValue(
164 executor,
165 v,
166 (type as TypeDef<TypeDefKind.ListKind>).typeDef,
167 ),
168 ),
169 )
170 case TypeDefKind.ObjectKind: {
171 const objectType = (type as TypeDef<TypeDefKind.ObjectKind>).name
172
173 // For module-defined types, reconstruct from fields.
174 // For core API types, the value is an ID string — load via node(id:).
175 if (executor.hasObject(objectType)) {
176 return executor.buildClass(objectType, value)
177 }
178
179 // Core type: construct a typed SDK client via node(id:)
180 const ctx = new Context(
181 [],
182 new Connection(dag.getGQLClient()),
183 ).selectNode(value, objectType)
184 // Look up the class from the generated client exports (e.g. "Directory" -> Directory class)
185 // Some names collide with JS builtins and get a _ suffix (e.g. "Module" -> Module_)
186 const className = (clientGen as any)[objectType]
187 ? objectType
188 : `${objectType}_`
189 const cls = (clientGen as any)[className]
190 if (cls) {
191 return new cls(ctx)
192 }
193 throw new Error(
194 `Generated client class not found for core type ${objectType}`,
195 )
196 }
197 case TypeDefKind.InterfaceKind: {
198 const interfaceType = (type as TypeDef<TypeDefKind.InterfaceKind>).name
199
200 return executor.buildInterface(interfaceType, value)
201 }
202 case TypeDefKind.EnumKind: {
203 const enumType = (type as TypeDef<TypeDefKind.EnumKind>).name
204
205 return executor.buildEnum(enumType, value)

Callers 2

loadArgsFunction · 0.85
loadParentStateFunction · 0.85

Calls 6

hasObjectMethod · 0.80
selectNodeMethod · 0.80
buildInterfaceMethod · 0.80
buildEnumMethod · 0.80
buildClassMethod · 0.45
getGQLClientMethod · 0.45

Tested by

no test coverage detected