Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@userscripters/stackexchange-api-types

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@userscripters/stackexchange-api-types - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

2

generator/index.ts

@@ -40,2 +40,3 @@ import got from "got";

const typeNameSel = ".mainbar > .subheader h1";
const typeFieldsSel = ".indented > .method";

@@ -108,2 +109,3 @@ const typeWrappers = indented.filter(

typeNameSel,
typeFieldsSel,
typeReqSel,

@@ -110,0 +112,0 @@ unionRegex,

74

generator/parsers.ts

@@ -43,10 +43,12 @@ import type { KeywordTypeSyntaxKind, Modifier, NodeFactory } from "typescript";

* @summary parses type members into array of PropertySignature
* @param {NodeFactory} f compiler factory to use
* @param {Element[]} fields type description fields
* @param {string} modifierSelector selector for matching optionality modifier
* @param {RegExp} unionRegex regular expression to split union members
* @param factory compiler factory to use
* @param fields type description fields
* @param modifierSelector selector for matching optionality modifier
* @param unionRegex regular expression to split union members
*/
export const parseFields = (
f: NodeFactory,
factory: NodeFactory,
fields: Element[],
nameSelector: string,
descrSelector: string,
modifierSelector: string,

@@ -57,9 +59,11 @@ unionRegex: RegExp

const optional = !!field.querySelector(modifierSelector);
const name = text(field.querySelector(".method-name")!);
const [desc] = (
field.querySelector(".method-description")!.textContent || ""
)
.trim()
.split("\n");
const name = text(field.querySelector(nameSelector)!);
const descrElement = field.querySelector(descrSelector);
const [desc] = (descrElement!.textContent || "").trim().split("\n");
const canBeMissing = !!descrElement?.querySelector(
"a[href*='/absent-fields']"
);
const [type] = desc.split(/,/);

@@ -71,8 +75,8 @@ const [, item] = /array of (.+)s/i.exec(desc) || [];

const keyword = desc.includes(" or ")
? parseUnion(f, desc, unionRegex)
: parseKeyword(f, key);
? parseUnion(factory, desc, unionRegex)
: parseKeyword(factory, key);
const node = item ? f.createArrayTypeNode(keyword) : keyword;
const node = item ? factory.createArrayTypeNode(keyword) : keyword;
return createProperty(f, name, node, optional);
return createProperty(factory, name, node, optional || canBeMissing);
});

@@ -88,12 +92,14 @@ };

* @summary parses type description into InterfaceDeclaration
* @param {NodeFactory} f compiler factory to use
* @param {Document} document document element to parse from
* @param {string} nameSelector interface identifier selector
* @param {string} modifierSelector selector for matching optionality modifier
* @param {RegExp} unionRegex regular expression to split union members
* @param factory compiler factory to use
* @param document document element to parse from
* @param nameSelector interface identifier selector
* @param fieldsSelector interface fields selector
* @param modifierSelector selector for matching optionality modifier
* @param unionRegex regular expression to split union members
*/
export const parseInterface = (
f: NodeFactory,
factory: NodeFactory,
document: Document,
nameSelector: string,
fieldsSelector: string,
modifierSelector: string,

@@ -103,7 +109,14 @@ unionRegex: RegExp,

) => {
const { textContent } = document.querySelector(nameSelector)!;
const name = normalizeTypeName(textContent!.replace(/type\s+/i, ""));
const { textContent } = document.querySelector(nameSelector) || {};
const name = normalizeTypeName(textContent?.replace(/type\s+/i, "") || "");
const typeFields = [...document.querySelectorAll(".indented > .method")];
const fields = parseFields(f, typeFields, modifierSelector, unionRegex);
const typeFields = [...document.querySelectorAll(fieldsSelector)];
const fields = parseFields(
factory,
typeFields,
".method-name",
".method-description",
modifierSelector,
unionRegex
);

@@ -119,3 +132,7 @@ const overridden = fields.map((field) => {

return override
? createProperty(f, fieldName, f.createKeywordTypeNode(override))
? createProperty(
factory,
fieldName,
factory.createKeywordTypeNode(override)
)
: field;

@@ -125,5 +142,6 @@ });

const modifiers: Modifier[] = [];
if (exported) modifiers.push(f.createModifier(ts.SyntaxKind.ExportKeyword));
if (exported)
modifiers.push(factory.createModifier(ts.SyntaxKind.ExportKeyword));
return f.createInterfaceDeclaration(
return factory.createInterfaceDeclaration(
undefined,

@@ -130,0 +148,0 @@ modifiers,

@@ -15,3 +15,3 @@ export interface Answer {

comments?: Comment[];
community_owned_date: number;
community_owned_date?: number;
content_license: string;

@@ -23,7 +23,7 @@ creation_date: number;

last_activity_date: number;
last_edit_date: number;
last_edit_date?: number;
last_editor?: ShallowUser;
link?: string;
locked_date: number;
owner: ShallowUser;
locked_date?: number;
owner?: ShallowUser;
posted_by_collectives: Collective[];

@@ -43,4 +43,4 @@ question_id: number;

account_id: number;
expires_on_date: number;
scope: string[];
expires_on_date?: number;
scope?: string[];
}

@@ -51,3 +51,3 @@

achievement_type: "badge" | "privilege" | "reputation";
badge_rank: "gold" | "silver" | "bronze";
badge_rank?: "gold" | "silver" | "bronze";
creation_date: number;

@@ -57,3 +57,3 @@ is_unread: boolean;

on_site: Site;
reputation_change: number;
reputation_change?: number;
title: string;

@@ -70,3 +70,3 @@ }

rank: "gold" | "silver" | "bronze";
user: ShallowUser;
user?: ShallowUser;
}

@@ -88,3 +88,3 @@

dimensions: string[];
download_link: string;
download_link?: string;
end_date: number;

@@ -95,3 +95,3 @@ health_report_dimensions?: ("date" | "page_views" | "unique_users" | "tag" | "total_questions" | "open_question" | "answered_questions" | "total_comments" | "total_answers" | "community_member_questions" | "community_member_answers" | "community_member_comments" | "percent_response_24hrs" | "percent_answer_24hrss")[];

name: string;
report_id: number;
report_id?: number;
report_type: "unknown" | "user" | "activity" | "health";

@@ -112,6 +112,6 @@ start_date: number;

link?: string;
owner: ShallowUser;
owner?: ShallowUser;
post_id: number;
post_type?: "question" | "answer" | "article";
reply_to_user: ShallowUser;
reply_to_user?: ShallowUser;
score: number;

@@ -142,20 +142,20 @@ upvoted?: boolean;

export interface FlagOption {
count: number;
description: string;
dialog_title: string;
has_flagged: boolean;
is_retraction: boolean;
option_id: number;
count?: number;
description?: string;
dialog_title?: string;
has_flagged?: boolean;
is_retraction?: boolean;
option_id?: number;
question?: Question;
requires_comment: boolean;
requires_question_id: boolean;
requires_site: boolean;
sub_options: FlagOption[];
title: string;
requires_comment?: boolean;
requires_question_id?: boolean;
requires_site?: boolean;
sub_options?: FlagOption[];
title?: string;
}
export interface InboxItem {
answer_id: number;
answer_id?: number;
body?: string;
comment_id: number;
comment_id?: number;
creation_date: number;

@@ -165,4 +165,4 @@ is_unread: boolean;

link: string;
question_id: number;
site: Site;
question_id?: number;
site?: Site;
title: string;

@@ -214,9 +214,9 @@ }

api_site_parameter: string;
badge_id: number;
badge_id?: number;
creation_date: number;
description: string;
link: string;
post_id: number;
score: number;
tags: string[];
post_id?: number;
score?: number;
tags?: string[];
title: string;

@@ -230,3 +230,3 @@ }

notification_type: "generic" | "profile_activity" | "bounty_expired" | "bounty_expires_in_one_day" | "badge_earned" | "bounty_expires_in_three_days" | "reputation_bonus" | "accounts_associated" | "new_privilege" | "post_migrated" | "moderator_message" | "registration_reminder" | "edit_suggested" | "substantive_edit" | "bounty_grace_period_started";
post_id: number;
post_id?: number;
site: Site;

@@ -238,3 +238,3 @@ }

body_markdown?: string;
collectives: Collective[];
collectives?: Collective[];
comment_count?: number;

@@ -247,9 +247,9 @@ comments?: Comment[];

last_activity_date: number;
last_edit_date: number;
last_edit_date?: number;
last_editor?: ShallowUser;
link: string;
owner: ShallowUser;
owner?: ShallowUser;
post_id: number;
post_type: "question" | "answer" | "article";
posted_by_collectives: Collective[];
posted_by_collectives?: Collective[];
score: number;

@@ -269,3 +269,3 @@ share_link?: string;

export interface Question {
accepted_answer_id: number;
accepted_answer_id?: number;
answer_count: number;

@@ -275,4 +275,4 @@ answers?: Answer[];

body_markdown?: string;
bounty_amount: number;
bounty_closes_date: number;
bounty_amount?: number;
bounty_closes_date?: number;
bounty_user?: ShallowUser;

@@ -286,9 +286,9 @@ can_answer?: boolean;

close_vote_count?: number;
closed_date: number;
closed_date?: number;
closed_details?: ClosedDetails;
closed_reason: string;
closed_reason?: string;
collectives: Collective[];
comment_count?: number;
comments?: Comment[];
community_owned_date: number;
community_owned_date?: number;
content_license: string;

@@ -303,12 +303,12 @@ creation_date: number;

last_activity_date: number;
last_edit_date: number;
last_edit_date?: number;
last_editor?: ShallowUser;
link: string;
locked_date: number;
migrated_from: MigrationInfo;
migrated_to: MigrationInfo;
locked_date?: number;
migrated_from?: MigrationInfo;
migrated_to?: MigrationInfo;
notice?: Notice;
owner: ShallowUser;
owner?: ShallowUser;
posted_by_collectives: Collective[];
protected_date: number;
protected_date?: number;
question_id: number;

@@ -326,13 +326,13 @@ reopen_vote_count?: number;

export interface QuestionTimeline {
comment_id: number;
content_license: string;
comment_id?: number;
content_license?: string;
creation_date: number;
down_vote_count: number;
owner: ShallowUser;
post_id: number;
down_vote_count?: number;
owner?: ShallowUser;
post_id?: number;
question_id: number;
revision_guid: string;
revision_guid?: string;
timeline_type: "question" | "answer" | "comment" | "unaccepted_answer" | "accepted_answer" | "vote_aggregate" | "revision" | "post_state_changed";
up_vote_count: number;
user: ShallowUser;
up_vote_count?: number;
user?: ShallowUser;
}

@@ -353,3 +353,3 @@

creation_date: number;
post_id: number;
post_id?: number;
reputation_change: number;

@@ -367,12 +367,12 @@ reputation_history_type: "asker_accepts_answer" | "asker_unaccept_answer" | "answer_accepted" | "answer_unaccepted" | "voter_downvotes" | "voter_undownvotes" | "post_downvoted" | "post_undownvoted" | "post_upvoted" | "post_unupvoted" | "suggested_edit_approval_received" | "post_flagged_as_spam" | "post_flagged_as_offensive" | "bounty_given" | "bounty_earned" | "bounty_cancelled" | "post_deleted" | "post_undeleted" | "association_bonus" | "arbitrary_reputation_change" | "vote_fraud_reversal" | "post_migrated" | "user_deleted" | "example_upvoted" | "example_unupvoted" | "proposed_change_approved" | "doc_link_upvoted" | "doc_link_unupvoted" | "doc_source_removed" | "suggested_edit_approval_overridden";

last_body?: string;
last_tags: string[];
last_title: string;
last_tags?: string[];
last_title?: string;
post_id: number;
post_type: "question" | "answer" | "article";
revision_guid: string;
revision_number: number;
revision_number?: number;
revision_type: "single_user" | "vote_based";
set_community_wiki: boolean;
tags: string[];
title: string;
tags?: string[];
title?: string;
user: ShallowUser;

@@ -382,4 +382,4 @@ }

export interface SearchExcerpt {
answer_count: number;
answer_id: number;
answer_count?: number;
answer_id?: number;
body: string;

@@ -389,7 +389,7 @@ closed_date?: number;

creation_date: number;
equivalent_tag_search: string[];
equivalent_tag_search?: string[];
excerpt: string;
has_accepted_answer: boolean;
is_accepted: boolean;
is_answered: boolean;
has_accepted_answer?: boolean;
is_accepted?: boolean;
is_answered?: boolean;
item_type: "question" | "answer";

@@ -400,6 +400,6 @@ last_activity_date: number;

owner?: ShallowUser;
question_id: number;
question_score: number;
question_id?: number;
question_score?: number;
score: number;
tags: string[];
tags?: string[];
title: string;

@@ -409,15 +409,15 @@ }

export interface Site {
aliases: string[];
aliases?: string[];
api_site_parameter: string;
audience: string;
closed_beta_date: number;
closed_beta_date?: number;
favicon_url: string;
high_resolution_icon_url: string;
high_resolution_icon_url?: string;
icon_url: string;
launch_date: number;
logo_url: string;
markdown_extensions: ("MathJax" | "Prettify" | "Balsamiq" | "jTab" | "strings")[];
markdown_extensions?: ("MathJax" | "Prettify" | "Balsamiq" | "jTab" | "strings")[];
name: string;
open_beta_date: number;
related_sites: RelatedSite[];
open_beta_date?: number;
related_sites?: RelatedSite[];
site_state: "normal" | "closed_beta" | "open_beta" | "linked_meta";

@@ -427,7 +427,7 @@ site_type: "main_site" | "meta_site";

styling: Styling;
twitter_account: string;
twitter_account?: string;
}
export interface SuggestedEdit {
approval_date: number;
approval_date?: number;
body?: string;

@@ -438,11 +438,11 @@ comment: string;

post_type: "question" | "answer" | "article";
proposing_user: ShallowUser;
rejection_date: number;
proposing_user?: ShallowUser;
rejection_date?: number;
suggested_edit_id: number;
tags: string[];
title: string;
tags?: string[];
title?: string;
}
export interface Tag {
collectives: Collective[];
collectives?: Collective[];
count: number;

@@ -455,3 +455,3 @@ has_synonyms: boolean;

synonyms?: string[];
user_id: number;
user_id?: number;
}

@@ -475,3 +475,3 @@

from_tag: string;
last_applied_date: number;
last_applied_date?: number;
to_tag: string;

@@ -482,5 +482,5 @@ }

body?: string;
body_last_edit_date: number;
excerpt: string;
excerpt_last_edit_date: number;
body_last_edit_date?: number;
excerpt?: string;
excerpt_last_edit_date?: number;
last_body_editor?: ShallowUser;

@@ -502,8 +502,8 @@ last_excerpt_editor?: ShallowUser;

about_me?: string;
accept_rate: number;
accept_rate?: number;
account_id: number;
age: number;
age?: number;
answer_count?: number;
badge_counts: BadgeCount;
collectives: CollectiveMembership[];
collectives?: CollectiveMembership[];
creation_date: number;

@@ -514,5 +514,5 @@ display_name: string;

last_access_date: number;
last_modified_date: number;
last_modified_date?: number;
link: string;
location: string;
location?: string;
profile_image: string;

@@ -526,3 +526,3 @@ question_count?: number;

reputation_change_year: number;
timed_penalty_date: number;
timed_penalty_date?: number;
up_vote_count?: number;

@@ -532,16 +532,16 @@ user_id: number;

view_count?: number;
website_url: string;
website_url?: string;
}
export interface UserTimeline {
badge_id: number;
comment_id: number;
badge_id?: number;
comment_id?: number;
creation_date: number;
detail: string;
detail?: string;
link?: string;
post_id: number;
post_id?: number;
post_type: "question" | "answer" | "article";
suggested_edit_id: number;
suggested_edit_id?: number;
timeline_type: "commented" | "asked" | "answered" | "badge" | "revision" | "accepted" | "reviewed" | "suggested";
title: string;
title?: string;
user_id: number;

@@ -561,10 +561,10 @@ }

export interface ShallowUser {
accept_rate: number;
accept_rate?: number;
account_id: number;
badge_counts?: BadgeCount;
display_name: string;
link: string;
profile_image: string;
reputation: number;
user_id: number;
display_name?: string;
link?: string;
profile_image?: string;
reputation?: number;
user_id?: number;
user_type: "unregistered" | "registered" | "moderator" | "team_admin" | "does_not_exist";

@@ -600,3 +600,3 @@ }

on_hold: boolean;
original_questions: OriginalQuestion[];
original_questions?: OriginalQuestion[];
reason: string;

@@ -606,3 +606,3 @@ }

export interface OriginalQuestion {
accepted_answer_id: number;
accepted_answer_id?: number;
answer_count: number;

@@ -626,3 +626,3 @@ question_id: number;

export interface RelatedSite {
api_site_parameter: string;
api_site_parameter?: string;
name: string;

@@ -629,0 +629,0 @@ relation: "parent" | "meta" | "chat";

{
"name": "@userscripters/stackexchange-api-types",
"description": "Stack Exchange API types generator",
"version": "1.0.0",
"version": "2.0.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Oleg Valter",

@@ -9,3 +9,3 @@

| License | [GPL-3.0-or-later](https://spdx.org/licenses/GPL-3.0-or-later) |
| Version | 1.0.0 |
| Version | 2.0.0 |

@@ -12,0 +12,0 @@ # Support

@@ -11,2 +11,2 @@ import { expectType } from "tsd";

expectType<Comment[] | undefined>(answer.comments);
expectType<ShallowUser>(answer.owner);
expectType<ShallowUser | undefined>(answer.owner);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc