Skip to content

Commit 7243e71

Browse files
authored
Merge pull request #164 from takker99:update-deno-dependencies
build(deno-udd): Update Deno dependencies
2 parents 8ab0bac + d07091d commit 7243e71

File tree

6 files changed

+56
-56
lines changed

6 files changed

+56
-56
lines changed

browser/websocket/_fetch.ts

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import {
22
Change,
33
CommitNotification,
4-
Delete,
5-
Pin,
4+
DeletePageChange,
5+
PageCommitError,
6+
PageCommitResponse,
7+
PinChange,
68
ProjectUpdatesStreamCommit,
79
ProjectUpdatesStreamEvent,
10+
Result,
11+
TimeoutError,
12+
UnexpectedError,
813
wrap,
914
} from "../../deps/socket.ts";
1015
import { pull } from "./pull.ts";
@@ -22,28 +27,37 @@ export type PushCommitInit = {
2227
userId: string;
2328
};
2429

25-
export const pushCommit = async (
30+
export const pushCommit = (
2631
request: RequestFunc,
27-
changes: Change[] | [Delete] | [Pin],
32+
changes: Change[] | [DeletePageChange] | [PinChange],
2833
commitInit: PushCommitInit,
29-
) => {
30-
if (changes.length === 0) return { commitId: commitInit.parentId };
31-
const res = await request("socket.io-request", {
32-
method: "commit",
33-
data: {
34-
kind: "page",
35-
...commitInit,
36-
changes,
37-
cursor: null,
38-
freeze: true,
39-
},
40-
});
41-
return res as { commitId: string };
42-
};
34+
): Promise<
35+
Result<
36+
PageCommitResponse,
37+
UnexpectedError | TimeoutError | PageCommitError
38+
>
39+
> =>
40+
changes.length === 0
41+
? Promise.resolve({ ok: true, value: { commitId: commitInit.parentId } })
42+
: request("socket.io-request", {
43+
method: "commit",
44+
data: {
45+
kind: "page",
46+
...commitInit,
47+
changes,
48+
cursor: null,
49+
freeze: true,
50+
},
51+
}) as Promise<
52+
Result<
53+
PageCommitResponse,
54+
UnexpectedError | TimeoutError | PageCommitError
55+
>
56+
>;
4357

4458
export const pushWithRetry = async (
4559
request: RequestFunc,
46-
changes: Change[] | [Delete] | [Pin],
60+
changes: Change[] | [DeletePageChange] | [PinChange],
4761
{ project, title, retry = 3, parentId, ...commitInit }:
4862
& PushCommitInit
4963
& {
@@ -57,8 +71,9 @@ export const pushWithRetry = async (
5771
parentId,
5872
...commitInit,
5973
});
60-
parentId = res.commitId;
61-
} catch (_e) {
74+
if (!res.ok) throw Error("Faild to push a commit");
75+
parentId = res.value.commitId;
76+
} catch (_) {
6277
console.log("Faild to push a commit. Retry after pulling new commits");
6378
for (let i = 0; i < retry; i++) {
6479
const { commitId } = await pull(project, title);
@@ -68,10 +83,11 @@ export const pushWithRetry = async (
6883
parentId,
6984
...commitInit,
7085
});
71-
parentId = res.commitId;
86+
if (!res.ok) throw Error("Faild to push a commit");
87+
parentId = res.value.commitId;
7288
console.log("Success in retrying");
7389
break;
74-
} catch (_e) {
90+
} catch (_) {
7591
continue;
7692
}
7793
}

browser/websocket/diffToChanges.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { diff, toExtendedChanges } from "../../deps/onp.ts";
22
import type { Line } from "../../deps/scrapbox.ts";
33
import type {
4-
DeleteCommit,
5-
InsertCommit,
6-
UpdateCommit,
4+
DeleteChange,
5+
InsertChange,
6+
UpdateChange,
77
} from "../../deps/socket.ts";
88
import { createNewLineId } from "./id.ts";
99

@@ -14,7 +14,7 @@ export function* diffToChanges(
1414
left: Pick<Line, "text" | "id">[],
1515
right: string[],
1616
{ userId }: Options,
17-
): Generator<DeleteCommit | InsertCommit | UpdateCommit, void, unknown> {
17+
): Generator<DeleteChange | InsertChange | UpdateChange, void, unknown> {
1818
const { buildSES } = diff(
1919
left.map(({ text }) => text),
2020
right,

browser/websocket/updateCodeBlock.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Line } from "../../deps/scrapbox-rest.ts";
22
import {
3-
DeleteCommit,
4-
InsertCommit,
3+
DeleteChange,
4+
InsertChange,
55
Socket,
66
socketIO,
7-
UpdateCommit,
7+
UpdateChange,
88
} from "../../deps/socket.ts";
99
import { TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
1010
import { diffToChanges } from "./diffToChanges.ts";
@@ -91,9 +91,9 @@ const getCodeBody = (code: string | string[] | SimpleCodeFile): string[] => {
9191

9292
/** insertコミットの行IDとtextのインデントを修正する */
9393
function* fixCommits(
94-
commits: readonly (DeleteCommit | InsertCommit | UpdateCommit)[],
94+
commits: readonly (DeleteChange | InsertChange | UpdateChange)[],
9595
target: TinyCodeBlock,
96-
): Generator<DeleteCommit | InsertCommit | UpdateCommit, void, unknown> {
96+
): Generator<DeleteChange | InsertChange | UpdateChange, void, unknown> {
9797
const { nextLine } = target;
9898
const indent = " ".repeat(countBodyIndent(target));
9999
for (const commit of commits) {
@@ -136,7 +136,7 @@ function* fixCommits(
136136
const makeTitleChangeCommit = (
137137
code: SimpleCodeFile,
138138
target: Pick<TinyCodeBlock, "titleLine">,
139-
): UpdateCommit | null => {
139+
): UpdateChange | null => {
140140
const lineId = target.titleLine.id;
141141
const targetTitle = extractFromCodeTitle(target.titleLine.text);
142142
if (

browser/websocket/updateCodeFile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Line } from "../../deps/scrapbox-rest.ts";
22
import {
3-
DeleteCommit,
4-
InsertCommit,
3+
DeleteChange,
4+
InsertChange,
55
Socket,
66
socketIO,
7-
UpdateCommit,
7+
UpdateChange,
88
} from "../../deps/socket.ts";
99
import { getCodeBlocks, TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
1010
import { pull } from "./pull.ts";
@@ -130,7 +130,7 @@ function* makeCommits(
130130
UpdateCodeFileOptions["isInsertEmptyLineInTail"]
131131
>;
132132
},
133-
): Generator<DeleteCommit | InsertCommit | UpdateCommit, void, unknown> {
133+
): Generator<DeleteChange | InsertChange | UpdateChange, void, unknown> {
134134
function makeIndent(codeBlock: Pick<TinyCodeBlock, "titleLine">): string {
135135
return " ".repeat(countBodyIndent(codeBlock));
136136
}

deps/socket.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
export type {
2-
Change,
3-
CommitNotification,
4-
Delete,
5-
DeleteCommit,
6-
InsertCommit,
7-
ListenEventMap,
8-
Pin,
9-
ProjectUpdatesStreamCommit,
10-
ProjectUpdatesStreamEvent,
11-
Socket,
12-
UpdateCommit,
13-
} from "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.1.6/mod.ts";
14-
export {
15-
socketIO,
16-
wrap,
17-
} from "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.1.6/mod.ts";
1+
export * from "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.1/mod.ts";

deps/testing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from "https://deno.land/std@0.222.1/testing/asserts.ts";
2-
export * from "https://deno.land/std@0.222.1/testing/snapshot.ts";
1+
export * from "https://deno.land/std@0.223.0/testing/asserts.ts";
2+
export * from "https://deno.land/std@0.223.0/testing/snapshot.ts";

0 commit comments

Comments
 (0)