Skip to content

Latest commit

 

History

History
3525 lines (2154 loc) · 103 KB

modules.md

File metadata and controls

3525 lines (2154 loc) · 103 KB

@jitl/notion-api / Exports

@jitl/notion-api

Table of contents

API Type aliases

Page Type aliases

Block Type aliases

Rich Text Type aliases

Property Type aliases

Date Type aliases

Query Type aliases

User Type aliases

CMS Type aliases

Asset Type aliases

Cache Type aliases

Database Type aliases

API Functions

Page Functions

Block Functions

Rich Text Functions

Property Functions

Date Functions

Query Functions

CMS Functions

Asset Functions

Backlink Functions

Cache Functions

Database Functions

Query Variables

Asset Variables

API

A logger for the @notionhq/client Client that logs to the @jitl/notion-api namespace. Variables

API Interfaces

Block Interfaces

Property Interfaces

Query Interfaces

CMS Interfaces

Asset Interfaces

Backlink Interfaces

CMS Classes

Backlink Classes

Cache Classes

API Type aliases

NotionClientDebugLogger

Ƭ NotionClientDebugLogger: Logger & NotionClientLoggers

A logger for the @notionhq/client Client that logs to the @jitl/notion-api namespace.

Defined in

lib/notion-api.ts:42


EmptyObject

Ƭ EmptyObject: Record<string, never>

Object with no properties.

Defined in

lib/notion-api.ts:83


IdRequest

Ƭ IdRequest: string

IDs in the Notion API are strings containing UUIDs.

Defined in

lib/query.ts:48


Page Type aliases

Page

Ƭ Page: Extract<GetPageResponse, { parent: unknown }>

A full Notion API page.

Defined in

lib/notion-api.ts:178


PageWithChildren

Ƭ PageWithChildren: Page & { children: BlockWithChildren[] }

An extension of the Notion API page type that ads a children attribute forming a recursive tree of blocks.

Defined in

lib/notion-api.ts:196


Block Type aliases

BlockType

Ƭ BlockType: AnyBlock["type"]

Type of any block.

Defined in

lib/notion-api.ts:215


Block

Ƭ Block<Type>: Extract<AnyBlock, { type: Type }>

A full Notion API block.

Type parameters

Name Type
Type extends BlockType = BlockType

Defined in

lib/notion-api.ts:221


BlockDataMap

Ƭ BlockDataMap: { [K in BlockType]: BlockTypeMap[K] extends { [key in K]: unknown } ? BlockTypeMap[K][K] : never }

Type-level map from a BlockType to the data of that block.

source

export type BlockDataMap = {
    [K in BlockType]: BlockTypeMap[K] extends {
        [key in K]: unknown;
    } ? BlockTypeMap[K][K] : never;
};

Defined in

lib/notion-api.ts:283


BlockWithChildren

Ƭ BlockWithChildren<Type>: Block<Type> & { children: BlockWithChildren[] }

An extension of the Notion API block type that adds a children attribute forming a recursive tree of blocks.

Type parameters

Name Type
Type extends BlockType = BlockType

Defined in

lib/notion-api.ts:304


Rich Text Type aliases

RichText

Ƭ RichText: Block<"paragraph">["paragraph"][typeof RICH_TEXT_BLOCK_PROPERTY]

Notion API rich text. An array of rich text tokens.

Defined in

lib/notion-api.ts:421


RichTextToken

Ƭ RichTextToken: any[][number]

A single token of rich text.

Defined in

lib/notion-api.ts:426


MentionType

Ƭ MentionType: AnyMention["mention"]["type"]

The type of mention.

Defined in

lib/notion-api.ts:434


MentionData

Ƭ MentionData<Type>: Extract<AnyMention["mention"], { type: Type }>

The data of a mention type.

Type parameters

Name Type
Type extends MentionType

Defined in

lib/notion-api.ts:440


Mention

Ƭ Mention<Type>: Omit<AnyMention, "mention"> & { mention: MentionData<Type> }

A mention token. (This type doesn't seem to work very well.)

Type parameters

Name Type
Type extends MentionType = MentionType

Defined in

lib/notion-api.ts:447


Property Type aliases

PropertyFilterDataMap

Ƭ PropertyFilterDataMap: { [K in PropertyType]: PropertyFilterTypeMap[K] extends { [key in K]: unknown } ? PropertyFilterTypeMap[K][K] : never }

Type-level map from property type to the inner filter of that property

source

export type PropertyFilterDataMap = {
    [K in PropertyType]: PropertyFilterTypeMap[K] extends {
        [key in K]: unknown;
    } ? PropertyFilterTypeMap[K][K] : never;
};

Defined in

lib/notion-api.ts:614


PropertyType

Ƭ PropertyType: AnyProperty["type"]

The type of a property.

Defined in

lib/notion-api.ts:797


Property

Ƭ Property<Type>: Extract<AnyProperty, { type: Type }>

A property of a Notion page.

Type parameters

Name Type
Type extends PropertyType = PropertyType

Defined in

lib/notion-api.ts:803


PropertyDataMap

Ƭ PropertyDataMap: { [K in PropertyType]: PropertyTypeMap[K] extends { [key in K]: unknown } ? PropertyTypeMap[K][K] : never }

Type-level map from property type to the data of that property.

source

export type PropertyDataMap = {
    [K in PropertyType]: PropertyTypeMap[K] extends {
        [key in K]: unknown;
    } ? PropertyTypeMap[K][K] : never;
};

Defined in

lib/notion-api.ts:817


SelectPropertyValue

Ƭ SelectPropertyValue: NonNullable<PropertyDataMap["select"]>

Defined in

lib/notion-api.ts:827


MultiSelectPropertyValue

Ƭ MultiSelectPropertyValue: NonNullable<PropertyDataMap["multi_select"]>

Defined in

lib/notion-api.ts:832


FormulaPropertyValueType

Ƭ FormulaPropertyValueType: AnyFormulaPropertyValue["type"]

Defined in

lib/notion-api.ts:862


FormulaPropertyValue

Ƭ FormulaPropertyValue<Type>: Extract<AnyFormulaPropertyValue, { type: Type }>

Type parameters

Name Type
Type extends FormulaPropertyValueType = FormulaPropertyValueType

Defined in

lib/notion-api.ts:867


FormulaPropertyValueData

Ƭ FormulaPropertyValueData: string | number | boolean | DateResponse | null

Defined in

lib/notion-api.ts:873


PropertyPointerWithOutput

Ƭ PropertyPointerWithOutput<T>: { [P in keyof PropertyDataMap]: PropertyDataMap[P] extends T | null ? PropertyPointer<P> : never }[PropertyType]

A pointer to a property in a Notion API page of any property type that has T as the property data.

Type parameters

Name
T

Defined in

lib/notion-api.ts:908


Date Type aliases

DateResponse

Ƭ DateResponse: DateMentionData["date"]

Notion date type.

Defined in

lib/notion-api.ts:473


Query Type aliases

Filter

Ƭ Filter: NonNullable<QueryDatabaseParameters["filter"]>

Any kind of filter in a database query.

Defined in

lib/notion-api.ts:579


AnyPropertyFilter

Ƭ AnyPropertyFilter: Extract<Filter, { type?: string }>

Defined in

lib/notion-api.ts:584


PropertyFilterType

Ƭ PropertyFilterType: AnyPropertyFilter["type"]

Type of a property filter.

Defined in

lib/notion-api.ts:590


PropertyFilter

Ƭ PropertyFilter<Type>: Extract<AnyPropertyFilter, { type?: Type }>

Property filters in a database query.

Type parameters

Name Type
Type extends PropertyFilterType = PropertyFilterType

Defined in

lib/notion-api.ts:596


CompoundFilter

Ƭ CompoundFilter: Exclude<Filter, PropertyFilter>

Compound filters, like and or or.

Defined in

lib/notion-api.ts:716


AndFilter

Ƭ AndFilter: Extract<CompoundFilter, { and: any }>

Defined in

lib/notion-api.ts:721


OrFilter

Ƭ OrFilter: Extract<CompoundFilter, { or: any }>

Defined in

lib/notion-api.ts:726


Sorts

Ƭ Sorts: NonNullable<QueryDatabaseParameters["sorts"]>

Sorting for a database query.

Defined in

lib/notion-api.ts:732


Sort

Ƭ Sort: any[][number]

A single sort in a database query.

Defined in

lib/notion-api.ts:738


TimestampSort

Ƭ TimestampSort: Extract<Sort, { timestamp: any }>

Defined in

lib/notion-api.ts:743


PropertySort

Ƭ PropertySort: Extract<Sort, { property: any }>

Defined in

lib/notion-api.ts:748


FilterOperatorTypeMap

Ƭ FilterOperatorTypeMap<T>: { [K in keyof UnionToIntersection<T>]: true }

An object mapping from filter operator name to true.

Type parameters

Name
T

Defined in

lib/query.ts:39


ExistenceFilterOperator

Ƭ ExistenceFilterOperator: { is_empty: true } | { is_not_empty: true }

Defined in

lib/query.ts:53


TextFilterOperator

Ƭ TextFilterOperator: { equals: string } | { does_not_equal: string } | { contains: string } | { does_not_contain: string } | { starts_with: string } | { ends_with: string } | ExistenceFilterOperator

source

export type TextFilterOperator = {
    equals: string;
} | {
    does_not_equal: string;
} | {
    contains: string;
} | {
    does_not_contain: string;
} | {
    starts_with: string;
} | {
    ends_with: string;
} | ExistenceFilterOperator;

Defined in

lib/query.ts:78


NumberFilterOperator

Ƭ NumberFilterOperator: { equals: number } | { does_not_equal: number } | { greater_than: number } | { less_than: number } | { greater_than_or_equal_to: number } | { less_than_or_equal_to: number } | ExistenceFilterOperator

source

export type NumberFilterOperator = {
    equals: number;
} | {
    does_not_equal: number;
} | {
    greater_than: number;
} | {
    less_than: number;
} | {
    greater_than_or_equal_to: number;
} | {
    less_than_or_equal_to: number;
} | ExistenceFilterOperator;

Defined in

lib/query.ts:103


CheckboxFilterOperator

Ƭ CheckboxFilterOperator: { equals: boolean } | { does_not_equal: boolean }

source

export type CheckboxFilterOperator = {
    equals: boolean;
} | {
    does_not_equal: boolean;
};

Defined in

lib/query.ts:129


SelectFilterOperator

Ƭ SelectFilterOperator: { equals: string } | { does_not_equal: string } | ExistenceFilterOperator

source

export type SelectFilterOperator = {
    equals: string;
} | {
    does_not_equal: string;
} | ExistenceFilterOperator;

Defined in

lib/query.ts:142


MultiSelectFilterOperator

Ƭ MultiSelectFilterOperator: { contains: string } | { does_not_contain: string } | ExistenceFilterOperator

source

export type MultiSelectFilterOperator = {
    contains: string;
} | {
    does_not_contain: string;
} | ExistenceFilterOperator;

Defined in

lib/query.ts:160


DateFilterOperator

Ƭ DateFilterOperator: { equals: string } | { before: string } | { after: string } | { on_or_before: string } | { on_or_after: string } | { past_week: EmptyObject } | { past_month: EmptyObject } | { past_year: EmptyObject } | { next_week: EmptyObject } | { next_month: EmptyObject } | { next_year: EmptyObject } | ExistenceFilterOperator

source

export type DateFilterOperator = {
    equals: string;
} | {
    before: string;
} | {
    after: string;
} | {
    on_or_before: string;
} | {
    on_or_after: string;
} | {
    past_week: EmptyObject;
} | {
    past_month: EmptyObject;
} | {
    past_year: EmptyObject;
} | {
    next_week: EmptyObject;
} | {
    next_month: EmptyObject;
} | {
    next_year: EmptyObject;
} | ExistenceFilterOperator;

Defined in

lib/query.ts:178


PeopleFilterOperator

Ƭ PeopleFilterOperator: { contains: IdRequest } | { does_not_contain: IdRequest } | ExistenceFilterOperator

source

export type PeopleFilterOperator = {
    contains: IdRequest;
} | {
    does_not_contain: IdRequest;
} | ExistenceFilterOperator;

Defined in

lib/query.ts:215


RelationFilterOperator

Ƭ RelationFilterOperator: { contains: IdRequest } | { does_not_contain: IdRequest } | ExistenceFilterOperator

source

export type RelationFilterOperator = {
    contains: IdRequest;
} | {
    does_not_contain: IdRequest;
} | ExistenceFilterOperator;

Defined in

lib/query.ts:233


FormulaFilterOperator

Ƭ FormulaFilterOperator: { string: TextFilterOperator } | { checkbox: CheckboxFilterOperator } | { number: NumberFilterOperator } | { date: DateFilterOperator }

source

export type FormulaFilterOperator = {
    string: TextFilterOperator;
} | {
    checkbox: CheckboxFilterOperator;
} | {
    number: NumberFilterOperator;
} | {
    date: DateFilterOperator;
};

Defined in

lib/query.ts:251


RollupSubfilterOperator

Ƭ RollupSubfilterOperator: { rich_text: TextFilterOperator } | { number: NumberFilterOperator } | { checkbox: CheckboxFilterOperator } | { select: SelectFilterOperator } | { multi_select: MultiSelectFilterOperator } | { relation: RelationFilterOperator } | { date: DateFilterOperator } | { people: PeopleFilterOperator } | { files: ExistenceFilterOperator }

source

export type RollupSubfilterOperator = {
    rich_text: TextFilterOperator;
} | {
    number: NumberFilterOperator;
} | {
    checkbox: CheckboxFilterOperator;
} | {
    select: SelectFilterOperator;
} | {
    multi_select: MultiSelectFilterOperator;
} | {
    relation: RelationFilterOperator;
} | {
    date: DateFilterOperator;
} | {
    people: PeopleFilterOperator;
} | {
    files: ExistenceFilterOperator;
};

Defined in

lib/query.ts:277


RollupFilterOperator

Ƭ RollupFilterOperator: { any: RollupSubfilterOperator } | { none: RollupSubfilterOperator } | { every: RollupSubfilterOperator } | { date: DateFilterOperator } | { number: NumberFilterOperator }

source

export type RollupFilterOperator = {
    any: RollupSubfilterOperator;
} | {
    none: RollupSubfilterOperator;
} | {
    every: RollupSubfilterOperator;
} | {
    date: DateFilterOperator;
} | {
    number: NumberFilterOperator;
};

Defined in

lib/query.ts:292


PropertyToToFilterOperator

Ƭ PropertyToToFilterOperator: Object

This duplicates PropertyFilterDataMap, but seems more correct.

source

export type PropertyToToFilterOperator = {
    title: TextFilterOperator;
    rich_text: TextFilterOperator;
    number: NumberFilterOperator;
    checkbox: CheckboxFilterOperator;
    select: SelectFilterOperator;
    multi_select: MultiSelectFilterOperator;
    date: DateFilterOperator;
    people: PeopleFilterOperator;
    files: ExistenceFilterOperator;
    url: TextFilterOperator;
    email: TextFilterOperator;
    phone_number: TextFilterOperator;
    relation: RelationFilterOperator;
    created_by: PeopleFilterOperator;
    created_time: DateFilterOperator;
    last_edited_by: PeopleFilterOperator;
    last_edited_time: DateFilterOperator;
    formula: FormulaFilterOperator;
    rollup: RollupFilterOperator;
};

Type declaration

Name Type
title TextFilterOperator
rich_text TextFilterOperator
number NumberFilterOperator
checkbox CheckboxFilterOperator
select SelectFilterOperator
multi_select MultiSelectFilterOperator
date DateFilterOperator
people PeopleFilterOperator
files ExistenceFilterOperator
url TextFilterOperator
email TextFilterOperator
phone_number TextFilterOperator
relation RelationFilterOperator
created_by PeopleFilterOperator
created_time DateFilterOperator
last_edited_by PeopleFilterOperator
last_edited_time DateFilterOperator
formula FormulaFilterOperator
rollup RollupFilterOperator

Defined in

lib/query.ts:316


PropertyFilterBuilder

Ƭ PropertyFilterBuilder<Type>: { schema: PropertyPointer<Type> } & { [K in FilterOperatorType<Type>]: Function }

Contains a key for each filter operator for this property type. This allows easy tab completion when building filters for a database query.

Create with propertyFilterBuilder, or use one created as part of CMS.filter or databaseFilterBuilder.

Type parameters

Name Type
Type extends PropertyType

Defined in

lib/query.ts:418


DatabaseFilterBuilder

Ƭ DatabaseFilterBuilder<T>: { [K in keyof T]: PropertyFilterBuilder<T[K]["type"]> } & typeof Filter & { schema: T }

Contains a PropertyFilterBuilder for each property in a PartialDatabaseSchema.

Create one with databaseFilterBuilder, or use the filter builders from CMS.filter.

Type parameters

Name Type
T extends PartialDatabaseSchema

Defined in

lib/query.ts:470


DatabaseSortBuilder

Ƭ DatabaseSortBuilder<T>: TimestampSortBuilder & { [K in keyof T]: Object & SortBuilder<PropertySort> }

For each property in PartialDatabaseSchema

Create one with databaseSortBuilder or use the sort builders from CMS.sort.

Type parameters

Name Type
T extends PartialDatabaseSchema

Defined in

lib/query.ts:529


User Type aliases

User

Ƭ User: GetUserResponse

Person or Bot

Defined in

lib/notion-api.ts:557


Person

Ƭ Person: Extract<User, { type: "person" }>

Person

Defined in

lib/notion-api.ts:563


Bot

Ƭ Bot: Extract<User, { type: "bot" }>

Bot

Defined in

lib/notion-api.ts:569


CMS Type aliases

CMSCustomPropertyPointer

Ƭ CMSCustomPropertyPointer<T>: Object

Specifies that the CMS should look up a custom property from regular Page property. Consider using this with a formula property for maximum flexibility.

See CMSConfig.

source

export type CMSCustomPropertyPointer<T> = {
    type: 'property';
    /** Indicates which property to fetch data from */
    property: PropertyPointerWithOutput<T>;
};

Type parameters

Name
T

Type declaration

Name Type Description
type "property" -
property PropertyPointerWithOutput<T> Indicates which property to fetch data from

Defined in

lib/content-management-system.ts:71


CMSSchemaPropertyPointer

Ƭ CMSSchemaPropertyPointer<T, Schema>: { [K in keyof Schema]: Schema[K] extends PropertyPointerWithOutput<T> ? K : never }[keyof Schema]

Property key name in a database schema. Specifies that the CMS should look up a property in the page's schema.

For a database schema { name: { type: 'rich_text', name: 'Name', id: 'qX124' } }, a valid CMSSchemaPropertyPointer<RichText, typeof schema> would be 'name'.

See CMSConfig, CMSConfig.schema.

Type parameters

Name Type
T T
Schema extends PartialDatabaseSchema

Defined in

lib/content-management-system.ts:109


CMSCustomProperty

Ƭ CMSCustomProperty<T, CustomFrontmatter, Schema>: CMSSchemaPropertyPointer<T, Schema> | CMSCustomPropertyPointer<T> | CMSCustomPropertyDerived<T, CustomFrontmatter, Schema>

Specifies how a CMS should get a custom property.

See CMSConfig.

source

export type CMSCustomProperty<T, CustomFrontmatter, Schema extends PartialDatabaseSchema> = CMSSchemaPropertyPointer<T, Schema> | CMSCustomPropertyPointer<T> | CMSCustomPropertyDerived<T, CustomFrontmatter, Schema>;

Type parameters

Name Type
T T
CustomFrontmatter CustomFrontmatter
Schema extends PartialDatabaseSchema

Defined in

lib/content-management-system.ts:121


CMSFrontmatter

Ƭ CMSFrontmatter<CustomFrontmatter>: CMSDefaultFrontmatter & Omit<CustomFrontmatter, keyof CMSDefaultFrontmatter>

The frontmatter of a CMSPage.

source

export type CMSFrontmatter<CustomFrontmatter> = CMSDefaultFrontmatter & Omit<CustomFrontmatter, keyof CMSDefaultFrontmatter>;

Type parameters

Name
CustomFrontmatter

Defined in

lib/content-management-system.ts:345


CMSPageOf

Ƭ CMSPageOf<T>: T extends CMS<infer CustomFrontmatter, any> ? CMSPage<CustomFrontmatter> : never

Get the CMSPage type from a CMS.

const MyCMS = new CMS({ ... })
type MyPage = CMSPageOf<typeof MyCMS>;

Type parameters

Name Type
T extends CMS<any, any>

Defined in

lib/content-management-system.ts:365


Asset Type aliases

Asset

Ƭ Asset: NonNullable<Page["icon"]>

An internal, external or emoji asset from the Notion API.

Defined in

lib/assets.ts:35


AssetRequest

Ƭ AssetRequest: { object: "page" ; id: string ; field: "icon" } | { object: "page" ; id: string ; field: "cover" } | { object: "page" ; id: string ; field: "properties" ; property: PropertyPointer<any> ; propertyIndex?: number } | { object: "block" ; id: string ; field: "image" } | { object: "block" ; id: string ; field: "file" } | { object: "block" ; id: string ; field: "icon" } | { object: "user" ; id: string ; field: "avatar_url" }

An AssetRequest indicates an asset within a Notion API object, such as a page icon or a image block's image.

source

export type AssetRequest = {
    object: 'page';
    id: string;
    field: 'icon';
} | {
    object: 'page';
    id: string;
    field: 'cover';
} | {
    object: 'page';
    id: string;
    field: 'properties';
    property: PropertyPointer<any>;
    propertyIndex?: number; // assumed to be 0
} | {
    object: 'block';
    id: string;
    field: 'image';
} | {
    object: 'block';
    id: string;
    field: 'file';
} | {
    object: 'block';
    id: string;
    field: 'icon';
} // eg, for callout block
 | {
    object: 'user';
    id: string;
    field: 'avatar_url';
};

Defined in

lib/assets.ts:43


Cache Type aliases

CacheBehavior

Ƭ CacheBehavior: "read-only" | "fill" | "refresh"

source

export type CacheBehavior = 
/** Read from the cache, but don't update it */
'read-only'
/** Read from the cache, or update it if needed. */
 | 'fill'
/** Don't read from the cache, and update it with new values */
 | 'refresh';

Defined in

lib/cache.ts:14


Database Type aliases

Database

Ƭ Database: Extract<GetDatabaseResponse, { title: unknown }>

A full database from the Notion API.

Defined in

lib/notion-api.ts:998


DatabaseSchema

Ƭ DatabaseSchema: Database["properties"]

The properties that a Database has.

Defined in

lib/notion-api.ts:1015


PropertySchema

Ƭ PropertySchema<Type>: Extract<AnyPropertySchema, { type: Type }>

A property type of the pages in a Database. Think of this like a column in a SQL database.

WARNING: the documented name of this is "Property", WARNING: the documented name of page properties is "PropertyValue".

Type parameters

Name Type
Type extends PropertyType = PropertyType

Defined in

lib/notion-api.ts:1036


PropertySchemaDataMap

Ƭ PropertySchemaDataMap: { [K in PropertyType]: PropertySchemaTypeMap[K] extends { [key in K]: unknown } ? PropertySchemaTypeMap[K][K] : never }

Type-level map from property type to the schema data of that property.

source

export type PropertySchemaDataMap = {
    [K in PropertyType]: PropertySchemaTypeMap[K] extends {
        [key in K]: unknown;
    } ? PropertySchemaTypeMap[K][K] : never;
};

Defined in

lib/notion-api.ts:1050


PartialPropertySchema

Ƭ PartialPropertySchema<Type>: Partial<PropertySchema<Type>> & { name: string ; type: Type }

A partial PropertySchema that contains at least the type field. Used to create a PartialDatabaseSchema.

Type parameters

Name Type
Type extends PropertyType = PropertyType

Defined in

lib/notion-api.ts:1074


PartialDatabaseSchema

Ƭ PartialDatabaseSchema: Record<string, PartialPropertySchema>

A partial DatabaseSchema that contains at least the type field of any defined property.

Defined in

lib/notion-api.ts:1082


PartialDatabaseSchemaWithOnlyType

Ƭ PartialDatabaseSchemaWithOnlyType: Record<string, Partial<PropertySchema> & { type: PropertyType }>

Used in inferDatabaseSchema.

Defined in

lib/notion-api.ts:1088


PartialDatabaseSchemaFromSchemaWithOnlyType

Ƭ PartialDatabaseSchemaFromSchemaWithOnlyType<T>: Assert<PartialDatabaseSchema, { [K in keyof T]: T[K] & PartialPropertySchema<T[K]["type"]> }>

Used in inferDatabaseSchema.

Type parameters

Name Type
T extends PartialDatabaseSchemaWithOnlyType

Defined in

lib/notion-api.ts:1097


DatabaseSchemaDiff

Ƭ DatabaseSchemaDiff<Before, After>: { type: "key" ; property: PropertyDiffPointer ; before: keyof Before ; after: keyof After } | { type: `property.id.${"added" | "removed"}` ; property: { name: string } ; id: string } | { type: "property.type" ; property: PropertyDiffPointer ; before: PropertyType ; after: PropertyType } | { type: "property.name" ; property: { id: string } ; before: string ; after: string } | { type: "property.schema" ; before: PropertySchema ; after: PropertySchema } | { type: "removed" ; property: Assert<PropertyDiffPointer, PartialPropertySchema> ; before: keyof Before } | { type: "added" ; property: Assert<PropertyDiffPointer, PartialPropertySchema> ; after: keyof After }

Type parameters

Name Type
Before extends PartialDatabaseSchema
After extends PartialDatabaseSchema

Defined in

lib/notion-api.ts:1180


DatabasePropertyValues

Ƭ DatabasePropertyValues<T>: { [K in keyof T]?: PropertyDataMap[T[K]["type"]] }

Type parameters

Name Type
T extends PartialDatabaseSchema

Defined in

lib/notion-api.ts:1485


FilterOperator

Ƭ FilterOperator<Type>: PropertyToToFilterOperator[Type]

Type parameters

Name Type
Type extends PropertyType = PropertyType

Defined in

lib/query.ts:369


FilterOperatorType

Ƭ FilterOperatorType<Type>: keyof UnionToIntersection<FilterOperator<Type>>

Type parameters

Name Type
Type extends PropertyType = PropertyType

Defined in

lib/query.ts:381

API Functions

isNotionDomain

isNotionDomain(domain): boolean

Parameters

Name Type
domain string

Returns

boolean

Defined in

lib/backlinks.ts:38


uuidWithDashes

uuidWithDashes(id): string

Ensure a UUID has dashes, since sometimes Notion IDs don't have dashes.

Parameters

Name Type
id string

Returns

string

Defined in

lib/backlinks.ts:208


iteratePaginatedAPI

iteratePaginatedAPI<Args, Item>(listFn, firstPageArgs): AsyncIterableIterator<Item>

Iterate over all results in a paginated list API.

for await (const block of iteratePaginatedAPI(notion.blocks.children.list, {
  block_id: parentBlockId,
})) {
  // Do something with block.
}

Type parameters

Name Type
Args extends PaginatedArgs
Item Item

Parameters

Name Type Description
listFn (args: Args) => Promise<PaginatedList<Item>> API to call
firstPageArgs Args These arguments are used for each page, with an updated start_cursor.

Returns

AsyncIterableIterator<Item>

Defined in

lib/notion-api.ts:124


asyncIterableToArray

asyncIterableToArray<T>(iterable): Promise<T[]>

Gather all an async iterable's items into an array.

const iterator = iteratePaginatedAPI(notion.blocks.children.list, { block_id: parentBlockId });
const blocks = await asyncIterableToArray(iterator);
const paragraphs = blocks.filter(block => isFullBlock(block, 'paragraph'))

Type parameters

Name
T

Parameters

Name Type
iterable AsyncIterable<T>

Returns

Promise<T[]>

Defined in

lib/notion-api.ts:162


Page Functions

getPageTitle

getPageTitle(page): any[]

Parameters

Name Type
page Object

Returns

any[]

The title of page, as RichText.

Defined in

lib/content-management-system.ts:1052


isFullPage

isFullPage(page): page is Object

The Notion API may return a "partial" page object if your API token can't access the page.

This function confirms that all page data is available.

Parameters

Name Type
page GetPageResponse

Returns

page is Object

Defined in

lib/notion-api.ts:187


isPageWithChildren

isPageWithChildren(page): page is PageWithChildren

Parameters

Name Type
page GetPageResponse

Returns

page is PageWithChildren

Defined in

lib/notion-api.ts:201


Block Functions

isFullBlock

isFullBlock(block): block is Block<"paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported">

The Notion API may return a "partial" block object if your API token can't access the block.

This function confirms that all block data is available.

Parameters

Name Type
block GetBlockResponse

Returns

block is Block<"paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported">

Defined in

lib/notion-api.ts:230

isFullBlock<Type>(block, blockType): block is Block<Type>

The Notion API may return a "partial" block object if your API token can't access the block.

This function confirms that all block data is available, and the block has type blockType.

Type parameters

Name Type
Type extends "paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported"

Parameters

Name Type
block GetBlockResponse
blockType Type

Returns

block is Block<Type>

Defined in

lib/notion-api.ts:239


isFullBlockFilter

isFullBlockFilter<Type>(type): BlockFilterFunction<Type>

Returns a filter type guard for blocks of the given type. See isFullBlock for more information.

const paragraphs: Array<Block<"paragraph">> = blocks.filter(isFullBlockFilter("paragraph"));

Type parameters

Name Type
Type extends "paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported"

Parameters

Name Type
type Type

Returns

BlockFilterFunction<Type>

Defined in

lib/notion-api.ts:269


getBlockData

getBlockData<Type>(block): BlockDataMap[Type]

Generic way to get a block's data.

Type parameters

Name Type
Type extends "paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported"

Parameters

Name Type
block Block<Type>

Returns

BlockDataMap[Type]

Defined in

lib/notion-api.ts:294


isBlockWithChildren

isBlockWithChildren(block): block is BlockWithChildren<"paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported">

Parameters

Name Type
block GetBlockResponse

Returns

block is BlockWithChildren<"paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported">

Defined in

lib/notion-api.ts:311


getChildBlocks

getChildBlocks(notion, parentBlockId): Promise<Block[]>

Fetch all supported children of a block.

Parameters

Name Type
notion default
parentBlockId string

Returns

Promise<Block[]>

Defined in

lib/notion-api.ts:323


getChildBlocksWithChildrenRecursively

getChildBlocksWithChildrenRecursively(notion, parentId): Promise<BlockWithChildren[]>

Recursively fetch all children of parentBlockId as BlockWithChildren. This function can be used to fetch an entire page's contents in one call.

Parameters

Name Type
notion default
parentId string

Returns

Promise<BlockWithChildren[]>

Defined in

lib/notion-api.ts:347


getBlockWithChildren

getBlockWithChildren(notion, blockId): Promise<BlockWithChildren | undefined>

Parameters

Name Type
notion default
blockId string

Returns

Promise<BlockWithChildren | undefined>

Defined in

lib/notion-api.ts:377


visitChildBlocks

visitChildBlocks(blocks, fn): void

Recurse over the blocks and their children, calling fn on each block.

Parameters

Name Type
blocks BlockWithChildren<"paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported">[]
fn (block: BlockWithChildren<"paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported">) => void

Returns

void

Defined in

lib/notion-api.ts:401


Rich Text Functions

richTextAsPlainText

richTextAsPlainText(richText): string

Parameters

Name Type
richText undefined | string | RichTextItemResponse[]

Returns

string

Plaintext string of rich text.

Defined in

lib/notion-api.ts:455


visitTextTokens

visitTextTokens(object, fn): void

Visit all text tokens in a block or page. Relations are treated as mention tokens. Does not consider children.

Parameters

Name Type
object {} | Block<"paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "quote" | "to_do" | "toggle" | "template" | "synced_block" | "child_page" | "child_database" | "equation" | "code" | "callout" | "divider" | "breadcrumb" | "table_of_contents" | "column_list" | "column" | "link_to_page" | "table" | "table_row" | "embed" | "bookmark" | "image" | "video" | "pdf" | "file" | "audio" | "link_preview" | "unsupported">
fn (token: RichTextItemResponse) => void

Returns

void

Defined in

lib/notion-api.ts:503


Property Functions

getPropertyData

getPropertyData<Type>(property): PropertyDataMap[Type]

Generic way to get a property's data. Suggested usage is with a switch statement on property.type to narrow the result.

switch (prop.type) {
  case 'title':
  case 'rich_text':
    getPropertyData(prop).forEach((token) => fn(token));
    break;
  // ...
}

Type parameters

Name Type
Type extends "number" | "rich_text" | "date" | "url" | "select" | "multi_select" | "email" | "phone_number" | "checkbox" | "files" | "created_by" | "created_time" | "last_edited_by" | "last_edited_time" | "formula" | "title" | "people" | "relation" | "rollup"

Parameters

Name Type
property Property<Type>

Returns

PropertyDataMap[Type]

Defined in

lib/notion-api.ts:850


getFormulaPropertyValueData

getFormulaPropertyValueData(propertyValue): FormulaPropertyValueData

Parameters

Name Type
propertyValue FormulaPropertyValue<"string" | "number" | "boolean" | "date">

Returns

FormulaPropertyValueData

Defined in

lib/notion-api.ts:878


getProperty

getProperty(page, property): Property | undefined

Get the property with name and/or id from page.

Parameters

Name Type Description
page Object
property Pick<PropertyPointer<"number" | "rich_text" | "date" | "url" | "select" | "multi_select" | "email" | "phone_number" | "checkbox" | "files" | "created_by" | "created_time" | "last_edited_by" | "last_edited_time" | "formula" | "title" | "people" | "relation" | "rollup">, "name" | "id"> Which property?

Returns

Property | undefined

The property with that name or id, or undefined if not found.

Defined in

lib/notion-api.ts:922


getPropertyValue

getPropertyValue<Type>(page, propertyPointer): PropertyDataMap[Type] | undefined

Get the value of property propertyPointer in page.

Type parameters

Name Type
Type extends "number" | "rich_text" | "date" | "url" | "select" | "multi_select" | "email" | "phone_number" | "checkbox" | "files" | "created_by" | "created_time" | "last_edited_by" | "last_edited_time" | "formula" | "title" | "people" | "relation" | "rollup"

Parameters

Name Type
page Object
propertyPointer PropertyPointer<Type>

Returns

PropertyDataMap[Type] | undefined

The value of the property, or undefined if the property isn't found, or has a different type.

Defined in

lib/notion-api.ts:943

getPropertyValue<Type, T>(page, propertyPointer, transform): T | undefined

Get the value of property propertyPointer in page, transformed by transform.

Type parameters

Name Type
Type extends "number" | "rich_text" | "date" | "url" | "select" | "multi_select" | "email" | "phone_number" | "checkbox" | "files" | "created_by" | "created_time" | "last_edited_by" | "last_edited_time" | "formula" | "title" | "people" | "relation" | "rollup"
T T

Parameters

Name Type
page Object
propertyPointer PropertyPointer<Type>
transform (propertyValue: PropertyDataMap[Type]) => T

Returns

T | undefined

The result of as(propertyValue), or undefined if the property isn't found or has a different type.

Defined in

lib/notion-api.ts:952

getPropertyValue<T>(page, propertyPointer): T | undefined

Get the value of property propertyPointer in page.

Type parameters

Name
T

Parameters

Name Type
page Object
propertyPointer PropertyPointerWithOutput<T>

Returns

T | undefined

The value of the property, or undefined if the property isn't found, or has a different type.

Defined in

lib/notion-api.ts:962

getPropertyValue<P, T>(page, propertyPointer, transform): T | undefined

Get the value of property propertyPointer in page, transformed by transform.

Type parameters

Name
P
T

Parameters

Name Type
page Object
propertyPointer PropertyPointerWithOutput<P>
transform (propertyValue: P) => T

Returns

T | undefined

The result of as(propertyValue), or undefined if the property isn't found or has a different type.

Defined in

lib/notion-api.ts:971


getAllProperties

getAllProperties<Schema>(page, schema): DatabasePropertyValues<Schema>

Get all properties in a schema from the database.

Type parameters

Name Type
Schema extends PartialDatabaseSchema

Parameters

Name Type
page Object
schema Schema

Returns

DatabasePropertyValues<Schema>

Defined in

lib/notion-api.ts:1495


Date Functions

notionDateStartAsDate

notionDateStartAsDate(date): Date

Convert a Notion date's start into a Javascript Date object.

Parameters

Name Type
date DateResponse | Date

Returns

Date

Defined in

lib/notion-api.ts:479

notionDateStartAsDate(date): Date | undefined

Convert a Notion date's start into a Javascript Date object.

Parameters

Name Type
date undefined | DateResponse | Date

Returns

Date | undefined

Defined in

lib/notion-api.ts:484


Query Functions

propertyFilterBuilder

propertyFilterBuilder<Type>(property): PropertyFilterBuilder<Type>

Helper object for building PropertyFilters for the given property.

Type parameters

Name Type
Type extends "number" | "rich_text" | "date" | "url" | "select" | "multi_select" | "email" | "phone_number" | "checkbox" | "files" | "created_by" | "created_time" | "last_edited_by" | "last_edited_time" | "formula" | "title" | "people" | "relation" | "rollup"

Parameters

Name Type Description
property PropertyPointer<Type> Property to build a filter for.

Returns

PropertyFilterBuilder<Type>

a property filter builder.

Defined in

lib/query.ts:446


databaseFilterBuilder

databaseFilterBuilder<T>(schema): DatabaseFilterBuilder<T>

Helper object for building PropertyFilters for the properties in the given schema.

Type parameters

Name Type
T extends PartialDatabaseSchema

Parameters

Name Type Description
schema T Database schema to build filters for.

Returns

DatabaseFilterBuilder<T>

A property filter builder for schema property, plus compound filter builders.

Defined in

lib/query.ts:481


databaseSortBuilder

databaseSortBuilder<T>(schema): DatabaseSortBuilder<T>

Type parameters

Name Type
T extends PartialDatabaseSchema

Parameters

Name Type
schema T

Returns

DatabaseSortBuilder<T>

Defined in

lib/query.ts:536


extendQueryParameters

extendQueryParameters(base, extension): QueryDatabaseParameters

Extend a base query with additional filters, sorts, etc. Filters will be anded together and sorts concatenated.

Parameters

Name Type
base QueryDatabaseParameters
extension Partial<QueryDatabaseParameters>

Returns

QueryDatabaseParameters

Defined in

lib/query.ts:578


CMS Functions

defaultSlug

defaultSlug(page): string

Parameters

Name Type
page Object

Returns

string

The default slug for the page, based on the page's ID.

Defined in

lib/content-management-system.ts:1042


getPageTitle

getPageTitle(page): any[]

Parameters

Name Type
page Object

Returns

any[]

The title of page, as RichText.

Defined in

lib/content-management-system.ts:1052


getCustomPropertyValue

getCustomPropertyValue<T, CustomFrontmatter, Schema>(customProperty, page, cms): Promise<T | undefined>

Compute a custom property.

Type parameters

Name Type
T T
CustomFrontmatter CustomFrontmatter
Schema extends PartialDatabaseSchema

Parameters

Name Type Description
customProperty CMSCustomProperty<T, CustomFrontmatter, Schema> The custom property to compute.
page {} | PageWithChildren
cms CMS<CustomFrontmatter, Schema>

Returns

Promise<T | undefined>

Defined in

lib/content-management-system.ts:1091


Asset Functions

getAssetRequestKey

getAssetRequestKey(assetRequest): string

Get a unique string key for de-duplicating AssetRequests

Parameters

Name Type
assetRequest AssetRequest

Returns

string

Defined in

lib/assets.ts:64


getAssetRequestUrl

getAssetRequestUrl(assetRequest, baseUrl, last_edited_time): URL

Build a URL to GET an asset.

Parameters

Name Type Description
assetRequest AssetRequest -
baseUrl URL The base URL where the asset request handler is mounted (ending with a /), eg https://mydomain.com/api/notion-assets/.
last_edited_time undefined | string -

Returns

URL

Defined in

lib/assets.ts:80


getAssetRequestPathname

getAssetRequestPathname(assetRequest, basePathOrURL, last_edited_time): string

Get an absolute pathname (eg /api/notion-assets/...) for the given asset request.

Parameters

Name Type Description
assetRequest AssetRequest The asset request.
basePathOrURL string | URL Eg /api/notion-assets/. A path or URL ending with a '/'.
last_edited_time undefined | string The last_edited_time of the object that contains this asset, for immutable caching.

Returns

string

Defined in

lib/assets.ts:105


parseAssetRequestQuery

parseAssetRequestQuery(query): ParsedAssetRequest

Parse an AssetRequest from a NextJS-style query object.

Parameters

Name Type
query AssetRequestNextJSQuery | NextJSQuery

Returns

ParsedAssetRequest

Defined in

lib/assets.ts:164


parseAssetRequestUrl

parseAssetRequestUrl(assetUrl, baseURL): ParsedAssetRequest

Inverse of getAssetRequestUrl.

Parameters

Name Type
assetUrl string | URL
baseURL URL

Returns

ParsedAssetRequest

Defined in

lib/assets.ts:197


performAssetRequest

performAssetRequest(args): Promise<undefined | Asset>

Look up an asset from the Notion API.

Parameters

Name Type
args Object
args.notion default
args.cache NotionObjectIndex
args.request AssetRequest

Returns

Promise<undefined | Asset>

Defined in

lib/assets.ts:385


getAssetKey

getAssetKey(asset): string

Parameters

Name Type
asset Asset

Returns

string

a string key unique for the asset, suitable for use in a hashmap, cache, or filename.

Defined in

lib/assets.ts:418


ensureImageDownloaded

ensureImageDownloaded(args): Promise<string | undefined>

Download image at url to a path in directory starting with filenamePrefix if it does not exist, or return the existing path on disk that has that prefix.

Parameters

Name Type
args Object
args.url string
args.filenamePrefix string
args.directory string
args.cacheBehavior? CacheBehavior

Returns

Promise<string | undefined>

Promise Relative path from directory to image on disk.

Defined in

lib/assets.ts:460


ensureEmojiCopied

ensureEmojiCopied(args): Promise<string | undefined>

Copy an emoji image for emoji into directory.

Parameters

Name Type Description
args Object -
args.emoji string -
args.directory string -
args.filenamePrefix string -
args.emojiSourceDirectory? string Path to directory containing emoji images. The directory should have contents like this: https://github.com/iamcal/emoji-data/tree/1ddc9ca67c1379c372b4ca39824659f71caa2825/img-apple-160 If undefined, this path will be looked up using require.resolve('emoji-datasource-apple'), or fall back to ${process.cwd()}/node_modules/emoji-datasource-apple/img/apple/64.
args.cacheBehavior? CacheBehavior -

Returns

Promise<string | undefined>

relative path from directory to the image.

Defined in

lib/assets.ts:518


ensureAssetInDirectory

ensureAssetInDirectory(args): Promise<string | undefined>

Ensure asset is present on disk in directory.

Parameters

Name Type Description
args Object -
args.asset Asset -
args.directory string -
args.emojiSourceDirectory? string See ensureEmojiCopied
args.cacheBehavior? CacheBehavior -

Returns

Promise<string | undefined>

Relative path from directory to the asset on disk, or undefined.

Defined in

lib/assets.ts:582


Backlink Functions

buildBacklinks

buildBacklinks(pages, backlinks?): Backlinks

Crawl the given pages and build all the backlinks between them into backlinks. If no Backlinks is given, a new one will be created and returned.

Parameters

Name Type
pages PageWithChildren[]
backlinks Backlinks

Returns

Backlinks

Defined in

lib/backlinks.ts:158


Cache Functions

getFromCache

getFromCache<T1, T2>(cacheBehavior, fromCache, fromScratch): [T1, true] | Promise<[T2, false]>

Either returns a value by calling fromCache, or by calling fromScratch, depending on cacheBehavior.

Type parameters

Name
T1
T2

Parameters

Name Type Description
cacheBehavior undefined | CacheBehavior "fill" by default.
fromCache () => undefined | T1 Function to read the value from the cache.
fromScratch () => Promise<T2> Function to compute the value from scratch.

Returns

[T1, true] | Promise<[T2, false]>

[value, hit] where hit is true if the value was fetched from the cache.

Defined in

lib/cache.ts:31


fillCache

fillCache(cacheBehavior, fill): void

Possibly call fill to fill the cache, depending on cacheBehavior.

Parameters

Name Type Description
cacheBehavior undefined | CacheBehavior "fill" by default.
fill () => void Function to fill the cache.

Returns

void

Defined in

lib/cache.ts:50

fillCache(cacheBehavior, hit, fill): void

Possibly call fill to fill the cache, depending on cacheBehavior and hit. If hit is true, or cacheBehavior is "read-only", then fill is not called.

Parameters

Name Type Description
cacheBehavior undefined | CacheBehavior "fill" by default.
hit boolean -
fill () => void Function to fill the cache.

Returns

void

Defined in

lib/cache.ts:61


Database Functions

isFullDatabase

isFullDatabase(database): database is Object

The Notion API may return a "partial" database object if your API token doesn't have permission for the full database.

This function confirms that all database data is available.

Parameters

Name Type
database GetDatabaseResponse

Returns

database is Object

Defined in

lib/notion-api.ts:1007


getPropertySchemaData

getPropertySchemaData<Type>(propertySchema): PropertySchemaDataMap[Type]

Get the type-specific schema data of propertySchema.

Type parameters

Name Type
Type extends "number" | "rich_text" | "date" | "url" | "select" | "multi_select" | "email" | "phone_number" | "checkbox" | "files" | "created_by" | "created_time" | "last_edited_by" | "last_edited_time" | "formula" | "title" | "people" | "relation" | "rollup"

Parameters

Name Type
propertySchema PropertySchema<Type>

Returns

PropertySchemaDataMap[Type]

Defined in

lib/notion-api.ts:1063


inferDatabaseSchema

inferDatabaseSchema<T>(schema): PartialDatabaseSchemaFromSchemaWithOnlyType<T>

This function helps you infer a concrete subtype of PartialDatabaseSchema for use with other APIs in this package. It will fill in missing name fields of each PartialPropertySchema with the object's key.

Use the fields of the returned schema to access a page's properties via getPropertyValue or getProperty.

You can check or update your inferred schema against data fetched from the API with [[compareDatabaseSchema]].

const mySchema = inferDatabaseSchema({
  Title: { type: 'title' },
  SubTitle: { type: 'rich_text', name: 'Subtitle' },
  PublishedDate: { type: 'date', name: 'Published Date' },
  IsPublished: {
    type: 'checkbox',
    name: 'Show In Production',
    id: 'asdf123',
  },
});

// inferDatabaseSchema infers a concrete type with the same shape as the input,
// so you can reference properties easily. It also adds `name` to each [PropertySchema](modules.md#propertyschema)
// based on the key name.
console.log(mySchema.Title.name); // "Title"

// You can use the properties in the inferred schema to access the corresponding
// property value on a Page.
for await (const page of iteratePaginatedAPI(notion.databases.query, {
  database_id,
})) {
  if (isFullPage(page)) {
    const titleRichText = getPropertyValue(page, mySchema.Title);
    console.log('Title: ', richTextAsPlainText(titleRichText));
    const isPublished = getPropertyValue(page, mySchema.IsPublished);
    console.log('Is published: ', isPublished);
  }
}

Type parameters

Name Type
T extends PartialDatabaseSchemaWithOnlyType

Parameters

Name Type Description
schema T A partial database schema object literal.

Returns

PartialDatabaseSchemaFromSchemaWithOnlyType<T>

The inferred PartialDatabaseSchema subtype.

Defined in

lib/notion-api.ts:1154


diffDatabaseSchemas

diffDatabaseSchemas<Before, After>(args): DatabaseSchemaDiff<Before, After>[]

Diff a before and after database schemas.

You can use this to validate an inferred schema literal against the actual schema fetched from the Notion API.

const mySchema = inferDatabaseSchema({
  Title: { type: 'title' },
  SubTitle: { type: 'rich_text', name: 'Subtitle' },
  PublishedDate: { type: 'date', name: 'Published Date' },
  IsPublished: {
    type: 'checkbox',
    name: 'Show In Production',
    id: 'asdf123',
  },
});

// Print schema differences between our literal and the API.
const database = await notion.databases.retrieve({ database_id });
const diffs = diffDatabaseSchemas({ before: mySchema, after: database.properties });
for (const change of diffs) {
  console.log(
    databaseSchemaDiffToString(change, { beforeName: "mySchema", afterName: "API database" })
  );
}

warning This is O(N * M) over length of the schemas currently, but may be optimized in the future.

Type parameters

Name Type
Before extends PartialDatabaseSchema
After extends PartialDatabaseSchema

Parameters

Name Type
args Object
args.before Before
args.after After

Returns

DatabaseSchemaDiff<Before, After>[]

An array of diffs between the before and after schemas.

Defined in

lib/notion-api.ts:1289


databaseSchemaDiffToString

databaseSchemaDiffToString<Before, After>(diff, options?): string

See diffDatabaseSchemas.

Type parameters

Name Type
Before extends PartialDatabaseSchema
After extends PartialDatabaseSchema

Parameters

Name Type Description
diff DatabaseSchemaDiff<Before, After> -
options Object -
options.beforeName? string Show "before" as this string
options.afterName? string show "after" as this string

Returns

string

A string describing a diff between two database schemas.

Defined in

lib/notion-api.ts:1393


getAllProperties

getAllProperties<Schema>(page, schema): DatabasePropertyValues<Schema>

Get all properties in a schema from the database.

Type parameters

Name Type
Schema extends PartialDatabaseSchema

Parameters

Name Type
page Object
schema Schema

Returns

DatabasePropertyValues<Schema>

Defined in

lib/notion-api.ts:1495


databaseFilterBuilder

databaseFilterBuilder<T>(schema): DatabaseFilterBuilder<T>

Helper object for building PropertyFilters for the properties in the given schema.

Type parameters

Name Type
T extends PartialDatabaseSchema

Parameters

Name Type Description
schema T Database schema to build filters for.

Returns

DatabaseFilterBuilder<T>

A property filter builder for schema property, plus compound filter builders.

Defined in

lib/query.ts:481

Query Variables

Filter

Filter: Object

Filter builder functions.

Type declaration

Name Type
property <Type>(filter: PropertyFilter<Type>) => PropertyFilter<Type>
compound (type: "or" | "and", ...filters: (undefined | false | Filter)[]) => undefined | Filter
isCompound (filter: Filter) => filter is CompoundFilter
and (...filters: (undefined | false | Filter)[]) => undefined | Filter
isAnd (filter: Filter) => filter is Object
or (...filters: (undefined | false | Filter)[]) => undefined | Filter
isOr (filter: Filter) => filter is Object

Defined in

lib/notion-api.ts:625


Sort

Sort: Object

Sort builder functions.

Type declaration

Name Type
property { ascending: (property: string) => {} ; descending: (property: string) => {} }
property.ascending (property: string) => {}
property.descending (property: string) => {}
created_time { ascending: { timestamp: "created_time" = 'created_time'; direction: "ascending" = 'ascending' } ; descending: { timestamp: "created_time" = 'created_time'; direction: "descending" = 'descending' } }
created_time.ascending { timestamp: "created_time" = 'created_time'; direction: "ascending" = 'ascending' }
created_time.ascending.timestamp "created_time"
created_time.ascending.direction "ascending"
created_time.descending { timestamp: "created_time" = 'created_time'; direction: "descending" = 'descending' }
created_time.descending.timestamp "created_time"
created_time.descending.direction "descending"
last_edited_time { ascending: { timestamp: "last_edited_time" = 'last_edited_time'; direction: "ascending" = 'ascending' } ; descending: { timestamp: "last_edited_time" = 'last_edited_time'; direction: "descending" = 'descending' } }
last_edited_time.ascending { timestamp: "last_edited_time" = 'last_edited_time'; direction: "ascending" = 'ascending' }
last_edited_time.ascending.timestamp "last_edited_time"
last_edited_time.ascending.direction "ascending"
last_edited_time.descending { timestamp: "last_edited_time" = 'last_edited_time'; direction: "descending" = 'descending' }
last_edited_time.descending.timestamp "last_edited_time"
last_edited_time.descending.direction "descending"

Defined in

lib/notion-api.ts:754


EXISTENCE_FILTER_OPERATORS

Const EXISTENCE_FILTER_OPERATORS: FilterOperatorTypeMap<ExistenceFilterOperator>

Runtime type information for ExistenceFilterOperator.

Defined in

lib/query.ts:59


TEXT_FILTER_OPERATORS

Const TEXT_FILTER_OPERATORS: FilterOperatorTypeMap<TextFilterOperator>

Runtime type information for TextFilterOperator.

Defined in

lib/query.ts:91


NUMBER_FILTER_OPERATORS

Const NUMBER_FILTER_OPERATORS: FilterOperatorTypeMap<NumberFilterOperator>

Runtime type information for NumberFilterOperator.

Defined in

lib/query.ts:116


CHECKBOX_FILTER_OPERATORS

Const CHECKBOX_FILTER_OPERATORS: FilterOperatorTypeMap<CheckboxFilterOperator> = EQUALITY_OPERATORS

Runtime type information for NumberFilterOperator.

Defined in

lib/query.ts:135


SELECT_FILTER_OPERATORS

Const SELECT_FILTER_OPERATORS: FilterOperatorTypeMap<SelectFilterOperator>

Runtime type information for SelectFilterOperator.

Defined in

lib/query.ts:151


MULTI_SELECT_FILTER_OPERATORS

Const MULTI_SELECT_FILTER_OPERATORS: FilterOperatorTypeMap<MultiSelectFilterOperator>

Runtime type information for MultiSelectFilterOperator.

Defined in

lib/query.ts:169


DATE_FILTER_OPERATORS

Const DATE_FILTER_OPERATORS: FilterOperatorTypeMap<DateFilterOperator>

Runtime type information for DateFilterOperator.

Defined in

lib/query.ts:196


PEOPLE_FILTER_OPERATORS

Const PEOPLE_FILTER_OPERATORS: FilterOperatorTypeMap<PeopleFilterOperator>

Runtime type information for PeopleFilterOperator.

Defined in

lib/query.ts:224


RELATION_FILTER_OPERATORS

Const RELATION_FILTER_OPERATORS: FilterOperatorTypeMap<RelationFilterOperator>

Runtime type information for RelationFilterOperator.

Defined in

lib/query.ts:242


FORMULA_FILTER_OPERATORS

Const FORMULA_FILTER_OPERATORS: FilterOperatorTypeMap<FormulaFilterOperator>

Runtime type information for FormulaFilterOperator.

Defined in

lib/query.ts:266


ROLLUP_FILTER_OPERATORS

Const ROLLUP_FILTER_OPERATORS: FilterOperatorTypeMap<RollupFilterOperator>

Runtime type information for RollupFilterOperator.

Defined in

lib/query.ts:303


PROPERTY_FILTER_OPERATORS

Const PROPERTY_FILTER_OPERATORS: { [T in PropertyType]: { [O in FilterOperatorType<T>]: true } }

Runtime type information for PropertyToToFilterOperator.

Defined in

lib/query.ts:342


ALL_PROPERTY_FILTER_OPERATORS

Const ALL_PROPERTY_FILTER_OPERATORS: Record<AnyFilterOperator, true>

Runtime information for all known filter operators.

Defined in

lib/query.ts:394


Asset Variables

ASSET_REQUEST_QUERY_PATH_PARAM

Const ASSET_REQUEST_QUERY_PATH_PARAM: "asset_request"

Defined in

lib/assets.ts:122


ASSET_REQUEST_LAST_EDITED_TIME_PARAM

Const ASSET_REQUEST_LAST_EDITED_TIME_PARAM: "last_edited_time"

Defined in

lib/assets.ts:124


DOWNLOAD_PERMISSION_ERROR

Const DOWNLOAD_PERMISSION_ERROR: "DownloadPermissionError"

[[Error.name]] of errors thrown by ensureImageDownloaded when encountering a permission error, eg if the asset is expired.

Defined in

lib/assets.ts:444


DOWNLOAD_HTTP_ERROR

Const DOWNLOAD_HTTP_ERROR: "DownloadHTTPError"

[[Error.name]] of errors thrown by ensureImageDownloaded when encountering other HTTP error codes.

Defined in

lib/assets.ts:450


API

A logger for the @notionhq/client Client that logs to the @jitl/notion-api namespace. Variables

NotionClientDebugLogger

NotionClientDebugLogger: NotionClientDebugLogger

example

const client = new NotionClient({
  logger: NotionClientDebugLogger,
  // ...
})

Defined in

lib/notion-api.ts:62