Skip to content

Commit c5a50b6

Browse files
authored
Merge pull request #207 from takker99/export-push
feat: Export `push`
2 parents 5d03fe6 + 7fffd4f commit c5a50b6

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

browser/websocket/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./socket.ts";
2+
export * from "./push.ts";
23
export * from "./patch.ts";
34
export * from "./deletePage.ts";
45
export * from "./pin.ts";

browser/websocket/push.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ export type PushError =
6868
| NetworkError
6969
| AbortError;
7070

71+
/**
72+
* pushしたいcommitを作る関数
73+
*
74+
* {@linkcode push} で使う
75+
*
76+
* @param page ページのメタデータ
77+
* @param attempts 何回目の試行か
78+
* @param prev 前回のcommitの変更
79+
* @param reason 再試行した場合、その理由が渡される
80+
* @returns commits
81+
*/
82+
export type CommitMakeHandler = (
83+
page: PushMetadata,
84+
attempts: number,
85+
prev: Change[] | [DeletePageChange] | [PinChange],
86+
reason?: "NotFastForwardError" | "DuplicateTitleError",
87+
) =>
88+
| Promise<Change[] | [DeletePageChange] | [PinChange]>
89+
| Change[]
90+
| [DeletePageChange]
91+
| [PinChange];
92+
7193
/** 特定のページのcommitをpushする
7294
*
7395
* serverからpush errorが返ってきた場合、エラーに応じてpushを再試行する
@@ -81,16 +103,7 @@ export type PushError =
81103
export const push = async (
82104
project: string,
83105
title: string,
84-
makeCommit: (
85-
page: PushMetadata,
86-
attempts: number,
87-
prev: Change[] | [DeletePageChange] | [PinChange],
88-
reason?: "NotFastForwardError" | "DuplicateTitleError",
89-
) =>
90-
| Promise<Change[] | [DeletePageChange] | [PinChange]>
91-
| Change[]
92-
| [DeletePageChange]
93-
| [PinChange],
106+
makeCommit: CommitMakeHandler,
94107
options?: PushOptions,
95108
): Promise<Result<string, PushError>> => {
96109
const result = await connect(options?.socket);

0 commit comments

Comments
 (0)