Skip to content

Commit 5baa0a9

Browse files
committed
CodeFileSimpleCodeFileへ変更
1 parent b440bd0 commit 5baa0a9

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

browser/websocket/updateCodeBlock.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TinyCodeBlock } from "../../rest/getCodeBlocks.ts";
1010
import { diffToChanges } from "./diffToChanges.ts";
1111
import { getUserId } from "./id.ts";
1212
import { pull } from "./pull.ts";
13-
import { CodeFile, isCodeFile } from "./updateCodeFile.ts";
13+
import { SimpleCodeFile, isSimpleCodeFile } from "./updateCodeFile.ts";
1414
import {
1515
applyCommit,
1616
countBodyIndent,
@@ -27,15 +27,15 @@ export interface UpdateCodeBlockOptions {
2727

2828
/** コードブロックの中身を更新する
2929
*
30-
* newCodeにCodeFileオブジェクトを渡すと、そのオブジェクトに添ってコードブロックのファイル名も書き換えます
30+
* newCodeにSimpleCodeFileオブジェクトを渡すと、そのオブジェクトに添ってコードブロックのファイル名も書き換えます
3131
* (文字列や文字列配列を渡した場合は書き換えません)。
3232
*
3333
* @param newCode 更新後のコードブロック
3434
* @param target 更新対象のコードブロック
3535
* @param project 更新対象のコードブロックが存在するプロジェクト名
3636
*/
3737
export const updateCodeBlock = async (
38-
newCode: string | string[] | CodeFile,
38+
newCode: string | string[] | SimpleCodeFile,
3939
target: TinyCodeBlock,
4040
options?: UpdateCodeBlockOptions,
4141
) => {
@@ -63,7 +63,7 @@ export const updateCodeBlock = async (
6363
userId,
6464
});
6565
const commits = [...fixCommits([...diffGenerator], target)];
66-
if (isCodeFile(newCode)) {
66+
if (isSimpleCodeFile(newCode)) {
6767
const titleCommit = makeTitleChangeCommit(newCode, target);
6868
if (titleCommit) commits.push(titleCommit);
6969
}
@@ -82,8 +82,8 @@ export const updateCodeBlock = async (
8282
};
8383

8484
/** コード本文のテキストを取得する */
85-
function getCodeBody(code: string | string[] | CodeFile): string[] {
86-
const content = isCodeFile(code) ? code.content : code;
85+
function getCodeBody(code: string | string[] | SimpleCodeFile): string[] {
86+
const content = isSimpleCodeFile(code) ? code.content : code;
8787
if (Array.isArray(content)) return content;
8888
return content.split("\n");
8989
}
@@ -133,7 +133,7 @@ function* fixCommits(
133133

134134
/** コードタイトルが違う場合は書き換える */
135135
function makeTitleChangeCommit(
136-
code: CodeFile,
136+
code: SimpleCodeFile,
137137
target: Pick<TinyCodeBlock, "titleLine">,
138138
): UpdateCommit | null {
139139
const lineId = target.titleLine.id;
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
/// <reference lib="deno.ns" />
22

33
import { assert, assertFalse } from "../../deps/testing.ts";
4-
import { CodeFile, isCodeFile } from "./updateCodeFile.ts";
4+
import { SimpleCodeFile, isSimpleCodeFile } from "./updateCodeFile.ts";
55

6-
const codeFile: CodeFile = {
6+
const codeFile: SimpleCodeFile = {
77
filename: "filename",
88
content: ["line 0", "line 1"],
99
lang: "language",
1010
};
1111

12-
Deno.test("isCodeFile()", async (t) => {
13-
await t.step("CodeFile object", () => {
14-
assert(isCodeFile(codeFile));
15-
assert(isCodeFile({ ...codeFile, content: "line 0" }));
16-
assert(isCodeFile({ ...codeFile, lang: undefined }));
12+
Deno.test("isSimpleCodeFile()", async (t) => {
13+
await t.step("SimpleCodeFile object", () => {
14+
assert(isSimpleCodeFile(codeFile));
15+
assert(isSimpleCodeFile({ ...codeFile, content: "line 0" }));
16+
assert(isSimpleCodeFile({ ...codeFile, lang: undefined }));
1717
});
1818
await t.step("similer objects", () => {
19-
assertFalse(isCodeFile({ ...codeFile, filename: 10 }));
20-
assertFalse(isCodeFile({ ...codeFile, content: 10 }));
21-
assertFalse(isCodeFile({ ...codeFile, content: [0, 1] }));
22-
assertFalse(isCodeFile({ ...codeFile, lang: 10 }));
19+
assertFalse(isSimpleCodeFile({ ...codeFile, filename: 10 }));
20+
assertFalse(isSimpleCodeFile({ ...codeFile, content: 10 }));
21+
assertFalse(isSimpleCodeFile({ ...codeFile, content: [0, 1] }));
22+
assertFalse(isSimpleCodeFile({ ...codeFile, lang: 10 }));
2323
});
2424
await t.step("other type values", () => {
25-
assertFalse(isCodeFile(10));
26-
assertFalse(isCodeFile(undefined));
27-
assertFalse(isCodeFile(["0", "1", "2"]));
25+
assertFalse(isSimpleCodeFile(10));
26+
assertFalse(isSimpleCodeFile(undefined));
27+
assertFalse(isSimpleCodeFile(["0", "1", "2"]));
2828
});
2929
});

browser/websocket/updateCodeFile.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { diff, toExtendedChanges } from "../../deps/onp.ts";
1313
import { applyCommit, countBodyIndent } from "./_codeBlock.ts";
1414

1515
/** コードブロックの上書きに使う情報のinterface */
16-
export interface CodeFile {
16+
export interface SimpleCodeFile {
1717
/** ファイル名 */
1818
filename: string;
1919

@@ -45,10 +45,10 @@ export interface UpdateCodeFileOptions {
4545
debug?: boolean;
4646
}
4747

48-
/** objectがCodeFile型かどうかを判別する */
49-
export function isCodeFile(obj: unknown): obj is CodeFile {
48+
/** objectがSimpleCodeFile型かどうかを判別する */
49+
export function isSimpleCodeFile(obj: unknown): obj is SimpleCodeFile {
5050
if (Array.isArray(obj) || !(obj instanceof Object)) return false;
51-
const code = obj as CodeFile;
51+
const code = obj as SimpleCodeFile;
5252
const { filename, content, lang } = code;
5353
return (
5454
typeof filename == "string" &&
@@ -72,7 +72,7 @@ export function isCodeFile(obj: unknown): obj is CodeFile {
7272
* @param options その他の設定
7373
*/
7474
export const updateCodeFile = async (
75-
codeFile: CodeFile,
75+
codeFile: SimpleCodeFile,
7676
project: string,
7777
title: string,
7878
options?: UpdateCodeFileOptions,
@@ -133,7 +133,7 @@ function flatCodeBodies(codeBlocks: readonly TinyCodeBlock[]): Line[] {
133133
/** コードブロックの差分からコミットデータを作成する */
134134
function* makeCommits(
135135
_codeBlocks: readonly TinyCodeBlock[],
136-
codeFile: CodeFile,
136+
codeFile: SimpleCodeFile,
137137
lines: Line[],
138138
{ userId, insertPositionIfNotExist, isInsertEmptyLineInTail }: {
139139
userId: string;
@@ -247,7 +247,7 @@ function* makeCommits(
247247
}
248248
}
249249

250-
function makeCodeBlockTitle(code: CodeFile) {
250+
function makeCodeBlockTitle(code: SimpleCodeFile) {
251251
const codeName = code.filename + (code.lang ? `(${code.lang})` : "");
252252
return `code:${codeName}`;
253253
}

0 commit comments

Comments
 (0)