Skip to content

Commit 5db89f4

Browse files
committed
feat(type): provided data types in relation to pages and databases
1 parent 8ef3461 commit 5db89f4

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

source/types/collection.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* *** MIT LICENSE ***
3+
* -------------------------------------------------------------------------
4+
* This code may be modified and distributed under the MIT license.
5+
* See the LICENSE file for details.
6+
* -------------------------------------------------------------------------
7+
*
8+
* @summary Collection of collection related types
9+
*
10+
* @author Alvis HT Tang <alvis@hilbert.space>
11+
* @license MIT
12+
* @copyright Copyright (c) 2021 - All Rights Reserved.
13+
* -------------------------------------------------------------------------
14+
*/
15+
16+
/* eslint-disable @typescript-eslint/naming-convention */
17+
18+
import type { Block, FullBlock } from './block';
19+
import type { RichText } from './format';
20+
import type { PropertyMetaMap, PropertyValueMap } from './property';
21+
import type { User } from './user';
22+
23+
/*
24+
* Parent
25+
*/
26+
27+
interface ParentDatabase {
28+
type: 'database_id';
29+
database_id: string;
30+
}
31+
32+
interface ParentPage {
33+
type: 'page_id';
34+
page_id: string;
35+
}
36+
37+
interface ParentWorkspace {
38+
type: 'workspace';
39+
}
40+
41+
/*
42+
* Page
43+
*/
44+
45+
export interface Page {
46+
object: 'page';
47+
id: string;
48+
parent: ParentDatabase | ParentPage | ParentWorkspace;
49+
created_time: string;
50+
last_edited_time: string;
51+
archived: boolean;
52+
properties: PropertyValueMap;
53+
url: string;
54+
}
55+
56+
export interface FullPage extends Page {
57+
blocks: FullBlock[];
58+
markdown: string;
59+
title: string;
60+
}
61+
62+
/*
63+
* Database
64+
*/
65+
66+
export interface Database {
67+
object: 'database';
68+
id: string;
69+
parent: ParentPage | ParentWorkspace;
70+
created_time: string;
71+
last_edited_time: string;
72+
title: RichText[];
73+
properties: PropertyMetaMap;
74+
}
75+
76+
export interface FullDatabase extends Omit<Database, 'title'> {
77+
pages: FullPage[];
78+
title: string;
79+
}
80+
81+
/*
82+
* List
83+
*/
84+
85+
export type Entity = Block | Database | Page | User;
86+
87+
export interface List<E extends Entity = Entity> {
88+
object: 'list';
89+
results: E[];
90+
has_more: boolean;
91+
next_cursor: string | null;
92+
}
93+
94+
/* eslint-enable */

source/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/* istanbul ignore file */
1717

1818
export * from './block';
19+
export * from './collection';
1920
export * from './format';
2021
export * from './user';
2122
export * from './property';

0 commit comments

Comments
 (0)