Schema builder
Thej export from @notionhq/workers/schema-builder builds JSON Schemas
for tool input and output. Use it instead
of hand-writing JSON Schema so tool contracts stay compatible across a wide
range of closed and open-source models. Builder methods return a
SchemaBuilder<T>.
j.object()
required, and additionalProperties is set to false.
j.string()
j.number()
j.array()
.describe()
description field and returns a new builder.
.nullable()
anyOf with { type: "null" } and returns a new builder. In object schemas, the property is still required, but its value may be null.
j.integer()
j.boolean()
j.enum()
j.datetime()
format: "date-time".
j.date()
format: "date".
j.time()
format: "time".
j.duration()
format: "duration".
j.email()
format: "email".
j.hostname()
format: "hostname".
j.ipv4()
format: "ipv4".
j.ipv6()
format: "ipv6".
j.uuid()
format: "uuid".
j.anyOf()
anyOf schema from the provided schema builders.
j.ref()
$ref set to path.
Database schema helpers
UseSchema helpers to define the properties of managed databases declared with worker.database().
Schema.title()
Schema.richText()
Schema.url()
Schema.email()
Schema.phoneNumber()
Schema.checkbox()
Schema.file()
Schema.number()
format is provided, it is included in the returned configuration.
Schema.date()
dateFormat is provided, it is emitted as date_format.
Schema.select()
Schema.multiSelect()
Schema.status()
Schema.people()
Schema.place()
Schema.relation()
relatedDatabaseKey must match the key passed to worker.database() for the related database. If config is omitted, the relation is one-way.
Property value builders
UseBuilder helpers to construct property values returned by sync changes. These properties must match the types defined in the database schema.
Builder.richText()
Builder.richText() does not accept formatting
options; it returns a single text token with no annotations.
Builder.url()
Builder.title()
Builder.text()
Builder.email()
Builder.phoneNumber()
Builder.checkbox()
true returns Yes; false returns No.
Builder.file()
fileName is omitted, the URL is also used as the display text.
Builder.number()
value to a string. If value is NaN, returns an empty value.
Builder.date()
YYYY-MM-DD date string. Throws if the input does
not match that format or cannot be parsed by JavaScript Date.
Builder.dateTime()
YYYY-MM-DDTHH:mm. The builder stores the first 10 characters as start_date
and characters 11 through 16 as start_time. If timeZone is provided, it is
included as time_zone.
Builder.dateRange()
YYYY-MM-DD date strings. Throws if either
input does not match that format or cannot be parsed by JavaScript Date. The
builder does not validate that startDate is before endDate.
Builder.dateTimeRange()
YYYY-MM-DDTHH:mm. If timeZone is provided, it is included as
time_zone. The builder does not validate that startDateTime is before
endDateTime.
Builder.link()
Builder.select()
Builder.multiSelect()
Builder.status()
Builder.people()
Builder.place()
lat and lon; otherwise the function throws.
Builder.relation()
Builder.emojiIcon()
Builder.notionIcon()
color is omitted, it defaults to "gray".
Builder.imageIcon()
Builder.imageCover()
position controls the vertical image position from 0 (top) to 1 (bottom). If omitted, position defaults to 0.5.