Skip to content

Instantly share code, notes, and snippets.

@Mearman
Last active March 27, 2024 20:10
Show Gist options
  • Save Mearman/4b78c73bd6a3cf85989c5a3476e683f3 to your computer and use it in GitHub Desktop.
Save Mearman/4b78c73bd6a3cf85989c5a3476e683f3 to your computer and use it in GitHub Desktop.
import { Schema, base, code } from "@google-labs/breadboard";
import { core } from "@google-labs/core-kit";
import { templates } from "@google-labs/template-kit";
import { countryCodes } from "../../utils/countryCodes";
const getCurrentYear = code((): { year: number } => {
return {
year: new Date().getFullYear(),
};
});
const makeSchmaWithYearValue = code(({ year }: { year: number }) => {
return {
schema: {
type: "object",
properties: {
year: {
title: "year",
type: "number",
description: "The data for year",
default: year.toString(),
},
countryCode: {
title: "countryCode",
type: "string",
description: "The data for countryCode",
enum: countryCodes,
default: "US",
},
},
required: ["year", "countryCode"],
} satisfies Schema,
};
});
const schema = getCurrentYear().year.to(makeSchmaWithYearValue());
const newLocal = {
type: "object",
properties: {
year: {
title: "year",
type: "number",
description: "The data for year",
// default: new Date().getFullYear().toString(),
},
countryCode: {
title: "countryCode",
type: "string",
description: "The data for countryCode",
enum: countryCodes,
default: "US",
},
},
required: ["year", "countryCode"],
};
const input = base.input({
$id: "query",
});
schema.schema.to(input);
const urlTemplate = templates.urlTemplate({
$id: "urlTemplate",
template: "https://date.nager.at/api/v3/LongWeekend/{year}/{countryCode}",
year: input.year,
countryCode: input.countryCode,
});
const fetchUrl = core.fetch({
$id: "fetch",
method: "GET",
url: urlTemplate.url,
});
const output = base.output({
dates: fetchUrl.response,
});
export default await output.serialize({
title: "Nager Date Long Weekend API",
description: "API for long weekends",
version: "0.0.1",
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment