-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from takker99/deal-with-push-errors
feat(websocket): websocketから返されるcommit errorを適切に処理する
- Loading branch information
Showing
12 changed files
with
313 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,22 @@ | ||
import { Socket, socketIO, wrap } from "../../deps/socket.ts"; | ||
import { connect, disconnect } from "./socket.ts"; | ||
import { getProjectId, getUserId } from "./id.ts"; | ||
import { pull } from "./pull.ts"; | ||
import { pushWithRetry } from "./_fetch.ts"; | ||
import { push, PushOptions, RetryError } from "./push.ts"; | ||
import { Result } from "../../rest/util.ts"; | ||
|
||
export interface DeletePageOptions { | ||
socket?: Socket; | ||
} | ||
export type DeletePageOptions = PushOptions; | ||
|
||
/** 指定したページを削除する | ||
* | ||
* @param project 削除したいページのproject | ||
* @param title 削除したいページのタイトル | ||
* @param options 使用したいSocketがあれば指定する | ||
* @param options | ||
*/ | ||
export const deletePage = async ( | ||
export const deletePage = ( | ||
project: string, | ||
title: string, | ||
options?: DeletePageOptions, | ||
): Promise<void> => { | ||
const [ | ||
{ id: pageId, commitId: parentId, persistent }, | ||
projectId, | ||
userId, | ||
] = await Promise.all([ | ||
pull(project, title), | ||
getProjectId(project), | ||
getUserId(), | ||
]); | ||
|
||
if (!persistent) return; | ||
|
||
const injectedSocket = options?.socket; | ||
const socket = injectedSocket ?? await socketIO(); | ||
await connect(socket); | ||
const { request } = wrap(socket); | ||
try { | ||
await pushWithRetry(request, [{ deleted: true }], { | ||
projectId, | ||
pageId, | ||
parentId, | ||
userId, | ||
project, | ||
title, | ||
}); | ||
} finally { | ||
if (!injectedSocket) await disconnect(socket); | ||
} | ||
}; | ||
): Promise<Result<string, RetryError>> => | ||
push( | ||
project, | ||
title, | ||
(page) => page.persistent ? [{ deleted: true }] : [], | ||
options, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.