Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/websocket/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./socket.ts";
export * from "./push.ts";
export * from "./patch.ts";
export * from "./deletePage.ts";
export * from "./pin.ts";
Expand Down
33 changes: 23 additions & 10 deletions browser/websocket/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ export type PushError =
| NetworkError
| AbortError;

/**
* pushしたいcommitを作る関数
*
* {@linkcode push} で使う
*
* @param page ページのメタデータ
* @param attempts 何回目の試行か
* @param prev 前回のcommitの変更
* @param reason 再試行した場合、その理由が渡される
* @returns commits
*/
export type CommitMakeHandler = (
page: PushMetadata,
attempts: number,
prev: Change[] | [DeletePageChange] | [PinChange],
reason?: "NotFastForwardError" | "DuplicateTitleError",
) =>
| Promise<Change[] | [DeletePageChange] | [PinChange]>
| Change[]
| [DeletePageChange]
| [PinChange];

/** 特定のページのcommitをpushする
*
* serverからpush errorが返ってきた場合、エラーに応じてpushを再試行する
Expand All @@ -81,16 +103,7 @@ export type PushError =
export const push = async (
project: string,
title: string,
makeCommit: (
page: PushMetadata,
attempts: number,
prev: Change[] | [DeletePageChange] | [PinChange],
reason?: "NotFastForwardError" | "DuplicateTitleError",
) =>
| Promise<Change[] | [DeletePageChange] | [PinChange]>
| Change[]
| [DeletePageChange]
| [PinChange],
makeCommit: CommitMakeHandler,
options?: PushOptions,
): Promise<Result<string, PushError>> => {
const result = await connect(options?.socket);
Expand Down