-
I found an example of using const fileListType = object({
kind: enumeration("drive#fileList"),
nextPageToken: optional("string"),
incompleteSearch: "boolean",
files: array(fileType),
});
...
const rawResponse = fetch({ url, headers });
const response = cast(rawResponse, fileListType);
const { files, incompleteSearch, nextPageToken } = unnest(response); I was wondering if it's intended for I tried it with and without using import { board, enumeration, input } from "@breadboard-ai/build";
import { fetch, unnest } from "@google-labs/core-kit";
import { urlTemplate } from "@google-labs/template-kit";
import { countryCodes } from "../../../utils/countryCodes";
const countryCodeInput = input({
title: "countryCode",
type: enumeration(...countryCodes),
description: "The data for countryCode",
default: "US"
});
const url = urlTemplate({
$id: "url",
template: "https://date.nager.at/api/v3/CountryInfo/{countryCode}",
countryCode: countryCodeInput
});
const rawResponse = fetch({
$id: "fetchResult",
method: "GET",
url: url.outputs.url,
});
// const response = cast(rawResponse, object({
// commonName: "string",
// officialName: "string",
// countryCode: "string",
// region: "string",
// borders: array(object({}))
// })); // Passing this into `unnest` works
const { commonName, officialName, countryCode, region, borders } = unnest(rawResponse); // Error
export default board({
title: "Nager Date Country Info API",
inputs: { countryCode: countryCodeInput },
outputs: { commonName, officialName, countryCode, region, borders },
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yep, |
Beta Was this translation helpful? Give feedback.
Yep,
unnest
requires that the value you wire to it has a schema, and that the schema has typeobject
.cast
is the best way to assign a schema to some value when it's unknown, such as in the case offetch
. In other situations where there is already a schema, you wouldn't need thecast
.