refactor(parser): type YTNodes' data arg as RawNode (wip) (#339)

* replaced YTNode's data arg as RawNode

* updated documentation

* removed unused import

---- Note that there are still many nodes that need to be updated, hence the WIP status.
This commit is contained in:
Chinmay Kumar
2023-03-07 10:32:07 +05:30
committed by GitHub
parent 95033e723e
commit cfc1a183e0
90 changed files with 190 additions and 132 deletions

View File

@@ -1,4 +1,5 @@
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class AuthorCommentBadge extends YTNode {
static type = 'AuthorCommentBadge';
@@ -9,7 +10,7 @@ class AuthorCommentBadge extends YTNode {
tooltip: string;
style?: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.icon_type = data.icon?.iconType || null;

View File

@@ -16,6 +16,7 @@ import type Actions from '../../../core/Actions.js';
import Proto from '../../../proto/index.js';
import { InnertubeError } from '../../../utils/Utils.js';
import { YTNode, SuperParsedResult } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class Comment extends YTNode {
static type = 'Comment';
@@ -44,7 +45,7 @@ class Comment extends YTNode {
is_pinned: boolean;
is_member: boolean;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.content = new Text(data.contentText);
this.published = new Text(data.publishedTimeText);

View File

@@ -3,6 +3,7 @@ import type Button from '../Button.js';
import type ToggleButton from '../ToggleButton.js';
import type CreatorHeart from './CreatorHeart.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class CommentActionButtons extends YTNode {
static type = 'CommentActionButtons';
@@ -12,7 +13,7 @@ class CommentActionButtons extends YTNode {
reply_button;
creator_heart;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.like_button = Parser.parseItem<ToggleButton>(data.likeButton);
this.dislike_button = Parser.parseItem<ToggleButton>(data.dislikeButton);

View File

@@ -4,6 +4,7 @@ import Thumbnail from '../misc/Thumbnail.js';
import type Button from '../Button.js';
import type EmojiPicker from './EmojiPicker.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class CommentDialog extends YTNode {
static type = 'CommentDialog';
@@ -16,7 +17,7 @@ class CommentDialog extends YTNode {
emoji_button: Button | null;
emoji_picker: any | null;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.editable_text = new Text(data.editableText);
this.author_thumbnail = Thumbnail.fromResponse(data.authorThumbnail);

View File

@@ -2,7 +2,7 @@ import Parser from '../../index.js';
import Thumbnail from '../misc/Thumbnail.js';
import type Button from '../Button.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class CommentReplies extends YTNode {
static type = 'CommentReplies';
@@ -12,7 +12,7 @@ class CommentReplies extends YTNode {
view_replies_creator_thumbnail: Thumbnail[];
has_channel_owner_replied: boolean;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.contents = Parser.parseArray(data.contents);
this.view_replies = Parser.parseItem<Button>(data.viewReplies);

View File

@@ -3,6 +3,7 @@ import Thumbnail from '../misc/Thumbnail.js';
import Text from '../misc/Text.js';
import type Button from '../Button.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class CommentReplyDialog extends YTNode {
static type = 'CommentReplyDialog';
@@ -13,7 +14,7 @@ class CommentReplyDialog extends YTNode {
placeholder: Text;
error_message: Text;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.reply_button = Parser.parseItem<Button>(data.replyButton);
this.cancel_button = Parser.parseItem<Button>(data.cancelButton);

View File

@@ -3,6 +3,7 @@ import Thumbnail from '../misc/Thumbnail.js';
import Text from '../misc/Text.js';
import type Button from '../Button.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class CommentSimplebox extends YTNode {
static type = 'CommentSimplebox';
@@ -13,7 +14,7 @@ class CommentSimplebox extends YTNode {
placeholder: Text;
avatar_size;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.submit_button = Parser.parseItem<Button>(data.submitButton);
this.cancel_button = Parser.parseItem<Button>(data.cancelButton);

View File

@@ -7,6 +7,7 @@ import type Actions from '../../../core/Actions.js';
import type { ObservedArray } from '../../helpers.js';
import { InnertubeError } from '../../../utils/Utils.js';
import { observe, YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class CommentThread extends YTNode {
static type = 'CommentThread';
@@ -20,7 +21,7 @@ class CommentThread extends YTNode {
is_moderated_elq_comment: boolean;
has_replies: boolean;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.comment = Parser.parseItem<Comment>(data.comment, Comment);
this.comment_replies_data = Parser.parseItem<CommentReplies>(data.replies);

View File

@@ -1,6 +1,7 @@
import Text from '../misc/Text.js';
import Thumbnail from '../misc/Thumbnail.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class CommentsEntryPointHeader extends YTNode {
static type = 'CommentsEntryPointHeader';
@@ -11,7 +12,7 @@ class CommentsEntryPointHeader extends YTNode {
teaser_content?: Text;
simplebox_placeholder?: Text;
constructor(data: any) {
constructor(data: RawNode) {
super();
if (data.header) {

View File

@@ -3,6 +3,7 @@ import Text from '../misc/Text.js';
import Thumbnail from '../misc/Thumbnail.js';
import type SortFilterSubMenu from '../SortFilterSubMenu.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class CommentsHeader extends YTNode {
static type = 'CommentsHeader';
@@ -21,7 +22,7 @@ class CommentsHeader extends YTNode {
is_custom_emoji: boolean;
}[] | null;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.titleText);
this.count = new Text(data.countText);

View File

@@ -1,5 +1,6 @@
import { YTNode } from '../../helpers.js';
import Thumbnail from '../misc/Thumbnail.js';
import type { RawNode } from '../../index.js';
class CreatorHeart extends YTNode {
static type = 'CreatorHeart';
@@ -16,7 +17,7 @@ class CreatorHeart extends YTNode {
is_enabled: boolean;
kennedy_heart_color_string: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.creator_thumbnail = Thumbnail.fromResponse(data.creatorThumbnail);
this.heart_icon_type = data.heartIcon?.iconType;

View File

@@ -1,6 +1,7 @@
import Text from '../misc/Text.js';
import { YTNode } from '../../helpers.js';
import Parser from '../../index.js';
import type { RawNode } from '../../index.js';
class EmojiPicker extends YTNode {
static type = 'EmojiPicker';
@@ -19,7 +20,7 @@ class EmojiPicker extends YTNode {
skin_tone_medium_dark_label: string;
skin_tone_dark_label: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.id;
this.categories = Parser.parseArray(data.categories);

View File

@@ -1,5 +1,6 @@
import Text from '../misc/Text.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class PdgCommentChip extends YTNode {
static type = 'PdgCommentChip';
@@ -11,7 +12,7 @@ class PdgCommentChip extends YTNode {
};
icon_type: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.text = new Text(data.chipText);
this.color_pallette = {

View File

@@ -1,5 +1,6 @@
import Thumbnail from '../misc/Thumbnail.js';
import { YTNode } from '../../helpers.js';
import type { RawNode } from '../../index.js';
class SponsorCommentBadge extends YTNode {
static type = 'SponsorCommentBadge';
@@ -7,7 +8,7 @@ class SponsorCommentBadge extends YTNode {
custom_badge: Thumbnail[];
tooltip: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.custom_badge = Thumbnail.fromResponse(data.customBadge);
this.tooltip = data.tooltip;