Skip to content

Commit e44d195

Browse files
committed
doc(notion): create documentation
1 parent 8e90bcd commit e44d195

File tree

8 files changed

+250
-145
lines changed

8 files changed

+250
-145
lines changed
4.25 MB
Loading

docs/table.png

73.5 KB
Loading

packages/@contentlayer/source-notion/src/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@ import type * as core from '@contentlayer/core'
22
import { processArgs } from '@contentlayer/core'
33
import { pipe, S, T } from '@contentlayer/utils/effect'
44
import { NotionRenderer } from '@notion-render/client';
5-
import type * as notion from '@notionhq/client';
65

76
import { fetchAllDocuments } from './fetchData/index.js'
87
import { provideSchema } from './schema/provideSchema.js'
9-
import type * as LocalSchema from './schema/types.js'
108
import type { PluginOptions } from "./types.js"
119

1210
export * from './schema/types.js'
1311

14-
export type Args = {
15-
client: notion.Client,
16-
renderer?: NotionRenderer,
17-
databaseTypes: LocalSchema.DatabaseTypes
18-
}
1912

20-
export const makeSource: core.MakeSourcePlugin<Args & PluginOptions> = async (args) => {
13+
export const makeSource: core.MakeSourcePlugin<PluginOptions & core.PartialArgs> = async (args) => {
2114
const {
2215
options,
2316
extensions,

packages/@contentlayer/source-notion/src/schema/provideDatabaseSchema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type * as core from '@contentlayer/core'
2-
import type { FieldDef } from '@contentlayer/core';
32
import type { OT } from "@contentlayer/utils/effect";
43
import { pipe, T } from "@contentlayer/utils/effect";
54

5+
import type { FieldDef } from '../types.js';
66
import { provideDatabaseFieldSchema } from './provideDatabaseFieldSchema.js';
77
import type { ProvideSchemaArgs } from "./provideSchema.js";
88
import type { DatabaseTypeDef } from "./types.js";

packages/@contentlayer/source-notion/src/schema/types.ts

+37-14
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import type { Thunk } from "@contentlayer/utils"
22
import type { QueryDatabaseParameters } from "@notionhq/client/build/src/api-endpoints"
33

44
export type DatabaseFieldTypeDefBase = {
5-
/**
6-
* When required, pages without this property defined will not be generated.
7-
*/
8-
isRequired?: boolean,
9-
105
/**
116
* Map this property to a specific key.
127
* Defaults to the property name.
@@ -17,25 +12,49 @@ export type DatabaseFieldTypeDefBase = {
1712
* Field description used to generate comments.
1813
*/
1914
description?: string;
20-
} & ({ id: string } | { label: string })
15+
16+
/**
17+
* When required, pages without this property defined will not be generated.
18+
*/
19+
isRequired?: boolean,
20+
} & ({ id: string } | { name: string })
2121

2222
export type DatabaseRelationFieldTypeDef = DatabaseFieldTypeDefBase & {
23+
/**
24+
* Type of the property to configure it.
25+
*/
2326
type: 'relation',
24-
// TODO : Not used yet
25-
relation: DatabaseType,
26-
single?: boolean,
27-
}
2827

29-
export type DatabaseRollupFieldTypeDef = DatabaseFieldTypeDefBase & {
30-
type: 'rollup',
31-
relation: DatabaseType,
28+
/**
29+
* Database related to this relation.
30+
*
31+
* TODO : Will be used for Rollup properties.
32+
*/
33+
relation?: DatabaseType,
34+
35+
/**
36+
* If true, the property will be of type `string` instead of type `string[]`
37+
* and only the first item will be taken.
38+
*/
39+
single?: boolean,
3240
}
3341

34-
export type DatabaseFieldTypeDef = DatabaseFieldTypeDefBase | DatabaseRollupFieldTypeDef | DatabaseRelationFieldTypeDef
42+
export type DatabaseFieldTypeDef = DatabaseFieldTypeDefBase | DatabaseRelationFieldTypeDef
3543

3644
export type DatabaseTypeDef<Flattened extends boolean = true, DefName extends string = string> = {
45+
/**
46+
* The database name.
47+
*/
3748
name: DefName,
49+
50+
/**
51+
* The database description used to generate comments.
52+
*/
3853
description?: string,
54+
55+
/**
56+
* The database ID used as the content source.
57+
*/
3958
databaseId: string,
4059

4160
/**
@@ -56,6 +75,10 @@ export type DatabaseTypeDef<Flattened extends boolean = true, DefName extends st
5675
*/
5776
query?: Omit<QueryDatabaseParameters, 'database_id' | 'filter_properties' | 'start_cursor' | 'page_size'>
5877

78+
/**
79+
* The fields configuration, usefull to remap keys and configure complex properties.
80+
* Not required as the properties types are already inferred.
81+
*/
5982
fields?: Flattened extends false ? Record<string, DatabaseFieldTypeDef> | DatabaseFieldTypeDef[] : DatabaseFieldTypeDef[]
6083
}
6184

packages/@contentlayer/source-notion/src/schema/utils/findDatabaseFieldDef.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const findDatabaseFieldDef = ({ databaseTypeDef, property }: FindDatabase
1010
if (!databaseTypeDef.fields) return;
1111

1212
return databaseTypeDef.fields.find((fieldDef) => {
13-
if ('label' in fieldDef) return fieldDef.label === property.name
13+
if ('label' in fieldDef) return fieldDef.name === property.name
1414
if ('id' in fieldDef) return fieldDef.id === property.id
1515
})
1616
}

packages/@contentlayer/source-notion/src/types.ts

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
import type * as core from '@contentlayer/core';
2+
import type { NotionRenderer } from '@notion-render/client';
3+
import type * as notion from '@notionhq/client'
24
import type { DatabaseObjectResponse, PageObjectResponse } from "@notionhq/client/build/src/api-endpoints"
35

4-
export type PluginOptions = {
5-
fieldOptions?: FieldOptions
6-
}
6+
import type { DatabaseTypes } from './schema/types.js';
77

8-
export type FieldOptions = {
9-
/**
10-
* Name of the field containing the body/content extracted when `contentType` is `markdown` or `mdx`.
11-
* @default "body"
12-
*/
13-
bodyFieldName?: string
14-
/**
15-
* Name of the field containing the name of the document type (or nested document type).
16-
* @default "type"
17-
*/
18-
typeFieldName?: string
8+
export type PluginOptions = {
9+
client: notion.Client,
10+
renderer?: NotionRenderer,
11+
databaseTypes: DatabaseTypes
1912
}
2013

2114
export type FieldDef = core.FieldDef & { propertyKey: string }

0 commit comments

Comments
 (0)