Skip to content

Commit 5fb5763

Browse files
committed
refactor: Remove std/hash from vendor/ and Organize scrapbox-userscript-websocket roughly
1 parent c34e418 commit 5fb5763

25 files changed

+54
-362
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// this file is copied from https://cdn.esm.sh/v54/socket.io-client@4.2.0/build/index.d.ts
2-
import { ManagerOptions } from "./manager.ts";
3-
import { Socket, SocketOptions } from "./socket.ts";
2+
import type { ManagerOptions } from "./manager.ts";
3+
import type { Socket, SocketOptions } from "./socket.ts";
44
/**
55
* Looks up an existing `Manager` for multiplexing.
66
* If the user summons:
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// this file is copied from https://cdn.esm.sh/v54/socket.io-client@4.2.0/build/manager.d.ts
22
// deno-lint-ignore-file no-explicit-any camelcase ban-types
3-
import { Socket, SocketOptions } from "./socket.ts";
4-
import { Packet } from "./parser.ts";
3+
import type { Socket, SocketOptions } from "./socket.ts";
4+
import type { Packet } from "./parser.ts";
55
import {
6-
DefaultEventsMap,
7-
EventsMap,
6+
type DefaultEventsMap,
7+
type EventsMap,
88
StrictEventEmitter,
99
} from "./typed-events.ts";
1010
interface EngineOptions {
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// deno-lint-ignore-file no-explicit-any camelcase
22
// this file is copied from https://cdn.esm.sh/v54/socket.io-client@4.2.0/build/socket.d.ts
3-
import { Packet } from "./parser.ts";
4-
import { Manager } from "./manager.ts";
3+
import type { Packet } from "./parser.ts";
4+
import type { Manager } from "./manager.ts";
55
import {
6-
DefaultEventsMap,
7-
EventNames,
8-
EventParams,
9-
EventsMap,
6+
type DefaultEventsMap,
7+
type EventNames,
8+
type EventParams,
9+
type EventsMap,
1010
StrictEventEmitter,
1111
} from "./typed-events.ts";
1212
export interface SocketOptions {

browser/websocket/applyCommit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CommitNotification } from "../../deps/socket.ts";
1+
import type { CommitNotification } from "./websocket-types.ts";
22
import type { Page } from "@cosense/types/rest";
33
import { getUnixTimeFromId } from "./id.ts";
44
type Line = Page["lines"][number];

browser/websocket/diffToChanges.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
DeleteChange,
55
InsertChange,
66
UpdateChange,
7-
} from "../../deps/socket.ts";
7+
} from "./websocket-types.ts";
88
import { createNewLineId } from "./id.ts";
99

1010
type Options = {

browser/websocket/listen.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import {
1010
type Socket,
1111
socketIO,
1212
wrap,
13-
} from "../../deps/socket.ts";
13+
} from "./wrap.ts";
1414
import type { HTTPError } from "../../rest/responseIntoResult.ts";
1515
import type { AbortError, NetworkError } from "../../rest/robustFetch.ts";
1616
import { getProjectId } from "./pull.ts";
1717
import { connect, disconnect } from "./socket.ts";
1818
export type {
1919
ProjectUpdatesStreamCommit,
2020
ProjectUpdatesStreamEvent,
21-
} from "../../deps/socket.ts";
21+
} from "./websocket-types.ts";
2222

2323
export interface ListenStreamOptions {
2424
socket?: Socket;

browser/websocket/makeChanges.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { diffToChanges } from "./diffToChanges.ts";
22
import type { Page } from "@cosense/types/rest";
3-
import type { Change } from "../../deps/socket.ts";
3+
import type { Change } from "./websocket-types.ts";
44
import { findMetadata, getHelpfeels } from "./findMetadata.ts";
55
import { isSameArray } from "./isSameArray.ts";
66

browser/websocket/patch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Change, DeletePageChange, PinChange } from "../../deps/socket.ts";
1+
import type { Change, DeletePageChange, PinChange } from "./wrap.ts";
22
import { makeChanges } from "./makeChanges.ts";
33
import type { Page } from "@cosense/types/rest";
44
import { push, type PushError, type PushOptions } from "./push.ts";

browser/websocket/pin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Result } from "option-t/plain_result";
2-
import type { Change, Socket } from "../../deps/socket.ts";
2+
import type { Change, Socket } from "./wrap.ts";
33
import { push, type PushError, type PushOptions } from "./push.ts";
44

55
export interface PinOptions extends PushOptions {

browser/websocket/push.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
socketIO,
1111
type TimeoutError,
1212
wrap,
13-
} from "../../deps/socket.ts";
13+
} from "./wrap.ts";
1414
import { connect, disconnect } from "./socket.ts";
1515
import { pull } from "./pull.ts";
1616
import type {
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
ManagerOptions,
44
Socket,
55
SocketOptions,
6-
} from "./types/socketIO/index.ts";
6+
} from "./@types/socket-io/index.ts";
77
export type { Manager, ManagerOptions, Socket, SocketOptions };
88

99
export const socketIO = async (): Promise<Socket> => {

browser/websocket/socket.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { type Socket, socketIO } from "../../deps/socket.ts";
2-
export type { Socket } from "../../deps/socket.ts";
1+
import { type Socket, socketIO } from "./socket-io.ts";
2+
export type { Socket } from "./socket-io.ts";
33

44
/** 新しいsocketを作る */
55
export const makeSocket = (): Promise<Socket> => socketIO();

browser/websocket/updateCodeBlock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
DeleteChange,
44
InsertChange,
55
UpdateChange,
6-
} from "../../deps/socket.ts";
6+
} from "./websocket-types.ts";
77
import type { TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
88
import { diffToChanges } from "./diffToChanges.ts";
99
import { isSimpleCodeFile } from "./isSimpleCodeFile.ts";

browser/websocket/updateCodeFile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
DeleteChange,
44
InsertChange,
55
UpdateChange,
6-
} from "../../deps/socket.ts";
6+
} from "./websocket-types.ts";
77
import { getCodeBlocks, type TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
88
import { createNewLineId } from "./id.ts";
99
import { diff, toExtendedChanges } from "../../deps/onp.ts";
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import type { Socket } from "./socket.ts";
1+
import type { Socket } from "./socket-io.ts";
22
import {
3-
DataOf,
4-
EventMap,
5-
FailedResOf,
3+
type DataOf,
4+
type EventMap,
5+
type FailedResOf,
66
isPageCommitError,
7-
ListenEventMap,
8-
Result,
9-
SuccessResOf,
10-
TimeoutError,
11-
UnexpectedError,
12-
} from "./types.ts";
13-
export * from "./types.ts";
14-
export * from "./socket.ts";
7+
type ListenEventMap,
8+
type Result,
9+
type SuccessResOf,
10+
type TimeoutError,
11+
type UnexpectedError,
12+
} from "./websocket-types.ts";
13+
export * from "./websocket-types.ts";
14+
export * from "./socket-io.ts";
1515

1616
export interface SocketOperator {
1717
request: <EventName extends keyof EventMap>(

deno.jsonc

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"@progfay/scrapbox-parser": "jsr:@progfay/scrapbox-parser@9",
1717
"@std/assert": "jsr:@std/assert@1",
1818
"@std/async": "jsr:@std/async@1",
19-
"@std/hash": "./vendor/deno.land/std@0.160.0/hash/md5.ts",
19+
"@std/encoding": "jsr:@std/encoding@1",
20+
"@takker/md5": "jsr:@takker/md5@0.1",
2021
"@std/testing/snapshot": "jsr:@std/testing@0/snapshot",
2122
"@takker/onp": "./vendor/raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts",
22-
"@takker/scrapbox-userscript-websocket": "./vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/mod.ts",
2323
"option-t": "npm:option-t@^49.1.0"
2424
},
2525
"exports": {

deno.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps/socket.ts

-1
This file was deleted.

rest/uploadToGCS.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
setDefaults,
66
} from "./options.ts";
77
import type { ErrorLike, NotFoundError } from "@cosense/types/rest";
8-
import { Md5 } from "@std/hash";
8+
import { md5 } from "@takker/md5";
9+
import { encodeHex } from "@std/encoding/hex";
910
import {
1011
createOk,
1112
isErr,
@@ -46,14 +47,14 @@ export const uploadToGCS = async (
4647
projectId: string,
4748
options?: ExtendedOptions,
4849
): Promise<Result<GCSFile, UploadGCSError | FetchError>> => {
49-
const md5 = `${new Md5().update(await file.arrayBuffer())}`;
50-
const res = await uploadRequest(file, projectId, md5, options);
50+
const md5Hash = `${encodeHex(md5(await file.arrayBuffer()))}`;
51+
const res = await uploadRequest(file, projectId, md5Hash, options);
5152
if (isErr(res)) return res;
5253
const fileOrRequest = unwrapOk(res);
5354
if ("embedUrl" in fileOrRequest) return createOk(fileOrRequest);
5455
const result = await upload(fileOrRequest.signedUrl, file, options);
5556
if (isErr(result)) return result;
56-
return verify(projectId, fileOrRequest.fileId, md5, options);
57+
return verify(projectId, fileOrRequest.fileId, md5Hash, options);
5758
};
5859

5960
/** 容量を使い切ったときに発生するerror */

vendor/deno.land/std@0.160.0/encoding/hex.ts

-67
This file was deleted.

0 commit comments

Comments
 (0)