Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5618e2b

Browse files
Tweaked the object and interface properties
All object properties are now required, because they are set to `null` if missing. All interface properties are now optional, because they can be filtered out from requests (Note: Filters do not exist in this package yet).
1 parent c2455cf commit 5618e2b

34 files changed

+334
-318
lines changed

‎src/objects/Answer.ts‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {TypeAnswer} from '../result-types/TypeAnswer';
1010
*/
1111
export class Answer {
1212

13-
public accepted?: boolean;
13+
public accepted: boolean;
1414

1515
/**
1616
* Refers to an [[Answer]]
@@ -20,36 +20,36 @@ export class Answer {
2020
/**
2121
* *May be absent, in which case it is set to `null`*
2222
*/
23-
public awardedBountyAmount?: number;
23+
public awardedBountyAmount: number;
2424

2525
/**
2626
* *May be absent, in which case it is set to `null`*
2727
*/
28-
public awardedBountyUsers?: ShallowUser[];
28+
public awardedBountyUsers: ShallowUser[];
2929

30-
public body?: string;
30+
public body: string;
3131

32-
public bodyMarkdown?: string;
32+
public bodyMarkdown: string;
3333

34-
public canFlag?: boolean;
34+
public canFlag: boolean;
3535

36-
public commentCount?: number;
36+
public commentCount: number;
3737

3838
/**
3939
* *May be absent, in which case it is set to `null`*
4040
*/
41-
public comments?: Comment[];
41+
public comments: Comment[];
4242

4343
/**
4444
* *May be absent, in which case it is set to `null`*
4545
*/
46-
public communityOwnedDate?: Date;
46+
public communityOwnedDate: Date;
4747

4848
public creationDate: Date;
4949

50-
public downVoteCount?: number;
50+
public downVoteCount: number;
5151

52-
public downvoted?: boolean;
52+
public downvoted: boolean;
5353

5454
public isAccepted: boolean;
5555

@@ -58,21 +58,21 @@ export class Answer {
5858
/**
5959
* *May be absent, in which case it is set to `null`*
6060
*/
61-
public lastEditDate?: Date;
61+
public lastEditDate: Date;
6262

63-
public lastEditor?: ShallowUser;
63+
public lastEditor: ShallowUser;
6464

65-
public link?: string;
65+
public link: string;
6666

6767
/**
6868
* *May be absent, in which case it is set to `null`*
6969
*/
70-
public lockedDate?: Date;
70+
public lockedDate: Date;
7171

7272
/**
7373
* *May be absent, in which case it is set to `null`*
7474
*/
75-
public owner?: ShallowUser;
75+
public owner: ShallowUser;
7676

7777
/**
7878
* Refers to a [[Question]]
@@ -81,19 +81,19 @@ export class Answer {
8181

8282
public score: number;
8383

84-
public shareLink?: string;
84+
public shareLink: string;
8585

86-
public tags?: string[];
86+
public tags: string[];
8787

88-
public title?: string;
88+
public title: string;
8989

90-
public upVoteCount?: number;
90+
public upVoteCount: number;
9191

92-
public upvoted?: boolean;
92+
public upvoted: boolean;
9393

9494
public constructor (answer: TypeAnswer) {
9595
this.accepted = answer.accepted ?? null;
96-
this.answerId = answer.answer_id;
96+
this.answerId = answer.answer_id??null;
9797
this.awardedBountyAmount = answer.awarded_bounty_amount ?? null;
9898
if (typeof answer.awarded_bounty_users === 'undefined') {
9999
this.awardedBountyUsers = null;
@@ -112,11 +112,11 @@ export class Answer {
112112
.map((comment) => new Comment(comment));
113113
}
114114
this.communityOwnedDate = answer.community_owned_date ?? null;
115-
this.creationDate = answer.creation_date;
115+
this.creationDate = answer.creation_date??null;
116116
this.downVoteCount = answer.down_vote_count ?? null;
117117
this.downvoted = answer.downvoted ?? null;
118-
this.isAccepted = answer.is_accepted;
119-
this.lastActivityDate = answer.last_activity_date;
118+
this.isAccepted = answer.is_accepted??null;
119+
this.lastActivityDate = answer.last_activity_date??null;
120120
this.lastEditDate = answer.last_edit_date ?? null;
121121
if (typeof answer.last_editor === 'undefined') {
122122
this.lastEditor = null;
@@ -130,8 +130,8 @@ export class Answer {
130130
} else {
131131
this.owner = new ShallowUser(answer.owner);
132132
}
133-
this.questionId = answer.question_id;
134-
this.score = answer.score;
133+
this.questionId = answer.question_id??null;
134+
this.score = answer.score??null;
135135
this.shareLink = answer.share_link ?? null;
136136
this.tags = answer.tags ?? null;
137137
this.title = answer.title ?? null;

‎src/objects/Badge.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Badge {
1919

2020
public badgeType: 'named' | 'tag_based';
2121

22-
public description?: string;
22+
public description: string;
2323

2424
public link: string;
2525

@@ -30,16 +30,16 @@ export class Badge {
3030
/**
3131
* *May be absent, in which case it is set to `null`*
3232
*/
33-
public user?: ShallowUser;
33+
public user: ShallowUser;
3434

3535
public constructor (badge: TypeBadge) {
36-
this.awardCount = badge.award_count;
37-
this.badgeId = badge.badge_id;
38-
this.badgeType = badge.badge_type;
36+
this.awardCount = badge.award_count??null;
37+
this.badgeId = badge.badge_id??null;
38+
this.badgeType = badge.badge_type??null;
3939
this.description = badge.description ?? null;
40-
this.link = badge.link;
41-
this.name = badge.name;
42-
this.rank = badge.rank;
40+
this.link = badge.link??null;
41+
this.name = badge.name??null;
42+
this.rank = badge.rank??null;
4343
if (typeof badge.user === 'undefined') {
4444
this.user = null;
4545
} else {

‎src/objects/BadgeCount.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class BadgeCount {
1313
public silver: number;
1414

1515
public constructor (badge_count: TypeBadgeCount) {
16-
this.bronze = badge_count.bronze;
17-
this.gold = badge_count.gold;
18-
this.silver = badge_count.silver;
16+
this.bronze = badge_count.bronze??null;
17+
this.gold = badge_count.gold??null;
18+
this.silver = badge_count.silver??null;
1919
}
2020
}

‎src/objects/ClosedDetails.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class ClosedDetails {
1919
/**
2020
* *May be absent, in which case it is set to `null`*
2121
*/
22-
public originalQuestions?: OriginalQuestion[];
22+
public originalQuestions: OriginalQuestion[];
2323

2424
public reason: string;
2525

@@ -30,14 +30,14 @@ export class ClosedDetails {
3030
this.byUsers = closed_details.by_users
3131
.map((shallow_user) => new ShallowUser(shallow_user));
3232
}
33-
this.description = closed_details.description;
34-
this.onHold = closed_details.on_hold;
33+
this.description = closed_details.description??null;
34+
this.onHold = closed_details.on_hold??null;
3535
if (typeof closed_details.original_questions === 'undefined') {
3636
this.originalQuestions = null;
3737
} else {
3838
this.originalQuestions = closed_details.original_questions
3939
.map((original_question) => new OriginalQuestion(original_question));
4040
}
41-
this.reason = closed_details.reason;
41+
this.reason = closed_details.reason??null;
4242
}
4343
}

‎src/objects/Comment.ts‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {TypeComment} from '../result-types/TypeComment';
99
*/
1010
export class Comment {
1111

12-
public body?: string;
12+
public body: string;
1313

14-
public bodyMarkdown?: string;
14+
public bodyMarkdown: string;
1515

16-
public canFlag?: boolean;
16+
public canFlag: boolean;
1717

1818
/**
1919
* Refers to a [[Comment]]
@@ -24,50 +24,50 @@ export class Comment {
2424

2525
public edited: boolean;
2626

27-
public link?: string;
27+
public link: string;
2828

2929
/**
3030
* *May be absent, in which case it is set to `null`*
3131
*/
32-
public owner?: ShallowUser;
32+
public owner: ShallowUser;
3333

3434
/**
3535
* Refers to a [[Post]]
3636
*/
3737
public postId: number;
3838

39-
public postType?: 'question' | 'answer';
39+
public postType: 'question' | 'answer';
4040

4141
/**
4242
* *May be absent, in which case it is set to `null`*
4343
*/
44-
public replyToUser?: ShallowUser;
44+
public replyToUser: ShallowUser;
4545

4646
public score: number;
4747

48-
public upvoted?: boolean;
48+
public upvoted: boolean;
4949

5050
public constructor (comment: TypeComment) {
5151
this.body = comment.body ?? null;
5252
this.bodyMarkdown = comment.body_markdown ?? null;
5353
this.canFlag = comment.can_flag ?? null;
54-
this.commentId = comment.comment_id;
55-
this.creationDate = comment.creation_date;
56-
this.edited = comment.edited;
54+
this.commentId = comment.comment_id??null;
55+
this.creationDate = comment.creation_date??null;
56+
this.edited = comment.edited??null;
5757
this.link = comment.link ?? null;
5858
if (typeof comment.owner === 'undefined') {
5959
this.owner = null;
6060
} else {
6161
this.owner = new ShallowUser(comment.owner);
6262
}
63-
this.postId = comment.post_id;
63+
this.postId = comment.post_id??null;
6464
this.postType = comment.post_type ?? null;
6565
if (typeof comment.reply_to_user === 'undefined') {
6666
this.replyToUser = null;
6767
} else {
6868
this.replyToUser = new ShallowUser(comment.reply_to_user);
6969
}
70-
this.score = comment.score;
70+
this.score = comment.score??null;
7171
this.upvoted = comment.upvoted ?? null;
7272
}
7373
}

‎src/objects/Info.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Info {
1818

1919
public questionsPerMinute: number;
2020

21-
public site?: Site;
21+
public site: Site;
2222

2323
public totalAccepted: number;
2424

@@ -37,23 +37,23 @@ export class Info {
3737
public totalVotes: number;
3838

3939
public constructor (info: TypeInfo) {
40-
this.answersPerMinute = info.answers_per_minute;
41-
this.apiRevision = info.api_revision;
42-
this.badgesPerMinute = info.badges_per_minute;
43-
this.newActiveUsers = info.new_active_users;
44-
this.questionsPerMinute = info.questions_per_minute;
40+
this.answersPerMinute = info.answers_per_minute??null;
41+
this.apiRevision = info.api_revision??null;
42+
this.badgesPerMinute = info.badges_per_minute??null;
43+
this.newActiveUsers = info.new_active_users??null;
44+
this.questionsPerMinute = info.questions_per_minute??null;
4545
if (typeof info.site === 'undefined') {
4646
this.site = null;
4747
} else {
4848
this.site = new Site(info.site);
4949
}
50-
this.totalAccepted = info.total_accepted;
51-
this.totalAnswers = info.total_answers;
52-
this.totalBadges = info.total_badges;
53-
this.totalComments = info.total_comments;
54-
this.totalQuestions = info.total_questions;
55-
this.totalUnanswered = info.total_unanswered;
56-
this.totalUsers = info.total_users;
57-
this.totalVotes = info.total_votes;
50+
this.totalAccepted = info.total_accepted??null;
51+
this.totalAnswers = info.total_answers??null;
52+
this.totalBadges = info.total_badges??null;
53+
this.totalComments = info.total_comments??null;
54+
this.totalQuestions = info.total_questions??null;
55+
this.totalUnanswered = info.total_unanswered??null;
56+
this.totalUsers = info.total_users??null;
57+
this.totalVotes = info.total_votes??null;
5858
}
5959
}

‎src/objects/MigrationInfo.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ export class MigrationInfo {
1818
public questionId: number;
1919

2020
public constructor (migration_info: TypeMigrationInfo) {
21-
this.onDate = migration_info.on_date;
22-
this.otherSite = new Site(migration_info.other_site);
23-
this.questionId = migration_info.question_id;
21+
this.onDate = migration_info.on_date ?? null;
22+
if (typeof migration_info.other_site === 'undefined') {
23+
this.otherSite = null;
24+
} else {
25+
this.otherSite = new Site(migration_info.other_site);
26+
}
27+
this.questionId = migration_info.question_id ?? null;
2428
}
2529
}

‎src/objects/Notice.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class Notice {
1313
public ownerUserId: number;
1414

1515
public constructor (notice: TypeNotice) {
16-
this.body = notice.body;
17-
this.creationDate = notice.creation_date;
18-
this.ownerUserId = notice.owner_user_id;
16+
this.body = notice.body??null;
17+
this.creationDate = notice.creation_date??null;
18+
this.ownerUserId = notice.owner_user_id??null;
1919
}
2020
}

‎src/objects/OriginalQuestion.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class OriginalQuestion {
1010
/**
1111
* *May be absent, in which case it is set to `null`*
1212
*/
13-
public acceptedAnswerId?: number;
13+
public acceptedAnswerId: number;
1414

1515
public answerCount: number;
1616

@@ -23,8 +23,8 @@ export class OriginalQuestion {
2323

2424
public constructor (original_question: TypeOriginalQuestion) {
2525
this.acceptedAnswerId = original_question.accepted_answer_id ?? null;
26-
this.answerCount = original_question.answer_count;
27-
this.questionId = original_question.question_id;
28-
this.title = original_question.title;
26+
this.answerCount = original_question.answer_count??null;
27+
this.questionId = original_question.question_id??null;
28+
this.title = original_question.title??null;
2929
}
3030
}

‎src/objects/Privilege.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export class Privilege {
1414
public shortDescription: string;
1515

1616
public constructor (privilege: TypePrivilege) {
17-
this.description = privilege.description;
18-
this.reputation = privilege.reputation;
19-
this.shortDescription = privilege.short_description;
17+
this.description = privilege.description??null;
18+
this.reputation = privilege.reputation??null;
19+
this.shortDescription = privilege.short_description??null;
2020
}
2121
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /