Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ index とは `toContent` が返す iterator から取得したときに `props`
- [ ] formula
- [x] title - plain text へ変換される
- [x] rich_text - plain text へ変換される
- [x] people - [People property values](https://developers.notion.com/reference/property-item-object#people-property-values)を出力(`person` のみ対応、`null` と `undefined` は `''` へ変換される)
- [x] people - [People property values](https://developers.notion.com/reference/property-item-object#people-property-values)を出力(`person` と `group` に対応、`null` と `undefined` は `''` へ変換される)
- [x] relation - id の配列へ変換
- [ ] rollup

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/lib/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { PageObjectResponse } from '@notionhq/client/build/src/api-endpoints'
import type {
PartialUserObjectResponse,
UserObjectResponse,
PersonUserObjectResponse
PersonUserObjectResponse,
GroupObjectResponse
} from '@notionhq/client/build/src/api-endpoints'
import { PropsItem, PropsItemValue } from './types'

Expand All @@ -11,7 +12,7 @@ function isPersonUserObjectResponse(v: any): v is PersonUserObjectResponse {
}

function userToPersonItems(
user: PartialUserObjectResponse | UserObjectResponse
user: PartialUserObjectResponse | UserObjectResponse | GroupObjectResponse
) {
if (isPersonUserObjectResponse(user)) {
return {
Expand All @@ -22,6 +23,11 @@ function userToPersonItems(
}
}
}
if (user.object === 'group') {
return {
name: user.name !== null ? user.name : ''
}
}
return {
name: '',
avatar_url: '',
Expand Down
10 changes: 10 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,29 @@ export type PropsItemValue =
time_zone: string
}
| {
// user
name: string
avatar_url: string
person: {
email: string
}
}
| {
// user(array)
name: string
avatar_url: string
person: {
email: string
}
}[]
| {
// group
name: string
}
| {
// group(array)
name: string
}[]

export type PropsItem = Record<string, PropsItemValue>

Expand Down
46 changes: 46 additions & 0 deletions test/lib/props.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,52 @@ describe('propsToItems()', () => {
).toEqual({ 'test-rich': 'text1text2' })
})

it('should convert group properties to items', async () => {
const propsToItems = new PropsToItems()
expect(
await propsToItems.toItems({
'test-group': {
id: '',
type: 'people',
people: [
{
id: 'person-id-1',
name: 'hankei6km-grp-1',
object: 'group'
},
{
id: 'person-id-2',
name: 'hankei6km-grp-2',
object: 'group'
}
]
}
})
).toEqual({
'test-group': [
{
name: 'hankei6km-grp-1'
},
{ name: 'hankei6km-grp-2' }
]
})
expect(
await propsToItems.toItems({
'test-group': {
id: '',
type: 'people',
people: [
{
id: 'person-id-1',
name: null,
object: 'group'
}
]
}
})
).toEqual({ 'test-group': [{ name: '' }] })
})

it('should convert people properties to items', async () => {
const propsToItems = new PropsToItems()
expect(
Expand Down