Skip to content
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

[修正] xml2jsの型ガードを公開・型のインポートを修正 #91

Merged
merged 1 commit into from
Jan 4, 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
8 changes: 6 additions & 2 deletions src/@types/IComment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { CommentLoc, FormattedCommentWithSize, Position } from "@/@types/";
import type { IRenderer } from "@/@types/renderer";
import type {
CommentLoc,
FormattedCommentWithSize,
IRenderer,
Position,
} from "@/@types/";

export interface IComment {
comment: FormattedCommentWithSize;
Expand Down
3 changes: 1 addition & 2 deletions src/@types/IPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { IComment } from "@/@types/";
import type { IRenderer } from "@/@types/renderer";
import type { IComment, IRenderer } from "@/@types/";

export interface IPluginConstructor {
id: string;
Expand Down
1 change: 1 addition & 0 deletions src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from "./format.formatted";
export * from "./format.legacy";
export * from "./format.owner";
export * from "./format.v1";
export * from "./format.xml2js";
export * from "./IComment";
export * from "./input-parser";
export * from "./IPlugins";
Expand Down
2 changes: 1 addition & 1 deletion src/@types/input-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FormattedComment } from "@/@types/format.formatted";
import type { FormattedComment } from "@/@types/";

export interface InputParser {
key: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/@types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
OwnerComment,
RawApiResponse,
V1Thread,
Xml2jsPacket,
} from "@/@types/";
import type { Xml2jsPacket } from "@/@types/format.xml2js";

export const ZInputFormatType = union([
literal("XMLDocument"),
Expand Down
2 changes: 1 addition & 1 deletion src/comments/BaseComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type {
FormattedCommentWithFont,
FormattedCommentWithSize,
IComment,
IRenderer,
MeasureTextInput,
MeasureTextResult,
ParseContentResult,
Position,
} from "@/@types/";
import type { IRenderer } from "@/@types/renderer";
import { imageCache } from "@/contexts";
import { isDebug } from "@/contexts/debug";
import { config } from "@/definition/config";
Expand Down
2 changes: 1 addition & 1 deletion src/comments/FlashComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type {
FormattedComment,
FormattedCommentWithFont,
FormattedCommentWithSize,
IRenderer,
MeasureTextInput,
MeasureTextResult,
Position,
} from "@/@types/";
import type { IRenderer } from "@/@types/renderer";
import { config, options } from "@/definition/config";
import { TypeGuardError } from "@/errors/TypeGuardError";
import typeGuard from "@/typeGuard";
Expand Down
2 changes: 1 addition & 1 deletion src/comments/HTML5Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type {
FormattedCommentWithFont,
FormattedCommentWithSize,
HTML5Fonts,
IRenderer,
MeasureTextInput,
MeasureTextResult,
} from "@/@types/";
import type { IRenderer } from "@/@types/renderer";
import { config, options } from "@/definition/config";
import { TypeGuardError } from "@/errors/TypeGuardError";
import typeGuard from "@/typeGuard";
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRenderer } from "@/@types/renderer";
import type { IRenderer } from "@/@types/";

let imageCache: {
[key: string]: { image: IRenderer; timeout: number };
Expand Down
5 changes: 2 additions & 3 deletions src/input/xml2js.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { parse } from "valibot";

import type { FormattedComment, InputParser } from "@/@types";
import type { Xml2jsPacket } from "@/@types/format.xml2js";
import { ZXml2jsPacket } from "@/@types/format.xml2js";
import type { FormattedComment, InputParser, Xml2jsPacket } from "@/@types";
import { ZXml2jsPacket } from "@/@types/";

export const Xml2jsParser: InputParser = {
key: ["xml2js"],
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type {
IComment,
InputFormat,
IPluginList,
IRenderer,
Options,
Position,
Timeline,
} from "@/@types/";
import type { IRenderer } from "@/@types/renderer";
import { FlashComment } from "@/comments/";
import {
plugins,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRenderer } from "@/@types/renderer";
import type { IRenderer } from "@/@types/";
import { CanvasRenderingContext2DError } from "@/errors";

/**
Expand Down
11 changes: 11 additions & 0 deletions src/typeGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import type {
RawApiResponse,
V1Comment,
V1Thread,
Xml2jsChat,
Xml2jsChatItem,
Xml2jsPacket,
} from "@/@types/";
import {
ZApiChat,
Expand All @@ -58,6 +61,9 @@ import {
ZRawApiResponse,
ZV1Comment,
ZV1Thread,
ZXml2jsChat,
ZXml2jsChatItem,
ZXml2jsPacket,
} from "@/@types/";
import { colors } from "@/definition/colors";

Expand Down Expand Up @@ -117,6 +123,11 @@ const typeGuard = {
}
return true;
},
xml2js: {
packet: (i: unknown): i is Xml2jsPacket => is(ZXml2jsPacket, i),
chat: (i: unknown): i is Xml2jsChat => is(ZXml2jsChat, i),
chatItem: (i: unknown): i is Xml2jsChatItem => is(ZXml2jsChatItem, i),
},
legacyOwner: {
comments: (i: unknown): i is string =>
is(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/border.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRenderer } from "@/@types/renderer";
import type { IRenderer } from "@/@types/";

/**
* ボタンの左端枠を描画する
Expand Down
2 changes: 1 addition & 1 deletion src/utils/niconico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type {
CommentContentItem,
CommentHTML5Font,
CommentSize,
IRenderer,
MeasureInput,
} from "@/@types";
import type { IRenderer } from "@/@types/renderer";
import { config } from "@/definition/config";
import { TypeGuardError } from "@/errors/TypeGuardError";

Expand Down
3 changes: 1 addition & 2 deletions src/utils/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { FormattedComment } from "@/@types";
import type { IRenderer } from "@/@types/renderer";
import type { FormattedComment, IRenderer } from "@/@types";
import { HTML5Comment } from "@/comments";
import { config } from "@/definition/config";

Expand Down
Loading