Skip to content

Commit 781e098

Browse files
authored
Merge pull request #28 from takker99/add-commit
✨ Implement types related to /api/commits/:projectname/:pageid
2 parents 1d95e00 + 317856b commit 781e098

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

change.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { BasePage, LineId, StringLc } from "./base.ts";
2+
3+
/** ページの変更内容 */
4+
export type Change =
5+
| InsertChange
6+
| UpdateChange
7+
| DeleteChange
8+
| LinksChange
9+
| DescriptionsChange
10+
| ImageChange
11+
| TitleChange
12+
| PinChange;
13+
14+
/** 行を新規作成する変更 */
15+
export interface InsertChange {
16+
/** このIDが示す行の上に挿入する
17+
*
18+
* 末尾に挿入するときは`"_end"`を指定する
19+
*/
20+
_insert: LineId;
21+
22+
/** 挿入する行のデータ */
23+
lines: NewLine;
24+
}
25+
26+
export interface NewLine {
27+
/** 新しく挿入する行のID */
28+
id: LineId;
29+
30+
/** 行のテキスト */
31+
text: string;
32+
}
33+
34+
/** 既存の行を書き換える変更 */
35+
export interface UpdateChange {
36+
/** 書き換える行のID */
37+
_update: LineId;
38+
39+
/** 行の変更内容 */
40+
lines: ChangeLine;
41+
}
42+
43+
export interface ChangeLine {
44+
/**変更前の文字列*/
45+
origText: string;
46+
47+
/**変更後の文字列*/
48+
text: string;
49+
}
50+
51+
/** 既存の行を削除する変更 */
52+
export interface DeleteChange {
53+
/** 削除する行のID */
54+
_delete: LineId;
55+
56+
/** 常に `-1` */
57+
lines: -1;
58+
}
59+
60+
/** ページ中のリンクが変更されると発生する */
61+
export interface LinksChange {
62+
/** 新しいリンク */
63+
links: string[];
64+
65+
/** 新しいリンク */
66+
linksLc: StringLc[];
67+
}
68+
69+
/** ページのサムネイル本文が変更されると発生する */
70+
export interface DescriptionsChange {
71+
/** 新しいサムネイル本文 */
72+
descriptions: string[];
73+
}
74+
75+
/** ページのサムネイルが変更されると発生する */
76+
export interface ImageChange {
77+
/** 新しいサムネイルのURL
78+
*
79+
* サムネイルがなくなったときは`null`になる
80+
*/
81+
image: string | null;
82+
}
83+
84+
/** ページのタイトルが変更されると発生する */
85+
export interface TitleChange {
86+
/** 新しいタイトル */
87+
title: string;
88+
89+
/** 新しいタイトル */
90+
titleLc: StringLc;
91+
}
92+
93+
/** ページのピンの状態が変更されると発生する */
94+
export interface PinChange {
95+
pin: BasePage["pin"];
96+
}

commit.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { CommitId, PageId, UnixTime, UserId } from "./base.ts";
2+
import { Change } from "./change.ts";
3+
4+
/** Scrapboxのページの編集commit */
5+
export interface Commit {
6+
id: CommitId;
7+
8+
/** 一つ前のcommitのID
9+
*
10+
* 存在しないときは`null`になる
11+
*/
12+
parentId: CommitId | null;
13+
14+
pageId: PageId;
15+
16+
/** commitの作成者 */
17+
userId: UserId;
18+
19+
/** commitの作成日時 */
20+
created: UnixTime;
21+
22+
/** 変更内容 */
23+
changes: Change[];
24+
25+
/** 詳細不明 */
26+
kind: "page";
27+
}

response.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
UnixTime,
88
UserId,
99
} from "./base.ts";
10+
import { Commit } from "./commit.ts";
1011

1112
/** 関連ページのメタデータ */
1213
export interface RelatedPage extends BasePage {
@@ -254,3 +255,9 @@ export interface SearchQuery {
254255
/** NOT検索に使う語句 */
255256
excludes: string[];
256257
}
258+
259+
/** the response type of /api/commits/:projectname/:pageid */
260+
export interface CommitsResponse {
261+
/** 指定したページのcommits */
262+
commits: Commit[];
263+
}

rest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** @module types used at REST API */
22

33
export * from "./base.ts";
4+
export * from "./commit.ts";
5+
export * from "./change.ts";
46
export * from "./response.ts";
57
export * from "./error.ts";

0 commit comments

Comments
 (0)