Skip to content

Commit 89d10c9

Browse files
authored
Merge pull request #3 from takker99/feature/scrapbox-types
Add type definitions of Scrapbox
2 parents 4c3fef0 + ea3f7a9 commit 89d10c9

File tree

1 file changed

+199
-0
lines changed

1 file changed

+199
-0
lines changed

scrapbox.d.ts

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,202 @@
1+
// utilities
2+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
3+
4+
/** scrapboxの行のメタデータ */
5+
export interface Line {
6+
/** 行のid */ id: string;
7+
/** 行のテキスト */ text: string;
8+
/** 一番最後に行を編集した人のid */ userId: string;
9+
/** 行の作成日時 */ created: number;
10+
/** 行の最終更新日時 */ updated: number;
11+
}
12+
13+
/** 関連ページのメタデータ */
14+
export interface RelatedPage {
15+
/** ページのid */ id: string;
16+
/** ページのタイトル */ title: string;
17+
/** ページのタイトルを小文字にして、` `を`_`に変換したもの */ titleLc: string;
18+
/** ページのサムネイル画像 */ image: string;
19+
/** ページのサムネイル本文。最大5行 */ descriptions: string[];
20+
/** ページ内のリンク */ linksLc: string[];
21+
/** おそらく被リンク数 */ linked: number;
22+
/** ページの最終更新日時 */ updated: number;
23+
/** おそらくページの閲覧日時 */ accessed: number;
24+
}
25+
26+
/** user information */
27+
export interface User {
28+
/** user id */ id: string;
29+
/** user name */ name: string;
30+
/** user display name */ displayName: string;
31+
/** profile image URL */ photo: string;
32+
}
33+
34+
/** user detailed information */
35+
export interface UserInfo extends User {
36+
/** user e-mail */ email: string;
37+
/** whether the user is a pro user or not */ pro: boolean;
38+
/** login provider */ provider: "google" | "microsoft" | "email";
39+
/** accountの作成日時 */ created: number;
40+
/** accountの更新日時 */ updated: number;
41+
}
42+
43+
/** summary of page information */
44+
export interface PageSummary {
45+
/** ページのid */ id: string;
46+
/** ページのタイトル */ title: string;
47+
/** ページのサムネイル画像
48+
* 存在しなければ`null`
49+
*/
50+
image: string | null;
51+
/** ページのサムネイル本文。最大5行 */ descriptions: string[];
52+
/** ピン留めされていたら1, されていなかったら0 */ pin: 0 | 1;
53+
/** ページの閲覧回数 */ views: number;
54+
/** おそらく被リンク数 */ linked: number;
55+
/** 最新の編集コミットid */ commitId: string;
56+
/** ページの作成日時 */ created: number;
57+
/** ページの最終更新日時 */ updated: number;
58+
/** Date last visitedに使われる最終アクセス日時 */ accessed: number;
59+
/** page rank */ pageRank: number;
60+
/** Page historyの最終生成日時 */ snapshotCreated: number | null;
61+
}
62+
63+
/** page information */
64+
export interface Page extends PageSummary {
65+
/** APIを叩いたuserの最終アクセス日時。おそらくこの値を元にテロメアの未読/既読の判別をしている */ lastAccessed:
66+
| number
67+
| null;
68+
/** 生成されたPage historyの数 */ snapshotCount: number;
69+
/** 不明。削除されたページだとfalse? */ persistent: boolean;
70+
/** ページの行情報 */ lines: Line[];
71+
/** ページ内のリンク */ links: string[];
72+
/** ページ内のアイコン */ icons: string[];
73+
/** ページ内に含まれる、scrapbox.ioにアップロードしたファイルへのリンク */ files: string[];
74+
/** 関連ページリスト */
75+
relatedPages: {
76+
/** 1 hop links */ links1hop: RelatedPage[];
77+
/** 2 hop links */ links2hop: RelatedPage[];
78+
/** このページを参照しているページorアイコンがあればtrue */ hasBackLinksOrIcons: boolean;
79+
};
80+
/** 最後にページを更新したユーザー */ user: User;
81+
/** ページを編集したユーザーのうち、`user`以外の人 */ collaborators: User[];
82+
}
83+
84+
/** the response type of https://scrpabox.io/api/pages/:projectname */
85+
export type PageListResponse =
86+
| NotFoundError
87+
| NotMemberError
88+
| {
89+
/** data取得先のproject名 */ projectName: string;
90+
/** parameterに渡したskipと同じ */ skip: number;
91+
/** parameterに渡したlimitと同じ */ limit: number;
92+
/** projectの全ページ数 (中身のないページを除く) */ count: number;
93+
/** 取得できたページ情報 */ pages: PageSummary[];
94+
};
95+
96+
/** project basic information */
97+
export interface Project {
98+
id: string;
99+
name: string;
100+
displayName: string;
101+
publicVisible: boolean;
102+
loginStrategies: string[];
103+
theme: string;
104+
gyazoTeamsName: string | null;
105+
googleAnalyticsCode: string | null;
106+
image?: string;
107+
created: number;
108+
updated: number;
109+
isMember: boolean;
110+
plan?: string;
111+
}
112+
113+
export type NotMemberError = {
114+
name: "NotMemberError";
115+
message: string;
116+
};
117+
118+
export type NotFoundError = {
119+
name: "NotFoundError";
120+
message: string;
121+
};
122+
123+
/** the response type of https://scrpabox.io/api/projects/:projectname */
124+
export type ProjectResponse =
125+
| NotFoundError
126+
| NotMemberError
127+
| (
128+
& Omit<Omit<Project, "isMember">, "plan">
129+
& ({ isMember: false } | {
130+
isMember: true;
131+
plan?: string | null;
132+
users: UserInfo[];
133+
admins: string[];
134+
owner: string;
135+
trialing: boolean;
136+
trialMaxPages: number;
137+
skipPayment: boolean;
138+
uploadFileTo: "gcs";
139+
uploadImaegTo: "gyazo" | "gcs";
140+
emailAddressPatterns: string[];
141+
backuped: number | null;
142+
})
143+
);
144+
145+
/** the response type of https://scrapbox.io/api/users/me */
146+
export type UserResponse =
147+
| {
148+
isGuest: true;
149+
csrfToken: string;
150+
}
151+
| ({
152+
isGuest: false;
153+
csrfToken: string;
154+
config: {
155+
userScript: boolean;
156+
emacsBinding: boolean;
157+
};
158+
} & UserInfo);
159+
160+
/** the response type of https://scrapbox.io/api/pages/:projectname/search/titles */
161+
export type LinksResponse =
162+
| NotFoundError
163+
| NotMemberError
164+
| {
165+
message: "Invalid pageId";
166+
}
167+
| {
168+
/** page id */ id: string;
169+
/** page title */ title: string;
170+
/** 画像が存在するかどうか */ hasIcon: boolean;
171+
/** ページの更新日時 */ updated: number;
172+
/** ページ内のリンク */ links: string[];
173+
}[];
174+
175+
export type ProjectBackup = {
176+
name: string;
177+
displayName: string;
178+
exported: number;
179+
pages: {
180+
id: string;
181+
title: string;
182+
created: number;
183+
updated: number;
184+
lines: string[];
185+
};
186+
};
187+
export type ProjectBackupWithMetadata = {
188+
name: string;
189+
displayName: string;
190+
exported: number;
191+
pages: {
192+
id: string;
193+
title: string;
194+
created: number;
195+
updated: number;
196+
lines: { text: string; updated: number; created: number }[];
197+
};
198+
};
199+
1200
export type Layout =
2201
| "list"
3202
| "page"

0 commit comments

Comments
 (0)