Skip to content

Commit 554d9b2

Browse files
committed
🚧 型を色々整理
一部の`type`を`interface`に変えた JSDocの一部を英語化した IDにtype aliasを当てた
1 parent 6652f7c commit 554d9b2

File tree

4 files changed

+87
-87
lines changed

4 files changed

+87
-87
lines changed

api/response.ts

Lines changed: 48 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Omit } from "../utils.ts";
2-
import { Line } from "../base.ts";
2+
import {
3+
CommitId,
4+
Line,
5+
Page as PageBase,
6+
PageId,
7+
ProjectId,
8+
UserId,
9+
} from "../base.ts";
310
import { NotFoundError, NotMemberError } from "./error.ts";
411

512
/** 関連ページのメタデータ */
6-
export interface RelatedPage {
7-
/** ページのid */ id: string;
8-
/** ページのタイトル */ title: string;
9-
/** ページのタイトルを小文字にして、` `を`_`に変換したもの */ titleLc: string;
10-
/** ページのサムネイル画像 */ image: string;
11-
/** ページのサムネイル本文。最大5行 */ descriptions: string[];
13+
export interface RelatedPage extends PageBase {
1214
/** ページ内のリンク */ linksLc: string[];
1315
/** おそらく被リンク数 */ linked: number;
14-
/** ページの最終更新日時 */ updated: number;
15-
/** おそらくページの閲覧日時 */ accessed: number;
1616
}
1717

1818
/** user information */
1919
export interface User {
20-
/** user id */ id: string;
20+
id: UserId;
2121
/** user name */ name: string;
2222
/** user display name */ displayName: string;
2323
/** profile image URL */ photo: string;
@@ -33,21 +33,12 @@ export interface UserInfo extends User {
3333
}
3434

3535
/** summary of page information */
36-
export interface PageSummary {
37-
/** ページのid */ id: string;
38-
/** ページのタイトル */ title: string;
39-
/** ページのサムネイル画像
40-
* 存在しなければ`null`
41-
*/
42-
image: string | null;
43-
/** ページのサムネイル本文。最大5行 */ descriptions: string[];
36+
export interface PageSummary extends PageBase {
4437
/** ピン留めされていたら1, されていなかったら0 */ pin: 0 | 1;
4538
/** ページの閲覧回数 */ views: number;
4639
/** おそらく被リンク数 */ linked: number;
47-
/** 最新の編集コミットid */ commitId: string;
40+
/** 最新の編集コミットid */ commitId: CommitId;
4841
/** ページの作成日時 */ created: number;
49-
/** ページの最終更新日時 */ updated: number;
50-
/** Date last visitedに使われる最終アクセス日時 */ accessed: number;
5142
/** page rank */ pageRank: number;
5243
/** Page historyの最終生成日時 */ snapshotCreated: number | null;
5344
}
@@ -74,20 +65,17 @@ export interface Page extends PageSummary {
7465
}
7566

7667
/** the response type of https://scrpabox.io/api/pages/:projectname */
77-
export type PageListResponse =
78-
| NotFoundError
79-
| NotMemberError
80-
| {
81-
/** data取得先のproject名 */ projectName: string;
82-
/** parameterに渡したskipと同じ */ skip: number;
83-
/** parameterに渡したlimitと同じ */ limit: number;
84-
/** projectの全ページ数 (中身のないページを除く) */ count: number;
85-
/** 取得できたページ情報 */ pages: PageSummary[];
86-
};
68+
export interface PageList {
69+
/** data取得先のproject名 */ projectName: string;
70+
/** parameterに渡したskipと同じ */ skip: number;
71+
/** parameterに渡したlimitと同じ */ limit: number;
72+
/** projectの全ページ数 (中身のないページを除く) */ count: number;
73+
/** 取得できたページ情報 */ pages: PageSummary[];
74+
}
8775

88-
/** project basic information */
89-
export interface Project {
90-
id: string;
76+
/** project information which isn't joined */
77+
export interface NotMemberProject {
78+
id: ProjectId;
9179
name: string;
9280
displayName: string;
9381
publicVisible: boolean;
@@ -98,31 +86,24 @@ export interface Project {
9886
image?: string;
9987
created: number;
10088
updated: number;
101-
isMember: boolean;
102-
plan?: string;
89+
isMember: false;
10390
}
10491

105-
/** the response type of https://scrpabox.io/api/projects/:projectname */
106-
export type ProjectResponse =
107-
| NotFoundError
108-
| NotMemberError
109-
| (
110-
& Omit<Omit<Project, "isMember">, "plan">
111-
& ({ isMember: false } | {
112-
isMember: true;
113-
plan?: string | null;
114-
users: UserInfo[];
115-
admins: string[];
116-
owner: string;
117-
trialing: boolean;
118-
trialMaxPages: number;
119-
skipPayment: boolean;
120-
uploadFileTo: "gcs";
121-
uploadImaegTo: "gyazo" | "gcs";
122-
emailAddressPatterns: string[];
123-
backuped: number | null;
124-
})
125-
);
92+
/** project information which is joined */
93+
export interface MemberProject extends Omit<NotMemberProject, "isMember"> {
94+
isMember: true;
95+
plan?: string | null;
96+
users: UserInfo[];
97+
admins: UserId[];
98+
owner: UserId;
99+
trialing: boolean;
100+
trialMaxPages: number;
101+
skipPayment: boolean;
102+
uploadFileTo: "gcs";
103+
uploadImaegTo: "gyazo" | "gcs";
104+
emailAddressPatterns: string[];
105+
backuped: number | null;
106+
}
126107

127108
/** the response type of https://scrapbox.io/api/users/me */
128109
export type UserResponse =
@@ -140,26 +121,20 @@ export type UserResponse =
140121
} & UserInfo);
141122

142123
/** the response type of https://scrapbox.io/api/pages/:projectname/search/titles */
143-
export type LinksResponse =
144-
| NotFoundError
145-
| NotMemberError
146-
| {
147-
message: "Invalid pageId";
148-
}
149-
| {
150-
/** page id */ id: string;
151-
/** page title */ title: string;
152-
/** 画像が存在するかどうか */ hasIcon: boolean;
153-
/** ページの更新日時 */ updated: number;
154-
/** ページ内のリンク */ links: string[];
155-
}[];
124+
export interface SearchedTitle {
125+
id: PageId;
126+
/** page title */ title: string;
127+
/** 画像が存在するかどうか */ hasIcon: boolean;
128+
/** ページの更新日時 */ updated: number;
129+
/** ページ内のリンク */ links: string[];
130+
}
156131

157132
export type ProjectBackup = {
158133
name: string;
159134
displayName: string;
160135
exported: number;
161136
pages: {
162-
id: string;
137+
id: PageId;
163138
title: string;
164139
created: number;
165140
updated: number;
@@ -171,10 +146,10 @@ export type ProjectBackupWithMetadata = {
171146
displayName: string;
172147
exported: number;
173148
pages: {
174-
id: string;
149+
id: PageId;
175150
title: string;
176151
created: number;
177152
updated: number;
178-
lines: { text: string; updated: number; created: number }[];
153+
lines: Omit<Line, "id" | "userId">[];
179154
};
180155
};

base.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
/** scrapboxの行のメタデータ */
22
export interface Line {
3-
/** 行のid */ id: string;
3+
/** 行のid */ id: LineId;
44
/** 行のテキスト */ text: string;
55
/** 一番最後に行を編集した人のid */ userId: string;
66
/** 行の作成日時 */ created: number;
77
/** 行の最終更新日時 */ updated: number;
88
}
9+
10+
/** basic information about a page */
11+
export interface Page {
12+
/** the id of a page */ id: PageId;
13+
/** the title of a page */ title: string;
14+
/** the thumbnail URL of a page if exists
15+
*
16+
* set to `null` if not exists
17+
*/
18+
image: string | null;
19+
/** the thumbnail text of a page.
20+
* the maximum number of lines is 5.
21+
* */ descriptions: string[];
22+
/** ページの最終更新日時 */ updated: number;
23+
/** Date last visitedに使われる最終アクセス日時 */ accessed: number;
24+
}
25+
26+
/** the user id */
27+
export type UserId = string;
28+
/** the line id */
29+
export type LineId = string;
30+
/** the commit id */
31+
export type CommitId = string;
32+
/** the page id */
33+
export type PageId = string;
34+
/** the project id */
35+
export type ProjectId = string;

userscript.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ export type Scrapbox =
7373
};
7474
});
7575

76-
export type PageBrief = {
77-
exists: boolean;
78-
hasIcon?: boolean;
79-
id: string;
80-
title: string;
81-
titleLc: string;
82-
updated: number;
83-
};
76+
export interface PageBrief {
77+
/** true when the page has contents */ exists: boolean;
78+
/** whether the page contains any image */ hasIcon?: boolean;
79+
/** the page id */ id: string;
80+
/** the page title */ title: string;
81+
/** the converted page title */ titleLc: string;
82+
/** updated time */ updated: number;
83+
}
8484

8585
type TimeStamp = {
8686
addFormat: (format: string | (() => string)) => void;
@@ -111,6 +111,7 @@ type PageMenu = {
111111
>;
112112
};
113113

114+
/** built-in UserScript events */
114115
export type eventName =
115116
| "lines:changed"
116117
| "page:changed"

userscript/blocks.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { Node, NodeWithoutIndent } from "./nodes.ts";
2+
import { Line } from "../base.ts";
23

34
export type ParsedLine =
5+
& Line
46
& {
5-
text: string;
6-
id: string;
7-
userId: string;
8-
updated: number;
9-
created: number;
107
section: {
118
number: number;
129
start: boolean;

0 commit comments

Comments
 (0)