Skip to content

Commit b888ac6

Browse files
committed
feat(websocket): Add /websocket submodule, which provides types about Websocket events used in Cosense
1 parent 790ef72 commit b888ac6

File tree

6 files changed

+362
-67
lines changed

6 files changed

+362
-67
lines changed

change.ts

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
import type { BasePage, LineId, StringLc } from "./base.ts";
1+
import type { LineId, StringLc } from "./base.ts";
2+
import type {
3+
ChangeLine,
4+
CharsCountChange,
5+
DeleteChange,
6+
DescriptionsChange,
7+
FilesChange,
8+
HelpFeelsChange,
9+
ImageChange,
10+
InfoboxDefinitionChange,
11+
InsertChange,
12+
LinesCountChange,
13+
PinChange,
14+
} from "./websocket/change.ts";
215

316
/** ページの変更内容 */
417
export type Change =
518
| InsertChange
619
| UpdateChange
720
| DeleteChange
821
| LinksChange
22+
| ProjectLinksChange
23+
| IconsChange
924
| DescriptionsChange
1025
| ImageChange
26+
| FilesChange
27+
| HelpFeelsChange
28+
| InfoboxDefinitionChange
1129
| TitleChange
30+
| LinesCountChange
31+
| CharsCountChange
1232
| PinChange;
1333

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-
3434
/** 既存の行を書き換える変更 */
3535
export interface UpdateChange {
3636
/** 書き換える行のID */
@@ -40,23 +40,6 @@ export interface UpdateChange {
4040
lines: ChangeLine;
4141
}
4242

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-
6043
/** ページ中のリンクが変更されると発生する */
6144
export interface LinksChange {
6245
/** 新しいリンク */
@@ -66,19 +49,22 @@ export interface LinksChange {
6649
linksLc: StringLc[];
6750
}
6851

69-
/** ページのサムネイル本文が変更されると発生する */
70-
export interface DescriptionsChange {
71-
/** 新しいサムネイル本文 */
72-
descriptions: string[];
52+
/** ページ中のproject linksが変更されると発生する */
53+
export interface ProjectLinksChange {
54+
/** 新しいリンク */
55+
projectLinks: string[];
56+
57+
/** 新しいリンク */
58+
projectLinksLc: StringLc[];
7359
}
7460

75-
/** ページのサムネイルが変更されると発生する */
76-
export interface ImageChange {
77-
/** 新しいサムネイルのURL
78-
*
79-
* サムネイルがなくなったときは`null`になる
80-
*/
81-
image: string | null;
61+
/** ページ中のiconsが変更されると発生する */
62+
export interface IconsChange {
63+
/** 新しいicons */
64+
icons: string[];
65+
66+
/** 新しいicons */
67+
iconsLc: StringLc[];
8268
}
8369

8470
/** ページのタイトルが変更されると発生する */
@@ -89,8 +75,3 @@ export interface TitleChange {
8975
/** 新しいタイトル */
9076
titleLc: StringLc;
9177
}
92-
93-
/** ページのピンの状態が変更されると発生する */
94-
export interface PinChange {
95-
pin: BasePage["pin"];
96-
}

deno.jsonc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
"fix": "deno fmt && deno lint --fix && deno test --allow-read --doc --parallel --shuffle && deno publish --dry-run --allow-dirty",
66
"check": "deno fmt --check && deno lint && deno test --allow-read --doc --parallel --shuffle && deno publish --dry-run",
77
"coverage": "deno test --allow-read=./ --parallel --shuffle --coverage && deno coverage --html",
8-
"doc": "deno doc --html rest.ts userscript.ts"
8+
"doc": "deno doc --html rest.ts userscript.ts websocket.ts"
99
},
1010
"imports": {
1111
"@std/testing/types": "jsr:@std/testing@0/types"
1212
},
1313
"exports": {
1414
"./rest": "./rest.ts",
15-
"./userscript": "./userscript.ts"
15+
"./userscript": "./userscript.ts",
16+
"./websocket": "./websocket.ts"
1617
},
1718
"compilerOptions": {
1819
"lib": [

deno.lock

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

websocket.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./websocket/change.ts";
2+
export * from "./websocket/event.ts";

websocket/change.ts

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import type { BasePage, LineId } from "../base.ts";
2+
3+
/** Changes to push to the cosense server */
4+
export type ChangeToPush =
5+
| InsertChange
6+
| UpdateChange
7+
| DeleteChange
8+
| LinksChange
9+
| ProjectLinksChange
10+
| IconsChange
11+
| DescriptionsChange
12+
| ImageChange
13+
| FilesChange
14+
| HelpFeelsChange
15+
| InfoboxDefinitionChange
16+
| TitleChange
17+
| LinesCountChange
18+
| CharsCountChange
19+
| PinChange;
20+
21+
/** 行を新規作成する変更 */
22+
export interface InsertChange {
23+
/** このIDが示す行の上に挿入する
24+
*
25+
* 末尾に挿入するときは`"_end"`を指定する
26+
*/
27+
_insert: LineId;
28+
29+
/** 挿入する行のデータ */
30+
lines: NewLine;
31+
}
32+
export interface NewLine {
33+
/** 新しく挿入する行のID */
34+
id: LineId;
35+
36+
/** 行のテキスト */
37+
text: string;
38+
}
39+
40+
export interface UpdateChange {
41+
_update: string;
42+
lines: Pick<ChangeLine, "text">;
43+
noTimestampUpdate?: unknown;
44+
}
45+
46+
export interface ChangeLine {
47+
/**変更前の文字列*/
48+
origText: string;
49+
50+
/**変更後の文字列*/
51+
text: string;
52+
}
53+
54+
/** 既存の行を削除する変更 */
55+
export interface DeleteChange {
56+
/** 削除する行のID */
57+
_delete: LineId;
58+
59+
/** 常に `-1` */
60+
lines: -1;
61+
}
62+
63+
export interface LinksChange {
64+
links: string[];
65+
}
66+
67+
export interface ProjectLinksChange {
68+
projectLinks: string[];
69+
}
70+
71+
export interface IconsChange {
72+
icons: string[];
73+
}
74+
75+
/** ページのサムネイル本文が変更されると発生する */
76+
export interface DescriptionsChange {
77+
/** 新しいサムネイル本文 */
78+
descriptions: string[];
79+
}
80+
81+
/** ページのサムネイルが変更されると発生する */
82+
export interface ImageChange {
83+
/** 新しいサムネイルのURL
84+
*
85+
* サムネイルがなくなったときは`null`になる
86+
*/
87+
image: string | null;
88+
}
89+
90+
export interface TitleChange {
91+
title: string;
92+
}
93+
94+
export interface FilesChange {
95+
/** Array of file IDs
96+
*
97+
* These IDs reference files that have been uploaded to the page.
98+
* Files can include images, documents, or other attachments.
99+
*/
100+
files: string[];
101+
}
102+
export interface HelpFeelsChange {
103+
/** Array of Helpfeel entries without the leading "? " prefix
104+
*
105+
* Helpfeel is a Scrapbox notation for creating help/documentation entries.
106+
* Example: "? How to use" becomes "How to use" in this array.
107+
* These entries are used to build the page's help documentation.
108+
*/
109+
helpfeels: string[];
110+
}
111+
112+
export interface InfoboxDefinitionChange {
113+
/** Array of trimmed lines from infobox tables
114+
*
115+
* Contains lines from tables marked with either `table:infobox` or `table:cosense`
116+
*/
117+
infoboxDefinition: string[];
118+
}
119+
120+
export interface LinesCountChange {
121+
linesCount: number;
122+
}
123+
124+
export interface CharsCountChange {
125+
charsCount: number;
126+
}
127+
128+
/** ページのピンの状態が変更されると発生する */
129+
export interface PinChange {
130+
pin: BasePage["pin"];
131+
}
132+
133+
export interface DeletePageChange {
134+
deleted: true;
135+
merged?: true;
136+
}

0 commit comments

Comments
 (0)