Skip to content

Commit

Permalink
Merge pull request #207 from takker99/export-push
Browse files Browse the repository at this point in the history
feat: Export `push`
  • Loading branch information
takker99 authored Sep 26, 2024
2 parents 5d03fe6 + 7fffd4f commit c5a50b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
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

0 comments on commit c5a50b6

Please sign in to comment.