Skip to content

build(deno-udd): Update Deno dependencies #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2024
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
62 changes: 39 additions & 23 deletions browser/websocket/_fetch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {
Change,
CommitNotification,
Delete,
Pin,
DeletePageChange,
PageCommitError,
PageCommitResponse,
PinChange,
ProjectUpdatesStreamCommit,
ProjectUpdatesStreamEvent,
Result,
TimeoutError,
UnexpectedError,
wrap,
} from "../../deps/socket.ts";
import { pull } from "./pull.ts";
Expand All @@ -22,28 +27,37 @@ export type PushCommitInit = {
userId: string;
};

export const pushCommit = async (
export const pushCommit = (
request: RequestFunc,
changes: Change[] | [Delete] | [Pin],
changes: Change[] | [DeletePageChange] | [PinChange],
commitInit: PushCommitInit,
) => {
if (changes.length === 0) return { commitId: commitInit.parentId };
const res = await request("socket.io-request", {
method: "commit",
data: {
kind: "page",
...commitInit,
changes,
cursor: null,
freeze: true,
},
});
return res as { commitId: string };
};
): Promise<
Result<
PageCommitResponse,
UnexpectedError | TimeoutError | PageCommitError
>
> =>
changes.length === 0
? Promise.resolve({ ok: true, value: { commitId: commitInit.parentId } })
: request("socket.io-request", {
method: "commit",
data: {
kind: "page",
...commitInit,
changes,
cursor: null,
freeze: true,
},
}) as Promise<
Result<
PageCommitResponse,
UnexpectedError | TimeoutError | PageCommitError
>
>;

export const pushWithRetry = async (
request: RequestFunc,
changes: Change[] | [Delete] | [Pin],
changes: Change[] | [DeletePageChange] | [PinChange],
{ project, title, retry = 3, parentId, ...commitInit }:
& PushCommitInit
& {
Expand All @@ -57,8 +71,9 @@ export const pushWithRetry = async (
parentId,
...commitInit,
});
parentId = res.commitId;
} catch (_e) {
if (!res.ok) throw Error("Faild to push a commit");
parentId = res.value.commitId;
} catch (_) {
console.log("Faild to push a commit. Retry after pulling new commits");
for (let i = 0; i < retry; i++) {
const { commitId } = await pull(project, title);
Expand All @@ -68,10 +83,11 @@ export const pushWithRetry = async (
parentId,
...commitInit,
});
parentId = res.commitId;
if (!res.ok) throw Error("Faild to push a commit");
parentId = res.value.commitId;
console.log("Success in retrying");
break;
} catch (_e) {
} catch (_) {
continue;
}
}
Expand Down
8 changes: 4 additions & 4 deletions browser/websocket/diffToChanges.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { diff, toExtendedChanges } from "../../deps/onp.ts";
import type { Line } from "../../deps/scrapbox.ts";
import type {
DeleteCommit,
InsertCommit,
UpdateCommit,
DeleteChange,
InsertChange,
UpdateChange,
} from "../../deps/socket.ts";
import { createNewLineId } from "./id.ts";

Expand All @@ -14,7 +14,7 @@ export function* diffToChanges(
left: Pick<Line, "text" | "id">[],
right: string[],
{ userId }: Options,
): Generator<DeleteCommit | InsertCommit | UpdateCommit, void, unknown> {
): Generator<DeleteChange | InsertChange | UpdateChange, void, unknown> {
const { buildSES } = diff(
left.map(({ text }) => text),
right,
Expand Down
12 changes: 6 additions & 6 deletions browser/websocket/updateCodeBlock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Line } from "../../deps/scrapbox-rest.ts";
import {
DeleteCommit,
InsertCommit,
DeleteChange,
InsertChange,
Socket,
socketIO,
UpdateCommit,
UpdateChange,
} from "../../deps/socket.ts";
import { TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
import { diffToChanges } from "./diffToChanges.ts";
Expand Down Expand Up @@ -91,9 +91,9 @@ const getCodeBody = (code: string | string[] | SimpleCodeFile): string[] => {

/** insertコミットの行IDとtextのインデントを修正する */
function* fixCommits(
commits: readonly (DeleteCommit | InsertCommit | UpdateCommit)[],
commits: readonly (DeleteChange | InsertChange | UpdateChange)[],
target: TinyCodeBlock,
): Generator<DeleteCommit | InsertCommit | UpdateCommit, void, unknown> {
): Generator<DeleteChange | InsertChange | UpdateChange, void, unknown> {
const { nextLine } = target;
const indent = " ".repeat(countBodyIndent(target));
for (const commit of commits) {
Expand Down Expand Up @@ -136,7 +136,7 @@ function* fixCommits(
const makeTitleChangeCommit = (
code: SimpleCodeFile,
target: Pick<TinyCodeBlock, "titleLine">,
): UpdateCommit | null => {
): UpdateChange | null => {
const lineId = target.titleLine.id;
const targetTitle = extractFromCodeTitle(target.titleLine.text);
if (
Expand Down
8 changes: 4 additions & 4 deletions browser/websocket/updateCodeFile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Line } from "../../deps/scrapbox-rest.ts";
import {
DeleteCommit,
InsertCommit,
DeleteChange,
InsertChange,
Socket,
socketIO,
UpdateCommit,
UpdateChange,
} from "../../deps/socket.ts";
import { getCodeBlocks, TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
import { pull } from "./pull.ts";
Expand Down Expand Up @@ -130,7 +130,7 @@ function* makeCommits(
UpdateCodeFileOptions["isInsertEmptyLineInTail"]
>;
},
): Generator<DeleteCommit | InsertCommit | UpdateCommit, void, unknown> {
): Generator<DeleteChange | InsertChange | UpdateChange, void, unknown> {
function makeIndent(codeBlock: Pick<TinyCodeBlock, "titleLine">): string {
return " ".repeat(countBodyIndent(codeBlock));
}
Expand Down
18 changes: 1 addition & 17 deletions deps/socket.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
export type {
Change,
CommitNotification,
Delete,
DeleteCommit,
InsertCommit,
ListenEventMap,
Pin,
ProjectUpdatesStreamCommit,
ProjectUpdatesStreamEvent,
Socket,
UpdateCommit,
} from "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.1.6/mod.ts";
export {
socketIO,
wrap,
} from "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.1.6/mod.ts";
export * from "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.1/mod.ts";
4 changes: 2 additions & 2 deletions deps/testing.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "https://deno.land/std@0.222.1/testing/asserts.ts";
export * from "https://deno.land/std@0.222.1/testing/snapshot.ts";
export * from "https://deno.land/std@0.223.0/testing/asserts.ts";
export * from "https://deno.land/std@0.223.0/testing/snapshot.ts";